Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9274be53 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Move OM calls to the background

Test: manual
Test: atest ThemeOverlayApplierTest
Bug: 181591270
Bug: 181617612
Change-Id: I42907260fb2287d58d9e9c22740fbb45e0c64f05
parent 74d4d029
Loading
Loading
Loading
Loading
+39 −33
Original line number Original line Diff line number Diff line
@@ -15,6 +15,7 @@
 */
 */
package com.android.systemui.theme;
package com.android.systemui.theme;


import android.annotation.AnyThread;
import android.content.om.FabricatedOverlay;
import android.content.om.FabricatedOverlay;
import android.content.om.OverlayIdentifier;
import android.content.om.OverlayIdentifier;
import android.content.om.OverlayInfo;
import android.content.om.OverlayInfo;
@@ -159,6 +160,8 @@ public class ThemeOverlayApplier implements Dumpable {
            FabricatedOverlay[] pendingCreation,
            FabricatedOverlay[] pendingCreation,
            int currentUser,
            int currentUser,
            Set<UserHandle> managedProfiles) {
            Set<UserHandle> managedProfiles) {
        mExecutor.execute(() -> {

            // Disable all overlays that have not been specified in the user setting.
            // Disable all overlays that have not been specified in the user setting.
            final Set<String> overlayCategoriesToDisable = new HashSet<>(THEME_CATEGORIES);
            final Set<String> overlayCategoriesToDisable = new HashSet<>(THEME_CATEGORIES);
            final Set<String> targetPackagesToQuery = overlayCategoriesToDisable.stream()
            final Set<String> targetPackagesToQuery = overlayCategoriesToDisable.stream()
@@ -169,9 +172,11 @@ public class ThemeOverlayApplier implements Dumpable {
                    .getOverlayInfosForTarget(targetPackage, UserHandle.SYSTEM)));
                    .getOverlayInfosForTarget(targetPackage, UserHandle.SYSTEM)));
            final List<Pair<String, String>> overlaysToDisable = overlays.stream()
            final List<Pair<String, String>> overlaysToDisable = overlays.stream()
                    .filter(o ->
                    .filter(o ->
                        mTargetPackageToCategories.get(o.targetPackageName).contains(o.category))
                            mTargetPackageToCategories.get(o.targetPackageName).contains(
                                    o.category))
                    .filter(o -> overlayCategoriesToDisable.contains(o.category))
                    .filter(o -> overlayCategoriesToDisable.contains(o.category))
                .filter(o -> !categoryToPackage.containsValue(new OverlayIdentifier(o.packageName)))
                    .filter(o -> !categoryToPackage.containsValue(
                            new OverlayIdentifier(o.packageName)))
                    .filter(o -> o.isEnabled())
                    .filter(o -> o.isEnabled())
                    .map(o -> new Pair<>(o.category, o.packageName))
                    .map(o -> new Pair<>(o.category, o.packageName))
                    .collect(Collectors.toList());
                    .collect(Collectors.toList());
@@ -192,11 +197,11 @@ public class ThemeOverlayApplier implements Dumpable {
            for (String category : THEME_CATEGORIES) {
            for (String category : THEME_CATEGORIES) {
                if (categoryToPackage.containsKey(category)) {
                if (categoryToPackage.containsKey(category)) {
                    OverlayIdentifier overlayInfo = categoryToPackage.get(category);
                    OverlayIdentifier overlayInfo = categoryToPackage.get(category);
                setEnabled(transaction, overlayInfo, category, currentUser, managedProfiles, true);
                    setEnabled(transaction, overlayInfo, category, currentUser, managedProfiles,
                            true);
                }
                }
            }
            }


        mExecutor.execute(() -> {
            try {
            try {
                mOverlayManager.commit(transaction.build());
                mOverlayManager.commit(transaction.build());
            } catch (SecurityException | IllegalStateException e) {
            } catch (SecurityException | IllegalStateException e) {
@@ -210,6 +215,7 @@ public class ThemeOverlayApplier implements Dumpable {
        return new OverlayManagerTransaction.Builder();
        return new OverlayManagerTransaction.Builder();
    }
    }


    @AnyThread
    private void setEnabled(OverlayManagerTransaction.Builder transaction,
    private void setEnabled(OverlayManagerTransaction.Builder transaction,
            OverlayIdentifier identifier, String category, int currentUser,
            OverlayIdentifier identifier, String category, int currentUser,
            Set<UserHandle> managedProfiles, boolean enabled) {
            Set<UserHandle> managedProfiles, boolean enabled) {