Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Initial import of Face Unlock for S
Browse files Browse the repository at this point in the history
Change-Id: If784cd1283dade71e72995e828586e3be2b4abb0
  • Loading branch information
jhenrique09 committed Mar 20, 2022
1 parent e8a20fb commit 0b5c323
Show file tree
Hide file tree
Showing 19 changed files with 2,019 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/SystemUI/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ android_library {
"jsr330",
"lottie",
"vendor.lineage.powershare-V1.0-java",
"faceunlock_framework",
],
manifest: "AndroidManifest.xml",

Expand Down
1 change: 1 addition & 0 deletions services/core/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ java_library_static {
"overlayable_policy_aidl-java",
"SurfaceFlingerProperties",
"com.android.sysprop.watchdog",
"faceunlock_framework",
],
javac_shard_size: 50,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.android.server.biometrics.sensors.LockoutResetDispatcher;
import com.android.server.biometrics.sensors.LockoutTracker;
import com.android.server.biometrics.sensors.face.aidl.FaceProvider;
import com.android.server.biometrics.sensors.face.custom.CustomFaceProvider;
import com.android.server.biometrics.sensors.face.hidl.Face10;

import java.io.FileDescriptor;
Expand Down Expand Up @@ -652,6 +653,12 @@ private void addAidlProviders() {
}
}

private void addCustomProviders() {
if (CustomFaceProvider.useCustomFaceUnlockService()) {
mServiceProviders.add(new CustomFaceProvider(getContext(), new FaceSensorPropertiesInternal(CustomFaceProvider.DEVICE_ID, 0, 1, new ArrayList(), 1, false, false, false), mLockoutResetDispatcher));
}
}

