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

Commit 86165211 authored by Jay Aliomer's avatar Jay Aliomer Committed by Automerger Merge Worker
Browse files

Merge "Dark theme twilight mode not initializing properly" into rvc-dev am:...

Merge "Dark theme twilight mode not initializing properly" into rvc-dev am: 284afca8 am: ab4d9abd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11794325

Change-Id: I2cd309199afbd2efbd6f9c6d62589a70f99dbb3c
parents e97e49b3 ab4d9abd
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -233,7 +233,7 @@ final class UiModeManagerService extends SystemService {
        public void onTwilightStateChanged(@Nullable TwilightState state) {
            synchronized (mLock) {
                if (mNightMode == UiModeManager.MODE_NIGHT_AUTO && mSystemReady) {
                    if (mCar) {
                    if (shouldApplyAutomaticChangesImmediately()) {
                        updateLocked(0, 0);
                    } else {
                        registerScreenOffEventLocked();
@@ -1155,7 +1155,6 @@ final class UiModeManagerService extends SystemService {
    void updateLocked(int enableFlags, int disableFlags) {
        String action = null;
        String oldAction = null;
        boolean originalComputedNightMode = mComputedNightMode;
        if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_CAR) {
            adjustStatusBarCarModeLocked();
            oldAction = UiModeManager.ACTION_EXIT_CAR_MODE;
@@ -1236,11 +1235,6 @@ final class UiModeManagerService extends SystemService {
            sendConfigurationAndStartDreamOrDockAppLocked(category);
        }

        // reset overrides if mComputedNightMode changes
        if (originalComputedNightMode != mComputedNightMode) {
            resetNightModeOverrideLocked();
        }

        // keep screen on when charging and in car mode
        boolean keepScreenOn = mCharging &&
                ((mCarModeEnabled && mCarModeKeepsScreenOn &&
@@ -1403,6 +1397,7 @@ final class UiModeManagerService extends SystemService {
            mComputedNightMode = false;
            return;
        }
        resetNightModeOverrideLocked();
    }

    private boolean resetNightModeOverrideLocked() {
+39 −2
Original line number Diff line number Diff line
@@ -31,9 +31,10 @@ import android.os.PowerManager;
import android.os.PowerManagerInternal;
import android.os.PowerSaveState;
import android.os.RemoteException;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

import com.android.server.twilight.TwilightListener;
import com.android.server.twilight.TwilightManager;
import com.android.server.twilight.TwilightState;
import com.android.server.wm.WindowManagerInternal;
@@ -55,7 +56,6 @@ import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
@@ -65,6 +65,7 @@ import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -100,12 +101,17 @@ public class UiModeManagerServiceTest extends UiServiceTestCase {
    private BroadcastReceiver mTimeChangedCallback;
    private AlarmManager.OnAlarmListener mCustomListener;
    private Consumer<PowerSaveState> mPowerSaveConsumer;
    private TwilightListener mTwilightListener;

    @Before
    public void setUp() {
        initMocks(this);
        when(mContext.checkCallingOrSelfPermission(anyString()))
                .thenReturn(PackageManager.PERMISSION_GRANTED);
        doAnswer(inv -> {
            mTwilightListener = (TwilightListener) inv.getArgument(0);
            return null;
        }).when(mTwilightManager).registerListener(any(), any());
        doAnswer(inv -> {
            mPowerSaveConsumer = (Consumer<PowerSaveState>) inv.getArgument(1);
            return null;
@@ -159,6 +165,37 @@ public class UiModeManagerServiceTest extends UiServiceTestCase {
        LocalServices.addService(clazz, service);
    }

    @Test
    public void setNightMoveActivated_overridesFunctionCorrectly() throws RemoteException {
        // set up
        when(mPowerManager.isInteractive()).thenReturn(false);
        mService.setNightMode(MODE_NIGHT_NO);
        assertFalse(mUiManagerService.getConfiguration().isNightModeActive());

        // assume it is day time
        doReturn(false).when(mTwilightState).isNight();

        // set mode to auto
        mService.setNightMode(MODE_NIGHT_AUTO);

        // set night mode on overriding current config
        mService.setNightModeActivated(true);

        assertTrue(mUiManagerService.getConfiguration().isNightModeActive());

        // now it is night time
        doReturn(true).when(mTwilightState).isNight();
        mTwilightListener.onTwilightStateChanged(mTwilightState);

        assertTrue(mUiManagerService.getConfiguration().isNightModeActive());

        // now it is next day mid day
        doReturn(false).when(mTwilightState).isNight();
        mTwilightListener.onTwilightStateChanged(mTwilightState);

        assertFalse(mUiManagerService.getConfiguration().isNightModeActive());
    }

    @Test
    public void setAutoMode_screenOffRegistered() throws RemoteException {
        try {