Merge changes from topic "dozeTapGesture_dualDisplaySupport" into sc-v2-dev am: a2fb749631 am: fa69d14957
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15933708 Change-Id: Ie7a182b3694401a2cbbb223831425cf69e961fdc
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2316,6 +2316,15 @@
|
||||
<!-- Type of the tap sensor. Empty if tap is not supported. -->
|
||||
<string name="config_dozeTapSensorType" translatable="false"></string>
|
||||
|
||||
<!-- Type of the ambient tap sensor per device posture (defined by WM Jetpack posture).
|
||||
Unspecified values use config_dozeTapSensor -->
|
||||
<string-array name="config_dozeTapSensorPostureMapping" translatable="false">
|
||||
<item></item> <!-- UNKNOWN -->
|
||||
<item></item> <!-- CLOSED -->
|
||||
<item></item> <!-- HALF_OPENED -->
|
||||
<item></item> <!-- OPENED -->
|
||||
</string-array>
|
||||
|
||||
<!-- Type of the long press sensor. Empty if long press is not supported. -->
|
||||
<string name="config_dozeLongPressSensorType" translatable="false"></string>
|
||||
|
||||
|
||||
@@ -3259,6 +3259,7 @@
|
||||
|
||||
<java-symbol type="string" name="config_dozeDoubleTapSensorType" />
|
||||
<java-symbol type="string" name="config_dozeTapSensorType" />
|
||||
<java-symbol type="array" name="config_dozeTapSensorPostureMapping" />
|
||||
<java-symbol type="bool" name="config_dozePulsePickup" />
|
||||
|
||||
<!-- Used for MimeIconUtils. -->
|
||||
|
||||
@@ -191,6 +191,15 @@
|
||||
low powered state yet. -->
|
||||
<bool name="doze_single_tap_uses_prox">true</bool>
|
||||
|
||||
<!-- Doze: whether the single tap sensor uses the proximity sensor in the given posture.
|
||||
See doze_single_tap_uses_prox for usage. -->
|
||||
<integer-array name="doze_single_tap_uses_prox_posture_mapping">
|
||||
<item>1</item> <!-- UNKNOWN -->
|
||||
<item>1</item> <!-- CLOSED -->
|
||||
<item>1</item> <!-- HALF_OPENED -->
|
||||
<item>1</item> <!-- OPENED -->
|
||||
</integer-array>
|
||||
|
||||
<!-- Doze: whether the long press sensor uses the proximity sensor.
|
||||
If both this parameter and doze_selectively_register_prox are true, registration for the
|
||||
sensor will be delayed when the device first enters dozing but the device has not entered its
|
||||
@@ -211,6 +220,16 @@
|
||||
always-on display) -->
|
||||
<string name="doze_brightness_sensor_type" translatable="false"></string>
|
||||
|
||||
<!-- Name of a sensor per posture state that provides a low-power estimate of the desired
|
||||
display brightness, suitable to listen to while the device is asleep (e.g. during
|
||||
always-on display) -->
|
||||
<string-array name="doze_brightness_sensor_name_posture_mapping" translatable="false">
|
||||
<item></item> <!-- UNKNOWN -->
|
||||
<item></item> <!-- CLOSED -->
|
||||
<item></item> <!-- HALF_OPENED -->
|
||||
<item></item> <!-- OPENED -->
|
||||
</string-array>
|
||||
|
||||
<!-- Override value to use for proximity sensor. -->
|
||||
<string name="proximity_sensor_type" translatable="false"></string>
|
||||
|
||||
|
||||
@@ -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<Boolean> 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<Sensor> 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<Sensor> 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Sensor> 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())
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -50,6 +50,26 @@ public interface DevicePostureController extends CallbackController<Callback> {
|
||||
/** 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. */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Sensor> 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<Sensor> constr = Sensor.class.getDeclaredConstructor();
|
||||
constr.setAccessible(true);
|
||||
Sensor sensor = constr.newInstance();
|
||||
setSensorType(sensor, type, strType);
|
||||
return sensor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user