Merge "Allow wallpaper color updates if screen off" into sc-dev am: a06ab7e8c6 am: 918277c08f

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14533682

Change-Id: I444e23871844f70240c24bc724f8611b1f678376
This commit is contained in:
Lucas Dupin
2021-05-21 19:31:02 +00:00
committed by Automerger Merge Worker
2 changed files with 99 additions and 9 deletions

View File

@@ -15,6 +15,7 @@
*/ */
package com.android.systemui.theme; package com.android.systemui.theme;
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_ASLEEP;
import static com.android.systemui.theme.ThemeOverlayApplier.COLOR_SOURCE_PRESET; import static com.android.systemui.theme.ThemeOverlayApplier.COLOR_SOURCE_PRESET;
import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_CATEGORY_ACCENT_COLOR; import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_CATEGORY_ACCENT_COLOR;
import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_CATEGORY_SYSTEM_PALETTE; import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_CATEGORY_SYSTEM_PALETTE;
@@ -54,6 +55,7 @@ import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager; import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.settings.UserTracker; import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.FeatureFlags; import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.statusbar.policy.DeviceProvisionedController;
@@ -115,6 +117,12 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
private FabricatedOverlay mNeutralOverlay; private FabricatedOverlay mNeutralOverlay;
// If wallpaper color event will be accepted and change the UI colors. // If wallpaper color event will be accepted and change the UI colors.
private boolean mAcceptColorEvents = true; private boolean mAcceptColorEvents = true;
// If non-null, colors that were sent to the framework, and processing was deferred until
// the next time the screen is off.
private WallpaperColors mDeferredWallpaperColors;
private int mDeferredWallpaperColorsFlags;
private WakefulnessLifecycle mWakefulnessLifecycle;
// Defers changing themes until Setup Wizard is done. // Defers changing themes until Setup Wizard is done.
private boolean mDeferredThemeEvaluation; private boolean mDeferredThemeEvaluation;
// Determines if we should ignore THEME_CUSTOMIZATION_OVERLAY_PACKAGES setting changes. // Determines if we should ignore THEME_CUSTOMIZATION_OVERLAY_PACKAGES setting changes.
@@ -137,18 +145,28 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
}; };
private final OnColorsChangedListener mOnColorsChangedListener = (wallpaperColors, which) -> { private final OnColorsChangedListener mOnColorsChangedListener = (wallpaperColors, which) -> {
if (!mAcceptColorEvents) { if (!mAcceptColorEvents && mWakefulnessLifecycle.getWakefulness() != WAKEFULNESS_ASLEEP) {
Log.i(TAG, "Wallpaper color event rejected: " + wallpaperColors); mDeferredWallpaperColors = wallpaperColors;
mDeferredWallpaperColorsFlags = which;
Log.i(TAG, "colors received; processing deferred until screen off: " + wallpaperColors);
return; return;
} }
if (wallpaperColors != null) { if (wallpaperColors != null) {
mAcceptColorEvents = false; mAcceptColorEvents = false;
// Any cache of colors deferred for process is now stale.
mDeferredWallpaperColors = null;
mDeferredWallpaperColorsFlags = 0;
} }
handleWallpaperColors(wallpaperColors, which);
};
private void handleWallpaperColors(WallpaperColors wallpaperColors, int flags) {
final boolean hadWallpaperColors = mSystemColors != null; final boolean hadWallpaperColors = mSystemColors != null;
if ((which & WallpaperManager.FLAG_SYSTEM) != 0) { if ((flags & WallpaperManager.FLAG_SYSTEM) != 0) {
mSystemColors = wallpaperColors; mSystemColors = wallpaperColors;
if (DEBUG) Log.d(TAG, "got new colors: " + wallpaperColors + " where: " + which); if (DEBUG) Log.d(TAG, "got new colors: " + wallpaperColors + " where: " + flags);
} }
if (mDeviceProvisionedController != null if (mDeviceProvisionedController != null
@@ -206,7 +224,7 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
} }
} }
reevaluateSystemTheme(false /* forceReload */); reevaluateSystemTheme(false /* forceReload */);
}; }
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override @Override
@@ -233,7 +251,8 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
@Background Executor bgExecutor, ThemeOverlayApplier themeOverlayApplier, @Background Executor bgExecutor, ThemeOverlayApplier themeOverlayApplier,
SecureSettings secureSettings, WallpaperManager wallpaperManager, SecureSettings secureSettings, WallpaperManager wallpaperManager,
UserManager userManager, DeviceProvisionedController deviceProvisionedController, UserManager userManager, DeviceProvisionedController deviceProvisionedController,
UserTracker userTracker, DumpManager dumpManager, FeatureFlags featureFlags) { UserTracker userTracker, DumpManager dumpManager, FeatureFlags featureFlags,
WakefulnessLifecycle wakefulnessLifecycle) {
super(context); super(context);
mIsMonetEnabled = featureFlags.isMonetEnabled(); mIsMonetEnabled = featureFlags.isMonetEnabled();
@@ -247,6 +266,7 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
mSecureSettings = secureSettings; mSecureSettings = secureSettings;
mWallpaperManager = wallpaperManager; mWallpaperManager = wallpaperManager;
mUserTracker = userTracker; mUserTracker = userTracker;
mWakefulnessLifecycle = wakefulnessLifecycle;
dumpManager.registerDumpable(TAG, this); dumpManager.registerDumpable(TAG, this);
} }
@@ -311,6 +331,20 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
} }
mWallpaperManager.addOnColorsChangedListener(mOnColorsChangedListener, null, mWallpaperManager.addOnColorsChangedListener(mOnColorsChangedListener, null,
UserHandle.USER_ALL); UserHandle.USER_ALL);
mWakefulnessLifecycle.addObserver(new WakefulnessLifecycle.Observer() {
@Override
public void onFinishedGoingToSleep() {
if (mDeferredWallpaperColors != null) {
WallpaperColors colors = mDeferredWallpaperColors;
int flags = mDeferredWallpaperColorsFlags;
mDeferredWallpaperColors = null;
mDeferredWallpaperColorsFlags = 0;
handleWallpaperColors(colors, flags);
}
}
});
} }
private void reevaluateSystemTheme(boolean forceReload) { private void reevaluateSystemTheme(boolean forceReload) {

View File

@@ -16,6 +16,7 @@
package com.android.systemui.theme; package com.android.systemui.theme;
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_AWAKE;
import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_CATEGORY_ACCENT_COLOR; import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_CATEGORY_ACCENT_COLOR;
import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_CATEGORY_SYSTEM_PALETTE; import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_CATEGORY_SYSTEM_PALETTE;
@@ -51,6 +52,7 @@ import androidx.test.filters.SmallTest;
import com.android.systemui.SysuiTestCase; import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dump.DumpManager; import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.settings.UserTracker; import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.FeatureFlags; import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.statusbar.policy.DeviceProvisionedController;
@@ -99,22 +101,26 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
private DeviceProvisionedController mDeviceProvisionedController; private DeviceProvisionedController mDeviceProvisionedController;
@Mock @Mock
private FeatureFlags mFeatureFlags; private FeatureFlags mFeatureFlags;
@Mock
private WakefulnessLifecycle mWakefulnessLifecycle;
@Captor @Captor
private ArgumentCaptor<BroadcastReceiver> mBroadcastReceiver; private ArgumentCaptor<BroadcastReceiver> mBroadcastReceiver;
@Captor @Captor
private ArgumentCaptor<WallpaperManager.OnColorsChangedListener> mColorsListener; private ArgumentCaptor<WallpaperManager.OnColorsChangedListener> mColorsListener;
@Captor @Captor
private ArgumentCaptor<DeviceProvisionedListener> mDeviceProvisionedListener; private ArgumentCaptor<DeviceProvisionedListener> mDeviceProvisionedListener;
@Captor
private ArgumentCaptor<WakefulnessLifecycle.Observer> mWakefulnessLifecycleObserver;
@Before @Before
public void setup() { public void setup() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
when(mFeatureFlags.isMonetEnabled()).thenReturn(true); when(mFeatureFlags.isMonetEnabled()).thenReturn(true);
when(mWakefulnessLifecycle.getWakefulness()).thenReturn(WAKEFULNESS_AWAKE);
when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(true); when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(true);
mThemeOverlayController = new ThemeOverlayController(null /* context */, mThemeOverlayController = new ThemeOverlayController(null /* context */,
mBroadcastDispatcher, mBgHandler, mMainExecutor, mBgExecutor, mThemeOverlayApplier, mBroadcastDispatcher, mBgHandler, mMainExecutor, mBgExecutor, mThemeOverlayApplier,
mSecureSettings, mWallpaperManager, mUserManager, mDeviceProvisionedController, mSecureSettings, mWallpaperManager, mUserManager, mDeviceProvisionedController,
mUserTracker, mDumpManager, mFeatureFlags) { mUserTracker, mDumpManager, mFeatureFlags, mWakefulnessLifecycle) {
@Nullable @Nullable
@Override @Override
protected FabricatedOverlay getOverlay(int color, int type) { protected FabricatedOverlay getOverlay(int color, int type) {
@@ -125,11 +131,13 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
} }
}; };
mWakefulnessLifecycle.dispatchFinishedWakingUp();
mThemeOverlayController.start(); mThemeOverlayController.start();
verify(mWallpaperManager).addOnColorsChangedListener(mColorsListener.capture(), eq(null), verify(mWallpaperManager).addOnColorsChangedListener(mColorsListener.capture(), eq(null),
eq(UserHandle.USER_ALL)); eq(UserHandle.USER_ALL));
verify(mBroadcastDispatcher).registerReceiver(mBroadcastReceiver.capture(), any(), verify(mBroadcastDispatcher).registerReceiver(mBroadcastReceiver.capture(), any(),
eq(mMainExecutor), any()); eq(mMainExecutor), any());
verify(mWakefulnessLifecycle).addObserver(mWakefulnessLifecycleObserver.capture());
verify(mDumpManager).registerDumpable(any(), any()); verify(mDumpManager).registerDumpable(any(), any());
verify(mDeviceProvisionedController).addCallback(mDeviceProvisionedListener.capture()); verify(mDeviceProvisionedController).addCallback(mDeviceProvisionedListener.capture());
} }
@@ -347,7 +355,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
mThemeOverlayController = new ThemeOverlayController(null /* context */, mThemeOverlayController = new ThemeOverlayController(null /* context */,
mBroadcastDispatcher, mBgHandler, executor, executor, mThemeOverlayApplier, mBroadcastDispatcher, mBgHandler, executor, executor, mThemeOverlayApplier,
mSecureSettings, mWallpaperManager, mUserManager, mDeviceProvisionedController, mSecureSettings, mWallpaperManager, mUserManager, mDeviceProvisionedController,
mUserTracker, mDumpManager, mFeatureFlags) { mUserTracker, mDumpManager, mFeatureFlags, mWakefulnessLifecycle) {
@Nullable @Nullable
@Override @Override
protected FabricatedOverlay getOverlay(int color, int type) { protected FabricatedOverlay getOverlay(int color, int type) {
@@ -380,6 +388,54 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
verify(mThemeOverlayApplier).applyCurrentUserOverlays(any(), any(), anyInt(), any()); verify(mThemeOverlayApplier).applyCurrentUserOverlays(any(), any(), anyInt(), any());
} }
@Test
public void onWallpaperColorsChanged_screenOff_deviceSetupNotFinished_doesNotProcessQueued() {
when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(false);
mDeviceProvisionedListener.getValue().onUserSetupChanged();
// Second color application is not applied.
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
Color.valueOf(Color.BLUE), null);
mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM);
clearInvocations(mThemeOverlayApplier);
// Device went to sleep and second set of colors was applied.
mainColors = new WallpaperColors(Color.valueOf(Color.BLUE),
Color.valueOf(Color.RED), null);
mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM);
verify(mThemeOverlayApplier, never())
.applyCurrentUserOverlays(any(), any(), anyInt(), any());
mWakefulnessLifecycle.dispatchFinishedGoingToSleep();
verify(mThemeOverlayApplier, never())
.applyCurrentUserOverlays(any(), any(), anyInt(), any());
}
@Test
public void onWallpaperColorsChanged_screenOff_processesQueued() {
when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(true);
mDeviceProvisionedListener.getValue().onUserSetupChanged();
// Second color application is not applied.
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
Color.valueOf(Color.BLUE), null);
mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM);
clearInvocations(mThemeOverlayApplier);
// Device went to sleep and second set of colors was applied.
mainColors = new WallpaperColors(Color.valueOf(Color.BLUE),
Color.valueOf(Color.RED), null);
mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM);
verify(mThemeOverlayApplier, never())
.applyCurrentUserOverlays(any(), any(), anyInt(), any());
mWakefulnessLifecycleObserver.getValue().onFinishedGoingToSleep();
verify(mThemeOverlayApplier).applyCurrentUserOverlays(any(), any(), anyInt(), any());
}
@Test @Test
public void onWallpaperColorsChanged_parsesColorsFromWallpaperPicker() { public void onWallpaperColorsChanged_parsesColorsFromWallpaperPicker() {
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED), WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),