Loading packages/SystemUI/res/values/config.xml +5 −0 Original line number Diff line number Diff line Loading @@ -194,6 +194,11 @@ low powered state yet. --> <bool name="doze_long_press_uses_prox">true</bool> <!-- Doze: whether the brightness sensor uses the proximity sensor. If both this parameter and doze_selectively_register_prox are true, registration for the brightness sensor won't occur when the display state is ON. --> <bool name="doze_brightness_uses_prox">true</bool> <!-- Doze: should notifications be used as a pulse signal? --> <bool name="doze_pulse_on_notifications">true</bool> Loading packages/SystemUI/src/com/android/systemui/doze/DozeScreenBrightness.java +13 −2 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.os.UserHandle; import android.provider.Settings; import android.view.Display; import com.android.systemui.dock.DockManager; import com.android.systemui.doze.dagger.BrightnessSensor; import com.android.systemui.doze.dagger.DozeScope; import com.android.systemui.doze.dagger.WrappedService; Loading Loading @@ -63,6 +64,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi private final Optional<Sensor> mLightSensorOptional; private final WakefulnessLifecycle mWakefulnessLifecycle; private final DozeParameters mDozeParameters; private final DockManager mDockManager; private final int[] mSensorToBrightness; private final int[] mSensorToScrimOpacity; private final int mScreenBrightnessDim; Loading @@ -87,7 +89,8 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi @BrightnessSensor Optional<Sensor> lightSensorOptional, DozeHost host, Handler handler, AlwaysOnDisplayPolicy alwaysOnDisplayPolicy, WakefulnessLifecycle wakefulnessLifecycle, DozeParameters dozeParameters) { DozeParameters dozeParameters, DockManager dockManager) { mContext = context; mDozeService = service; mSensorManager = sensorManager; Loading @@ -96,6 +99,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi mDozeParameters = dozeParameters; mDozeHost = host; mHandler = handler; mDockManager = dockManager; mDefaultDozeBrightness = alwaysOnDisplayPolicy.defaultDozeBrightness; mScreenBrightnessDim = alwaysOnDisplayPolicy.dimBrightness; Loading @@ -122,13 +126,20 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi @Override public void onScreenState(int state) { if (state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND) { boolean isDockedScreenOn = state == Display.STATE_ON && mDockManager.isDocked(); if (state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND || (isDockedScreenOn && shouldRegisterLightSensorWhenScreenOnDocked())) { setLightSensorEnabled(true); } else { setLightSensorEnabled(false); } } private boolean shouldRegisterLightSensorWhenScreenOnDocked() { return !mDozeParameters.brightnessUsesProx() || !mDozeParameters.getSelectivelyRegisterSensorsUsingProx(); } private void onDestroy() { setLightSensorEnabled(false); } Loading packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java +8 −0 Original line number Diff line number Diff line Loading @@ -267,6 +267,13 @@ public class DozeParameters implements TunerService.Tunable, return mResources.getBoolean(R.bool.doze_long_press_uses_prox); } /** * Whether the brightness sensor uses the proximity sensor. */ public boolean brightnessUsesProx() { return mResources.getBoolean(R.bool.doze_brightness_uses_prox); } /** * Callback to listen for DozeParameter changes. */ Loading Loading @@ -303,6 +310,7 @@ public class DozeParameters implements TunerService.Tunable, pw.print("getPickupVibrationThreshold(): "); pw.println(getPickupVibrationThreshold()); pw.print("getSelectivelyRegisterSensorsUsingProx(): "); pw.println(getSelectivelyRegisterSensorsUsingProx()); pw.print("brightnessUsesProx(): "); pw.println(brightnessUsesProx()); } interface Callback { Loading packages/SystemUI/tests/src/com/android/systemui/doze/DozeConfigurationUtil.java +1 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ public class DozeConfigurationUtil { when(params.singleTapUsesProx()).thenReturn(true); when(params.longPressUsesProx()).thenReturn(true); when(params.getQuickPickupAodDuration()).thenReturn(500); when(params.brightnessUsesProx()).thenReturn(true); doneHolder[0] = true; return params; Loading packages/SystemUI/tests/src/com/android/systemui/doze/DozeScreenBrightnessTest.java +68 −3 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import static com.android.systemui.doze.DozeMachine.State.UNINITIALIZED; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; Loading @@ -47,6 +48,7 @@ import android.view.Display; import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; import com.android.systemui.dock.DockManager; import com.android.systemui.keyguard.WakefulnessLifecycle; import com.android.systemui.statusbar.phone.DozeParameters; import com.android.systemui.util.concurrency.FakeExecutor; Loading Loading @@ -82,6 +84,8 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { WakefulnessLifecycle mWakefulnessLifecycle; @Mock DozeParameters mDozeParameters; @Mock DockManager mDockManager; private FakeExecutor mFakeExecutor = new FakeExecutor(new FakeSystemClock()); private FakeThreadFactory mFakeThreadFactory = new FakeThreadFactory(mFakeExecutor); Loading Loading @@ -109,7 +113,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { mSensor = fakeSensorManager.getFakeLightSensor(); mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager, Optional.of(mSensor.getSensor()), mDozeHost, null /* handler */, mAlwaysOnDisplayPolicy, mWakefulnessLifecycle, mDozeParameters); mAlwaysOnDisplayPolicy, mWakefulnessLifecycle, mDozeParameters, mDockManager); mScreen.onScreenState(Display.STATE_ON); } Loading Loading @@ -156,6 +160,67 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { assertEquals(maxBrightness, mServiceFake.screenBrightness); } @Test public void testAodDocked_doNotSelectivelyUseProx_usesLightSensor() { // GIVEN the device doesn't need to selectively register for prox sensors and // brightness sensor uses prox when(mDozeParameters.getSelectivelyRegisterSensorsUsingProx()).thenReturn(false); when(mDozeParameters.brightnessUsesProx()).thenReturn(true); // GIVEN the device is docked and the display state changes to ON when(mDockManager.isDocked()).thenReturn(true); mScreen.onScreenState(Display.STATE_ON); waitForSensorManager(); // WHEN new sensor event sent mSensor.sendSensorEvent(3); // THEN brightness is updated assertEquals(3, mServiceFake.screenBrightness); } @Test public void testAodDocked_brightnessDoesNotUseProx_usesLightSensor() { // GIVEN the device doesn't need to selectively register for prox sensors but // the brightness sensor doesn't use prox when(mDozeParameters.getSelectivelyRegisterSensorsUsingProx()).thenReturn(true); when(mDozeParameters.brightnessUsesProx()).thenReturn(false); // GIVEN the device is docked and the display state changes to ON when(mDockManager.isDocked()).thenReturn(true); mScreen.onScreenState(Display.STATE_ON); waitForSensorManager(); // WHEN new sensor event sent mSensor.sendSensorEvent(3); // THEN brightness is updated assertEquals(3, mServiceFake.screenBrightness); } @Test public void testAodDocked_noProx_brightnessUsesProx_doNotUseLightSensor() { final int startBrightness = mServiceFake.screenBrightness; // GIVEN the device needs to selectively register for prox sensors and // the brightness sensor uses prox when(mDozeParameters.getSelectivelyRegisterSensorsUsingProx()).thenReturn(true); when(mDozeParameters.brightnessUsesProx()).thenReturn(true); // GIVEN the device is docked and the display state is on when(mDockManager.isDocked()).thenReturn(true); mScreen.onScreenState(Display.STATE_ON); waitForSensorManager(); // WHEN new sensor event sent mSensor.sendSensorEvent(3); // THEN brightness is NOT changed assertNotSame(3, mServiceFake.screenBrightness); assertEquals(startBrightness, mServiceFake.screenBrightness); } @Test public void testPausingAod_doesNotResetBrightness() throws Exception { mScreen.transitionTo(UNINITIALIZED, INITIALIZED); Loading @@ -175,7 +240,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { public void testPulsing_withoutLightSensor_setsAoDDimmingScrimTransparent() throws Exception { mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager, Optional.empty() /* sensor */, mDozeHost, null /* handler */, mAlwaysOnDisplayPolicy, mWakefulnessLifecycle, mDozeParameters); mAlwaysOnDisplayPolicy, mWakefulnessLifecycle, mDozeParameters, mDockManager); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); mScreen.transitionTo(INITIALIZED, DOZE); reset(mDozeHost); Loading Loading @@ -216,7 +281,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { public void testNullSensor() throws Exception { mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager, Optional.empty() /* sensor */, mDozeHost, null /* handler */, mAlwaysOnDisplayPolicy, mWakefulnessLifecycle, mDozeParameters); mAlwaysOnDisplayPolicy, mWakefulnessLifecycle, mDozeParameters, mDockManager); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); mScreen.transitionTo(INITIALIZED, DOZE_AOD); Loading Loading
packages/SystemUI/res/values/config.xml +5 −0 Original line number Diff line number Diff line Loading @@ -194,6 +194,11 @@ low powered state yet. --> <bool name="doze_long_press_uses_prox">true</bool> <!-- Doze: whether the brightness sensor uses the proximity sensor. If both this parameter and doze_selectively_register_prox are true, registration for the brightness sensor won't occur when the display state is ON. --> <bool name="doze_brightness_uses_prox">true</bool> <!-- Doze: should notifications be used as a pulse signal? --> <bool name="doze_pulse_on_notifications">true</bool> Loading
packages/SystemUI/src/com/android/systemui/doze/DozeScreenBrightness.java +13 −2 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.os.UserHandle; import android.provider.Settings; import android.view.Display; import com.android.systemui.dock.DockManager; import com.android.systemui.doze.dagger.BrightnessSensor; import com.android.systemui.doze.dagger.DozeScope; import com.android.systemui.doze.dagger.WrappedService; Loading Loading @@ -63,6 +64,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi private final Optional<Sensor> mLightSensorOptional; private final WakefulnessLifecycle mWakefulnessLifecycle; private final DozeParameters mDozeParameters; private final DockManager mDockManager; private final int[] mSensorToBrightness; private final int[] mSensorToScrimOpacity; private final int mScreenBrightnessDim; Loading @@ -87,7 +89,8 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi @BrightnessSensor Optional<Sensor> lightSensorOptional, DozeHost host, Handler handler, AlwaysOnDisplayPolicy alwaysOnDisplayPolicy, WakefulnessLifecycle wakefulnessLifecycle, DozeParameters dozeParameters) { DozeParameters dozeParameters, DockManager dockManager) { mContext = context; mDozeService = service; mSensorManager = sensorManager; Loading @@ -96,6 +99,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi mDozeParameters = dozeParameters; mDozeHost = host; mHandler = handler; mDockManager = dockManager; mDefaultDozeBrightness = alwaysOnDisplayPolicy.defaultDozeBrightness; mScreenBrightnessDim = alwaysOnDisplayPolicy.dimBrightness; Loading @@ -122,13 +126,20 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi @Override public void onScreenState(int state) { if (state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND) { boolean isDockedScreenOn = state == Display.STATE_ON && mDockManager.isDocked(); if (state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND || (isDockedScreenOn && shouldRegisterLightSensorWhenScreenOnDocked())) { setLightSensorEnabled(true); } else { setLightSensorEnabled(false); } } private boolean shouldRegisterLightSensorWhenScreenOnDocked() { return !mDozeParameters.brightnessUsesProx() || !mDozeParameters.getSelectivelyRegisterSensorsUsingProx(); } private void onDestroy() { setLightSensorEnabled(false); } Loading
packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java +8 −0 Original line number Diff line number Diff line Loading @@ -267,6 +267,13 @@ public class DozeParameters implements TunerService.Tunable, return mResources.getBoolean(R.bool.doze_long_press_uses_prox); } /** * Whether the brightness sensor uses the proximity sensor. */ public boolean brightnessUsesProx() { return mResources.getBoolean(R.bool.doze_brightness_uses_prox); } /** * Callback to listen for DozeParameter changes. */ Loading Loading @@ -303,6 +310,7 @@ public class DozeParameters implements TunerService.Tunable, pw.print("getPickupVibrationThreshold(): "); pw.println(getPickupVibrationThreshold()); pw.print("getSelectivelyRegisterSensorsUsingProx(): "); pw.println(getSelectivelyRegisterSensorsUsingProx()); pw.print("brightnessUsesProx(): "); pw.println(brightnessUsesProx()); } interface Callback { Loading
packages/SystemUI/tests/src/com/android/systemui/doze/DozeConfigurationUtil.java +1 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ public class DozeConfigurationUtil { when(params.singleTapUsesProx()).thenReturn(true); when(params.longPressUsesProx()).thenReturn(true); when(params.getQuickPickupAodDuration()).thenReturn(500); when(params.brightnessUsesProx()).thenReturn(true); doneHolder[0] = true; return params; Loading
packages/SystemUI/tests/src/com/android/systemui/doze/DozeScreenBrightnessTest.java +68 −3 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import static com.android.systemui.doze.DozeMachine.State.UNINITIALIZED; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; Loading @@ -47,6 +48,7 @@ import android.view.Display; import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; import com.android.systemui.dock.DockManager; import com.android.systemui.keyguard.WakefulnessLifecycle; import com.android.systemui.statusbar.phone.DozeParameters; import com.android.systemui.util.concurrency.FakeExecutor; Loading Loading @@ -82,6 +84,8 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { WakefulnessLifecycle mWakefulnessLifecycle; @Mock DozeParameters mDozeParameters; @Mock DockManager mDockManager; private FakeExecutor mFakeExecutor = new FakeExecutor(new FakeSystemClock()); private FakeThreadFactory mFakeThreadFactory = new FakeThreadFactory(mFakeExecutor); Loading Loading @@ -109,7 +113,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { mSensor = fakeSensorManager.getFakeLightSensor(); mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager, Optional.of(mSensor.getSensor()), mDozeHost, null /* handler */, mAlwaysOnDisplayPolicy, mWakefulnessLifecycle, mDozeParameters); mAlwaysOnDisplayPolicy, mWakefulnessLifecycle, mDozeParameters, mDockManager); mScreen.onScreenState(Display.STATE_ON); } Loading Loading @@ -156,6 +160,67 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { assertEquals(maxBrightness, mServiceFake.screenBrightness); } @Test public void testAodDocked_doNotSelectivelyUseProx_usesLightSensor() { // GIVEN the device doesn't need to selectively register for prox sensors and // brightness sensor uses prox when(mDozeParameters.getSelectivelyRegisterSensorsUsingProx()).thenReturn(false); when(mDozeParameters.brightnessUsesProx()).thenReturn(true); // GIVEN the device is docked and the display state changes to ON when(mDockManager.isDocked()).thenReturn(true); mScreen.onScreenState(Display.STATE_ON); waitForSensorManager(); // WHEN new sensor event sent mSensor.sendSensorEvent(3); // THEN brightness is updated assertEquals(3, mServiceFake.screenBrightness); } @Test public void testAodDocked_brightnessDoesNotUseProx_usesLightSensor() { // GIVEN the device doesn't need to selectively register for prox sensors but // the brightness sensor doesn't use prox when(mDozeParameters.getSelectivelyRegisterSensorsUsingProx()).thenReturn(true); when(mDozeParameters.brightnessUsesProx()).thenReturn(false); // GIVEN the device is docked and the display state changes to ON when(mDockManager.isDocked()).thenReturn(true); mScreen.onScreenState(Display.STATE_ON); waitForSensorManager(); // WHEN new sensor event sent mSensor.sendSensorEvent(3); // THEN brightness is updated assertEquals(3, mServiceFake.screenBrightness); } @Test public void testAodDocked_noProx_brightnessUsesProx_doNotUseLightSensor() { final int startBrightness = mServiceFake.screenBrightness; // GIVEN the device needs to selectively register for prox sensors and // the brightness sensor uses prox when(mDozeParameters.getSelectivelyRegisterSensorsUsingProx()).thenReturn(true); when(mDozeParameters.brightnessUsesProx()).thenReturn(true); // GIVEN the device is docked and the display state is on when(mDockManager.isDocked()).thenReturn(true); mScreen.onScreenState(Display.STATE_ON); waitForSensorManager(); // WHEN new sensor event sent mSensor.sendSensorEvent(3); // THEN brightness is NOT changed assertNotSame(3, mServiceFake.screenBrightness); assertEquals(startBrightness, mServiceFake.screenBrightness); } @Test public void testPausingAod_doesNotResetBrightness() throws Exception { mScreen.transitionTo(UNINITIALIZED, INITIALIZED); Loading @@ -175,7 +240,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { public void testPulsing_withoutLightSensor_setsAoDDimmingScrimTransparent() throws Exception { mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager, Optional.empty() /* sensor */, mDozeHost, null /* handler */, mAlwaysOnDisplayPolicy, mWakefulnessLifecycle, mDozeParameters); mAlwaysOnDisplayPolicy, mWakefulnessLifecycle, mDozeParameters, mDockManager); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); mScreen.transitionTo(INITIALIZED, DOZE); reset(mDozeHost); Loading Loading @@ -216,7 +281,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { public void testNullSensor() throws Exception { mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager, Optional.empty() /* sensor */, mDozeHost, null /* handler */, mAlwaysOnDisplayPolicy, mWakefulnessLifecycle, mDozeParameters); mAlwaysOnDisplayPolicy, mWakefulnessLifecycle, mDozeParameters, mDockManager); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); mScreen.transitionTo(INITIALIZED, DOZE_AOD); Loading