diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayManager.java | 52 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayManagerTest.java | 13 |
2 files changed, 42 insertions, 23 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayManager.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayManager.java index 1a9fd5315c32..51ae70b84286 100644 --- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayManager.java +++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayManager.java @@ -23,9 +23,11 @@ import android.util.Log; import androidx.annotation.VisibleForTesting; +import com.google.android.collect.Lists; import com.google.android.collect.Sets; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -62,15 +64,18 @@ class ThemeOverlayManager { static final String OVERLAY_CATEGORY_ICON_LAUNCHER = "android.theme.customization.icon_pack.launcher"; - /* All theme customization categories used by the system. */ - static final Set<String> THEME_CATEGORIES = Sets.newHashSet( - OVERLAY_CATEGORY_COLOR, - OVERLAY_CATEGORY_FONT, + /* + * All theme customization categories used by the system, in order that they should be applied, + * starts with launcher and grouped by target package. + */ + static final List<String> THEME_CATEGORIES = Lists.newArrayList( + OVERLAY_CATEGORY_ICON_LAUNCHER, OVERLAY_CATEGORY_SHAPE, + OVERLAY_CATEGORY_FONT, + OVERLAY_CATEGORY_COLOR, OVERLAY_CATEGORY_ICON_ANDROID, OVERLAY_CATEGORY_ICON_SYSUI, - OVERLAY_CATEGORY_ICON_SETTINGS, - OVERLAY_CATEGORY_ICON_LAUNCHER); + OVERLAY_CATEGORY_ICON_SETTINGS); /* Categories that need to applied to the current user as well as the system user. */ @VisibleForTesting @@ -115,29 +120,30 @@ class ThemeOverlayManager { */ void applyCurrentUserOverlays( Map<String, String> categoryToPackage, Set<UserHandle> userHandles) { - final Map<Boolean, List<String>> categorySplit = THEME_CATEGORIES.stream().collect( - Collectors.partitioningBy((category) -> categoryToPackage.containsKey(category))); - final List<String> overlayCategoriesToEnable = categorySplit.get(true); - final List<String> overlayCategoriesToDisable = categorySplit.get(false); - // Disable all overlays that have not been specified in the user setting. - final List<OverlayInfo> overlays = new ArrayList<>(); - overlayCategoriesToDisable.stream() + final Set<String> overlayCategoriesToDisable = new HashSet<>(THEME_CATEGORIES); + overlayCategoriesToDisable.removeAll(categoryToPackage.keySet()); + final Set<String> targetPackagesToQuery = overlayCategoriesToDisable.stream() .map(category -> mCategoryToTargetPackage.get(category)) - .collect(Collectors.toSet()) - .forEach(targetPackage -> overlays.addAll(mOverlayManager - .getOverlayInfosForTarget(targetPackage, UserHandle.SYSTEM))); - overlays.stream() + .collect(Collectors.toSet()); + final List<OverlayInfo> overlays = new ArrayList<>(); + targetPackagesToQuery.forEach(targetPackage -> overlays.addAll(mOverlayManager + .getOverlayInfosForTarget(targetPackage, UserHandle.SYSTEM))); + final Map<String, String> overlaysToDisable = overlays.stream() .filter(o -> mTargetPackageToCategories.get(o.targetPackageName).contains(o.category)) .filter(o -> overlayCategoriesToDisable.contains(o.category)) .filter(o -> o.isEnabled()) - .forEach(o -> setEnabled(o.packageName, o.category, userHandles, false)); - - - // Enable all overlays specified in the user setting. - overlayCategoriesToEnable.forEach((category) -> - setEnabled(categoryToPackage.get(category), category, userHandles, true)); + .collect(Collectors.toMap((o) -> o.category, (o) -> o.packageName)); + + // Toggle overlays in the order of THEME_CATEGORIES. + for (String category : THEME_CATEGORIES) { + if (categoryToPackage.containsKey(category)) { + setEnabled(categoryToPackage.get(category), category, userHandles, true); + } else if (overlaysToDisable.containsKey(category)) { + setEnabled(overlaysToDisable.get(category), category, userHandles, false); + } + } } private void setEnabled( diff --git a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayManagerTest.java index da039a403087..a904704e3ea6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayManagerTest.java @@ -51,7 +51,9 @@ import com.google.common.collect.Sets; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InOrder; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import java.util.HashMap; @@ -134,6 +136,17 @@ public class ThemeOverlayManagerTest extends SysuiTestCase { } @Test + public void allCategoriesSpecified_enabledInOrder() { + mManager.applyCurrentUserOverlays(ALL_CATEGORIES_MAP, TEST_USER_HANDLES); + + InOrder inOrder = Mockito.inOrder(mOverlayManager); + for (String category : THEME_CATEGORIES) { + inOrder.verify(mOverlayManager) + .setEnabledExclusiveInCategory(ALL_CATEGORIES_MAP.get(category), TEST_USER); + } + } + + @Test public void allCategoriesSpecified_sysuiCategoriesAlsoAppliedToSysuiUser() { mManager.applyCurrentUserOverlays(ALL_CATEGORIES_MAP, TEST_USER_HANDLES); |