1 /* 2 * Copyright 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.remoteauth; 18 19 import android.annotation.Nullable; 20 import android.annotation.UserIdInt; 21 import android.content.Context; 22 import android.remoteauth.IDeviceDiscoveryListener; 23 import android.remoteauth.IRemoteAuthService; 24 25 import com.android.internal.util.Preconditions; 26 27 /** Service implementing remoteauth functionality. */ 28 public class RemoteAuthService extends IRemoteAuthService.Stub { 29 public static final String TAG = "RemoteAuthService"; 30 public static final String SERVICE_NAME = Context.REMOTE_AUTH_SERVICE; 31 RemoteAuthService(Context context)32 public RemoteAuthService(Context context) { 33 Preconditions.checkNotNull(context); 34 // TODO(b/290280702): Create here RemoteConnectivityManager and RangingManager 35 } 36 37 @Override isRemoteAuthSupported()38 public boolean isRemoteAuthSupported() { 39 // TODO(b/297301535): checkPermission(mContext, MANAGE_REMOTE_AUTH); 40 // TODO(b/290676192): integrate with RangingManager 41 // (check if UWB is supported by this device) 42 return true; 43 } 44 45 @Override registerDiscoveryListener( IDeviceDiscoveryListener deviceDiscoveryListener, @UserIdInt int userId, int timeoutMs, String packageName, @Nullable String attributionTag)46 public boolean registerDiscoveryListener( 47 IDeviceDiscoveryListener deviceDiscoveryListener, 48 @UserIdInt int userId, 49 int timeoutMs, 50 String packageName, 51 @Nullable String attributionTag) { 52 // TODO(b/297301535): checkPermission(mContext, MANAGE_REMOTE_AUTH); 53 // TODO(b/290280702): implement register discovery logic 54 return true; 55 } 56 57 @Override unregisterDiscoveryListener( IDeviceDiscoveryListener deviceDiscoveryListener, @UserIdInt int userId, String packageName, @Nullable String attributionTag)58 public void unregisterDiscoveryListener( 59 IDeviceDiscoveryListener deviceDiscoveryListener, 60 @UserIdInt int userId, 61 String packageName, 62 @Nullable String attributionTag) { 63 // TODO(b/297301535): checkPermission(mContext, MANAGE_REMOTE_AUTH); 64 // TODO(b/290094221): implement unregister logic 65 } 66 checkPermission(Context context, String permission)67 private static void checkPermission(Context context, String permission) { 68 context.enforceCallingOrSelfPermission( 69 permission, "Must have " + permission + " permission."); 70 } 71 } 72