1 /* 2 * Copyright (C) 2020 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.biometrics.sensors.face.hidl; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.content.Context; 22 import android.hardware.biometrics.face.V1_0.FaceError; 23 import android.hardware.biometrics.face.V1_0.IBiometricsFace; 24 import android.hardware.biometrics.face.V1_0.IBiometricsFaceClientCallback; 25 import android.hardware.biometrics.face.V1_0.OptionalBool; 26 import android.hardware.biometrics.face.V1_0.OptionalUint64; 27 import android.hardware.biometrics.face.V1_0.Status; 28 import android.hardware.face.Face; 29 import android.os.RemoteException; 30 import android.util.Slog; 31 32 import com.android.server.biometrics.sensors.face.FaceUtils; 33 34 import java.util.ArrayList; 35 import java.util.Collections; 36 import java.util.List; 37 38 public class TestHal extends IBiometricsFace.Stub { 39 private static final String TAG = "face.hidl.TestHal"; 40 41 @NonNull 42 private final Context mContext; 43 private final int mSensorId; 44 45 @Nullable 46 private IBiometricsFaceClientCallback mCallback; 47 private int mUserId; 48 TestHal(@onNull Context context, int sensorId)49 TestHal(@NonNull Context context, int sensorId) { 50 mContext = context; 51 mSensorId = sensorId; 52 } 53 54 @Override setCallback(IBiometricsFaceClientCallback clientCallback)55 public OptionalUint64 setCallback(IBiometricsFaceClientCallback clientCallback) { 56 mCallback = clientCallback; 57 final OptionalUint64 result = new OptionalUint64(); 58 result.status = Status.OK; 59 return new OptionalUint64(); 60 } 61 62 @Override setActiveUser(int userId, String storePath)63 public int setActiveUser(int userId, String storePath) { 64 mUserId = userId; 65 return 0; 66 } 67 68 @Override generateChallenge(int challengeTimeoutSec)69 public OptionalUint64 generateChallenge(int challengeTimeoutSec) { 70 Slog.w(TAG, "generateChallenge"); 71 final OptionalUint64 result = new OptionalUint64(); 72 result.status = Status.OK; 73 result.value = 0; 74 return result; 75 } 76 77 @Override enroll(ArrayList<Byte> hat, int timeoutSec, ArrayList<Integer> disabledFeatures)78 public int enroll(ArrayList<Byte> hat, int timeoutSec, ArrayList<Integer> disabledFeatures) { 79 Slog.w(TAG, "enroll"); 80 return 0; 81 } 82 83 @Override revokeChallenge()84 public int revokeChallenge() { 85 return 0; 86 } 87 88 @Override setFeature(int feature, boolean enabled, ArrayList<Byte> hat, int faceId)89 public int setFeature(int feature, boolean enabled, ArrayList<Byte> hat, int faceId) { 90 return 0; 91 } 92 93 @Override getFeature(int feature, int faceId)94 public OptionalBool getFeature(int feature, int faceId) { 95 final OptionalBool result = new OptionalBool(); 96 result.status = Status.OK; 97 result.value = true; 98 return result; 99 } 100 101 @Override getAuthenticatorId()102 public OptionalUint64 getAuthenticatorId() { 103 final OptionalUint64 result = new OptionalUint64(); 104 result.status = Status.OK; 105 result.value = 0; 106 return result; 107 } 108 109 @Override cancel()110 public int cancel() throws RemoteException { 111 if (mCallback != null) { 112 mCallback.onError(0 /* deviceId */, 0 /* userId */, FaceError.CANCELED, 113 0 /* vendorCode */); 114 } 115 return 0; 116 } 117 118 @Override enumerate()119 public int enumerate() throws RemoteException { 120 Slog.w(TAG, "enumerate"); 121 if (mCallback != null) { 122 mCallback.onEnumerate(0 /* deviceId */, new ArrayList<>(), 0 /* userId */); 123 } 124 return 0; 125 } 126 127 @Override remove(int faceId)128 public int remove(int faceId) throws RemoteException { 129 Slog.w(TAG, "remove"); 130 if (mCallback != null) { 131 if (faceId == 0) { 132 // For this HAL interface, remove(0) means to remove all enrollments. 133 final List<Face> faces = FaceUtils.getInstance(mSensorId) 134 .getBiometricsForUser(mContext, mUserId); 135 final ArrayList<Integer> faceIds = new ArrayList<>(); 136 for (Face face : faces) { 137 faceIds.add(face.getBiometricId()); 138 } 139 mCallback.onRemoved(0 /* deviceId */, faceIds, mUserId); 140 } else { 141 mCallback.onRemoved(0 /* deviceId */, 142 new ArrayList<>(Collections.singletonList(faceId)), 143 mUserId); 144 } 145 } 146 return 0; 147 } 148 149 @Override authenticate(long operationId)150 public int authenticate(long operationId) { 151 Slog.w(TAG, "authenticate"); 152 return 0; 153 } 154 155 @Override userActivity()156 public int userActivity() { 157 return 0; 158 } 159 160 @Override resetLockout(ArrayList<Byte> hat)161 public int resetLockout(ArrayList<Byte> hat) { 162 Slog.w(TAG, "resetLockout"); 163 return 0; 164 } 165 166 } 167