diff options
4 files changed, 55 insertions, 25 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java index 50a10bc0b15a..6da8c69c013b 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java @@ -114,6 +114,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.DisplayId; import com.android.systemui.dagger.qualifiers.Main; +import com.android.systemui.keyguard.WakefulnessLifecycle; import com.android.systemui.model.SysUiState; import com.android.systemui.navigationbar.NavigationBarComponent.NavigationBarScope; import com.android.systemui.navigationbar.NavigationModeController.ModeChangedListener; @@ -211,6 +212,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements private final NotificationShadeDepthController mNotificationShadeDepthController; private final OnComputeInternalInsetsListener mOnComputeInternalInsetsListener; private final UserContextProvider mUserContextProvider; + private final WakefulnessLifecycle mWakefulnessLifecycle; private final RegionSamplingHelper mRegionSamplingHelper; private final int mNavColorSampleMargin; private NavigationBarFrame mFrame; @@ -451,6 +453,28 @@ public class NavigationBar extends ViewController<NavigationBarView> implements } }; + private final WakefulnessLifecycle.Observer mWakefulnessObserver = + new WakefulnessLifecycle.Observer() { + private void notifyScreenStateChanged(boolean isScreenOn) { + notifyNavigationBarScreenOn(); + mView.onScreenStateChanged(isScreenOn); + } + + @Override + public void onStartedWakingUp() { + notifyScreenStateChanged(true); + if (isGesturalModeOnDefaultDisplay(getContext(), mNavBarMode)) { + mRegionSamplingHelper.start(mSamplingBounds); + } + } + + @Override + public void onFinishedGoingToSleep() { + notifyScreenStateChanged(false); + mRegionSamplingHelper.stop(); + } + }; + @Inject NavigationBar( NavigationBarView navigationBarView, @@ -491,7 +515,8 @@ public class NavigationBar extends ViewController<NavigationBarView> implements NavigationBarTransitions navigationBarTransitions, EdgeBackGestureHandler edgeBackGestureHandler, Optional<BackAnimation> backAnimation, - UserContextProvider userContextProvider) { + UserContextProvider userContextProvider, + WakefulnessLifecycle wakefulnessLifecycle) { super(navigationBarView); mFrame = navigationBarFrame; mContext = context; @@ -529,6 +554,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements mTelecomManagerOptional = telecomManagerOptional; mInputMethodManager = inputMethodManager; mUserContextProvider = userContextProvider; + mWakefulnessLifecycle = wakefulnessLifecycle; mNavColorSampleMargin = getResources() .getDimensionPixelSize(R.dimen.navigation_handle_sample_horizontal_margin); @@ -682,11 +708,10 @@ public class NavigationBar extends ViewController<NavigationBarView> implements prepareNavigationBarView(); checkNavBarModes(); - IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); - filter.addAction(Intent.ACTION_SCREEN_ON); - filter.addAction(Intent.ACTION_USER_SWITCHED); + IntentFilter filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); mBroadcastDispatcher.registerReceiverWithHandler(mBroadcastReceiver, filter, Handler.getMain(), UserHandle.ALL); + mWakefulnessLifecycle.addObserver(mWakefulnessObserver); notifyNavigationBarScreenOn(); mOverviewProxyService.addCallback(mOverviewProxyListener); @@ -737,6 +762,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements getBarTransitions().destroy(); mOverviewProxyService.removeCallback(mOverviewProxyListener); mBroadcastDispatcher.unregisterReceiver(mBroadcastReceiver); + mWakefulnessLifecycle.removeObserver(mWakefulnessObserver); if (mOrientationHandle != null) { resetSecondaryHandle(); getBarTransitions().removeDarkIntensityListener(mOrientationHandleIntensityListener); @@ -1619,19 +1645,6 @@ public class NavigationBar extends ViewController<NavigationBarView> implements return; } String action = intent.getAction(); - if (Intent.ACTION_SCREEN_OFF.equals(action) - || Intent.ACTION_SCREEN_ON.equals(action)) { - notifyNavigationBarScreenOn(); - boolean isScreenOn = Intent.ACTION_SCREEN_ON.equals(action); - mView.onScreenStateChanged(isScreenOn); - if (isScreenOn) { - if (isGesturalModeOnDefaultDisplay(getContext(), mNavBarMode)) { - mRegionSamplingHelper.start(mSamplingBounds); - } - } else { - mRegionSamplingHelper.stop(); - } - } if (Intent.ACTION_USER_SWITCHED.equals(action)) { // The accessibility settings may be different for the new user updateAccessibilityStateFlags(); diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java index 67dae9e7a0ea..51901e3c239f 100644 --- a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java +++ b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java @@ -46,6 +46,7 @@ import com.android.systemui.CoreStartable; import com.android.systemui.R; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.SysUISingleton; +import com.android.systemui.keyguard.WakefulnessLifecycle; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.phone.CentralSurfaces; @@ -78,6 +79,7 @@ public class PowerUI extends CoreStartable implements CommandQueue.Callbacks { private final PowerManager mPowerManager; private final WarningsUI mWarnings; + private final WakefulnessLifecycle mWakefulnessLifecycle; private InattentiveSleepWarningView mOverlayView; private final Configuration mLastConfiguration = new Configuration(); private int mPlugType = 0; @@ -106,11 +108,24 @@ public class PowerUI extends CoreStartable implements CommandQueue.Callbacks { private final BroadcastDispatcher mBroadcastDispatcher; private final CommandQueue mCommandQueue; private final Lazy<Optional<CentralSurfaces>> mCentralSurfacesOptionalLazy; + private final WakefulnessLifecycle.Observer mWakefulnessObserver = + new WakefulnessLifecycle.Observer() { + @Override + public void onStartedWakingUp() { + mScreenOffTime = -1; + } + + @Override + public void onFinishedGoingToSleep() { + mScreenOffTime = SystemClock.elapsedRealtime(); + } + }; @Inject public PowerUI(Context context, BroadcastDispatcher broadcastDispatcher, CommandQueue commandQueue, Lazy<Optional<CentralSurfaces>> centralSurfacesOptionalLazy, WarningsUI warningsUI, EnhancedEstimates enhancedEstimates, + WakefulnessLifecycle wakefulnessLifecycle, PowerManager powerManager) { super(context); mBroadcastDispatcher = broadcastDispatcher; @@ -119,6 +134,7 @@ public class PowerUI extends CoreStartable implements CommandQueue.Callbacks { mWarnings = warningsUI; mEnhancedEstimates = enhancedEstimates; mPowerManager = powerManager; + mWakefulnessLifecycle = wakefulnessLifecycle; } public void start() { @@ -137,6 +153,7 @@ public class PowerUI extends CoreStartable implements CommandQueue.Callbacks { false, obs, UserHandle.USER_ALL); updateBatteryWarningLevels(); mReceiver.init(); + mWakefulnessLifecycle.addObserver(mWakefulnessObserver); // Check to see if we need to let the user know that the phone previously shut down due // to the temperature being too high. @@ -232,8 +249,6 @@ public class PowerUI extends CoreStartable implements CommandQueue.Callbacks { IntentFilter filter = new IntentFilter(); filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); filter.addAction(Intent.ACTION_BATTERY_CHANGED); - filter.addAction(Intent.ACTION_SCREEN_OFF); - filter.addAction(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_USER_SWITCHED); mBroadcastDispatcher.registerReceiverWithHandler(this, filter, mHandler); // Force get initial values. Relying on Sticky behavior until API for getting info. @@ -316,10 +331,6 @@ public class PowerUI extends CoreStartable implements CommandQueue.Callbacks { plugged, bucket); }); - } else if (Intent.ACTION_SCREEN_OFF.equals(action)) { - mScreenOffTime = SystemClock.elapsedRealtime(); - } else if (Intent.ACTION_SCREEN_ON.equals(action)) { - mScreenOffTime = -1; } else if (Intent.ACTION_USER_SWITCHED.equals(action)) { mWarnings.userSwitched(); } else { diff --git a/packages/SystemUI/tests/src/com/android/systemui/navigationbar/NavigationBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/NavigationBarTest.java index 0e9d2799dddb..6adce7a827b6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/navigationbar/NavigationBarTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/NavigationBarTest.java @@ -80,6 +80,7 @@ import com.android.systemui.accessibility.SystemActions; import com.android.systemui.assist.AssistManager; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dump.DumpManager; +import com.android.systemui.keyguard.WakefulnessLifecycle; import com.android.systemui.model.SysUiState; import com.android.systemui.navigationbar.buttons.ButtonDispatcher; import com.android.systemui.navigationbar.buttons.DeadZone; @@ -197,6 +198,8 @@ public class NavigationBarTest extends SysuiTestCase { @Mock private UserContextProvider mUserContextProvider; @Mock + private WakefulnessLifecycle mWakefulnessLifecycle; + @Mock private Resources mResources; private FakeExecutor mFakeExecutor = new FakeExecutor(new FakeSystemClock()); private DeviceConfigProxyFake mDeviceConfigProxyFake = new DeviceConfigProxyFake(); @@ -474,7 +477,8 @@ public class NavigationBarTest extends SysuiTestCase { mNavigationBarTransitions, mEdgeBackGestureHandler, Optional.of(mock(BackAnimation.class)), - mUserContextProvider)); + mUserContextProvider, + mWakefulnessLifecycle)); } private void processAllMessages() { diff --git a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java index 4e9b2325b899..c377c374148f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java @@ -46,6 +46,7 @@ import com.android.settingslib.fuelgauge.Estimate; import com.android.systemui.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.broadcast.BroadcastDispatcher; +import com.android.systemui.keyguard.WakefulnessLifecycle; import com.android.systemui.power.PowerUI.WarningsUI; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.phone.CentralSurfaces; @@ -84,6 +85,7 @@ public class PowerUITest extends SysuiTestCase { private PowerUI mPowerUI; @Mock private EnhancedEstimates mEnhancedEstimates; @Mock private PowerManager mPowerManager; + @Mock private WakefulnessLifecycle mWakefulnessLifecycle; @Mock private IThermalService mThermalServiceMock; private IThermalEventListener mUsbThermalEventListener; private IThermalEventListener mSkinThermalEventListener; @@ -680,7 +682,7 @@ public class PowerUITest extends SysuiTestCase { private void createPowerUi() { mPowerUI = new PowerUI( mContext, mBroadcastDispatcher, mCommandQueue, mCentralSurfacesOptionalLazy, - mMockWarnings, mEnhancedEstimates, mPowerManager); + mMockWarnings, mEnhancedEstimates, mWakefulnessLifecycle, mPowerManager); mPowerUI.mThermalService = mThermalServiceMock; } |