From 7f5bc353d49fb5d7d2a8046dcd822d002a1847c4 Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Wed, 21 Apr 2021 23:06:12 -0700 Subject: [PATCH] Do not reload theme when managed profile When a managed profile is added, if setup wizard was not finished, do not reload the theme, postpone until it's done Bug: 185572689 Test: atest ThemeOverlayControllerTest Change-Id: I0cb1b2316a6837d85cf708403a34c2459a1dcc5a --- .../systemui/theme/ThemeOverlayController.java | 5 +++++ .../theme/ThemeOverlayControllerTest.java | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java index fdd929cae17d1..329cd71deda74 100644 --- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java +++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java @@ -166,6 +166,11 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { public void onReceive(Context context, Intent intent) { if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction()) || Intent.ACTION_MANAGED_PROFILE_ADDED.equals(intent.getAction())) { + if (!mDeviceProvisionedController.isCurrentUserSetup()) { + Log.i(TAG, "User setup not finished when " + intent.getAction() + + " was received. Deferring..."); + return; + } if (DEBUG) Log.d(TAG, "Updating overlays for user switch / profile added."); reevaluateSystemTheme(true /* forceReload */); } else if (Intent.ACTION_WALLPAPER_CHANGED.equals(intent.getAction())) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java index ddf39d1e7c6e7..60e70d01edc86 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java @@ -202,6 +202,22 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { .isEqualTo(new OverlayIdentifier("override.package.name")); } + @Test + public void onProfileAdded_setsTheme() { + mBroadcastReceiver.getValue().onReceive(null, + new Intent(Intent.ACTION_MANAGED_PROFILE_ADDED)); + verify(mThemeOverlayApplier).applyCurrentUserOverlays(any(), any(), anyInt(), any()); + } + + @Test + public void onProfileAdded_ignoresUntilSetupComplete() { + reset(mDeviceProvisionedController); + mBroadcastReceiver.getValue().onReceive(null, + new Intent(Intent.ACTION_MANAGED_PROFILE_ADDED)); + verify(mThemeOverlayApplier, never()) + .applyCurrentUserOverlays(any(), any(), anyInt(), any()); + } + @Test public void onWallpaperColorsChanged_firstEventBeforeUserSetup_shouldBeAccepted() { // By default, on setup() we make this controller return that the user finished setup