Merge "Update DozeSensors on fp enrollment changes" into sc-v2-dev

This commit is contained in:
TreeHugger Robot
2021-11-17 23:45:50 +00:00
committed by Android (Google) Code Review
2 changed files with 129 additions and 9 deletions

View File

@@ -16,6 +16,8 @@
package com.android.systemui.doze; package com.android.systemui.doze;
import static com.android.systemui.doze.DozeLog.REASON_SENSOR_QUICK_PICKUP;
import static com.android.systemui.doze.DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS;
import static com.android.systemui.plugins.SensorManagerPlugin.Sensor.TYPE_WAKE_DISPLAY; import static com.android.systemui.plugins.SensorManagerPlugin.Sensor.TYPE_WAKE_DISPLAY;
import static com.android.systemui.plugins.SensorManagerPlugin.Sensor.TYPE_WAKE_LOCK_SCREEN; import static com.android.systemui.plugins.SensorManagerPlugin.Sensor.TYPE_WAKE_LOCK_SCREEN;
@@ -98,6 +100,7 @@ public class DozeSensors {
private final DozeLog mDozeLog; private final DozeLog mDozeLog;
private final SecureSettings mSecureSettings; private final SecureSettings mSecureSettings;
private final DevicePostureController mDevicePostureController; private final DevicePostureController mDevicePostureController;
private final AuthController mAuthController;
private final boolean mScreenOffUdfpsEnabled; private final boolean mScreenOffUdfpsEnabled;
// Sensors // Sensors
@@ -115,6 +118,7 @@ public class DozeSensors {
private boolean mListening; private boolean mListening;
private boolean mListeningTouchScreenSensors; private boolean mListeningTouchScreenSensors;
private boolean mListeningProxSensors; private boolean mListeningProxSensors;
private boolean mUdfpsEnrolled;
@DevicePostureController.DevicePostureInt @DevicePostureController.DevicePostureInt
private int mDevicePosture; private int mDevicePosture;
@@ -169,10 +173,11 @@ public class DozeSensors {
config.screenOffUdfpsEnabled(KeyguardUpdateMonitor.getCurrentUser()); config.screenOffUdfpsEnabled(KeyguardUpdateMonitor.getCurrentUser());
mDevicePostureController = devicePostureController; mDevicePostureController = devicePostureController;
mDevicePosture = mDevicePostureController.getDevicePosture(); mDevicePosture = mDevicePostureController.getDevicePosture();
mAuthController = authController;
boolean udfpsEnrolled = mUdfpsEnrolled =
authController.isUdfpsEnrolled(KeyguardUpdateMonitor.getCurrentUser()); mAuthController.isUdfpsEnrolled(KeyguardUpdateMonitor.getCurrentUser());
boolean alwaysOn = mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT); mAuthController.addCallback(mAuthControllerCallback);
mTriggerSensors = new TriggerSensor[] { mTriggerSensors = new TriggerSensor[] {
new TriggerSensor( new TriggerSensor(
mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION), mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION),
@@ -221,7 +226,7 @@ public class DozeSensors {
findSensor(config.udfpsLongPressSensorType()), findSensor(config.udfpsLongPressSensorType()),
"doze_pulse_on_auth", "doze_pulse_on_auth",
true /* settingDef */, true /* settingDef */,
udfpsEnrolled && (alwaysOn || mScreenOffUdfpsEnabled), udfpsLongPressConfigured(),
DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS, DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS,
true /* reports touch coordinates */, true /* reports touch coordinates */,
true /* touchscreen */, true /* touchscreen */,
@@ -230,7 +235,8 @@ public class DozeSensors {
new PluginSensor( new PluginSensor(
new SensorManagerPlugin.Sensor(TYPE_WAKE_DISPLAY), new SensorManagerPlugin.Sensor(TYPE_WAKE_DISPLAY),
Settings.Secure.DOZE_WAKE_DISPLAY_GESTURE, Settings.Secure.DOZE_WAKE_DISPLAY_GESTURE,
mConfig.wakeScreenGestureAvailable() && alwaysOn, mConfig.wakeScreenGestureAvailable()
&& mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT),
DozeLog.REASON_SENSOR_WAKE_UP_PRESENCE, DozeLog.REASON_SENSOR_WAKE_UP_PRESENCE,
false /* reports touch coordinates */, false /* reports touch coordinates */,
false /* touchscreen */), false /* touchscreen */),
@@ -246,8 +252,7 @@ public class DozeSensors {
findSensor(config.quickPickupSensorType()), findSensor(config.quickPickupSensorType()),
Settings.Secure.DOZE_QUICK_PICKUP_GESTURE, Settings.Secure.DOZE_QUICK_PICKUP_GESTURE,
true /* setting default */, true /* setting default */,
config.quickPickupSensorEnabled(KeyguardUpdateMonitor.getCurrentUser()) quickPickUpConfigured(),
&& udfpsEnrolled,
DozeLog.REASON_SENSOR_QUICK_PICKUP, DozeLog.REASON_SENSOR_QUICK_PICKUP,
false /* requiresTouchCoordinates */, false /* requiresTouchCoordinates */,
false /* requiresTouchscreen */, false /* requiresTouchscreen */,
@@ -265,6 +270,16 @@ public class DozeSensors {
mDevicePostureController.addCallback(mDevicePostureCallback); mDevicePostureController.addCallback(mDevicePostureCallback);
} }
private boolean udfpsLongPressConfigured() {
return mUdfpsEnrolled
&& (mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT) || mScreenOffUdfpsEnabled);
}
private boolean quickPickUpConfigured() {
return mUdfpsEnrolled
&& mConfig.quickPickupSensorEnabled(KeyguardUpdateMonitor.getCurrentUser());
}
/** /**
* Unregister all sensors and callbacks. * Unregister all sensors and callbacks.
*/ */
@@ -276,6 +291,7 @@ public class DozeSensors {
mProximitySensor.pause(); mProximitySensor.pause();
mDevicePostureController.removeCallback(mDevicePostureCallback); mDevicePostureController.removeCallback(mDevicePostureCallback);
mAuthController.removeCallback(mAuthControllerCallback);
} }
/** /**
@@ -450,6 +466,7 @@ public class DozeSensors {
pw.println("mSelectivelyRegisterProxSensors=" + mSelectivelyRegisterProxSensors); pw.println("mSelectivelyRegisterProxSensors=" + mSelectivelyRegisterProxSensors);
pw.println("mListeningProxSensors=" + mListeningProxSensors); pw.println("mListeningProxSensors=" + mListeningProxSensors);
pw.println("mScreenOffUdfpsEnabled=" + mScreenOffUdfpsEnabled); pw.println("mScreenOffUdfpsEnabled=" + mScreenOffUdfpsEnabled);
pw.println("mUdfpsEnrolled=" + mUdfpsEnrolled);
IndentingPrintWriter idpw = new IndentingPrintWriter(pw); IndentingPrintWriter idpw = new IndentingPrintWriter(pw);
idpw.increaseIndent(); idpw.increaseIndent();
for (TriggerSensor s : mTriggerSensors) { for (TriggerSensor s : mTriggerSensors) {
@@ -468,7 +485,7 @@ public class DozeSensors {
@VisibleForTesting @VisibleForTesting
class TriggerSensor extends TriggerEventListener { class TriggerSensor extends TriggerEventListener {
@NonNull final Sensor[] mSensors; // index = posture, value = sensor @NonNull final Sensor[] mSensors; // index = posture, value = sensor
final boolean mConfigured; boolean mConfigured;
final int mPulseReason; final int mPulseReason;
private final String mSetting; private final String mSetting;
private final boolean mReportsTouchCoordinates; private final boolean mReportsTouchCoordinates;
@@ -606,8 +623,18 @@ public class DozeSensors {
updateListening(); updateListening();
} }
/**
* Update configured state.
*/
public void setConfigured(boolean configured) {
if (mConfigured == configured) return;
mConfigured = configured;
updateListening();
}
public void updateListening() { public void updateListening() {
final Sensor sensor = mSensors[mPosture]; final Sensor sensor = mSensors[mPosture];
if (!mConfigured || sensor == null) return; if (!mConfigured || sensor == null) return;
if (mRequested && !mDisabled && (enabledBySetting() || mIgnoresSetting)) { if (mRequested && !mDisabled && (enabledBySetting() || mIgnoresSetting)) {
if (!mRegistered) { if (!mRegistered) {
@@ -791,6 +818,30 @@ public class DozeSensors {
} }
}; };
private final AuthController.Callback mAuthControllerCallback = new AuthController.Callback() {
@Override
public void onAllAuthenticatorsRegistered() {
updateUdfpsEnrolled();
}
@Override
public void onEnrollmentsChanged() {
updateUdfpsEnrolled();
}
private void updateUdfpsEnrolled() {
mUdfpsEnrolled = mAuthController.isUdfpsEnrolled(
KeyguardUpdateMonitor.getCurrentUser());
for (TriggerSensor sensor : mTriggerSensors) {
if (REASON_SENSOR_QUICK_PICKUP == sensor.mPulseReason) {
sensor.setConfigured(quickPickUpConfigured());
} else if (REASON_SENSOR_UDFPS_LONG_PRESS == sensor.mPulseReason) {
sensor.setConfigured(udfpsLongPressConfigured());
}
}
}
};
public interface Callback { public interface Callback {
/** /**

View File

@@ -17,6 +17,7 @@
package com.android.systemui.doze; package com.android.systemui.doze;
import static com.android.systemui.doze.DozeLog.REASON_SENSOR_TAP; import static com.android.systemui.doze.DozeLog.REASON_SENSOR_TAP;
import static com.android.systemui.doze.DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS;
import static com.android.systemui.plugins.SensorManagerPlugin.Sensor.TYPE_WAKE_LOCK_SCREEN; import static com.android.systemui.plugins.SensorManagerPlugin.Sensor.TYPE_WAKE_LOCK_SCREEN;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -37,6 +38,7 @@ import static org.mockito.Mockito.when;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.hardware.Sensor; import android.hardware.Sensor;
import android.hardware.display.AmbientDisplayConfiguration; import android.hardware.display.AmbientDisplayConfiguration;
import android.os.UserHandle;
import android.testing.AndroidTestingRunner; import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper; import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper; import android.testing.TestableLooper.RunWithLooper;
@@ -57,6 +59,8 @@ import com.android.systemui.util.wakelock.WakeLock;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@@ -94,6 +98,13 @@ public class DozeSensorsTest extends SysuiTestCase {
private DevicePostureController mDevicePostureController; private DevicePostureController mDevicePostureController;
@Mock @Mock
private ProximitySensor mProximitySensor; private ProximitySensor mProximitySensor;
// Capture listeners so that they can be used to send events
@Captor
private ArgumentCaptor<AuthController.Callback> mAuthControllerCallbackCaptor =
ArgumentCaptor.forClass(AuthController.Callback.class);
private AuthController.Callback mAuthControllerCallback;
private FakeSettings mFakeSettings = new FakeSettings(); private FakeSettings mFakeSettings = new FakeSettings();
private SensorManagerPlugin.SensorEventListener mWakeLockScreenListener; private SensorManagerPlugin.SensorEventListener mWakeLockScreenListener;
private TestableLooper mTestableLooper; private TestableLooper mTestableLooper;
@@ -105,14 +116,18 @@ public class DozeSensorsTest extends SysuiTestCase {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mTestableLooper = TestableLooper.get(this); mTestableLooper = TestableLooper.get(this);
when(mAmbientDisplayConfiguration.tapSensorTypeMapping()) when(mAmbientDisplayConfiguration.tapSensorTypeMapping())
.thenReturn(new String[]{"tapSEnsor"}); .thenReturn(new String[]{"tapSensor"});
when(mAmbientDisplayConfiguration.getWakeLockScreenDebounce()).thenReturn(5000L); when(mAmbientDisplayConfiguration.getWakeLockScreenDebounce()).thenReturn(5000L);
when(mAmbientDisplayConfiguration.alwaysOnEnabled(anyInt())).thenReturn(true); when(mAmbientDisplayConfiguration.alwaysOnEnabled(anyInt())).thenReturn(true);
when(mAmbientDisplayConfiguration.enabled(UserHandle.USER_CURRENT)).thenReturn(true);
doAnswer(invocation -> { doAnswer(invocation -> {
((Runnable) invocation.getArgument(0)).run(); ((Runnable) invocation.getArgument(0)).run();
return null; return null;
}).when(mWakeLock).wrap(any(Runnable.class)); }).when(mWakeLock).wrap(any(Runnable.class));
mDozeSensors = new TestableDozeSensors(); mDozeSensors = new TestableDozeSensors();
verify(mAuthController).addCallback(mAuthControllerCallbackCaptor.capture());
mAuthControllerCallback = mAuthControllerCallbackCaptor.getValue();
} }
@Test @Test
@@ -375,6 +390,35 @@ public class DozeSensorsTest extends SysuiTestCase {
"some other name")); "some other name"));
} }
@Test
public void testUdfpsEnrollmentChanged() throws Exception {
// GIVEN a UDFPS_LONG_PRESS trigger sensor that's not configured
Sensor mockSensor = mock(Sensor.class);
TriggerSensor triggerSensor = mDozeSensors.createDozeSensor(
mockSensor,
REASON_SENSOR_UDFPS_LONG_PRESS,
/* configured */ false);
mDozeSensors.addSensor(triggerSensor);
when(mSensorManager.requestTriggerSensor(eq(triggerSensor), eq(mockSensor)))
.thenReturn(true);
// WHEN listening state is set to TRUE
mDozeSensors.setListening(true, true);
// THEN mRegistered is still false b/c !mConfigured
assertFalse(triggerSensor.mConfigured);
assertFalse(triggerSensor.mRegistered);
// WHEN enrollment changes to TRUE
when(mAuthController.isUdfpsEnrolled(anyInt())).thenReturn(true);
mAuthControllerCallback.onEnrollmentsChanged();
// THEN mConfigured = TRUE
assertTrue(triggerSensor.mConfigured);
// THEN mRegistered = TRUE
assertTrue(triggerSensor.mRegistered);
}
private class TestableDozeSensors extends DozeSensors { private class TestableDozeSensors extends DozeSensors {
TestableDozeSensors() { TestableDozeSensors() {
@@ -407,6 +451,22 @@ public class DozeSensorsTest extends SysuiTestCase {
requiresTouchScreen); requiresTouchScreen);
} }
public TriggerSensor createDozeSensor(
Sensor sensor,
int pulseReason,
boolean configured
) {
return new TriggerSensor(/* sensor */ sensor,
/* setting name */ "test_setting",
/* settingDefault */ true,
/* configured */ configured,
/* pulseReason*/ pulseReason,
/* reportsTouchCoordinate*/ false,
/* requiresTouchscreen */ false,
/* ignoresSetting */ false,
/* requiresTouchScreen */false);
}
/** /**
* create a doze sensor that supports postures and is enabled * create a doze sensor that supports postures and is enabled
*/ */
@@ -422,6 +482,15 @@ public class DozeSensorsTest extends SysuiTestCase {
/* requiresProx */false, /* requiresProx */false,
posture); posture);
} }
public void addSensor(TriggerSensor sensor) {
TriggerSensor[] newArray = new TriggerSensor[mTriggerSensors.length + 1];
for (int i = 0; i < mTriggerSensors.length; i++) {
newArray[i] = mTriggerSensors[i];
}
newArray[mTriggerSensors.length] = sensor;
mTriggerSensors = newArray;
}
} }
public static void setSensorType(Sensor sensor, int type, String strType) throws Exception { public static void setSensorType(Sensor sensor, int type, String strType) throws Exception {