From 188bf2ea315903df4aaab6de2a7b898e0cab306d Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Tue, 29 Aug 2017 18:58:00 -0400 Subject: [PATCH 1/4] Auto dim the nav bar to help prevent diff aging Test: runtest systemui Bug: 63630024 Change-Id: If2a6c0934f8751f82c027dbb3b5f103a34dc78d4 --- .../statusbar/phone/BarTransitions.java | 4 ++ .../phone/NavigationBarTransitions.java | 23 +++++-- .../systemui/statusbar/phone/StatusBar.java | 34 ++++++--- .../systemui/statusbar/policy/DeadZone.java | 5 ++ .../phone/NavigationBarTransitionsTest.java | 69 +++++++++++++++++++ 5 files changed, 121 insertions(+), 14 deletions(-) create mode 100644 packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarTransitionsTest.java diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java index f3c2bc56b4094..f379a4636623c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java @@ -75,6 +75,10 @@ public class BarTransitions { return mMode; } + public void setAutoDim(boolean autoDim) { + // Default is don't care. + } + /** * @param alwaysOpaque if {@code true}, the bar's background will always be opaque, regardless * of what mode it is currently set to. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java index cb925d5f7e169..f3ca66ffa9b3a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java @@ -32,6 +32,7 @@ public final class NavigationBarTransitions extends BarTransitions { private final LightBarTransitionsController mLightTransitionsController; private boolean mLightsOut; + private boolean mAutoDim; public NavigationBarTransitions(NavigationBarView view) { super(view, R.drawable.nav_background); @@ -44,7 +45,19 @@ public final class NavigationBarTransitions extends BarTransitions { public void init() { applyModeBackground(-1, getMode(), false /*animate*/); - applyMode(getMode(), false /*animate*/, true /*force*/); + applyLightsOut(false /*animate*/, true /*force*/); + } + + @Override + public void setAutoDim(boolean autoDim) { + if (mAutoDim == autoDim) return; + mAutoDim = autoDim; + applyLightsOut(true, false); + } + + @Override + protected boolean isLightsOut(int mode) { + return super.isLightsOut(mode) || mAutoDim; } public LightBarTransitionsController getLightTransitionsController() { @@ -54,13 +67,12 @@ public final class NavigationBarTransitions extends BarTransitions { @Override protected void onTransition(int oldMode, int newMode, boolean animate) { super.onTransition(oldMode, newMode, animate); - applyMode(newMode, animate, false /*force*/); + applyLightsOut(animate, false /*force*/); } - private void applyMode(int mode, boolean animate, boolean force) { - + private void applyLightsOut(boolean animate, boolean force) { // apply to lights out - applyLightsOut(isLightsOut(mode), animate, force); + applyLightsOut(isLightsOut(getMode()), animate, force); } private void applyLightsOut(boolean lightsOut, boolean animate, boolean force) { @@ -86,7 +98,6 @@ public final class NavigationBarTransitions extends BarTransitions { } } - public void reapplyDarkIntensity() { applyDarkIntensity(mLightTransitionsController.getCurrentDarkIntensity()); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index ada98b7a2ca38..5a5f164ede6d2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -560,14 +560,12 @@ public class StatusBar extends SystemUI implements DemoMode, protected DozeScrimController mDozeScrimController; private final UiOffloadThread mUiOffloadThread = Dependency.get(UiOffloadThread.class); - private final Runnable mAutohide = new Runnable() { - @Override - public void run() { - int requested = mSystemUiVisibility & ~STATUS_OR_NAV_TRANSIENT; - if (mSystemUiVisibility != requested) { - notifyUiVisibilityChanged(requested); - } - }}; + private final Runnable mAutohide = () -> { + int requested = mSystemUiVisibility & ~STATUS_OR_NAV_TRANSIENT; + if (mSystemUiVisibility != requested) { + notifyUiVisibilityChanged(requested); + } + }; private boolean mWaitingForKeyguardExit; protected boolean mDozing; @@ -3269,6 +3267,7 @@ public class StatusBar extends SystemUI implements DemoMode, } else { cancelAutohide(); } + touchAutoDim(); } protected int computeStatusBarMode(int oldVal, int newVal) { @@ -3354,6 +3353,7 @@ public class StatusBar extends SystemUI implements DemoMode, dismissVolumeDialog(); } checkBarModes(); + touchAutoDim(); } private void dismissVolumeDialog() { @@ -3385,6 +3385,16 @@ public class StatusBar extends SystemUI implements DemoMode, mHandler.postDelayed(mAutohide, AUTOHIDE_TIMEOUT_MS); } + public void touchAutoDim() { + if (mNavigationBar != null) { + mNavigationBar.getBarTransitions().setAutoDim(false); + } + mHandler.removeCallbacks(mAutoDim); + if (mState != StatusBarState.KEYGUARD && mState != StatusBarState.SHADE_LOCKED) { + mHandler.postDelayed(mAutoDim, AUTOHIDE_TIMEOUT_MS); + } + } + void checkUserAutohide(View v, MotionEvent event) { if ((mSystemUiVisibility & STATUS_OR_NAV_TRANSIENT) != 0 // a transient bar is revealed && event.getAction() == MotionEvent.ACTION_OUTSIDE // touch outside the source bar @@ -4791,6 +4801,7 @@ public class StatusBar extends SystemUI implements DemoMode, updateReportRejectedTouchVisibility(); updateDozing(); updateTheme(); + touchAutoDim(); mNotificationShelf.setStatusBarState(state); } @@ -5292,6 +5303,7 @@ public class StatusBar extends SystemUI implements DemoMode, @Override public void appTransitionFinished() { + touchAutoDim(); EventBus.getDefault().send(new AppTransitionFinishedEvent()); } @@ -7466,4 +7478,10 @@ public class StatusBar extends SystemUI implements DemoMode, } } // End Extra BaseStatusBarMethods. + + private final Runnable mAutoDim = () -> { + if (mNavigationBar != null) { + mNavigationBar.getBarTransitions().setAutoDim(true); + } + }; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeadZone.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeadZone.java index 13ee23fb7af99..06040e2b0bcc7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeadZone.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeadZone.java @@ -28,6 +28,8 @@ import android.view.Surface; import android.view.View; import com.android.systemui.R; +import com.android.systemui.SysUiServiceProvider; +import com.android.systemui.statusbar.phone.StatusBar; /** * The "dead zone" consumes unintentional taps along the top edge of the navigation bar. @@ -44,6 +46,7 @@ public class DeadZone extends View { public static final int VERTICAL = 1; // Consume taps along the left edge. private static final boolean CHATTY = true; // print to logcat when we eat a click + private final StatusBar mStatusBar; private boolean mShouldFlash; private float mFlashFrac = 0f; @@ -88,6 +91,7 @@ public class DeadZone extends View { + (mVertical ? " vertical" : " horizontal")); setFlashOnTouchCapture(context.getResources().getBoolean(R.bool.config_dead_zone_flash)); + mStatusBar = SysUiServiceProvider.getComponent(context, StatusBar.class); } static float lerp(float a, float b, float f) { @@ -132,6 +136,7 @@ public class DeadZone extends View { if (DEBUG) { Slog.v(TAG, this + " ACTION_DOWN: " + event.getX() + "," + event.getY()); } + if (mStatusBar != null) mStatusBar.touchAutoDim(); int size = (int) getSize(event.getEventTime()); // In the vertical orientation consume taps along the left edge. // In horizontal orientation consume taps along the top edge. diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarTransitionsTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarTransitionsTest.java new file mode 100644 index 0000000000000..0c1baaa1b4765 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarTransitionsTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.android.systemui.statusbar.phone; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import android.support.test.filters.SmallTest; +import android.testing.AndroidTestingRunner; +import android.testing.TestableLooper.RunWithLooper; + +import com.android.systemui.SysuiTestCase; +import com.android.systemui.statusbar.CommandQueue; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidTestingRunner.class) +@RunWithLooper +@SmallTest +public class NavigationBarTransitionsTest extends SysuiTestCase { + + private NavigationBarTransitions mTransitions; + + @Before + public void setup() { + mContext.putComponent(CommandQueue.class, mock(CommandQueue.class)); + NavigationBarView navBar = spy(new NavigationBarView(mContext, null)); + when(navBar.getCurrentView()).thenReturn(navBar); + when(navBar.findViewById(anyInt())).thenReturn(navBar); + mTransitions = new NavigationBarTransitions(navBar); + } + + @Test + public void setIsLightsOut_NoAutoDim() { + mTransitions.setAutoDim(false); + + assertFalse(mTransitions.isLightsOut(BarTransitions.MODE_OPAQUE)); + + assertTrue(mTransitions.isLightsOut(BarTransitions.MODE_LIGHTS_OUT)); + } + + @Test + public void setIsLightsOut_AutoDim() { + mTransitions.setAutoDim(true); + + assertTrue(mTransitions.isLightsOut(BarTransitions.MODE_OPAQUE)); + + assertTrue(mTransitions.isLightsOut(BarTransitions.MODE_LIGHTS_OUT)); + } + +} \ No newline at end of file From 53504c3aac19a3658782900d26b0f9da1abb3288 Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Wed, 30 Aug 2017 16:17:19 -0400 Subject: [PATCH 2/4] Don't touch auto dim on app change Test: manual Bug: 63630024 Change-Id: I134aa2695bad36606588ca3e52685826f25ea306 --- .../src/com/android/systemui/statusbar/phone/StatusBar.java | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 5a5f164ede6d2..4c2f0849110e1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -5303,7 +5303,6 @@ public class StatusBar extends SystemUI implements DemoMode, @Override public void appTransitionFinished() { - touchAutoDim(); EventBus.getDefault().send(new AppTransitionFinishedEvent()); } From 276f78eeaa77e8b9d6a3800182155c9eda10ee0d Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Mon, 18 Sep 2017 10:31:37 -0400 Subject: [PATCH 3/4] Refinement of auto-dimming nav - Make dimming only happen for interaction with nav - Extend time to dim - Shorten time to start dimming by same amount. Test: visual Change-Id: Ieb5b31bacdde9ce1952601ad65cff2d54386dd0f Fixes: 65694001 --- .../com/android/systemui/statusbar/phone/BarTransitions.java | 2 +- .../src/com/android/systemui/statusbar/phone/StatusBar.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java index f379a4636623c..3daaf59a38172 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java @@ -52,7 +52,7 @@ public class BarTransitions { public static final int MODE_LIGHTS_OUT_TRANSPARENT = 6; public static final int LIGHTS_IN_DURATION = 250; - public static final int LIGHTS_OUT_DURATION = 750; + public static final int LIGHTS_OUT_DURATION = 1500; public static final int BACKGROUND_DURATION = 200; private final String mTag; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 4c2f0849110e1..80aca28807231 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -340,7 +340,7 @@ public class StatusBar extends SystemUI implements DemoMode, private static final int STATUS_OR_NAV_TRANSIENT = View.STATUS_BAR_TRANSIENT | View.NAVIGATION_BAR_TRANSIENT; - private static final long AUTOHIDE_TIMEOUT_MS = 3000; + private static final long AUTOHIDE_TIMEOUT_MS = 2250; /** The minimum delay in ms between reports of notification visibility. */ private static final int VISIBILITY_REPORT_MIN_DELAY_MS = 500; @@ -3267,7 +3267,6 @@ public class StatusBar extends SystemUI implements DemoMode, } else { cancelAutohide(); } - touchAutoDim(); } protected int computeStatusBarMode(int oldVal, int newVal) { @@ -3350,10 +3349,10 @@ public class StatusBar extends SystemUI implements DemoMode, } // manually dismiss the volume panel when interacting with the nav bar if (changing && interacting && barWindow == StatusBarManager.WINDOW_NAVIGATION_BAR) { + touchAutoDim(); dismissVolumeDialog(); } checkBarModes(); - touchAutoDim(); } private void dismissVolumeDialog() { From 06bba6839f46fb1f6201c923c1774498cc52273e Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Fri, 13 Oct 2017 10:34:40 -0400 Subject: [PATCH 4/4] Auto-dim refinements - Don't auto-dim while wallpaper is showing - Up alpha to 60% Change-Id: Ie5fc33279ca46f7de37befacbbd7b42b7d4e5d15 Fixes: 67735001 Test: manual --- .../src/com/android/systemui/Dependency.java | 4 +++ .../phone/NavigationBarTransitions.java | 27 +++++++++++++++++-- .../phone/NavigationBarTransitionsTest.java | 2 ++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java index ecc2111366671..c2467c6300171 100644 --- a/packages/SystemUI/src/com/android/systemui/Dependency.java +++ b/packages/SystemUI/src/com/android/systemui/Dependency.java @@ -22,6 +22,8 @@ import android.os.HandlerThread; import android.os.Looper; import android.os.Process; import android.util.ArrayMap; +import android.view.IWindowManager; +import android.view.WindowManagerGlobal; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.NightDisplayController; @@ -300,6 +302,8 @@ public class Dependency extends SystemUI { mProviders.put(PowerUI.WarningsUI.class, () -> new PowerNotificationWarnings(mContext)); + mProviders.put(IWindowManager.class, () -> WindowManagerGlobal.getWindowManagerService()); + // Put all dependencies above here so the factory can override them if it wants. SystemUIFactory.getInstance().injectDependencies(mProviders, mContext); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java index f3ca66ffa9b3a..c9500363e9d81 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java @@ -17,12 +17,19 @@ package com.android.systemui.statusbar.phone; import android.content.Context; +import android.os.Handler; +import android.os.RemoteException; import android.os.ServiceManager; import android.util.SparseArray; +import android.view.Display; +import android.view.IWallpaperVisibilityListener; +import android.view.IWindowManager; import android.view.MotionEvent; import android.view.View; +import android.view.WindowManagerGlobal; import com.android.internal.statusbar.IStatusBarService; +import com.android.systemui.Dependency; import com.android.systemui.R; public final class NavigationBarTransitions extends BarTransitions { @@ -30,6 +37,7 @@ public final class NavigationBarTransitions extends BarTransitions { private final NavigationBarView mView; private final IStatusBarService mBarService; private final LightBarTransitionsController mLightTransitionsController; + private boolean mWallpaperVisible; private boolean mLightsOut; private boolean mAutoDim; @@ -41,6 +49,21 @@ public final class NavigationBarTransitions extends BarTransitions { ServiceManager.getService(Context.STATUS_BAR_SERVICE)); mLightTransitionsController = new LightBarTransitionsController(view.getContext(), this::applyDarkIntensity); + + IWindowManager windowManagerService = Dependency.get(IWindowManager.class); + Handler handler = Handler.getMain(); + try { + mWallpaperVisible = windowManagerService.registerWallpaperVisibilityListener( + new IWallpaperVisibilityListener.Stub() { + @Override + public void onWallpaperVisibilityChanged(boolean newVisibility, + int displayId) throws RemoteException { + mWallpaperVisible = newVisibility; + handler.post(() -> applyLightsOut(true, false)); + } + }, Display.DEFAULT_DISPLAY); + } catch (RemoteException e) { + } } public void init() { @@ -57,7 +80,7 @@ public final class NavigationBarTransitions extends BarTransitions { @Override protected boolean isLightsOut(int mode) { - return super.isLightsOut(mode) || mAutoDim; + return super.isLightsOut(mode) || (mAutoDim && !mWallpaperVisible); } public LightBarTransitionsController getLightTransitionsController() { @@ -85,7 +108,7 @@ public final class NavigationBarTransitions extends BarTransitions { // ok, everyone, stop it right there navButtons.animate().cancel(); - final float navButtonsAlpha = lightsOut ? 0.5f : 1f; + final float navButtonsAlpha = lightsOut ? 0.6f : 1f; if (!animate) { navButtons.setAlpha(navButtonsAlpha); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarTransitionsTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarTransitionsTest.java index 0c1baaa1b4765..76f57f049561c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarTransitionsTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarTransitionsTest.java @@ -24,6 +24,7 @@ import static org.mockito.Mockito.when; import android.support.test.filters.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper.RunWithLooper; +import android.view.IWindowManager; import com.android.systemui.SysuiTestCase; import com.android.systemui.statusbar.CommandQueue; @@ -41,6 +42,7 @@ public class NavigationBarTransitionsTest extends SysuiTestCase { @Before public void setup() { + mDependency.injectMockDependency(IWindowManager.class); mContext.putComponent(CommandQueue.class, mock(CommandQueue.class)); NavigationBarView navBar = spy(new NavigationBarView(mContext, null)); when(navBar.getCurrentView()).thenReturn(navBar);