Merge changes from topic "dozeTapGesture_dualDisplaySupport" into sc-v2-dev
* changes: Add dual-display support for aod brightness sensor Add support dual display support doze tap gesture
This commit is contained in:
committed by
Android (Google) Code Review
commit
a2fb749631
@@ -22,6 +22,7 @@ import android.os.Build;
|
|||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ import com.android.internal.R;
|
|||||||
*/
|
*/
|
||||||
@TestApi
|
@TestApi
|
||||||
public class AmbientDisplayConfiguration {
|
public class AmbientDisplayConfiguration {
|
||||||
|
private static final String TAG = "AmbientDisplayConfig";
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final boolean mAlwaysOnByDefault;
|
private final boolean mAlwaysOnByDefault;
|
||||||
|
|
||||||
@@ -141,10 +142,19 @@ public class AmbientDisplayConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** {@hide} */
|
/** {@hide} */
|
||||||
public String tapSensorType() {
|
private String tapSensorType() {
|
||||||
return mContext.getResources().getString(R.string.config_dozeTapSensorType);
|
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} */
|
/** {@hide} */
|
||||||
public String longPressSensorType() {
|
public String longPressSensorType() {
|
||||||
return mContext.getResources().getString(R.string.config_dozeLongPressSensorType);
|
return mContext.getResources().getString(R.string.config_dozeLongPressSensorType);
|
||||||
@@ -241,4 +251,19 @@ public class AmbientDisplayConfiguration {
|
|||||||
private boolean boolSetting(String name, int user, int def) {
|
private boolean boolSetting(String name, int user, int def) {
|
||||||
return Settings.Secure.getIntForUser(mContext.getContentResolver(), name, def, user) != 0;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2323,6 +2323,15 @@
|
|||||||
<!-- Type of the tap sensor. Empty if tap is not supported. -->
|
<!-- Type of the tap sensor. Empty if tap is not supported. -->
|
||||||
<string name="config_dozeTapSensorType" translatable="false"></string>
|
<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. -->
|
<!-- Type of the long press sensor. Empty if long press is not supported. -->
|
||||||
<string name="config_dozeLongPressSensorType" translatable="false"></string>
|
<string name="config_dozeLongPressSensorType" translatable="false"></string>
|
||||||
|
|
||||||
|
|||||||
@@ -3255,6 +3255,7 @@
|
|||||||
|
|
||||||
<java-symbol type="string" name="config_dozeDoubleTapSensorType" />
|
<java-symbol type="string" name="config_dozeDoubleTapSensorType" />
|
||||||
<java-symbol type="string" name="config_dozeTapSensorType" />
|
<java-symbol type="string" name="config_dozeTapSensorType" />
|
||||||
|
<java-symbol type="array" name="config_dozeTapSensorPostureMapping" />
|
||||||
<java-symbol type="bool" name="config_dozePulsePickup" />
|
<java-symbol type="bool" name="config_dozePulsePickup" />
|
||||||
|
|
||||||
<!-- Used for MimeIconUtils. -->
|
<!-- Used for MimeIconUtils. -->
|
||||||
|
|||||||
@@ -191,6 +191,15 @@
|
|||||||
low powered state yet. -->
|
low powered state yet. -->
|
||||||
<bool name="doze_single_tap_uses_prox">true</bool>
|
<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.
|
<!-- Doze: whether the long press sensor uses the proximity sensor.
|
||||||
If both this parameter and doze_selectively_register_prox are true, registration for the
|
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
|
sensor will be delayed when the device first enters dozing but the device has not entered its
|
||||||
@@ -211,6 +220,16 @@
|
|||||||
always-on display) -->
|
always-on display) -->
|
||||||
<string name="doze_brightness_sensor_type" translatable="false"></string>
|
<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. -->
|
<!-- Override value to use for proximity sensor. -->
|
||||||
<string name="proximity_sensor_type" translatable="false"></string>
|
<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.biometrics.AuthController;
|
||||||
import com.android.systemui.plugins.SensorManagerPlugin;
|
import com.android.systemui.plugins.SensorManagerPlugin;
|
||||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
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.AsyncSensorManager;
|
||||||
import com.android.systemui.util.sensors.ProximitySensor;
|
import com.android.systemui.util.sensors.ProximitySensor;
|
||||||
import com.android.systemui.util.settings.SecureSettings;
|
import com.android.systemui.util.settings.SecureSettings;
|
||||||
@@ -82,6 +83,9 @@ public class DozeSensors {
|
|||||||
private boolean mListeningTouchScreenSensors;
|
private boolean mListeningTouchScreenSensors;
|
||||||
private boolean mListeningProxSensors;
|
private boolean mListeningProxSensors;
|
||||||
|
|
||||||
|
@DevicePostureController.DevicePostureInt
|
||||||
|
private int mDevicePosture;
|
||||||
|
|
||||||
// whether to only register sensors that use prox when the display state is dozing or off
|
// whether to only register sensors that use prox when the display state is dozing or off
|
||||||
private boolean mSelectivelyRegisterProxSensors;
|
private boolean mSelectivelyRegisterProxSensors;
|
||||||
|
|
||||||
@@ -106,7 +110,8 @@ public class DozeSensors {
|
|||||||
DozeParameters dozeParameters, AmbientDisplayConfiguration config, WakeLock wakeLock,
|
DozeParameters dozeParameters, AmbientDisplayConfiguration config, WakeLock wakeLock,
|
||||||
Callback callback, Consumer<Boolean> proxCallback, DozeLog dozeLog,
|
Callback callback, Consumer<Boolean> proxCallback, DozeLog dozeLog,
|
||||||
ProximitySensor proximitySensor, SecureSettings secureSettings,
|
ProximitySensor proximitySensor, SecureSettings secureSettings,
|
||||||
AuthController authController) {
|
AuthController authController,
|
||||||
|
int devicePosture) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mSensorManager = sensorManager;
|
mSensorManager = sensorManager;
|
||||||
mConfig = config;
|
mConfig = config;
|
||||||
@@ -120,6 +125,7 @@ public class DozeSensors {
|
|||||||
mListeningProxSensors = !mSelectivelyRegisterProxSensors;
|
mListeningProxSensors = !mSelectivelyRegisterProxSensors;
|
||||||
mScreenOffUdfpsEnabled =
|
mScreenOffUdfpsEnabled =
|
||||||
config.screenOffUdfpsEnabled(KeyguardUpdateMonitor.getCurrentUser());
|
config.screenOffUdfpsEnabled(KeyguardUpdateMonitor.getCurrentUser());
|
||||||
|
mDevicePosture = devicePosture;
|
||||||
|
|
||||||
boolean udfpsEnrolled =
|
boolean udfpsEnrolled =
|
||||||
authController.isUdfpsEnrolled(KeyguardUpdateMonitor.getCurrentUser());
|
authController.isUdfpsEnrolled(KeyguardUpdateMonitor.getCurrentUser());
|
||||||
@@ -142,7 +148,7 @@ public class DozeSensors {
|
|||||||
false /* requires prox */,
|
false /* requires prox */,
|
||||||
dozeLog),
|
dozeLog),
|
||||||
new TriggerSensor(
|
new TriggerSensor(
|
||||||
findSensorWithType(config.doubleTapSensorType()),
|
findSensor(config.doubleTapSensorType()),
|
||||||
Settings.Secure.DOZE_DOUBLE_TAP_GESTURE,
|
Settings.Secure.DOZE_DOUBLE_TAP_GESTURE,
|
||||||
true /* configured */,
|
true /* configured */,
|
||||||
DozeLog.REASON_SENSOR_DOUBLE_TAP,
|
DozeLog.REASON_SENSOR_DOUBLE_TAP,
|
||||||
@@ -150,7 +156,7 @@ public class DozeSensors {
|
|||||||
true /* touchscreen */,
|
true /* touchscreen */,
|
||||||
dozeLog),
|
dozeLog),
|
||||||
new TriggerSensor(
|
new TriggerSensor(
|
||||||
findSensorWithType(config.tapSensorType()),
|
findSensor(config.tapSensorType(mDevicePosture)),
|
||||||
Settings.Secure.DOZE_TAP_SCREEN_GESTURE,
|
Settings.Secure.DOZE_TAP_SCREEN_GESTURE,
|
||||||
true /* settingDef */,
|
true /* settingDef */,
|
||||||
true /* configured */,
|
true /* configured */,
|
||||||
@@ -158,10 +164,10 @@ public class DozeSensors {
|
|||||||
false /* reports touch coordinates */,
|
false /* reports touch coordinates */,
|
||||||
true /* touchscreen */,
|
true /* touchscreen */,
|
||||||
false /* ignoresSetting */,
|
false /* ignoresSetting */,
|
||||||
dozeParameters.singleTapUsesProx() /* requiresProx */,
|
dozeParameters.singleTapUsesProx(mDevicePosture) /* requiresProx */,
|
||||||
dozeLog),
|
dozeLog),
|
||||||
new TriggerSensor(
|
new TriggerSensor(
|
||||||
findSensorWithType(config.longPressSensorType()),
|
findSensor(config.longPressSensorType()),
|
||||||
Settings.Secure.DOZE_PULSE_ON_LONG_PRESS,
|
Settings.Secure.DOZE_PULSE_ON_LONG_PRESS,
|
||||||
false /* settingDef */,
|
false /* settingDef */,
|
||||||
true /* configured */,
|
true /* configured */,
|
||||||
@@ -172,7 +178,7 @@ public class DozeSensors {
|
|||||||
dozeParameters.longPressUsesProx() /* requiresProx */,
|
dozeParameters.longPressUsesProx() /* requiresProx */,
|
||||||
dozeLog),
|
dozeLog),
|
||||||
new TriggerSensor(
|
new TriggerSensor(
|
||||||
findSensorWithType(config.udfpsLongPressSensorType()),
|
findSensor(config.udfpsLongPressSensorType()),
|
||||||
"doze_pulse_on_auth",
|
"doze_pulse_on_auth",
|
||||||
true /* settingDef */,
|
true /* settingDef */,
|
||||||
udfpsEnrolled && (alwaysOn || mScreenOffUdfpsEnabled),
|
udfpsEnrolled && (alwaysOn || mScreenOffUdfpsEnabled),
|
||||||
@@ -200,7 +206,7 @@ public class DozeSensors {
|
|||||||
mConfig.getWakeLockScreenDebounce(),
|
mConfig.getWakeLockScreenDebounce(),
|
||||||
dozeLog),
|
dozeLog),
|
||||||
new TriggerSensor(
|
new TriggerSensor(
|
||||||
findSensorWithType(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())
|
config.quickPickupSensorEnabled(KeyguardUpdateMonitor.getCurrentUser())
|
||||||
@@ -238,21 +244,29 @@ public class DozeSensors {
|
|||||||
mDebounceFrom = SystemClock.uptimeMillis();
|
mDebounceFrom = SystemClock.uptimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Sensor findSensorWithType(String type) {
|
private Sensor findSensor(String type) {
|
||||||
return findSensorWithType(mSensorManager, 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) {
|
public static Sensor findSensor(SensorManager sensorManager, String type, String name) {
|
||||||
if (TextUtils.isEmpty(type)) {
|
final boolean isNameSpecified = !TextUtils.isEmpty(name);
|
||||||
return null;
|
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;
|
||||||
}
|
}
|
||||||
List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
|
|
||||||
for (Sensor s : sensorList) {
|
|
||||||
if (type.equals(s.getStringType())) {
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -370,6 +384,8 @@ public class DozeSensors {
|
|||||||
/** Dump current state */
|
/** Dump current state */
|
||||||
public void dump(PrintWriter pw) {
|
public void dump(PrintWriter pw) {
|
||||||
pw.println("mListening=" + mListening);
|
pw.println("mListening=" + mListening);
|
||||||
|
pw.println("mDevicePosture="
|
||||||
|
+ DevicePostureController.devicePostureToString(mDevicePosture));
|
||||||
pw.println("mListeningTouchScreenSensors=" + mListeningTouchScreenSensors);
|
pw.println("mListeningTouchScreenSensors=" + mListeningTouchScreenSensors);
|
||||||
pw.println("mSelectivelyRegisterProxSensors=" + mSelectivelyRegisterProxSensors);
|
pw.println("mSelectivelyRegisterProxSensors=" + mSelectivelyRegisterProxSensors);
|
||||||
pw.println("mListeningProxSensors=" + mListeningProxSensors);
|
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.DozeMachine.State;
|
||||||
import com.android.systemui.doze.dagger.DozeScope;
|
import com.android.systemui.doze.dagger.DozeScope;
|
||||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
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.statusbar.policy.KeyguardStateController;
|
||||||
import com.android.systemui.util.Assert;
|
import com.android.systemui.util.Assert;
|
||||||
import com.android.systemui.util.concurrency.DelayableExecutor;
|
import com.android.systemui.util.concurrency.DelayableExecutor;
|
||||||
@@ -95,6 +96,9 @@ public class DozeTriggers implements DozeMachine.Part {
|
|||||||
private final DelayableExecutor mMainExecutor;
|
private final DelayableExecutor mMainExecutor;
|
||||||
private final KeyguardStateController mKeyguardStateController;
|
private final KeyguardStateController mKeyguardStateController;
|
||||||
private final UiEventLogger mUiEventLogger;
|
private final UiEventLogger mUiEventLogger;
|
||||||
|
private final DevicePostureController mDevicePostureController;
|
||||||
|
|
||||||
|
private @DevicePostureController.DevicePostureInt int mDevicePosture;
|
||||||
|
|
||||||
private long mNotificationPulseTime;
|
private long mNotificationPulseTime;
|
||||||
private boolean mPulsePending;
|
private boolean mPulsePending;
|
||||||
@@ -182,7 +186,8 @@ public class DozeTriggers implements DozeMachine.Part {
|
|||||||
SecureSettings secureSettings, AuthController authController,
|
SecureSettings secureSettings, AuthController authController,
|
||||||
@Main DelayableExecutor mainExecutor,
|
@Main DelayableExecutor mainExecutor,
|
||||||
UiEventLogger uiEventLogger,
|
UiEventLogger uiEventLogger,
|
||||||
KeyguardStateController keyguardStateController) {
|
KeyguardStateController keyguardStateController,
|
||||||
|
DevicePostureController devicePostureController) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mDozeHost = dozeHost;
|
mDozeHost = dozeHost;
|
||||||
mConfig = config;
|
mConfig = config;
|
||||||
@@ -190,9 +195,11 @@ public class DozeTriggers implements DozeMachine.Part {
|
|||||||
mSensorManager = sensorManager;
|
mSensorManager = sensorManager;
|
||||||
mWakeLock = wakeLock;
|
mWakeLock = wakeLock;
|
||||||
mAllowPulseTriggers = true;
|
mAllowPulseTriggers = true;
|
||||||
|
mDevicePostureController = devicePostureController;
|
||||||
|
mDevicePosture = devicePostureController.getDevicePosture();
|
||||||
mDozeSensors = new DozeSensors(context, mSensorManager, dozeParameters,
|
mDozeSensors = new DozeSensors(context, mSensorManager, dozeParameters,
|
||||||
config, wakeLock, this::onSensor, this::onProximityFar, dozeLog, proximitySensor,
|
config, wakeLock, this::onSensor, this::onProximityFar, dozeLog, proximitySensor,
|
||||||
secureSettings, authController);
|
secureSettings, authController, mDevicePosture);
|
||||||
mUiModeManager = mContext.getSystemService(UiModeManager.class);
|
mUiModeManager = mContext.getSystemService(UiModeManager.class);
|
||||||
mDockManager = dockManager;
|
mDockManager = dockManager;
|
||||||
mProxCheck = proxCheck;
|
mProxCheck = proxCheck;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import com.android.systemui.doze.DozeTriggers;
|
|||||||
import com.android.systemui.doze.DozeUi;
|
import com.android.systemui.doze.DozeUi;
|
||||||
import com.android.systemui.doze.DozeWallpaperState;
|
import com.android.systemui.doze.DozeWallpaperState;
|
||||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
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.AsyncSensorManager;
|
||||||
import com.android.systemui.util.wakelock.DelayedWakeLock;
|
import com.android.systemui.util.wakelock.DelayedWakeLock;
|
||||||
import com.android.systemui.util.wakelock.WakeLock;
|
import com.android.systemui.util.wakelock.WakeLock;
|
||||||
@@ -94,8 +95,15 @@ public abstract class DozeModule {
|
|||||||
@Provides
|
@Provides
|
||||||
@BrightnessSensor
|
@BrightnessSensor
|
||||||
static Optional<Sensor> providesBrightnessSensor(
|
static Optional<Sensor> providesBrightnessSensor(
|
||||||
AsyncSensorManager sensorManager, Context context) {
|
AsyncSensorManager sensorManager,
|
||||||
return Optional.ofNullable(DozeSensors.findSensorWithType(sensorManager,
|
Context context,
|
||||||
context.getString(R.string.doze_brightness_sensor_type)));
|
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.SystemProperties;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.MathUtils;
|
import android.util.MathUtils;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -35,6 +36,7 @@ import com.android.systemui.doze.DozeScreenState;
|
|||||||
import com.android.systemui.dump.DumpManager;
|
import com.android.systemui.dump.DumpManager;
|
||||||
import com.android.systemui.flags.FeatureFlags;
|
import com.android.systemui.flags.FeatureFlags;
|
||||||
import com.android.systemui.statusbar.policy.BatteryController;
|
import com.android.systemui.statusbar.policy.BatteryController;
|
||||||
|
import com.android.systemui.statusbar.policy.DevicePostureController;
|
||||||
import com.android.systemui.tuner.TunerService;
|
import com.android.systemui.tuner.TunerService;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
@@ -255,10 +257,21 @@ public class DozeParameters implements
|
|||||||
return mResources.getBoolean(R.bool.doze_double_tap_reports_touch_coordinates);
|
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.
|
* 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);
|
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);
|
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.
|
* Callback to listen for DozeParameter changes.
|
||||||
*/
|
*/
|
||||||
@@ -308,6 +332,20 @@ public class DozeParameters implements
|
|||||||
pw.println(getSelectivelyRegisterSensorsUsingProx());
|
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 {
|
interface Callback {
|
||||||
/**
|
/**
|
||||||
* Invoked when the value of getAlwaysOn may have changed.
|
* Invoked when the value of getAlwaysOn may have changed.
|
||||||
|
|||||||
@@ -50,6 +50,26 @@ public interface DevicePostureController extends CallbackController<Callback> {
|
|||||||
/** Return the current device posture. */
|
/** Return the current device posture. */
|
||||||
@DevicePostureInt int getDevicePosture();
|
@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. */
|
/** Callback to be notified about device posture changes. */
|
||||||
interface Callback {
|
interface Callback {
|
||||||
/** Called when the posture changes. */
|
/** Called when the posture changes. */
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class DozeConfigurationUtil {
|
|||||||
when(params.doubleTapReportsTouchCoordinates()).thenReturn(false);
|
when(params.doubleTapReportsTouchCoordinates()).thenReturn(false);
|
||||||
when(params.getDisplayNeedsBlanking()).thenReturn(false);
|
when(params.getDisplayNeedsBlanking()).thenReturn(false);
|
||||||
when(params.getSelectivelyRegisterSensorsUsingProx()).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.longPressUsesProx()).thenReturn(true);
|
||||||
when(params.getQuickPickupAodDuration()).thenReturn(500);
|
when(params.getQuickPickupAodDuration()).thenReturn(500);
|
||||||
|
|
||||||
@@ -61,14 +61,13 @@ public class DozeConfigurationUtil {
|
|||||||
when(config.getWakeLockScreenDebounce()).thenReturn(0L);
|
when(config.getWakeLockScreenDebounce()).thenReturn(0L);
|
||||||
|
|
||||||
when(config.doubleTapSensorType()).thenReturn(null);
|
when(config.doubleTapSensorType()).thenReturn(null);
|
||||||
when(config.tapSensorType()).thenReturn(null);
|
|
||||||
when(config.longPressSensorType()).thenReturn(null);
|
when(config.longPressSensorType()).thenReturn(null);
|
||||||
when(config.udfpsLongPressSensorType()).thenReturn(null);
|
when(config.udfpsLongPressSensorType()).thenReturn(null);
|
||||||
when(config.quickPickupSensorType()).thenReturn(null);
|
when(config.quickPickupSensorType()).thenReturn(null);
|
||||||
|
|
||||||
when(config.tapGestureEnabled(anyInt())).thenReturn(true);
|
when(config.tapGestureEnabled(anyInt())).thenReturn(true);
|
||||||
when(config.tapSensorAvailable()).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.dozePickupSensorAvailable()).thenReturn(false);
|
||||||
when(config.wakeScreenGestureAvailable()).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.doze.DozeLog.REASON_SENSOR_TAP;
|
||||||
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.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
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.doze.DozeSensors.TriggerSensor;
|
||||||
import com.android.systemui.plugins.SensorManagerPlugin;
|
import com.android.systemui.plugins.SensorManagerPlugin;
|
||||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
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.AsyncSensorManager;
|
||||||
import com.android.systemui.util.sensors.ProximitySensor;
|
import com.android.systemui.util.sensors.ProximitySensor;
|
||||||
import com.android.systemui.util.settings.FakeSettings;
|
import com.android.systemui.util.settings.FakeSettings;
|
||||||
@@ -58,6 +60,11 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
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;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@RunWith(AndroidTestingRunner.class)
|
@RunWith(AndroidTestingRunner.class)
|
||||||
@@ -85,6 +92,8 @@ public class DozeSensorsTest extends SysuiTestCase {
|
|||||||
private AuthController mAuthController;
|
private AuthController mAuthController;
|
||||||
@Mock
|
@Mock
|
||||||
private ProximitySensor mProximitySensor;
|
private ProximitySensor mProximitySensor;
|
||||||
|
private @DevicePostureController.DevicePostureInt int mDevicePosture =
|
||||||
|
DevicePostureController.DEVICE_POSTURE_UNKNOWN;
|
||||||
private FakeSettings mFakeSettings = new FakeSettings();
|
private FakeSettings mFakeSettings = new FakeSettings();
|
||||||
private SensorManagerPlugin.SensorEventListener mWakeLockScreenListener;
|
private SensorManagerPlugin.SensorEventListener mWakeLockScreenListener;
|
||||||
private TestableLooper mTestableLooper;
|
private TestableLooper mTestableLooper;
|
||||||
@@ -101,6 +110,7 @@ public class DozeSensorsTest extends SysuiTestCase {
|
|||||||
((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));
|
||||||
|
mDevicePosture = DevicePostureController.DEVICE_POSTURE_UNKNOWN;
|
||||||
mDozeSensors = new TestableDozeSensors();
|
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
|
// GIVEN we only should register sensors using prox when not in low-powered mode / off
|
||||||
// and the single tap sensor uses the proximity sensor
|
// and the single tap sensor uses the proximity sensor
|
||||||
when(mDozeParameters.getSelectivelyRegisterSensorsUsingProx()).thenReturn(true);
|
when(mDozeParameters.getSelectivelyRegisterSensorsUsingProx()).thenReturn(true);
|
||||||
when(mDozeParameters.singleTapUsesProx()).thenReturn(true);
|
when(mDozeParameters.singleTapUsesProx(anyInt())).thenReturn(true);
|
||||||
TestableDozeSensors dozeSensors = new TestableDozeSensors();
|
TestableDozeSensors dozeSensors = new TestableDozeSensors();
|
||||||
|
|
||||||
// THEN on initialization, the tap sensor isn't requested
|
// THEN on initialization, the tap sensor isn't requested
|
||||||
@@ -258,12 +268,55 @@ public class DozeSensorsTest extends SysuiTestCase {
|
|||||||
assertTrue(triggerSensor.mRegistered);
|
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 {
|
private class TestableDozeSensors extends DozeSensors {
|
||||||
|
|
||||||
TestableDozeSensors() {
|
TestableDozeSensors() {
|
||||||
super(getContext(), mSensorManager, mDozeParameters,
|
super(getContext(), mSensorManager, mDozeParameters,
|
||||||
mAmbientDisplayConfiguration, mWakeLock, mCallback, mProxCallback, mDozeLog,
|
mAmbientDisplayConfiguration, mWakeLock, mCallback, mProxCallback, mDozeLog,
|
||||||
mProximitySensor, mFakeSettings, mAuthController);
|
mProximitySensor, mFakeSettings, mAuthController,
|
||||||
|
mDevicePosture);
|
||||||
for (TriggerSensor sensor : mSensors) {
|
for (TriggerSensor sensor : mSensors) {
|
||||||
if (sensor instanceof PluginSensor
|
if (sensor instanceof PluginSensor
|
||||||
&& ((PluginSensor) sensor).mPluginSensor.getType()
|
&& ((PluginSensor) sensor).mPluginSensor.getType()
|
||||||
@@ -288,4 +341,23 @@ public class DozeSensorsTest extends SysuiTestCase {
|
|||||||
mDozeLog);
|
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.dock.DockManager;
|
||||||
import com.android.systemui.doze.DozeTriggers.DozingUpdateUiEvent;
|
import com.android.systemui.doze.DozeTriggers.DozingUpdateUiEvent;
|
||||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
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.statusbar.policy.KeyguardStateController;
|
||||||
import com.android.systemui.util.concurrency.FakeExecutor;
|
import com.android.systemui.util.concurrency.FakeExecutor;
|
||||||
import com.android.systemui.util.concurrency.FakeThreadFactory;
|
import com.android.systemui.util.concurrency.FakeThreadFactory;
|
||||||
@@ -86,6 +87,8 @@ public class DozeTriggersTest extends SysuiTestCase {
|
|||||||
private UiEventLogger mUiEventLogger;
|
private UiEventLogger mUiEventLogger;
|
||||||
@Mock
|
@Mock
|
||||||
private KeyguardStateController mKeyguardStateController;
|
private KeyguardStateController mKeyguardStateController;
|
||||||
|
@Mock
|
||||||
|
private DevicePostureController mDevicePostureController;
|
||||||
|
|
||||||
private DozeTriggers mTriggers;
|
private DozeTriggers mTriggers;
|
||||||
private FakeSensorManager mSensors;
|
private FakeSensorManager mSensors;
|
||||||
@@ -117,7 +120,8 @@ public class DozeTriggersTest extends SysuiTestCase {
|
|||||||
mTriggers = new DozeTriggers(mContext, mHost, config, dozeParameters,
|
mTriggers = new DozeTriggers(mContext, mHost, config, dozeParameters,
|
||||||
asyncSensorManager, wakeLock, mDockManager, mProximitySensor,
|
asyncSensorManager, wakeLock, mDockManager, mProximitySensor,
|
||||||
mProximityCheck, mock(DozeLog.class), mBroadcastDispatcher, new FakeSettings(),
|
mProximityCheck, mock(DozeLog.class), mBroadcastDispatcher, new FakeSettings(),
|
||||||
mAuthController, mExecutor, mUiEventLogger, mKeyguardStateController);
|
mAuthController, mExecutor, mUiEventLogger, mKeyguardStateController,
|
||||||
|
mDevicePostureController);
|
||||||
mTriggers.setDozeMachine(mMachine);
|
mTriggers.setDozeMachine(mMachine);
|
||||||
waitForSensorManager();
|
waitForSensorManager();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user