@Override // Binder call
public void registerAuthenticators(
@NonNull List<FaceSensorPropertiesInternal> hidlSensors) {
Expand All @@ -669,6 +676,7 @@ public void registerAuthenticators(
handler.post(() -> {
addHidlProviders(hidlSensors);
addAidlProviders();
addCustomProviders();

final IBiometricService biometricService = IBiometricService.Stub.asInterface(
ServiceManager.getService(Context.BIOMETRIC_SERVICE));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2022 The Pixel Experience Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.server.biometrics.sensors.face.custom;

import java.util.ArrayList;

public class ArrayUtils {
public static ArrayList<Byte> toByteArrayList(byte[] in) {
if (in == null) {
return null;
}
ArrayList<Byte> out = new ArrayList<>(in.length);
for (byte c : in) {
out.add(c);
}
return out;
}

public static ArrayList<Integer> toIntArrayList(int[] in) {
if (in == null) {
return null;
}
ArrayList<Integer> out = new ArrayList<>(in.length);
for (int c : in) {
out.add(c);
}
return out;
}

public static int[] toIntArray(ArrayList<Integer> in) {
if (in == null) {
return null;
}
int[] out = new int[in.size()];
for (int i = 0; i < in.size(); i++) {
out[i] = in.get(i);
}
return out;
}

public static byte[] toByteArray(ArrayList<Byte> in) {
if (in == null) {
return null;
}
byte[] out = new byte[in.size()];
for (int i = 0; i < in.size(); i++) {
out[i] = in.get(i);
}
return out;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* Copyright (C) 2022 The Pixel Experience Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.server.biometrics.sensors.face.custom;

import android.content.Context;
import android.hardware.biometrics.ITestSession;
import android.hardware.biometrics.ITestSessionCallback;
import android.hardware.face.Face;
import android.hardware.face.FaceAuthenticationFrame;
import android.hardware.face.FaceEnrollFrame;
import android.hardware.face.IFaceServiceReceiver;
import android.os.Binder;
import android.os.RemoteException;
import android.util.Slog;

import com.android.server.biometrics.Utils;
import com.android.server.biometrics.sensors.BaseClientMonitor;
import com.android.server.biometrics.sensors.face.FaceUtils;

import java.util.List;
import java.util.Random;

public class BiometricTestSessionImpl extends ITestSession.Stub {
private static final String TAG = "BiometricTestSessionImpl";
private final ITestSessionCallback mCallback;
private final Context mContext;
private final CustomFaceProvider.HalResultController mHalResultController;
private final CustomFaceProvider mCustomFaceProvider;
private final int mSensorId;
private final IFaceServiceReceiver mReceiver = new IFaceServiceReceiver.Stub() {
@Override
public void onEnrollResult(Face face, int remaining) {
}

@Override
public void onAcquired(int acquiredInfo, int vendorCode) {
}

@Override
public void onAuthenticationSucceeded(Face face, int userId, boolean isStrongBiometric) {
}

@Override
public void onFaceDetected(int sensorId, int userId, boolean isStrongBiometric) {
}

@Override
public void onAuthenticationFailed() {
}

@Override
public void onError(int error, int vendorCode) {
}

@Override
public void onRemoved(Face face, int remaining) {
}

@Override
public void onFeatureSet(boolean success, int feature) {
}

@Override
public void onFeatureGet(boolean success, int[] features, boolean[] featureState) {
}

public void onChallengeGenerated(int sensorId, int userId, long challenge) {
}

@Override
public void onAuthenticationFrame(FaceAuthenticationFrame frame) {
}

@Override
public void onEnrollmentFrame(FaceEnrollFrame frame) {
}
};
private final Random mRandom = new Random();

public BiometricTestSessionImpl(Context context, int sensorId, ITestSessionCallback callback, CustomFaceProvider customFaceProvider, CustomFaceProvider.HalResultController halResultController) {
mContext = context;
mSensorId = sensorId;
mCallback = callback;
mCustomFaceProvider = customFaceProvider;
mHalResultController = halResultController;
}

public void setTestHalEnabled(boolean enabled) {
Utils.checkPermission(mContext, "android.permission.TEST_BIOMETRIC");
mCustomFaceProvider.setTestHalEnabled(enabled);
}

public void startEnroll(int userId) {
Utils.checkPermission(mContext, "android.permission.TEST_BIOMETRIC");
mCustomFaceProvider.scheduleEnroll(mSensorId, new Binder(), new byte[69], userId, mReceiver, mContext.getOpPackageName(), new int[0], null, false);
}

public void finishEnroll(int userId) {
Utils.checkPermission(mContext, "android.permission.TEST_BIOMETRIC");
mHalResultController.onEnrollResult(1, userId, 0);
}

public void acceptAuthentication(int userId) {
Utils.checkPermission(mContext, "android.permission.TEST_BIOMETRIC");
List<Face> faces = FaceUtils.getLegacyInstance(mSensorId).getBiometricsForUser(mContext, userId);
if (faces.isEmpty()) {
Slog.w(TAG, "No faces, returning");
} else {
mHalResultController.onAuthenticated(faces.get(0).getBiometricId(), userId, new byte[]{0});
}
}

public void rejectAuthentication(int userId) {
Utils.checkPermission(mContext, "android.permission.TEST_BIOMETRIC");
mHalResultController.onAuthenticated(0, userId, null);
}

public void notifyAcquired(int userId, int acquireInfo) {
Utils.checkPermission(mContext, "android.permission.TEST_BIOMETRIC");
mHalResultController.onAcquired(userId, acquireInfo, 0);
}

public void notifyError(int userId, int errorCode) {
Utils.checkPermission(mContext, "android.permission.TEST_BIOMETRIC");
mHalResultController.onError(errorCode, 0);
}

public void cleanupInternalState(int userId) {
Utils.checkPermission(mContext, "android.permission.TEST_BIOMETRIC");
mCustomFaceProvider.scheduleInternalCleanup(mSensorId, userId, new BaseClientMonitor.Callback() {
@Override
public void onClientStarted(BaseClientMonitor clientMonitor) {
try {
mCallback.onCleanupStarted(clientMonitor.getTargetUserId());
} catch (RemoteException e) {
Slog.e(BiometricTestSessionImpl.TAG, "Remote exception", e);
}
}

@Override
public void onClientFinished(BaseClientMonitor clientMonitor, boolean success) {
try {
mCallback.onCleanupFinished(clientMonitor.getTargetUserId());
} catch (RemoteException e) {
Slog.e(BiometricTestSessionImpl.TAG, "Remote exception", e);
}
}
});
}
}

0 comments on commit 0b5c323

Please sign in to comment.