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

Commit c42a70fa authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Reset the color settings if the wallpaper changes" into sc-dev

parents 5183641b 5d53cde9
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -66,6 +66,13 @@ public class ThemeOverlayApplier implements Dumpable {
            "android.theme.customization.accent_color";
    static final String OVERLAY_CATEGORY_SYSTEM_PALETTE =
            "android.theme.customization.system_palette";

    static final String OVERLAY_COLOR_SOURCE = "android.theme.customization.color_source";

    static final String COLOR_SOURCE_PRESET = "preset";

    static final String TIMESTAMP_FIELD = "_applied_timestamp";

    @VisibleForTesting
    static final String OVERLAY_CATEGORY_FONT = "android.theme.customization.font";
    @VisibleForTesting
+41 −2
Original line number Diff line number Diff line
@@ -15,8 +15,11 @@
 */
package com.android.systemui.theme;

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_SYSTEM_PALETTE;
import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_COLOR_SOURCE;
import static com.android.systemui.theme.ThemeOverlayApplier.TIMESTAMP_FIELD;

import android.annotation.Nullable;
import android.app.WallpaperColors;
@@ -90,12 +93,12 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
    private final UserManager mUserManager;
    private final BroadcastDispatcher mBroadcastDispatcher;
    private final Executor mBgExecutor;
    private final SecureSettings mSecureSettings;
    private SecureSettings mSecureSettings;
    private final Executor mMainExecutor;
    private final Handler mBgHandler;
    private final WallpaperManager mWallpaperManager;
    private final boolean mIsMonetEnabled;
    private final UserTracker mUserTracker;
    private UserTracker mUserTracker;
    private DeviceProvisionedController mDeviceProvisionedController;
    private WallpaperColors mSystemColors;
    // If fabricated overlays were already created for the current theme.
@@ -112,6 +115,8 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
    private boolean mAcceptColorEvents = true;
    // Defers changing themes until Setup Wizard is done.
    private boolean mDeferredThemeEvaluation;
    // Determines if we should ignore THEME_CUSTOMIZATION_OVERLAY_PACKAGES setting changes.
    private boolean mSkipSettingChange;

    private final DeviceProvisionedListener mDeviceProvisionedListener =
            new DeviceProvisionedListener() {
@@ -162,6 +167,35 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
                }
            }
        }
        // Check if we need to reset to default colors (if a color override was set that is sourced
        // from the wallpaper)
        int currentUser = mUserTracker.getUserId();
        String overlayPackageJson = mSecureSettings.getStringForUser(
                Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
                currentUser);
        if (!TextUtils.isEmpty(overlayPackageJson)) {
            try {
                JSONObject jsonObject = new JSONObject(overlayPackageJson);
                if ((jsonObject.has(OVERLAY_CATEGORY_ACCENT_COLOR)
                        || jsonObject.has(OVERLAY_CATEGORY_SYSTEM_PALETTE))
                        && !COLOR_SOURCE_PRESET.equals(
                        jsonObject.optString(OVERLAY_COLOR_SOURCE))) {
                    mSkipSettingChange = true;
                    jsonObject.remove(OVERLAY_CATEGORY_ACCENT_COLOR);
                    jsonObject.remove(OVERLAY_CATEGORY_SYSTEM_PALETTE);
                    jsonObject.remove(OVERLAY_COLOR_SOURCE);
                    jsonObject.put(TIMESTAMP_FIELD, System.currentTimeMillis());
                    if (DEBUG) {
                        Log.d(TAG, "Updating theme setting from "
                                + overlayPackageJson + " to " + jsonObject.toString());
                    }
                    mSecureSettings.putString(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
                            jsonObject.toString());
                }
            } catch (JSONException e) {
                Log.i(TAG, "Failed to parse THEME_CUSTOMIZATION_OVERLAY_PACKAGES.", e);
            }
        }
        reevaluateSystemTheme(false /* forceReload */);
    };

@@ -232,6 +266,11 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
                            mDeferredThemeEvaluation = true;
                            return;
                        }
                        if (mSkipSettingChange) {
                            if (DEBUG) Log.d(TAG, "Skipping setting change");
                            mSkipSettingChange = false;
                            return;
                        }
                        reevaluateSystemTheme(true /* forceReload */);
                    }
                },
+28 −1
Original line number Diff line number Diff line
@@ -185,7 +185,8 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
                Color.valueOf(Color.BLUE), null);

        String jsonString =
                "{\"android.theme.customization.system_palette\":\"override.package.name\"}";
                "{\"android.theme.customization.system_palette\":\"override.package.name\","
                        + "\"android.theme.customization.color_source\":\"preset\"}";
        when(mSecureSettings.getStringForUser(
                eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
                .thenReturn(jsonString);
@@ -202,6 +203,32 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
                .isEqualTo(new OverlayIdentifier("override.package.name"));
    }

    @Test
    public void onWallpaperColorsChanged_resetThemeIfNotPreset() {
        // Should ask for a new theme when wallpaper colors change
        WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
                Color.valueOf(Color.BLUE), null);

        String jsonString =
                "{\"android.theme.customization.system_palette\":\"override.package.name\","
                        + "\"android.theme.customization.color_source\":\"home_wallpaper\"}";
        when(mSecureSettings.getStringForUser(
                eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
                .thenReturn(jsonString);

        mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM);

        ArgumentCaptor<String> updatedSetting = ArgumentCaptor.forClass(String.class);
        verify(mSecureSettings).putString(
                eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), updatedSetting.capture());

        assertThat(updatedSetting.getValue().contains("android.theme.customization.system_palette"))
                .isFalse();

        verify(mThemeOverlayApplier)
                .applyCurrentUserOverlays(any(), any(), anyInt(), any());
    }

    @Test
    public void onProfileAdded_setsTheme() {
        mBroadcastReceiver.getValue().onReceive(null,