Dark theme twilight mode not initializing properly
When overriding night mode, changes dont apply. The fix is to make sure that the overrride is reset in situation where it doesnt apply anymore Also, the other bug is that changes should apply when screen is off or in car mode, but was applying in car mode only Test: UiModeManagerServiceTest Bug: 158407234 Change-Id: I9023b16c6619ddd31954fbc0a0a527b36671d2ec
This commit is contained in:
@@ -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,16 +1235,11 @@ 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 &&
|
||||
(mCarModeEnableFlags & UiModeManager.ENABLE_CAR_MODE_ALLOW_SLEEP) == 0) ||
|
||||
(mCurUiMode == Configuration.UI_MODE_TYPE_DESK && mDeskModeKeepsScreenOn));
|
||||
(mCarModeEnableFlags & UiModeManager.ENABLE_CAR_MODE_ALLOW_SLEEP) == 0) ||
|
||||
(mCurUiMode == Configuration.UI_MODE_TYPE_DESK && mDeskModeKeepsScreenOn));
|
||||
if (keepScreenOn != mWakeLock.isHeld()) {
|
||||
if (keepScreenOn) {
|
||||
mWakeLock.acquire();
|
||||
@@ -1403,6 +1397,7 @@ final class UiModeManagerService extends SystemService {
|
||||
mComputedNightMode = false;
|
||||
return;
|
||||
}
|
||||
resetNightModeOverrideLocked();
|
||||
}
|
||||
|
||||
private boolean resetNightModeOverrideLocked() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user