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

Commit e26d0b87 authored by josephpv's avatar josephpv Committed by Joseph Vincent
Browse files

Use system theme for Private profile

Change to use generic profile added intent ACTION_PROFILE_ADDED intent
to apply theme

Change isManagedProfile() check to isProfile() to update theme overlay

Bug: 311348071
Test: atest ThemeOverlayControllerTest and Verified theme color by changing manually
Change-Id: I6caf2e9c2480925f00e6a61a899437bf5a80eabf
parent ab60847a
Loading
Loading
Loading
Loading
+25 −8
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@ package com.android.systemui.theme;

import static android.util.TypedValue.TYPE_INT_COLOR_ARGB8;

import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_ASLEEP;
import static com.android.systemui.Flags.themeOverlayControllerWakefulnessDeprecation;
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_ASLEEP;
import static com.android.systemui.theme.ThemeOverlayApplier.COLOR_SOURCE_HOME;
import static com.android.systemui.theme.ThemeOverlayApplier.COLOR_SOURCE_LOCK;
import static com.android.systemui.theme.ThemeOverlayApplier.COLOR_SOURCE_PRESET;
@@ -364,15 +364,23 @@ public class ThemeOverlayController implements CoreStartable, Dumpable {
    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            boolean newWorkProfile = Intent.ACTION_MANAGED_PROFILE_ADDED.equals(intent.getAction());
            boolean isManagedProfile = mUserManager.isManagedProfile(
                    intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
            if (newWorkProfile) {
                if (!mDeviceProvisionedController.isCurrentUserSetup() && isManagedProfile) {
            boolean newProfile = Intent.ACTION_PROFILE_ADDED.equals(intent.getAction());
            if (newProfile) {
                UserHandle newUserHandle = intent.getParcelableExtra(Intent.EXTRA_USER,
                        android.os.UserHandle.class);
                boolean isManagedProfile =
                        mUserManager.isManagedProfile(newUserHandle.getIdentifier());
                if (!mDeviceProvisionedController.isUserSetup(newUserHandle.getIdentifier())
                        && isManagedProfile) {
                    Log.i(TAG, "User setup not finished when " + intent.getAction()
                            + " was received. Deferring... Managed profile? " + isManagedProfile);
                    return;
                }
                if (android.os.Flags.allowPrivateProfile() && isPrivateProfile(newUserHandle)) {
                    mDeferredThemeEvaluation = true;
                    Log.i(TAG, "Deferring theme for private profile till user setup is complete");
                    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())) {
@@ -432,7 +440,7 @@ public class ThemeOverlayController implements CoreStartable, Dumpable {
    public void start() {
        if (DEBUG) Log.d(TAG, "Start");
        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
        filter.addAction(Intent.ACTION_PROFILE_ADDED);
        filter.addAction(Intent.ACTION_WALLPAPER_CHANGED);
        mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter, mMainExecutor,
                UserHandle.ALL);
@@ -608,6 +616,15 @@ public class ThemeOverlayController implements CoreStartable, Dumpable {
        return new FabricatedOverlay.Builder("com.android.systemui", name, "android").build();
    }

    @VisibleForTesting
    protected boolean isPrivateProfile(UserHandle userHandle) {
        Context usercontext = mContext.createContextAsUser(userHandle,0);
        if (usercontext.getSystemService(UserManager.class).isPrivateProfile()) {
            return true;
        }
        return false;
    }

    private void createOverlays(int color) {
        boolean nightMode = isNightMode();
        mColorScheme = new ColorScheme(color, nightMode, mThemeStyle);
@@ -784,7 +801,7 @@ public class ThemeOverlayController implements CoreStartable, Dumpable {

        Set<UserHandle> managedProfiles = new HashSet<>();
        for (UserInfo userInfo : mUserManager.getEnabledProfiles(currentUser)) {
            if (userInfo.isManagedProfile()) {
            if (userInfo.isProfile()) {
                managedProfiles.add(userInfo.getUserHandle());
            }
        }
+31 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.theme;

import static android.os.Flags.FLAG_ALLOW_PRIVATE_PROFILE;
import static android.util.TypedValue.TYPE_INT_COLOR_ARGB8;

import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_AWAKE;
@@ -90,6 +91,9 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {

    private static final int USER_SYSTEM = UserHandle.USER_SYSTEM;
    private static final int USER_SECONDARY = 10;
    private static final UserHandle MANAGED_USER_HANDLE = UserHandle.of(100);
    private static final UserHandle PRIVATE_USER_HANDLE = UserHandle.of(101);

    @Mock
    private JavaAdapter mJavaAdapter;
    @Mock
@@ -174,6 +178,14 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
                                Integer.toHexString(mColorScheme.getSeed() | 0xff000000)));
                return overlay;
            }

            @VisibleForTesting
            protected boolean isPrivateProfile(UserHandle userHandle) {
                if (userHandle.getIdentifier() == PRIVATE_USER_HANDLE.getIdentifier()) {
                    return true;
                }
                return false;
            }
        };

        mWakefulnessLifecycle.dispatchFinishedWakingUp();
@@ -675,7 +687,8 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
    @Test
    public void onProfileAdded_setsTheme() {
        mBroadcastReceiver.getValue().onReceive(null,
                new Intent(Intent.ACTION_MANAGED_PROFILE_ADDED));
                new Intent(Intent.ACTION_PROFILE_ADDED)
                        .putExtra(Intent.EXTRA_USER, MANAGED_USER_HANDLE));
        verify(mThemeOverlayApplier).applyCurrentUserOverlays(any(), any(), anyInt(), any());
    }

@@ -684,7 +697,8 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
        reset(mDeviceProvisionedController);
        when(mUserManager.isManagedProfile(anyInt())).thenReturn(false);
        mBroadcastReceiver.getValue().onReceive(null,
                new Intent(Intent.ACTION_MANAGED_PROFILE_ADDED));
                new Intent(Intent.ACTION_PROFILE_ADDED)
                        .putExtra(Intent.EXTRA_USER, MANAGED_USER_HANDLE));
        verify(mThemeOverlayApplier)
                .applyCurrentUserOverlays(any(), any(), anyInt(), any());
    }
@@ -694,11 +708,25 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
        reset(mDeviceProvisionedController);
        when(mUserManager.isManagedProfile(anyInt())).thenReturn(true);
        mBroadcastReceiver.getValue().onReceive(null,
                new Intent(Intent.ACTION_MANAGED_PROFILE_ADDED));
                new Intent(Intent.ACTION_PROFILE_ADDED)
                        .putExtra(Intent.EXTRA_USER, MANAGED_USER_HANDLE));
        verify(mThemeOverlayApplier, never())
                .applyCurrentUserOverlays(any(), any(), anyInt(), any());
    }

    @Test
    public void onPrivateProfileAdded_ignoresUntilStartComplete() {
        mSetFlagsRule.enableFlags(FLAG_ALLOW_PRIVATE_PROFILE);
        reset(mDeviceProvisionedController);
        when(mUserManager.isManagedProfile(anyInt())).thenReturn(false);
        mBroadcastReceiver.getValue().onReceive(null,
                (new Intent(Intent.ACTION_PROFILE_ADDED))
                        .putExtra(Intent.EXTRA_USER, PRIVATE_USER_HANDLE));
        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
+0 −1
Original line number Diff line number Diff line
@@ -306,7 +306,6 @@ public final class UserTypeFactory {
                .setDarkThemeBadgeColors(
                        R.color.white)
                .setDefaultRestrictions(getDefaultProfileRestrictions())
                .setDefaultSecureSettings(getDefaultNonManagedProfileSecureSettings())
                .setDefaultUserProperties(new UserProperties.Builder()
                        .setStartWithParent(true)
                        .setCredentialShareableWithParent(true)