diff --git a/core/java/android/hardware/display/AmbientDisplayConfiguration.java b/core/java/android/hardware/display/AmbientDisplayConfiguration.java
index a1f7aa12264b9..518b22bd5e10c 100644
--- a/core/java/android/hardware/display/AmbientDisplayConfiguration.java
+++ b/core/java/android/hardware/display/AmbientDisplayConfiguration.java
@@ -22,6 +22,7 @@ import android.os.Build;
import android.os.SystemProperties;
import android.provider.Settings;
import android.text.TextUtils;
+import android.util.Log;
import com.android.internal.R;
@@ -32,7 +33,7 @@ import com.android.internal.R;
*/
@TestApi
public class AmbientDisplayConfiguration {
-
+ private static final String TAG = "AmbientDisplayConfig";
private final Context mContext;
private final boolean mAlwaysOnByDefault;
@@ -141,10 +142,19 @@ public class AmbientDisplayConfiguration {
}
/** {@hide} */
- public String tapSensorType() {
+ private String tapSensorType() {
return mContext.getResources().getString(R.string.config_dozeTapSensorType);
}
+ /** {@hide} */
+ public String tapSensorType(int posture) {
+ return getSensorFromPostureMapping(
+ mContext.getResources().getStringArray(R.array.config_dozeTapSensorPostureMapping),
+ tapSensorType(),
+ posture
+ );
+ }
+
/** {@hide} */
public String longPressSensorType() {
return mContext.getResources().getString(R.string.config_dozeLongPressSensorType);
@@ -241,4 +251,19 @@ public class AmbientDisplayConfiguration {
private boolean boolSetting(String name, int user, int def) {
return Settings.Secure.getIntForUser(mContext.getContentResolver(), name, def, user) != 0;
}
+
+ /** {@hide} */
+ public static String getSensorFromPostureMapping(
+ String[] postureMapping,
+ String defaultValue,
+ int posture) {
+ String sensorType = defaultValue;
+ if (posture < postureMapping.length) {
+ sensorType = postureMapping[posture];
+ } else {
+ Log.e(TAG, "Unsupported doze posture " + posture);
+ }
+
+ return TextUtils.isEmpty(sensorType) ? defaultValue : sensorType;
+ }
}
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index f1a961d7cd1ac..40bd4cab2a6e8 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -2316,6 +2316,15 @@
+
+
+
+
+
+
+
+
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 0587474fc0543..0728fdf941675 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3259,6 +3259,7 @@
+
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index 60f6fe22e1e6c..786b371862849 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -191,6 +191,15 @@
low powered state yet. -->
true
+
+
+ - 1
+ - 1
+ - 1
+ - 1
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java b/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java
index 55e6154b829d1..3cefce83393a6 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java
@@ -47,6 +47,7 @@ import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.biometrics.AuthController;
import com.android.systemui.plugins.SensorManagerPlugin;
import com.android.systemui.statusbar.phone.DozeParameters;
+import com.android.systemui.statusbar.policy.DevicePostureController;
import com.android.systemui.util.sensors.AsyncSensorManager;
import com.android.systemui.util.sensors.ProximitySensor;
import com.android.systemui.util.settings.SecureSettings;
@@ -82,6 +83,9 @@ public class DozeSensors {
private boolean mListeningTouchScreenSensors;
private boolean mListeningProxSensors;
+ @DevicePostureController.DevicePostureInt
+ private int mDevicePosture;
+
// whether to only register sensors that use prox when the display state is dozing or off
private boolean mSelectivelyRegisterProxSensors;
@@ -106,7 +110,8 @@ public class DozeSensors {
DozeParameters dozeParameters, AmbientDisplayConfiguration config, WakeLock wakeLock,
Callback callback, Consumer proxCallback, DozeLog dozeLog,
ProximitySensor proximitySensor, SecureSettings secureSettings,
- AuthController authController) {
+ AuthController authController,
+ int devicePosture) {
mContext = context;
mSensorManager = sensorManager;
mConfig = config;
@@ -120,6 +125,7 @@ public class DozeSensors {
mListeningProxSensors = !mSelectivelyRegisterProxSensors;
mScreenOffUdfpsEnabled =
config.screenOffUdfpsEnabled(KeyguardUpdateMonitor.getCurrentUser());
+ mDevicePosture = devicePosture;
boolean udfpsEnrolled =
authController.isUdfpsEnrolled(KeyguardUpdateMonitor.getCurrentUser());
@@ -142,7 +148,7 @@ public class DozeSensors {
false /* requires prox */,
dozeLog),
new TriggerSensor(
- findSensorWithType(config.doubleTapSensorType()),
+ findSensor(config.doubleTapSensorType()),
Settings.Secure.DOZE_DOUBLE_TAP_GESTURE,
true /* configured */,
DozeLog.REASON_SENSOR_DOUBLE_TAP,
@@ -150,7 +156,7 @@ public class DozeSensors {
true /* touchscreen */,
dozeLog),
new TriggerSensor(
- findSensorWithType(config.tapSensorType()),
+ findSensor(config.tapSensorType(mDevicePosture)),
Settings.Secure.DOZE_TAP_SCREEN_GESTURE,
true /* settingDef */,
true /* configured */,
@@ -158,10 +164,10 @@ public class DozeSensors {
false /* reports touch coordinates */,
true /* touchscreen */,
false /* ignoresSetting */,
- dozeParameters.singleTapUsesProx() /* requiresProx */,
+ dozeParameters.singleTapUsesProx(mDevicePosture) /* requiresProx */,
dozeLog),
new TriggerSensor(
- findSensorWithType(config.longPressSensorType()),
+ findSensor(config.longPressSensorType()),
Settings.Secure.DOZE_PULSE_ON_LONG_PRESS,
false /* settingDef */,
true /* configured */,
@@ -172,7 +178,7 @@ public class DozeSensors {
dozeParameters.longPressUsesProx() /* requiresProx */,
dozeLog),
new TriggerSensor(
- findSensorWithType(config.udfpsLongPressSensorType()),
+ findSensor(config.udfpsLongPressSensorType()),
"doze_pulse_on_auth",
true /* settingDef */,
udfpsEnrolled && (alwaysOn || mScreenOffUdfpsEnabled),
@@ -200,7 +206,7 @@ public class DozeSensors {
mConfig.getWakeLockScreenDebounce(),
dozeLog),
new TriggerSensor(
- findSensorWithType(config.quickPickupSensorType()),
+ findSensor(config.quickPickupSensorType()),
Settings.Secure.DOZE_QUICK_PICKUP_GESTURE,
true /* setting default */,
config.quickPickupSensorEnabled(KeyguardUpdateMonitor.getCurrentUser())
@@ -238,21 +244,29 @@ public class DozeSensors {
mDebounceFrom = SystemClock.uptimeMillis();
}
- private Sensor findSensorWithType(String type) {
- return findSensorWithType(mSensorManager, type);
+ private Sensor findSensor(String type) {
+ return findSensor(mSensorManager, type, null);
}
/**
- * Utility method to find a {@link Sensor} for the supplied string type.
+ * Utility method to find a {@link Sensor} for the supplied string type and string name.
+ *
+ * Return the first sensor in the list that matches the specified inputs. Ignores type or name
+ * if the input is null or empty.
+ *
+ * @param type sensorType
+ * @parm name sensorName, to differentiate between sensors with the same type
*/
- public static Sensor findSensorWithType(SensorManager sensorManager, String type) {
- if (TextUtils.isEmpty(type)) {
- return null;
- }
- List sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
- for (Sensor s : sensorList) {
- if (type.equals(s.getStringType())) {
- return s;
+ public static Sensor findSensor(SensorManager sensorManager, String type, String name) {
+ final boolean isNameSpecified = !TextUtils.isEmpty(name);
+ final boolean isTypeSpecified = !TextUtils.isEmpty(type);
+ if (isNameSpecified || isTypeSpecified) {
+ final List sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
+ for (Sensor sensor : sensors) {
+ if ((!isNameSpecified || name.equals(sensor.getName()))
+ && (!isTypeSpecified || type.equals(sensor.getStringType()))) {
+ return sensor;
+ }
}
}
return null;
@@ -370,6 +384,8 @@ public class DozeSensors {
/** Dump current state */
public void dump(PrintWriter pw) {
pw.println("mListening=" + mListening);
+ pw.println("mDevicePosture="
+ + DevicePostureController.devicePostureToString(mDevicePosture));
pw.println("mListeningTouchScreenSensors=" + mListeningTouchScreenSensors);
pw.println("mSelectivelyRegisterProxSensors=" + mSelectivelyRegisterProxSensors);
pw.println("mListeningProxSensors=" + mListeningProxSensors);
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
index 756adca724e9a..1e7f0d9dc6302 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
@@ -41,6 +41,7 @@ import com.android.systemui.dock.DockManager;
import com.android.systemui.doze.DozeMachine.State;
import com.android.systemui.doze.dagger.DozeScope;
import com.android.systemui.statusbar.phone.DozeParameters;
+import com.android.systemui.statusbar.policy.DevicePostureController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.Assert;
import com.android.systemui.util.concurrency.DelayableExecutor;
@@ -95,6 +96,9 @@ public class DozeTriggers implements DozeMachine.Part {
private final DelayableExecutor mMainExecutor;
private final KeyguardStateController mKeyguardStateController;
private final UiEventLogger mUiEventLogger;
+ private final DevicePostureController mDevicePostureController;
+
+ private @DevicePostureController.DevicePostureInt int mDevicePosture;
private long mNotificationPulseTime;
private boolean mPulsePending;
@@ -182,7 +186,8 @@ public class DozeTriggers implements DozeMachine.Part {
SecureSettings secureSettings, AuthController authController,
@Main DelayableExecutor mainExecutor,
UiEventLogger uiEventLogger,
- KeyguardStateController keyguardStateController) {
+ KeyguardStateController keyguardStateController,
+ DevicePostureController devicePostureController) {
mContext = context;
mDozeHost = dozeHost;
mConfig = config;
@@ -190,9 +195,11 @@ public class DozeTriggers implements DozeMachine.Part {
mSensorManager = sensorManager;
mWakeLock = wakeLock;
mAllowPulseTriggers = true;
+ mDevicePostureController = devicePostureController;
+ mDevicePosture = devicePostureController.getDevicePosture();
mDozeSensors = new DozeSensors(context, mSensorManager, dozeParameters,
config, wakeLock, this::onSensor, this::onProximityFar, dozeLog, proximitySensor,
- secureSettings, authController);
+ secureSettings, authController, mDevicePosture);
mUiModeManager = mContext.getSystemService(UiModeManager.class);
mDockManager = dockManager;
mProxCheck = proxCheck;
diff --git a/packages/SystemUI/src/com/android/systemui/doze/dagger/DozeModule.java b/packages/SystemUI/src/com/android/systemui/doze/dagger/DozeModule.java
index 9c6e02a7924e2..571b666e45730 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/dagger/DozeModule.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/dagger/DozeModule.java
@@ -38,6 +38,7 @@ import com.android.systemui.doze.DozeTriggers;
import com.android.systemui.doze.DozeUi;
import com.android.systemui.doze.DozeWallpaperState;
import com.android.systemui.statusbar.phone.DozeParameters;
+import com.android.systemui.statusbar.policy.DevicePostureController;
import com.android.systemui.util.sensors.AsyncSensorManager;
import com.android.systemui.util.wakelock.DelayedWakeLock;
import com.android.systemui.util.wakelock.WakeLock;
@@ -94,8 +95,15 @@ public abstract class DozeModule {
@Provides
@BrightnessSensor
static Optional providesBrightnessSensor(
- AsyncSensorManager sensorManager, Context context) {
- return Optional.ofNullable(DozeSensors.findSensorWithType(sensorManager,
- context.getString(R.string.doze_brightness_sensor_type)));
+ AsyncSensorManager sensorManager,
+ Context context,
+ DozeParameters dozeParameters,
+ DevicePostureController devicePostureController) {
+ return Optional.ofNullable(
+ DozeSensors.findSensor(
+ sensorManager,
+ context.getString(R.string.doze_brightness_sensor_type),
+ dozeParameters.brightnessName(devicePostureController.getDevicePosture())
+ ));
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
index a8c62fe2984c3..5bf982b908cdd 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
@@ -22,6 +22,7 @@ import android.os.PowerManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
+import android.util.Log;
import android.util.MathUtils;
import androidx.annotation.NonNull;
@@ -35,6 +36,7 @@ import com.android.systemui.doze.DozeScreenState;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.statusbar.policy.BatteryController;
+import com.android.systemui.statusbar.policy.DevicePostureController;
import com.android.systemui.tuner.TunerService;
import java.io.FileDescriptor;
@@ -255,10 +257,21 @@ public class DozeParameters implements
return mResources.getBoolean(R.bool.doze_double_tap_reports_touch_coordinates);
}
+ /**
+ * Whether the single tap sensor uses the proximity sensor for this device posture.
+ */
+ public boolean singleTapUsesProx(@DevicePostureController.DevicePostureInt int devicePosture) {
+ return getPostureSpecificBool(
+ mResources.getIntArray(R.array.doze_single_tap_uses_prox_posture_mapping),
+ singleTapUsesProx(),
+ devicePosture
+ );
+ }
+
/**
* Whether the single tap sensor uses the proximity sensor.
*/
- public boolean singleTapUsesProx() {
+ private boolean singleTapUsesProx() {
return mResources.getBoolean(R.bool.doze_single_tap_uses_prox);
}
@@ -269,6 +282,17 @@ public class DozeParameters implements
return mResources.getBoolean(R.bool.doze_long_press_uses_prox);
}
+ /**
+ * Sensor to use for brightness changes.
+ */
+ public String brightnessName(@DevicePostureController.DevicePostureInt int posture) {
+ return AmbientDisplayConfiguration.getSensorFromPostureMapping(
+ mResources.getStringArray(R.array.doze_brightness_sensor_name_posture_mapping),
+ null /* defaultValue */,
+ posture
+ );
+ }
+
/**
* Callback to listen for DozeParameter changes.
*/
@@ -308,6 +332,20 @@ public class DozeParameters implements
pw.println(getSelectivelyRegisterSensorsUsingProx());
}
+ private boolean getPostureSpecificBool(
+ int[] postureMapping,
+ boolean defaultSensorBool,
+ int posture) {
+ boolean bool = defaultSensorBool;
+ if (posture < postureMapping.length) {
+ bool = postureMapping[posture] != 0;
+ } else {
+ Log.e("DozeParameters", "Unsupported doze posture " + posture);
+ }
+
+ return bool;
+ }
+
interface Callback {
/**
* Invoked when the value of getAlwaysOn may have changed.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DevicePostureController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DevicePostureController.java
index fbfa5e5ea109b..85968753d54f1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DevicePostureController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DevicePostureController.java
@@ -50,6 +50,26 @@ public interface DevicePostureController extends CallbackController {
/** Return the current device posture. */
@DevicePostureInt int getDevicePosture();
+ /**
+ * String representation of DevicePostureInt.
+ */
+ static String devicePostureToString(@DevicePostureInt int posture) {
+ switch (posture) {
+ case DEVICE_POSTURE_CLOSED:
+ return "DEVICE_POSTURE_CLOSED";
+ case DEVICE_POSTURE_HALF_OPENED:
+ return "DEVICE_POSTURE_HALF_OPENED";
+ case DEVICE_POSTURE_OPENED:
+ return "DEVICE_POSTURE_OPENED";
+ case DEVICE_POSTURE_FLIPPED:
+ return "DEVICE_POSTURE_FLIPPED";
+ case DEVICE_POSTURE_UNKNOWN:
+ return "DEVICE_POSTURE_UNKNOWN";
+ default:
+ return "UNSUPPORTED POSTURE posture=" + posture;
+ }
+ }
+
/** Callback to be notified about device posture changes. */
interface Callback {
/** Called when the posture changes. */
diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeConfigurationUtil.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeConfigurationUtil.java
index d6226aa53f67d..866791cc24cbd 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeConfigurationUtil.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeConfigurationUtil.java
@@ -40,7 +40,7 @@ public class DozeConfigurationUtil {
when(params.doubleTapReportsTouchCoordinates()).thenReturn(false);
when(params.getDisplayNeedsBlanking()).thenReturn(false);
when(params.getSelectivelyRegisterSensorsUsingProx()).thenReturn(false);
- when(params.singleTapUsesProx()).thenReturn(true);
+ when(params.singleTapUsesProx(anyInt())).thenReturn(true);
when(params.longPressUsesProx()).thenReturn(true);
when(params.getQuickPickupAodDuration()).thenReturn(500);
@@ -61,14 +61,13 @@ public class DozeConfigurationUtil {
when(config.getWakeLockScreenDebounce()).thenReturn(0L);
when(config.doubleTapSensorType()).thenReturn(null);
- when(config.tapSensorType()).thenReturn(null);
when(config.longPressSensorType()).thenReturn(null);
when(config.udfpsLongPressSensorType()).thenReturn(null);
when(config.quickPickupSensorType()).thenReturn(null);
when(config.tapGestureEnabled(anyInt())).thenReturn(true);
when(config.tapSensorAvailable()).thenReturn(true);
- when(config.tapSensorType()).thenReturn(FakeSensorManager.TAP_SENSOR_TYPE);
+ when(config.tapSensorType(anyInt())).thenReturn(FakeSensorManager.TAP_SENSOR_TYPE);
when(config.dozePickupSensorAvailable()).thenReturn(false);
when(config.wakeScreenGestureAvailable()).thenReturn(false);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeSensorsTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeSensorsTest.java
index 5c4c27ccc4ca7..42e34c81a7904 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeSensorsTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeSensorsTest.java
@@ -19,6 +19,7 @@ package com.android.systemui.doze;
import static com.android.systemui.doze.DozeLog.REASON_SENSOR_TAP;
import static com.android.systemui.plugins.SensorManagerPlugin.Sensor.TYPE_WAKE_LOCK_SCREEN;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -47,6 +48,7 @@ import com.android.systemui.biometrics.AuthController;
import com.android.systemui.doze.DozeSensors.TriggerSensor;
import com.android.systemui.plugins.SensorManagerPlugin;
import com.android.systemui.statusbar.phone.DozeParameters;
+import com.android.systemui.statusbar.policy.DevicePostureController;
import com.android.systemui.util.sensors.AsyncSensorManager;
import com.android.systemui.util.sensors.ProximitySensor;
import com.android.systemui.util.settings.FakeSettings;
@@ -58,6 +60,11 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
import java.util.function.Consumer;
@RunWith(AndroidTestingRunner.class)
@@ -85,6 +92,8 @@ public class DozeSensorsTest extends SysuiTestCase {
private AuthController mAuthController;
@Mock
private ProximitySensor mProximitySensor;
+ private @DevicePostureController.DevicePostureInt int mDevicePosture =
+ DevicePostureController.DEVICE_POSTURE_UNKNOWN;
private FakeSettings mFakeSettings = new FakeSettings();
private SensorManagerPlugin.SensorEventListener mWakeLockScreenListener;
private TestableLooper mTestableLooper;
@@ -101,6 +110,7 @@ public class DozeSensorsTest extends SysuiTestCase {
((Runnable) invocation.getArgument(0)).run();
return null;
}).when(mWakeLock).wrap(any(Runnable.class));
+ mDevicePosture = DevicePostureController.DEVICE_POSTURE_UNKNOWN;
mDozeSensors = new TestableDozeSensors();
}
@@ -157,7 +167,7 @@ public class DozeSensorsTest extends SysuiTestCase {
// GIVEN we only should register sensors using prox when not in low-powered mode / off
// and the single tap sensor uses the proximity sensor
when(mDozeParameters.getSelectivelyRegisterSensorsUsingProx()).thenReturn(true);
- when(mDozeParameters.singleTapUsesProx()).thenReturn(true);
+ when(mDozeParameters.singleTapUsesProx(anyInt())).thenReturn(true);
TestableDozeSensors dozeSensors = new TestableDozeSensors();
// THEN on initialization, the tap sensor isn't requested
@@ -258,12 +268,55 @@ public class DozeSensorsTest extends SysuiTestCase {
assertTrue(triggerSensor.mRegistered);
}
+ @Test
+ public void testPostureOpen_registersCorrectTapGesture() {
+ // GIVEN device posture open
+ mDevicePosture = DevicePostureController.DEVICE_POSTURE_OPENED;
+
+ // WHEN DozeSensors are initialized
+ new TestableDozeSensors();
+
+ // THEN we use the posture to determine which tap sensor to use
+ verify(mAmbientDisplayConfiguration).tapSensorType(eq(mDevicePosture));
+ }
+
+ @Test
+ public void testFindSensor() throws Exception {
+ // GIVEN a prox sensor
+ List sensors = new ArrayList<>();
+ Sensor proxSensor =
+ createSensor(Sensor.TYPE_PROXIMITY, Sensor.STRING_TYPE_PROXIMITY);
+ sensors.add(proxSensor);
+
+ when(mSensorManager.getSensorList(anyInt())).thenReturn(sensors);
+
+ // WHEN we try to find the prox sensor with the same type and name
+ // THEN we find the added sensor
+ assertEquals(
+ proxSensor,
+ DozeSensors.findSensor(
+ mSensorManager,
+ Sensor.STRING_TYPE_PROXIMITY,
+ proxSensor.getName()));
+
+ // WHEN we try to find a prox sensor with a different name
+ // THEN no sensor is found
+ assertEquals(
+ null,
+ DozeSensors.findSensor(
+ mSensorManager,
+ Sensor.STRING_TYPE_PROXIMITY,
+ "some other name"));
+ }
+
+
private class TestableDozeSensors extends DozeSensors {
TestableDozeSensors() {
super(getContext(), mSensorManager, mDozeParameters,
mAmbientDisplayConfiguration, mWakeLock, mCallback, mProxCallback, mDozeLog,
- mProximitySensor, mFakeSettings, mAuthController);
+ mProximitySensor, mFakeSettings, mAuthController,
+ mDevicePosture);
for (TriggerSensor sensor : mSensors) {
if (sensor instanceof PluginSensor
&& ((PluginSensor) sensor).mPluginSensor.getType()
@@ -288,4 +341,23 @@ public class DozeSensorsTest extends SysuiTestCase {
mDozeLog);
}
}
+
+ public static void setSensorType(Sensor sensor, int type, String strType) throws Exception {
+ Method setter = Sensor.class.getDeclaredMethod("setType", Integer.TYPE);
+ setter.setAccessible(true);
+ setter.invoke(sensor, type);
+ if (strType != null) {
+ Field f = sensor.getClass().getDeclaredField("mStringType");
+ f.setAccessible(true);
+ f.set(sensor, strType);
+ }
+ }
+
+ public static Sensor createSensor(int type, String strType) throws Exception {
+ Constructor constr = Sensor.class.getDeclaredConstructor();
+ constr.setAccessible(true);
+ Sensor sensor = constr.newInstance();
+ setSensorType(sensor, type, strType);
+ return sensor;
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
index 9577c7a2d6fa0..b688fcc50373b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
@@ -45,6 +45,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dock.DockManager;
import com.android.systemui.doze.DozeTriggers.DozingUpdateUiEvent;
import com.android.systemui.statusbar.phone.DozeParameters;
+import com.android.systemui.statusbar.policy.DevicePostureController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.concurrency.FakeThreadFactory;
@@ -86,6 +87,8 @@ public class DozeTriggersTest extends SysuiTestCase {
private UiEventLogger mUiEventLogger;
@Mock
private KeyguardStateController mKeyguardStateController;
+ @Mock
+ private DevicePostureController mDevicePostureController;
private DozeTriggers mTriggers;
private FakeSensorManager mSensors;
@@ -117,7 +120,8 @@ public class DozeTriggersTest extends SysuiTestCase {
mTriggers = new DozeTriggers(mContext, mHost, config, dozeParameters,
asyncSensorManager, wakeLock, mDockManager, mProximitySensor,
mProximityCheck, mock(DozeLog.class), mBroadcastDispatcher, new FakeSettings(),
- mAuthController, mExecutor, mUiEventLogger, mKeyguardStateController);
+ mAuthController, mExecutor, mUiEventLogger, mKeyguardStateController,
+ mDevicePostureController);
mTriggers.setDozeMachine(mMachine);
waitForSensorManager();
}