Loading packages/SystemUI/res/values/config.xml +1 −17 Original line number Original line Diff line number Diff line Loading @@ -194,25 +194,9 @@ <!-- Doze: duration to avoid false pickup gestures triggered by notification vibrations --> <!-- Doze: duration to avoid false pickup gestures triggered by notification vibrations --> <integer name="doze_pickup_vibration_threshold">2000</integer> <integer name="doze_pickup_vibration_threshold">2000</integer> <!-- Doze: can we assume the pickup sensor includes a proximity check? <!-- Doze: can we assume the pickup sensor includes a proximity check? --> This is ignored if doze_pickup_subtype_performs_proximity_check is not empty. @deprecated: use doze_pickup_subtype_performs_proximity_check instead.--> <bool name="doze_pickup_performs_proximity_check">false</bool> <bool name="doze_pickup_performs_proximity_check">false</bool> <!-- Doze: a list of pickup sensor subtypes that perform a proximity check before they trigger. If not empty, either * or !* must appear to specify the default. If empty, falls back to doze_pickup_performs_proximity_check. Examples: 1,2,3,!* -> subtypes 1,2 and 3 perform the check, all others don't. !1,!2,* -> subtypes 1 and 2 don't perform the check, all others do. !8,* -> subtype 8 does not perform the check, all others do 1,1,* -> illegal, every item may only appear once 1,!1,* -> illegal, no contradictions allowed 1,2 -> illegal, need either * or !* 1,,4a3 -> illegal, no empty or non-numeric terms allowed --> <string name="doze_pickup_subtype_performs_proximity_check"></string> <!-- Type of a sensor that provides a low-power estimate of the desired display <!-- Type of a sensor that provides a low-power estimate of the desired display brightness, suitable to listen to while the device is asleep (e.g. during brightness, suitable to listen to while the device is asleep (e.g. during always-on display) --> always-on display) --> Loading packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java +65 −23 Original line number Original line Diff line number Diff line Loading @@ -76,6 +76,8 @@ public class DozeSensors { private final ProxSensor mProxSensor; private final ProxSensor mProxSensor; private long mDebounceFrom; private long mDebounceFrom; private boolean mSettingRegistered; private boolean mSettingRegistered; private boolean mListening; private boolean mPaused; public DozeSensors(Context context, AlarmManager alarmManager, SensorManager sensorManager, public DozeSensors(Context context, AlarmManager alarmManager, SensorManager sensorManager, DozeParameters dozeParameters, AmbientDisplayConfiguration config, WakeLock wakeLock, DozeParameters dozeParameters, AmbientDisplayConfiguration config, WakeLock wakeLock, Loading @@ -100,9 +102,12 @@ public class DozeSensors { mPickupSensor = new TriggerSensor( mPickupSensor = new TriggerSensor( mSensorManager.getDefaultSensor(Sensor.TYPE_PICK_UP_GESTURE), mSensorManager.getDefaultSensor(Sensor.TYPE_PICK_UP_GESTURE), Settings.Secure.DOZE_PICK_UP_GESTURE, Settings.Secure.DOZE_PICK_UP_GESTURE, true /* settingDef */, config.dozePickupSensorAvailable(), config.dozePickupSensorAvailable(), DozeLog.REASON_SENSOR_PICKUP, false /* touchCoords */, DozeLog.REASON_SENSOR_PICKUP, false /* touchCoords */, false /* touchscreen */), false /* touchscreen */, false /* ignoresSetting */, mDozeParameters.getPickupPerformsProxCheck()), new TriggerSensor( new TriggerSensor( findSensorWithType(config.doubleTapSensorType()), findSensorWithType(config.doubleTapSensorType()), Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, Loading Loading @@ -170,11 +175,49 @@ public class DozeSensors { return null; return null; } } /** * If sensors should be registered and sending signals. */ public void setListening(boolean listen) { public void setListening(boolean listen) { if (mListening == listen) { return; } mListening = listen; updateListening(); } /** * Unregister sensors, when listening, unless they are prox gated. * @see #setListening(boolean) */ public void setPaused(boolean paused) { if (mPaused == paused) { return; } mPaused = paused; updateListening(); } private void updateListening() { boolean anyListening = false; for (TriggerSensor s : mSensors) { for (TriggerSensor s : mSensors) { // We don't want to be listening while we're PAUSED (prox sensor is covered) // except when the sensor is already gated by prox. boolean listen = mListening && (!mPaused || s.performsProxCheck()); s.setListening(listen); s.setListening(listen); if (listen) { anyListening = true; } } registerSettingsObserverIfNeeded(listen); } if (!anyListening) { mResolver.unregisterContentObserver(mSettingsObserver); } else if (!mSettingRegistered) { for (TriggerSensor s : mSensors) { s.registerSettingsObserver(mSettingsObserver); } } mSettingRegistered = anyListening; } } /** Set the listening state of only the sensors that require the touchscreen. */ /** Set the listening state of only the sensors that require the touchscreen. */ Loading Loading @@ -236,17 +279,6 @@ public class DozeSensors { return mProxSensor.mCurrentlyFar; return mProxSensor.mCurrentlyFar; } } private void registerSettingsObserverIfNeeded(boolean register) { if (!register) { mResolver.unregisterContentObserver(mSettingsObserver); } else if (!mSettingRegistered) { for (TriggerSensor s : mSensors) { s.registerSettingsObserver(mSettingsObserver); } } mSettingRegistered = register; } private class ProxSensor implements SensorEventListener { private class ProxSensor implements SensorEventListener { boolean mRequested; boolean mRequested; Loading Loading @@ -334,10 +366,11 @@ public class DozeSensors { final Sensor mSensor; final Sensor mSensor; final boolean mConfigured; final boolean mConfigured; final int mPulseReason; final int mPulseReason; final String mSetting; private final String mSetting; final boolean mReportsTouchCoordinates; private final boolean mReportsTouchCoordinates; final boolean mSettingDefault; private final boolean mSettingDefault; final boolean mRequiresTouchscreen; private final boolean mRequiresTouchscreen; private final boolean mSensorPerformsProxCheck; protected boolean mRequested; protected boolean mRequested; protected boolean mRegistered; protected boolean mRegistered; Loading @@ -354,12 +387,14 @@ public class DozeSensors { boolean configured, int pulseReason, boolean reportsTouchCoordinates, boolean configured, int pulseReason, boolean reportsTouchCoordinates, boolean requiresTouchscreen) { boolean requiresTouchscreen) { this(sensor, setting, settingDef, configured, pulseReason, reportsTouchCoordinates, this(sensor, setting, settingDef, configured, pulseReason, reportsTouchCoordinates, requiresTouchscreen, false /* ignoresSetting */); requiresTouchscreen, false /* ignoresSetting */, false /* sensorPerformsProxCheck */); } } private TriggerSensor(Sensor sensor, String setting, boolean settingDef, private TriggerSensor(Sensor sensor, String setting, boolean settingDef, boolean configured, int pulseReason, boolean reportsTouchCoordinates, boolean configured, int pulseReason, boolean reportsTouchCoordinates, boolean requiresTouchscreen, boolean ignoresSetting) { boolean requiresTouchscreen, boolean ignoresSetting, boolean sensorPerformsProxCheck) { mSensor = sensor; mSensor = sensor; mSetting = setting; mSetting = setting; mSettingDefault = settingDef; mSettingDefault = settingDef; Loading @@ -368,6 +403,7 @@ public class DozeSensors { mReportsTouchCoordinates = reportsTouchCoordinates; mReportsTouchCoordinates = reportsTouchCoordinates; mRequiresTouchscreen = requiresTouchscreen; mRequiresTouchscreen = requiresTouchscreen; mIgnoresSetting = ignoresSetting; mIgnoresSetting = ignoresSetting; mSensorPerformsProxCheck = sensorPerformsProxCheck; } } public void setListening(boolean listen) { public void setListening(boolean listen) { Loading Loading @@ -427,14 +463,11 @@ public class DozeSensors { DozeLog.traceSensor(mContext, mPulseReason); DozeLog.traceSensor(mContext, mPulseReason); mHandler.post(mWakeLock.wrap(() -> { mHandler.post(mWakeLock.wrap(() -> { if (DEBUG) Log.d(TAG, "onTrigger: " + triggerEventToString(event)); if (DEBUG) Log.d(TAG, "onTrigger: " + triggerEventToString(event)); boolean sensorPerformsProxCheck = false; if (mSensor != null && mSensor.getType() == Sensor.TYPE_PICK_UP_GESTURE) { if (mSensor != null && mSensor.getType() == Sensor.TYPE_PICK_UP_GESTURE) { int subType = (int) event.values[0]; int subType = (int) event.values[0]; MetricsLogger.action( MetricsLogger.action( mContext, MetricsProto.MetricsEvent.ACTION_AMBIENT_GESTURE, mContext, MetricsProto.MetricsEvent.ACTION_AMBIENT_GESTURE, subType); subType); sensorPerformsProxCheck = mDozeParameters.getPickupSubtypePerformsProxCheck(subType); } } mRegistered = false; mRegistered = false; Loading @@ -444,7 +477,7 @@ public class DozeSensors { screenX = event.values[0]; screenX = event.values[0]; screenY = event.values[1]; screenY = event.values[1]; } } mCallback.onSensorPulse(mPulseReason, sensorPerformsProxCheck, screenX, screenY, mCallback.onSensorPulse(mPulseReason, mSensorPerformsProxCheck, screenX, screenY, event.values); event.values); if (!mRegistered) { if (!mRegistered) { updateListener(); // reregister, this sensor only fires once updateListener(); // reregister, this sensor only fires once Loading @@ -452,6 +485,15 @@ public class DozeSensors { })); })); } } /** * If the sensor itself performs proximity checks, to avoid pocket dialing. * Gated sensors don't need to be stopped when the {@link DozeMachine} is * {@link DozeMachine.State#DOZE_AOD_PAUSED}. */ public boolean performsProxCheck() { return mSensorPerformsProxCheck; } public void registerSettingsObserver(ContentObserver settingsObserver) { public void registerSettingsObserver(ContentObserver settingsObserver) { if (mConfigured && !TextUtils.isEmpty(mSetting)) { if (mConfigured && !TextUtils.isEmpty(mSetting)) { mResolver.registerContentObserver( mResolver.registerContentObserver( Loading packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java +3 −1 Original line number Original line Diff line number Diff line Loading @@ -296,6 +296,7 @@ public class DozeTriggers implements DozeMachine.Part { case DOZE_AOD: case DOZE_AOD: mDozeSensors.setProxListening(newState != DozeMachine.State.DOZE); mDozeSensors.setProxListening(newState != DozeMachine.State.DOZE); mDozeSensors.setListening(true); mDozeSensors.setListening(true); mDozeSensors.setPaused(false); if (newState == DozeMachine.State.DOZE_AOD && !sWakeDisplaySensorState) { if (newState == DozeMachine.State.DOZE_AOD && !sWakeDisplaySensorState) { onWakeScreen(false, newState); onWakeScreen(false, newState); } } Loading @@ -303,12 +304,13 @@ public class DozeTriggers implements DozeMachine.Part { case DOZE_AOD_PAUSED: case DOZE_AOD_PAUSED: case DOZE_AOD_PAUSING: case DOZE_AOD_PAUSING: mDozeSensors.setProxListening(true); mDozeSensors.setProxListening(true); mDozeSensors.setListening(false); mDozeSensors.setPaused(true); break; break; case DOZE_PULSING: case DOZE_PULSING: case DOZE_PULSING_BRIGHT: case DOZE_PULSING_BRIGHT: mDozeSensors.setTouchscreenSensorsListening(false); mDozeSensors.setTouchscreenSensorsListening(false); mDozeSensors.setProxListening(true); mDozeSensors.setProxListening(true); mDozeSensors.setPaused(false); break; break; case DOZE_PULSE_DONE: case DOZE_PULSE_DONE: mDozeSensors.requestTemporaryDisable(); mDozeSensors.requestTemporaryDisable(); Loading packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java +2 −110 Original line number Original line Diff line number Diff line Loading @@ -22,9 +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.text.TextUtils; import android.util.MathUtils; import android.util.MathUtils; import android.util.SparseBooleanArray; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.systemui.Dependency; import com.android.systemui.Dependency; Loading @@ -41,13 +39,11 @@ import java.io.PrintWriter; public class DozeParameters implements TunerService.Tunable, public class DozeParameters implements TunerService.Tunable, com.android.systemui.plugins.statusbar.DozeParameters { com.android.systemui.plugins.statusbar.DozeParameters { private static final int MAX_DURATION = 60 * 1000; private static final int MAX_DURATION = 60 * 1000; public static final String DOZE_SENSORS_WAKE_UP_FULLY = "doze_sensors_wake_up_fully"; public static final boolean FORCE_NO_BLANKING = public static final boolean FORCE_NO_BLANKING = SystemProperties.getBoolean("debug.force_no_blanking", false); SystemProperties.getBoolean("debug.force_no_blanking", false); public static final boolean FORCE_BLANKING = public static final boolean FORCE_BLANKING = SystemProperties.getBoolean("debug.force_blanking", false); SystemProperties.getBoolean("debug.force_blanking", false); private static IntInOutMatcher sPickupSubtypePerformsProxMatcher; private static DozeParameters sInstance; private static DozeParameters sInstance; private final Context mContext; private final Context mContext; Loading Loading @@ -92,20 +88,6 @@ public class DozeParameters implements TunerService.Tunable, pw.print(" getVibrateOnPickup(): "); pw.println(getVibrateOnPickup()); pw.print(" getVibrateOnPickup(): "); pw.println(getVibrateOnPickup()); pw.print(" getProxCheckBeforePulse(): "); pw.println(getProxCheckBeforePulse()); pw.print(" getProxCheckBeforePulse(): "); pw.println(getProxCheckBeforePulse()); pw.print(" getPickupVibrationThreshold(): "); pw.println(getPickupVibrationThreshold()); pw.print(" getPickupVibrationThreshold(): "); pw.println(getPickupVibrationThreshold()); pw.print(" getPickupSubtypePerformsProxCheck(): ");pw.println( dumpPickupSubtypePerformsProxCheck()); } private String dumpPickupSubtypePerformsProxCheck() { // Refresh sPickupSubtypePerformsProxMatcher getPickupSubtypePerformsProxCheck(0); if (sPickupSubtypePerformsProxMatcher == null) { return "fallback: " + mContext.getResources().getBoolean( R.bool.doze_pickup_performs_proximity_check); } else { return "spec: " + sPickupSubtypePerformsProxMatcher.mSpec; } } } public boolean getDisplayStateSupported() { public boolean getDisplayStateSupported() { Loading Loading @@ -225,23 +207,10 @@ public class DozeParameters implements TunerService.Tunable, return SystemProperties.get(propName, mContext.getString(resId)); return SystemProperties.get(propName, mContext.getString(resId)); } } public boolean getPickupSubtypePerformsProxCheck(int subType) { public boolean getPickupPerformsProxCheck() { String spec = getString("doze.pickup.proxcheck", R.string.doze_pickup_subtype_performs_proximity_check); if (TextUtils.isEmpty(spec)) { // Fall back to non-subtype based property. return mContext.getResources().getBoolean(R.bool.doze_pickup_performs_proximity_check); return mContext.getResources().getBoolean(R.bool.doze_pickup_performs_proximity_check); } } if (sPickupSubtypePerformsProxMatcher == null || !TextUtils.equals(spec, sPickupSubtypePerformsProxMatcher.mSpec)) { sPickupSubtypePerformsProxMatcher = new IntInOutMatcher(spec); } return sPickupSubtypePerformsProxMatcher.isIn(subType); } public int getPulseVisibleDurationExtended() { public int getPulseVisibleDurationExtended() { return 2 * getPulseVisibleDuration(); return 2 * getPulseVisibleDuration(); } } Loading @@ -258,81 +227,4 @@ public class DozeParameters implements TunerService.Tunable, public AlwaysOnDisplayPolicy getPolicy() { public AlwaysOnDisplayPolicy getPolicy() { return mAlwaysOnPolicy; return mAlwaysOnPolicy; } } /** * Parses a spec of the form `1,2,3,!5,*`. The resulting object will match numbers that are * listed, will not match numbers that are listed with a ! prefix, and will match / not match * unlisted numbers depending on whether * or !* is present. * * * -> match any numbers that are not explicitly listed * !* -> don't match any numbers that are not explicitly listed * 2 -> match 2 * !3 -> don't match 3 * * It is illegal to specify: * - an empty spec * - a spec containing that are empty, or a lone ! * - a spec for anything other than numbers or * * - multiple terms for the same number / multiple *s */ public static class IntInOutMatcher { private static final String WILDCARD = "*"; private static final char OUT_PREFIX = '!'; private final SparseBooleanArray mIsIn; private final boolean mDefaultIsIn; final String mSpec; public IntInOutMatcher(String spec) { if (TextUtils.isEmpty(spec)) { throw new IllegalArgumentException("Spec must not be empty"); } boolean defaultIsIn = false; boolean foundWildcard = false; mSpec = spec; mIsIn = new SparseBooleanArray(); for (String itemPrefixed : spec.split(",", -1)) { if (itemPrefixed.length() == 0) { throw new IllegalArgumentException( "Illegal spec, must not have zero-length items: `" + spec + "`"); } boolean isIn = itemPrefixed.charAt(0) != OUT_PREFIX; String item = isIn ? itemPrefixed : itemPrefixed.substring(1); if (itemPrefixed.length() == 0) { throw new IllegalArgumentException( "Illegal spec, must not have zero-length items: `" + spec + "`"); } if (WILDCARD.equals(item)) { if (foundWildcard) { throw new IllegalArgumentException("Illegal spec, `" + WILDCARD + "` must not appear multiple times in `" + spec + "`"); } defaultIsIn = isIn; foundWildcard = true; } else { int key = Integer.parseInt(item); if (mIsIn.indexOfKey(key) >= 0) { throw new IllegalArgumentException("Illegal spec, `" + key + "` must not appear multiple times in `" + spec + "`"); } mIsIn.put(key, isIn); } } if (!foundWildcard) { throw new IllegalArgumentException("Illegal spec, must specify either * or !*"); } mDefaultIsIn = defaultIsIn; } public boolean isIn(int value) { return (mIsIn.get(value, mDefaultIsIn)); } } } } packages/SystemUI/tests/src/com/android/systemui/doze/DozeConfigurationUtil.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -36,7 +36,7 @@ public class DozeConfigurationUtil { when(params.getPulseOnSigMotion()).thenReturn(false); when(params.getPulseOnSigMotion()).thenReturn(false); when(params.getPickupVibrationThreshold()).thenReturn(0); when(params.getPickupVibrationThreshold()).thenReturn(0); when(params.getProxCheckBeforePulse()).thenReturn(true); when(params.getProxCheckBeforePulse()).thenReturn(true); when(params.getPickupSubtypePerformsProxCheck(anyInt())).thenReturn(true); when(params.getPickupPerformsProxCheck()).thenReturn(true); when(params.getPolicy()).thenReturn(mock(AlwaysOnDisplayPolicy.class)); when(params.getPolicy()).thenReturn(mock(AlwaysOnDisplayPolicy.class)); when(params.doubleTapReportsTouchCoordinates()).thenReturn(false); when(params.doubleTapReportsTouchCoordinates()).thenReturn(false); Loading Loading
packages/SystemUI/res/values/config.xml +1 −17 Original line number Original line Diff line number Diff line Loading @@ -194,25 +194,9 @@ <!-- Doze: duration to avoid false pickup gestures triggered by notification vibrations --> <!-- Doze: duration to avoid false pickup gestures triggered by notification vibrations --> <integer name="doze_pickup_vibration_threshold">2000</integer> <integer name="doze_pickup_vibration_threshold">2000</integer> <!-- Doze: can we assume the pickup sensor includes a proximity check? <!-- Doze: can we assume the pickup sensor includes a proximity check? --> This is ignored if doze_pickup_subtype_performs_proximity_check is not empty. @deprecated: use doze_pickup_subtype_performs_proximity_check instead.--> <bool name="doze_pickup_performs_proximity_check">false</bool> <bool name="doze_pickup_performs_proximity_check">false</bool> <!-- Doze: a list of pickup sensor subtypes that perform a proximity check before they trigger. If not empty, either * or !* must appear to specify the default. If empty, falls back to doze_pickup_performs_proximity_check. Examples: 1,2,3,!* -> subtypes 1,2 and 3 perform the check, all others don't. !1,!2,* -> subtypes 1 and 2 don't perform the check, all others do. !8,* -> subtype 8 does not perform the check, all others do 1,1,* -> illegal, every item may only appear once 1,!1,* -> illegal, no contradictions allowed 1,2 -> illegal, need either * or !* 1,,4a3 -> illegal, no empty or non-numeric terms allowed --> <string name="doze_pickup_subtype_performs_proximity_check"></string> <!-- Type of a sensor that provides a low-power estimate of the desired display <!-- Type of a sensor that provides a low-power estimate of the desired display brightness, suitable to listen to while the device is asleep (e.g. during brightness, suitable to listen to while the device is asleep (e.g. during always-on display) --> always-on display) --> Loading
packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java +65 −23 Original line number Original line Diff line number Diff line Loading @@ -76,6 +76,8 @@ public class DozeSensors { private final ProxSensor mProxSensor; private final ProxSensor mProxSensor; private long mDebounceFrom; private long mDebounceFrom; private boolean mSettingRegistered; private boolean mSettingRegistered; private boolean mListening; private boolean mPaused; public DozeSensors(Context context, AlarmManager alarmManager, SensorManager sensorManager, public DozeSensors(Context context, AlarmManager alarmManager, SensorManager sensorManager, DozeParameters dozeParameters, AmbientDisplayConfiguration config, WakeLock wakeLock, DozeParameters dozeParameters, AmbientDisplayConfiguration config, WakeLock wakeLock, Loading @@ -100,9 +102,12 @@ public class DozeSensors { mPickupSensor = new TriggerSensor( mPickupSensor = new TriggerSensor( mSensorManager.getDefaultSensor(Sensor.TYPE_PICK_UP_GESTURE), mSensorManager.getDefaultSensor(Sensor.TYPE_PICK_UP_GESTURE), Settings.Secure.DOZE_PICK_UP_GESTURE, Settings.Secure.DOZE_PICK_UP_GESTURE, true /* settingDef */, config.dozePickupSensorAvailable(), config.dozePickupSensorAvailable(), DozeLog.REASON_SENSOR_PICKUP, false /* touchCoords */, DozeLog.REASON_SENSOR_PICKUP, false /* touchCoords */, false /* touchscreen */), false /* touchscreen */, false /* ignoresSetting */, mDozeParameters.getPickupPerformsProxCheck()), new TriggerSensor( new TriggerSensor( findSensorWithType(config.doubleTapSensorType()), findSensorWithType(config.doubleTapSensorType()), Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, Loading Loading @@ -170,11 +175,49 @@ public class DozeSensors { return null; return null; } } /** * If sensors should be registered and sending signals. */ public void setListening(boolean listen) { public void setListening(boolean listen) { if (mListening == listen) { return; } mListening = listen; updateListening(); } /** * Unregister sensors, when listening, unless they are prox gated. * @see #setListening(boolean) */ public void setPaused(boolean paused) { if (mPaused == paused) { return; } mPaused = paused; updateListening(); } private void updateListening() { boolean anyListening = false; for (TriggerSensor s : mSensors) { for (TriggerSensor s : mSensors) { // We don't want to be listening while we're PAUSED (prox sensor is covered) // except when the sensor is already gated by prox. boolean listen = mListening && (!mPaused || s.performsProxCheck()); s.setListening(listen); s.setListening(listen); if (listen) { anyListening = true; } } registerSettingsObserverIfNeeded(listen); } if (!anyListening) { mResolver.unregisterContentObserver(mSettingsObserver); } else if (!mSettingRegistered) { for (TriggerSensor s : mSensors) { s.registerSettingsObserver(mSettingsObserver); } } mSettingRegistered = anyListening; } } /** Set the listening state of only the sensors that require the touchscreen. */ /** Set the listening state of only the sensors that require the touchscreen. */ Loading Loading @@ -236,17 +279,6 @@ public class DozeSensors { return mProxSensor.mCurrentlyFar; return mProxSensor.mCurrentlyFar; } } private void registerSettingsObserverIfNeeded(boolean register) { if (!register) { mResolver.unregisterContentObserver(mSettingsObserver); } else if (!mSettingRegistered) { for (TriggerSensor s : mSensors) { s.registerSettingsObserver(mSettingsObserver); } } mSettingRegistered = register; } private class ProxSensor implements SensorEventListener { private class ProxSensor implements SensorEventListener { boolean mRequested; boolean mRequested; Loading Loading @@ -334,10 +366,11 @@ public class DozeSensors { final Sensor mSensor; final Sensor mSensor; final boolean mConfigured; final boolean mConfigured; final int mPulseReason; final int mPulseReason; final String mSetting; private final String mSetting; final boolean mReportsTouchCoordinates; private final boolean mReportsTouchCoordinates; final boolean mSettingDefault; private final boolean mSettingDefault; final boolean mRequiresTouchscreen; private final boolean mRequiresTouchscreen; private final boolean mSensorPerformsProxCheck; protected boolean mRequested; protected boolean mRequested; protected boolean mRegistered; protected boolean mRegistered; Loading @@ -354,12 +387,14 @@ public class DozeSensors { boolean configured, int pulseReason, boolean reportsTouchCoordinates, boolean configured, int pulseReason, boolean reportsTouchCoordinates, boolean requiresTouchscreen) { boolean requiresTouchscreen) { this(sensor, setting, settingDef, configured, pulseReason, reportsTouchCoordinates, this(sensor, setting, settingDef, configured, pulseReason, reportsTouchCoordinates, requiresTouchscreen, false /* ignoresSetting */); requiresTouchscreen, false /* ignoresSetting */, false /* sensorPerformsProxCheck */); } } private TriggerSensor(Sensor sensor, String setting, boolean settingDef, private TriggerSensor(Sensor sensor, String setting, boolean settingDef, boolean configured, int pulseReason, boolean reportsTouchCoordinates, boolean configured, int pulseReason, boolean reportsTouchCoordinates, boolean requiresTouchscreen, boolean ignoresSetting) { boolean requiresTouchscreen, boolean ignoresSetting, boolean sensorPerformsProxCheck) { mSensor = sensor; mSensor = sensor; mSetting = setting; mSetting = setting; mSettingDefault = settingDef; mSettingDefault = settingDef; Loading @@ -368,6 +403,7 @@ public class DozeSensors { mReportsTouchCoordinates = reportsTouchCoordinates; mReportsTouchCoordinates = reportsTouchCoordinates; mRequiresTouchscreen = requiresTouchscreen; mRequiresTouchscreen = requiresTouchscreen; mIgnoresSetting = ignoresSetting; mIgnoresSetting = ignoresSetting; mSensorPerformsProxCheck = sensorPerformsProxCheck; } } public void setListening(boolean listen) { public void setListening(boolean listen) { Loading Loading @@ -427,14 +463,11 @@ public class DozeSensors { DozeLog.traceSensor(mContext, mPulseReason); DozeLog.traceSensor(mContext, mPulseReason); mHandler.post(mWakeLock.wrap(() -> { mHandler.post(mWakeLock.wrap(() -> { if (DEBUG) Log.d(TAG, "onTrigger: " + triggerEventToString(event)); if (DEBUG) Log.d(TAG, "onTrigger: " + triggerEventToString(event)); boolean sensorPerformsProxCheck = false; if (mSensor != null && mSensor.getType() == Sensor.TYPE_PICK_UP_GESTURE) { if (mSensor != null && mSensor.getType() == Sensor.TYPE_PICK_UP_GESTURE) { int subType = (int) event.values[0]; int subType = (int) event.values[0]; MetricsLogger.action( MetricsLogger.action( mContext, MetricsProto.MetricsEvent.ACTION_AMBIENT_GESTURE, mContext, MetricsProto.MetricsEvent.ACTION_AMBIENT_GESTURE, subType); subType); sensorPerformsProxCheck = mDozeParameters.getPickupSubtypePerformsProxCheck(subType); } } mRegistered = false; mRegistered = false; Loading @@ -444,7 +477,7 @@ public class DozeSensors { screenX = event.values[0]; screenX = event.values[0]; screenY = event.values[1]; screenY = event.values[1]; } } mCallback.onSensorPulse(mPulseReason, sensorPerformsProxCheck, screenX, screenY, mCallback.onSensorPulse(mPulseReason, mSensorPerformsProxCheck, screenX, screenY, event.values); event.values); if (!mRegistered) { if (!mRegistered) { updateListener(); // reregister, this sensor only fires once updateListener(); // reregister, this sensor only fires once Loading @@ -452,6 +485,15 @@ public class DozeSensors { })); })); } } /** * If the sensor itself performs proximity checks, to avoid pocket dialing. * Gated sensors don't need to be stopped when the {@link DozeMachine} is * {@link DozeMachine.State#DOZE_AOD_PAUSED}. */ public boolean performsProxCheck() { return mSensorPerformsProxCheck; } public void registerSettingsObserver(ContentObserver settingsObserver) { public void registerSettingsObserver(ContentObserver settingsObserver) { if (mConfigured && !TextUtils.isEmpty(mSetting)) { if (mConfigured && !TextUtils.isEmpty(mSetting)) { mResolver.registerContentObserver( mResolver.registerContentObserver( Loading
packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java +3 −1 Original line number Original line Diff line number Diff line Loading @@ -296,6 +296,7 @@ public class DozeTriggers implements DozeMachine.Part { case DOZE_AOD: case DOZE_AOD: mDozeSensors.setProxListening(newState != DozeMachine.State.DOZE); mDozeSensors.setProxListening(newState != DozeMachine.State.DOZE); mDozeSensors.setListening(true); mDozeSensors.setListening(true); mDozeSensors.setPaused(false); if (newState == DozeMachine.State.DOZE_AOD && !sWakeDisplaySensorState) { if (newState == DozeMachine.State.DOZE_AOD && !sWakeDisplaySensorState) { onWakeScreen(false, newState); onWakeScreen(false, newState); } } Loading @@ -303,12 +304,13 @@ public class DozeTriggers implements DozeMachine.Part { case DOZE_AOD_PAUSED: case DOZE_AOD_PAUSED: case DOZE_AOD_PAUSING: case DOZE_AOD_PAUSING: mDozeSensors.setProxListening(true); mDozeSensors.setProxListening(true); mDozeSensors.setListening(false); mDozeSensors.setPaused(true); break; break; case DOZE_PULSING: case DOZE_PULSING: case DOZE_PULSING_BRIGHT: case DOZE_PULSING_BRIGHT: mDozeSensors.setTouchscreenSensorsListening(false); mDozeSensors.setTouchscreenSensorsListening(false); mDozeSensors.setProxListening(true); mDozeSensors.setProxListening(true); mDozeSensors.setPaused(false); break; break; case DOZE_PULSE_DONE: case DOZE_PULSE_DONE: mDozeSensors.requestTemporaryDisable(); mDozeSensors.requestTemporaryDisable(); Loading
packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java +2 −110 Original line number Original line Diff line number Diff line Loading @@ -22,9 +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.text.TextUtils; import android.util.MathUtils; import android.util.MathUtils; import android.util.SparseBooleanArray; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.systemui.Dependency; import com.android.systemui.Dependency; Loading @@ -41,13 +39,11 @@ import java.io.PrintWriter; public class DozeParameters implements TunerService.Tunable, public class DozeParameters implements TunerService.Tunable, com.android.systemui.plugins.statusbar.DozeParameters { com.android.systemui.plugins.statusbar.DozeParameters { private static final int MAX_DURATION = 60 * 1000; private static final int MAX_DURATION = 60 * 1000; public static final String DOZE_SENSORS_WAKE_UP_FULLY = "doze_sensors_wake_up_fully"; public static final boolean FORCE_NO_BLANKING = public static final boolean FORCE_NO_BLANKING = SystemProperties.getBoolean("debug.force_no_blanking", false); SystemProperties.getBoolean("debug.force_no_blanking", false); public static final boolean FORCE_BLANKING = public static final boolean FORCE_BLANKING = SystemProperties.getBoolean("debug.force_blanking", false); SystemProperties.getBoolean("debug.force_blanking", false); private static IntInOutMatcher sPickupSubtypePerformsProxMatcher; private static DozeParameters sInstance; private static DozeParameters sInstance; private final Context mContext; private final Context mContext; Loading Loading @@ -92,20 +88,6 @@ public class DozeParameters implements TunerService.Tunable, pw.print(" getVibrateOnPickup(): "); pw.println(getVibrateOnPickup()); pw.print(" getVibrateOnPickup(): "); pw.println(getVibrateOnPickup()); pw.print(" getProxCheckBeforePulse(): "); pw.println(getProxCheckBeforePulse()); pw.print(" getProxCheckBeforePulse(): "); pw.println(getProxCheckBeforePulse()); pw.print(" getPickupVibrationThreshold(): "); pw.println(getPickupVibrationThreshold()); pw.print(" getPickupVibrationThreshold(): "); pw.println(getPickupVibrationThreshold()); pw.print(" getPickupSubtypePerformsProxCheck(): ");pw.println( dumpPickupSubtypePerformsProxCheck()); } private String dumpPickupSubtypePerformsProxCheck() { // Refresh sPickupSubtypePerformsProxMatcher getPickupSubtypePerformsProxCheck(0); if (sPickupSubtypePerformsProxMatcher == null) { return "fallback: " + mContext.getResources().getBoolean( R.bool.doze_pickup_performs_proximity_check); } else { return "spec: " + sPickupSubtypePerformsProxMatcher.mSpec; } } } public boolean getDisplayStateSupported() { public boolean getDisplayStateSupported() { Loading Loading @@ -225,23 +207,10 @@ public class DozeParameters implements TunerService.Tunable, return SystemProperties.get(propName, mContext.getString(resId)); return SystemProperties.get(propName, mContext.getString(resId)); } } public boolean getPickupSubtypePerformsProxCheck(int subType) { public boolean getPickupPerformsProxCheck() { String spec = getString("doze.pickup.proxcheck", R.string.doze_pickup_subtype_performs_proximity_check); if (TextUtils.isEmpty(spec)) { // Fall back to non-subtype based property. return mContext.getResources().getBoolean(R.bool.doze_pickup_performs_proximity_check); return mContext.getResources().getBoolean(R.bool.doze_pickup_performs_proximity_check); } } if (sPickupSubtypePerformsProxMatcher == null || !TextUtils.equals(spec, sPickupSubtypePerformsProxMatcher.mSpec)) { sPickupSubtypePerformsProxMatcher = new IntInOutMatcher(spec); } return sPickupSubtypePerformsProxMatcher.isIn(subType); } public int getPulseVisibleDurationExtended() { public int getPulseVisibleDurationExtended() { return 2 * getPulseVisibleDuration(); return 2 * getPulseVisibleDuration(); } } Loading @@ -258,81 +227,4 @@ public class DozeParameters implements TunerService.Tunable, public AlwaysOnDisplayPolicy getPolicy() { public AlwaysOnDisplayPolicy getPolicy() { return mAlwaysOnPolicy; return mAlwaysOnPolicy; } } /** * Parses a spec of the form `1,2,3,!5,*`. The resulting object will match numbers that are * listed, will not match numbers that are listed with a ! prefix, and will match / not match * unlisted numbers depending on whether * or !* is present. * * * -> match any numbers that are not explicitly listed * !* -> don't match any numbers that are not explicitly listed * 2 -> match 2 * !3 -> don't match 3 * * It is illegal to specify: * - an empty spec * - a spec containing that are empty, or a lone ! * - a spec for anything other than numbers or * * - multiple terms for the same number / multiple *s */ public static class IntInOutMatcher { private static final String WILDCARD = "*"; private static final char OUT_PREFIX = '!'; private final SparseBooleanArray mIsIn; private final boolean mDefaultIsIn; final String mSpec; public IntInOutMatcher(String spec) { if (TextUtils.isEmpty(spec)) { throw new IllegalArgumentException("Spec must not be empty"); } boolean defaultIsIn = false; boolean foundWildcard = false; mSpec = spec; mIsIn = new SparseBooleanArray(); for (String itemPrefixed : spec.split(",", -1)) { if (itemPrefixed.length() == 0) { throw new IllegalArgumentException( "Illegal spec, must not have zero-length items: `" + spec + "`"); } boolean isIn = itemPrefixed.charAt(0) != OUT_PREFIX; String item = isIn ? itemPrefixed : itemPrefixed.substring(1); if (itemPrefixed.length() == 0) { throw new IllegalArgumentException( "Illegal spec, must not have zero-length items: `" + spec + "`"); } if (WILDCARD.equals(item)) { if (foundWildcard) { throw new IllegalArgumentException("Illegal spec, `" + WILDCARD + "` must not appear multiple times in `" + spec + "`"); } defaultIsIn = isIn; foundWildcard = true; } else { int key = Integer.parseInt(item); if (mIsIn.indexOfKey(key) >= 0) { throw new IllegalArgumentException("Illegal spec, `" + key + "` must not appear multiple times in `" + spec + "`"); } mIsIn.put(key, isIn); } } if (!foundWildcard) { throw new IllegalArgumentException("Illegal spec, must specify either * or !*"); } mDefaultIsIn = defaultIsIn; } public boolean isIn(int value) { return (mIsIn.get(value, mDefaultIsIn)); } } } }
packages/SystemUI/tests/src/com/android/systemui/doze/DozeConfigurationUtil.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -36,7 +36,7 @@ public class DozeConfigurationUtil { when(params.getPulseOnSigMotion()).thenReturn(false); when(params.getPulseOnSigMotion()).thenReturn(false); when(params.getPickupVibrationThreshold()).thenReturn(0); when(params.getPickupVibrationThreshold()).thenReturn(0); when(params.getProxCheckBeforePulse()).thenReturn(true); when(params.getProxCheckBeforePulse()).thenReturn(true); when(params.getPickupSubtypePerformsProxCheck(anyInt())).thenReturn(true); when(params.getPickupPerformsProxCheck()).thenReturn(true); when(params.getPolicy()).thenReturn(mock(AlwaysOnDisplayPolicy.class)); when(params.getPolicy()).thenReturn(mock(AlwaysOnDisplayPolicy.class)); when(params.doubleTapReportsTouchCoordinates()).thenReturn(false); when(params.doubleTapReportsTouchCoordinates()).thenReturn(false); Loading