Merge changes from topic "presubmit-am-f2950471d1a747418b586b3c237b5a50" into sc-v2-dev am: d9fa19e00b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16681227

Change-Id: Icb1cddfd0d2a37af5e64c70ce085b6a9770c849c
This commit is contained in:
Joe Bolinger
2022-01-26 18:50:34 +00:00
committed by Automerger Merge Worker
11 changed files with 46 additions and 28 deletions

View File

@@ -25,6 +25,7 @@ import android.hardware.biometrics.IBiometricService;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.util.Slog; import android.util.Slog;
@@ -232,17 +233,14 @@ public class BiometricScheduler {
* Creates a new scheduler. * Creates a new scheduler.
* *
* @param tag for the specific instance of the scheduler. Should be unique. * @param tag for the specific instance of the scheduler. Should be unique.
* @param handler handler for callbacks (all methods of this class must be called on the
* thread associated with this handler)
* @param sensorType the sensorType that this scheduler is handling. * @param sensorType the sensorType that this scheduler is handling.
* @param gestureAvailabilityDispatcher may be null if the sensor does not support gestures * @param gestureAvailabilityDispatcher may be null if the sensor does not support gestures
* (such as fingerprint swipe). * (such as fingerprint swipe).
*/ */
public BiometricScheduler(@NonNull String tag, public BiometricScheduler(@NonNull String tag,
@NonNull Handler handler,
@SensorType int sensorType, @SensorType int sensorType,
@Nullable GestureAvailabilityDispatcher gestureAvailabilityDispatcher) { @Nullable GestureAvailabilityDispatcher gestureAvailabilityDispatcher) {
this(tag, handler, sensorType, gestureAvailabilityDispatcher, this(tag, new Handler(Looper.getMainLooper()), sensorType, gestureAvailabilityDispatcher,
IBiometricService.Stub.asInterface( IBiometricService.Stub.asInterface(
ServiceManager.getService(Context.BIOMETRIC_SERVICE)), ServiceManager.getService(Context.BIOMETRIC_SERVICE)),
LOG_NUM_RECENT_OPERATIONS, CoexCoordinator.getInstance()); LOG_NUM_RECENT_OPERATIONS, CoexCoordinator.getInstance());
@@ -376,8 +374,9 @@ public class BiometricScheduler {
// send ERROR_CANCELED and skip the operation. // send ERROR_CANCELED and skip the operation.
if (clientMonitor.interruptsPrecedingClients()) { if (clientMonitor.interruptsPrecedingClients()) {
for (BiometricSchedulerOperation operation : mPendingOperations) { for (BiometricSchedulerOperation operation : mPendingOperations) {
if (operation.markCanceling()) {
Slog.d(getTag(), "New client, marking pending op as canceling: " + operation); Slog.d(getTag(), "New client, marking pending op as canceling: " + operation);
operation.markCanceling(); }
} }
} }

View File

@@ -225,12 +225,13 @@ public class BiometricSchedulerOperation {
Slog.v(TAG, "Aborted: " + this); Slog.v(TAG, "Aborted: " + this);
} }
/** Flags this operation as canceled, but does not cancel it until started. */ /** Flags this operation as canceled, if possible, but does not cancel it until started. */
public void markCanceling() { public boolean markCanceling() {
if (mState == STATE_WAITING_IN_QUEUE && isInterruptable()) { if (mState == STATE_WAITING_IN_QUEUE && isInterruptable()) {
mState = STATE_WAITING_IN_QUEUE_CANCELING; mState = STATE_WAITING_IN_QUEUE_CANCELING;
Slog.v(TAG, "Marked cancelling: " + this); return true;
} }
return false;
} }
/** /**
@@ -280,6 +281,7 @@ public class BiometricSchedulerOperation {
@Override @Override
public void onClientFinished(@NonNull BaseClientMonitor clientMonitor, public void onClientFinished(@NonNull BaseClientMonitor clientMonitor,
boolean success) { boolean success) {
Slog.d(TAG, "[Finished / destroy]: " + clientMonitor);
mClientMonitor.destroy(); mClientMonitor.destroy();
mState = STATE_FINISHED; mState = STATE_FINISHED;
} }

View File

@@ -23,6 +23,7 @@ import android.annotation.Nullable;
import android.content.Context; import android.content.Context;
import android.hardware.biometrics.IBiometricService; import android.hardware.biometrics.IBiometricService;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.Slog; import android.util.Slog;
@@ -85,7 +86,7 @@ public class UserAwareBiometricScheduler extends BiometricScheduler {
} }
@VisibleForTesting @VisibleForTesting
UserAwareBiometricScheduler(@NonNull String tag, public UserAwareBiometricScheduler(@NonNull String tag,
@NonNull Handler handler, @NonNull Handler handler,
@SensorType int sensorType, @SensorType int sensorType,
@Nullable GestureAvailabilityDispatcher gestureAvailabilityDispatcher, @Nullable GestureAvailabilityDispatcher gestureAvailabilityDispatcher,
@@ -101,12 +102,11 @@ public class UserAwareBiometricScheduler extends BiometricScheduler {
} }
public UserAwareBiometricScheduler(@NonNull String tag, public UserAwareBiometricScheduler(@NonNull String tag,
@NonNull Handler handler,
@SensorType int sensorType, @SensorType int sensorType,
@Nullable GestureAvailabilityDispatcher gestureAvailabilityDispatcher, @Nullable GestureAvailabilityDispatcher gestureAvailabilityDispatcher,
@NonNull CurrentUserRetriever currentUserRetriever, @NonNull CurrentUserRetriever currentUserRetriever,
@NonNull UserSwitchCallback userSwitchCallback) { @NonNull UserSwitchCallback userSwitchCallback) {
this(tag, handler, sensorType, gestureAvailabilityDispatcher, this(tag, new Handler(Looper.getMainLooper()), sensorType, gestureAvailabilityDispatcher,
IBiometricService.Stub.asInterface( IBiometricService.Stub.asInterface(
ServiceManager.getService(Context.BIOMETRIC_SERVICE)), ServiceManager.getService(Context.BIOMETRIC_SERVICE)),
currentUserRetriever, userSwitchCallback, CoexCoordinator.getInstance()); currentUserRetriever, userSwitchCallback, CoexCoordinator.getInstance());

View File

@@ -494,7 +494,7 @@ public class Sensor {
mToken = new Binder(); mToken = new Binder();
mHandler = handler; mHandler = handler;
mSensorProperties = sensorProperties; mSensorProperties = sensorProperties;
mScheduler = new UserAwareBiometricScheduler(tag, mHandler, mScheduler = new UserAwareBiometricScheduler(tag,
BiometricScheduler.SENSOR_TYPE_FACE, null /* gestureAvailabilityDispatcher */, BiometricScheduler.SENSOR_TYPE_FACE, null /* gestureAvailabilityDispatcher */,
() -> mCurrentSession != null ? mCurrentSession.mUserId : UserHandle.USER_NULL, () -> mCurrentSession != null ? mCurrentSession.mUserId : UserHandle.USER_NULL,
new UserAwareBiometricScheduler.UserSwitchCallback() { new UserAwareBiometricScheduler.UserSwitchCallback() {

View File

@@ -363,7 +363,7 @@ public class Face10 implements IHwBinder.DeathRecipient, ServiceProvider {
@NonNull LockoutResetDispatcher lockoutResetDispatcher) { @NonNull LockoutResetDispatcher lockoutResetDispatcher) {
final Handler handler = new Handler(Looper.getMainLooper()); final Handler handler = new Handler(Looper.getMainLooper());
return new Face10(context, sensorProps, lockoutResetDispatcher, handler, return new Face10(context, sensorProps, lockoutResetDispatcher, handler,
new BiometricScheduler(TAG, handler, BiometricScheduler.SENSOR_TYPE_FACE, new BiometricScheduler(TAG, BiometricScheduler.SENSOR_TYPE_FACE,
null /* gestureAvailabilityTracker */)); null /* gestureAvailabilityTracker */));
} }
@@ -896,6 +896,8 @@ public class Face10 implements IHwBinder.DeathRecipient, ServiceProvider {
boolean success) { boolean success) {
if (success) { if (success) {
mCurrentUserId = targetUserId; mCurrentUserId = targetUserId;
} else {
Slog.w(TAG, "Failed to change user, still: " + mCurrentUserId);
} }
} }
}); });

