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

Commit 85fe7558 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixes inability to toggle dark mode when in a mode. " into main

parents cefc86d2 eb64e170
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -885,8 +885,6 @@ final class UiModeManagerService extends SystemService {
                                ? customModeType
                                : MODE_NIGHT_CUSTOM_TYPE_UNKNOWN;
                        mNightMode.set(mode);
                        //deactivates AttentionMode if user toggles DarkTheme
                        mAttentionModeThemeOverlay = MODE_ATTENTION_THEME_OVERLAY_OFF;
                        resetNightModeOverrideLocked();
                        persistNightMode(user);
                        // on screen off will update configuration instead
@@ -1009,15 +1007,16 @@ final class UiModeManagerService extends SystemService {

        @Override
        public boolean setNightModeActivatedForCustomMode(int modeNightCustomType, boolean active) {
            return setNightModeActivatedForModeInternal(modeNightCustomType, active);
            return setNightModeActivatedForModeInternal(modeNightCustomType, active, false);
        }

        @Override
        public boolean setNightModeActivated(boolean active) {
            return setNightModeActivatedForModeInternal(mNightModeCustomType, active);
            return setNightModeActivatedForModeInternal(mNightModeCustomType, active, true);
        }

        private boolean setNightModeActivatedForModeInternal(int modeCustomType, boolean active) {
        private boolean setNightModeActivatedForModeInternal(int modeCustomType,
            boolean active, boolean isUserInteraction) {
            if (getContext().checkCallingOrSelfPermission(
                    android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)
                    != PackageManager.PERMISSION_GRANTED) {
@@ -1053,13 +1052,16 @@ final class UiModeManagerService extends SystemService {
                        mOverrideNightModeOn = active;
                        mOverrideNightModeUser = mCurrentUser;
                        persistNightModeOverrides(mCurrentUser);
                    } else if (mNightMode.get() == UiModeManager.MODE_NIGHT_NO
                            && active) {
                    } else if (mNightMode.get() == UiModeManager.MODE_NIGHT_NO && active) {
                        mNightMode.set(UiModeManager.MODE_NIGHT_YES);
                    } else if (mNightMode.get() == UiModeManager.MODE_NIGHT_YES
                            && !active) {
                    } else if (mNightMode.get() == UiModeManager.MODE_NIGHT_YES && !active) {
                        mNightMode.set(UiModeManager.MODE_NIGHT_NO);
                    }

                    if (isUserInteraction) {
                        // deactivates AttentionMode if user toggles DarkTheme
                        mAttentionModeThemeOverlay = MODE_ATTENTION_THEME_OVERLAY_OFF;
                    }
                    updateConfigurationLocked();
                    applyConfigurationExternallyLocked();
                    persistNightMode(mCurrentUser);
+20 −9
Original line number Diff line number Diff line
@@ -1460,9 +1460,12 @@ public class UiModeManagerServiceTest extends UiServiceTestCase {
        verify(mInjector).startDreamWhenDockedIfAppropriate(mContext);
    }

    private void testAttentionModeThemeOverlay(boolean modeNight) throws RemoteException {
    // Test the attention mode overlay with all the possible attention modes and the initial night
    // mode state. Also tests if the attention mode is turned off when the night mode is toggled by
    // the user.
    private void testAttentionModeThemeOverlay(boolean initialNightMode) throws RemoteException {
        //setup
        if (modeNight) {
        if (initialNightMode) {
            mService.setNightMode(MODE_NIGHT_YES);
            assertTrue(mUiManagerService.getConfiguration().isNightModeActive());
        } else {
@@ -1472,21 +1475,29 @@ public class UiModeManagerServiceTest extends UiServiceTestCase {

        // attention modes with expected night modes
        Map<Integer, Boolean> modes = Map.of(
                MODE_ATTENTION_THEME_OVERLAY_OFF, modeNight,
                MODE_ATTENTION_THEME_OVERLAY_OFF, initialNightMode,
                MODE_ATTENTION_THEME_OVERLAY_DAY, false,
                MODE_ATTENTION_THEME_OVERLAY_NIGHT, true
        );

        // test
        for (int aMode : modes.keySet()) {
        for (int attentionMode : modes.keySet()) {
            try {
                mService.setAttentionModeThemeOverlay(aMode);
                mService.setAttentionModeThemeOverlay(attentionMode);

                int appliedAMode = mService.getAttentionModeThemeOverlay();
                boolean nMode = modes.get(aMode);
                boolean expectedNightMode = modes.get(attentionMode);

                assertEquals(aMode, appliedAMode);
                assertEquals(isNightModeActivated(), nMode);
                assertEquals(attentionMode, appliedAMode);
                assertEquals(expectedNightMode, isNightModeActivated());

                // If attentionMode is active, flip the night mode and assets
                // the attention mode is disabled
                if (attentionMode != MODE_ATTENTION_THEME_OVERLAY_OFF) {
                    mService.setNightModeActivated(!expectedNightMode);
                    assertEquals(MODE_ATTENTION_THEME_OVERLAY_OFF,
                            mService.getAttentionModeThemeOverlay());
                }
            } catch (RemoteException e) {
                fail("Error communicating with server: " + e.getMessage());
            }