View File

@@ -449,7 +449,7 @@ class Sensor {
mHandler = handler; mHandler = handler;
mSensorProperties = sensorProperties; mSensorProperties = sensorProperties;
mLockoutCache = new LockoutCache(); mLockoutCache = new LockoutCache();
mScheduler = new UserAwareBiometricScheduler(tag, handler, mScheduler = new UserAwareBiometricScheduler(tag,
BiometricScheduler.sensorTypeFromFingerprintProperties(mSensorProperties), BiometricScheduler.sensorTypeFromFingerprintProperties(mSensorProperties),
gestureAvailabilityDispatcher, gestureAvailabilityDispatcher,
() -> mCurrentSession != null ? mCurrentSession.mUserId : UserHandle.USER_NULL, () -> mCurrentSession != null ? mCurrentSession.mUserId : UserHandle.USER_NULL,

View File

@@ -360,7 +360,7 @@ public class Fingerprint21 implements IHwBinder.DeathRecipient, ServiceProvider
@NonNull LockoutResetDispatcher lockoutResetDispatcher, @NonNull LockoutResetDispatcher lockoutResetDispatcher,
@NonNull GestureAvailabilityDispatcher gestureAvailabilityDispatcher) { @NonNull GestureAvailabilityDispatcher gestureAvailabilityDispatcher) {
final BiometricScheduler scheduler = final BiometricScheduler scheduler =
new BiometricScheduler(TAG, handler, new BiometricScheduler(TAG,
BiometricScheduler.sensorTypeFromFingerprintProperties(sensorProps), BiometricScheduler.sensorTypeFromFingerprintProperties(sensorProps),
gestureAvailabilityDispatcher); gestureAvailabilityDispatcher);
final HalResultController controller = new HalResultController(sensorProps.sensorId, final HalResultController controller = new HalResultController(sensorProps.sensorId,
@@ -490,19 +490,25 @@ public class Fingerprint21 implements IHwBinder.DeathRecipient, ServiceProvider
!getEnrolledFingerprints(mSensorProperties.sensorId, targetUserId).isEmpty(); !getEnrolledFingerprints(mSensorProperties.sensorId, targetUserId).isEmpty();
final FingerprintUpdateActiveUserClient client = final FingerprintUpdateActiveUserClient client =
new FingerprintUpdateActiveUserClient(mContext, mLazyDaemon, targetUserId, new FingerprintUpdateActiveUserClient(mContext, mLazyDaemon, targetUserId,
mContext.getOpPackageName(), mSensorProperties.sensorId, mCurrentUserId, mContext.getOpPackageName(), mSensorProperties.sensorId,
hasEnrolled, mAuthenticatorIds, force); this::getCurrentUser, hasEnrolled, mAuthenticatorIds, force);
mScheduler.scheduleClientMonitor(client, new BaseClientMonitor.Callback() { mScheduler.scheduleClientMonitor(client, new BaseClientMonitor.Callback() {
@Override @Override
public void onClientFinished(@NonNull BaseClientMonitor clientMonitor, public void onClientFinished(@NonNull BaseClientMonitor clientMonitor,
boolean success) { boolean success) {
if (success) { if (success) {
mCurrentUserId = targetUserId; mCurrentUserId = targetUserId;
} else {
Slog.w(TAG, "Failed to change user, still: " + mCurrentUserId);
} }
} }
}); });
} }
private int getCurrentUser() {
return mCurrentUserId;
}
@Override @Override
public boolean containsSensor(int sensorId) { public boolean containsSensor(int sensorId) {
return mSensorProperties.sensorId == sensorId; return mSensorProperties.sensorId == sensorId;

View File

@@ -138,8 +138,7 @@ public class Fingerprint21UdfpsMock extends Fingerprint21 implements TrustManage
TestableBiometricScheduler(@NonNull String tag, @NonNull Handler handler, TestableBiometricScheduler(@NonNull String tag, @NonNull Handler handler,
@Nullable GestureAvailabilityDispatcher gestureAvailabilityDispatcher) { @Nullable GestureAvailabilityDispatcher gestureAvailabilityDispatcher) {
super(tag, handler, BiometricScheduler.SENSOR_TYPE_FP_OTHER, super(tag, BiometricScheduler.SENSOR_TYPE_FP_OTHER, gestureAvailabilityDispatcher);
gestureAvailabilityDispatcher);
} }
void init(@NonNull Fingerprint21UdfpsMock fingerprint21) { void init(@NonNull Fingerprint21UdfpsMock fingerprint21) {

View File

@@ -31,6 +31,7 @@ import com.android.server.biometrics.sensors.HalClientMonitor;
import java.io.File; import java.io.File;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier;
/** /**
* Sets the HAL's current active user, and updates the framework's authenticatorId cache. * Sets the HAL's current active user, and updates the framework's authenticatorId cache.
@@ -40,7 +41,7 @@ public class FingerprintUpdateActiveUserClient extends HalClientMonitor<IBiometr
private static final String TAG = "FingerprintUpdateActiveUserClient"; private static final String TAG = "FingerprintUpdateActiveUserClient";
private static final String FP_DATA_DIR = "fpdata"; private static final String FP_DATA_DIR = "fpdata";
private final int mCurrentUserId; private final Supplier<Integer> mCurrentUserId;
private final boolean mForceUpdateAuthenticatorId; private final boolean mForceUpdateAuthenticatorId;
private final boolean mHasEnrolledBiometrics; private final boolean mHasEnrolledBiometrics;
private final Map<Integer, Long> mAuthenticatorIds; private final Map<Integer, Long> mAuthenticatorIds;
@@ -48,8 +49,9 @@ public class FingerprintUpdateActiveUserClient extends HalClientMonitor<IBiometr
FingerprintUpdateActiveUserClient(@NonNull Context context, FingerprintUpdateActiveUserClient(@NonNull Context context,
@NonNull LazyDaemon<IBiometricsFingerprint> lazyDaemon, int userId, @NonNull LazyDaemon<IBiometricsFingerprint> lazyDaemon, int userId,
@NonNull String owner, int sensorId, int currentUserId, boolean hasEnrolledBiometrics, @NonNull String owner, int sensorId, Supplier<Integer> currentUserId,
@NonNull Map<Integer, Long> authenticatorIds, boolean forceUpdateAuthenticatorId) { boolean hasEnrolledBiometrics, @NonNull Map<Integer, Long> authenticatorIds,
boolean forceUpdateAuthenticatorId) {
super(context, lazyDaemon, null /* token */, null /* listener */, userId, owner, super(context, lazyDaemon, null /* token */, null /* listener */, userId, owner,
0 /* cookie */, sensorId, BiometricsProtoEnums.MODALITY_UNKNOWN, 0 /* cookie */, sensorId, BiometricsProtoEnums.MODALITY_UNKNOWN,
BiometricsProtoEnums.ACTION_UNKNOWN, BiometricsProtoEnums.CLIENT_UNKNOWN); BiometricsProtoEnums.ACTION_UNKNOWN, BiometricsProtoEnums.CLIENT_UNKNOWN);
@@ -63,7 +65,7 @@ public class FingerprintUpdateActiveUserClient extends HalClientMonitor<IBiometr
public void start(@NonNull Callback callback) { public void start(@NonNull Callback callback) {
super.start(callback); super.start(callback);
if (mCurrentUserId == getTargetUserId() && !mForceUpdateAuthenticatorId) { if (mCurrentUserId.get() == getTargetUserId() && !mForceUpdateAuthenticatorId) {
Slog.d(TAG, "Already user: " + mCurrentUserId + ", returning"); Slog.d(TAG, "Already user: " + mCurrentUserId + ", returning");
callback.onClientFinished(this, true /* success */); callback.onClientFinished(this, true /* success */);
return; return;
@@ -109,8 +111,10 @@ public class FingerprintUpdateActiveUserClient extends HalClientMonitor<IBiometr
@Override @Override
protected void startHalOperation() { protected void startHalOperation() {
try { try {
getFreshDaemon().setActiveGroup(getTargetUserId(), mDirectory.getAbsolutePath()); final int targetId = getTargetUserId();
mAuthenticatorIds.put(getTargetUserId(), mHasEnrolledBiometrics Slog.d(TAG, "Setting active user: " + targetId);
getFreshDaemon().setActiveGroup(targetId, mDirectory.getAbsolutePath());
mAuthenticatorIds.put(targetId, mHasEnrolledBiometrics
? getFreshDaemon().getAuthenticatorId() : 0L); ? getFreshDaemon().getAuthenticatorId() : 0L);
mCallback.onClientFinished(this, true /* success */); mCallback.onClientFinished(this, true /* success */);
} catch (RemoteException e) { } catch (RemoteException e) {

View File

@@ -33,6 +33,7 @@ import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
import com.android.server.biometrics.sensors.BiometricScheduler; import com.android.server.biometrics.sensors.BiometricScheduler;
import com.android.server.biometrics.sensors.CoexCoordinator;
import com.android.server.biometrics.sensors.LockoutCache; import com.android.server.biometrics.sensors.LockoutCache;
import com.android.server.biometrics.sensors.LockoutResetDispatcher; import com.android.server.biometrics.sensors.LockoutResetDispatcher;
import com.android.server.biometrics.sensors.LockoutTracker; import com.android.server.biometrics.sensors.LockoutTracker;
@@ -82,8 +83,10 @@ public class SensorTest {
new Handler(mLooper.getLooper()), new Handler(mLooper.getLooper()),
BiometricScheduler.SENSOR_TYPE_FACE, BiometricScheduler.SENSOR_TYPE_FACE,
null /* gestureAvailabilityDispatcher */, null /* gestureAvailabilityDispatcher */,
mBiometricService,
() -> USER_ID, () -> USER_ID,
mUserSwitchCallback); mUserSwitchCallback,
CoexCoordinator.getInstance());
mHalCallback = new Sensor.HalSessionCallback(mContext, new Handler(mLooper.getLooper()), mHalCallback = new Sensor.HalSessionCallback(mContext, new Handler(mLooper.getLooper()),
TAG, mScheduler, SENSOR_ID, TAG, mScheduler, SENSOR_ID,
USER_ID, mLockoutCache, mLockoutResetDispatcher, mHalSessionCallback); USER_ID, mLockoutCache, mLockoutResetDispatcher, mHalSessionCallback);

View File

@@ -33,6 +33,7 @@ import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
import com.android.server.biometrics.sensors.BiometricScheduler; import com.android.server.biometrics.sensors.BiometricScheduler;
import com.android.server.biometrics.sensors.CoexCoordinator;
import com.android.server.biometrics.sensors.LockoutCache; import com.android.server.biometrics.sensors.LockoutCache;
import com.android.server.biometrics.sensors.LockoutResetDispatcher; import com.android.server.biometrics.sensors.LockoutResetDispatcher;
import com.android.server.biometrics.sensors.LockoutTracker; import com.android.server.biometrics.sensors.LockoutTracker;
@@ -82,8 +83,10 @@ public class SensorTest {
new Handler(mLooper.getLooper()), new Handler(mLooper.getLooper()),
BiometricScheduler.SENSOR_TYPE_FP_OTHER, BiometricScheduler.SENSOR_TYPE_FP_OTHER,
null /* gestureAvailabilityDispatcher */, null /* gestureAvailabilityDispatcher */,
mBiometricService,
() -> USER_ID, () -> USER_ID,
mUserSwitchCallback); mUserSwitchCallback,
CoexCoordinator.getInstance());
mHalCallback = new Sensor.HalSessionCallback(mContext, new Handler(mLooper.getLooper()), mHalCallback = new Sensor.HalSessionCallback(mContext, new Handler(mLooper.getLooper()),
TAG, mScheduler, SENSOR_ID, TAG, mScheduler, SENSOR_ID,
USER_ID, mLockoutCache, mLockoutResetDispatcher, mHalSessionCallback); USER_ID, mLockoutCache, mLockoutResetDispatcher, mHalSessionCallback);