Merge "Rememeber the last dark mode before shutdown when in auto mode" into rvc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9be043388a
@@ -7896,6 +7896,12 @@ public final class Settings {
|
||||
*/
|
||||
public static final String UI_NIGHT_MODE_OVERRIDE_ON = "ui_night_mode_override_on";
|
||||
|
||||
/**
|
||||
* The last computed night mode bool the last time the phone was on
|
||||
* @hide
|
||||
*/
|
||||
public static final String UI_NIGHT_MODE_LAST_COMPUTED = "ui_night_mode_last_computed";
|
||||
|
||||
/**
|
||||
* The current night mode that has been overridden to turn off by the system. Owned
|
||||
* and controlled by UiModeManagerService. Constants are as per
|
||||
|
||||
@@ -327,6 +327,13 @@ final class UiModeManagerService extends SystemService {
|
||||
mCurrentUser = userHandle;
|
||||
getContext().getContentResolver().unregisterContentObserver(mSetupWizardObserver);
|
||||
verifySetupWizardCompleted();
|
||||
synchronized (mLock) {
|
||||
// only update if the value is actually changed
|
||||
if (updateNightModeFromSettingsLocked(getContext(), getContext().getResources(),
|
||||
mCurrentUser)) {
|
||||
updateLocked(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -354,11 +361,10 @@ final class UiModeManagerService extends SystemService {
|
||||
new IntentFilter(Intent.ACTION_DOCK_EVENT));
|
||||
IntentFilter batteryFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||
context.registerReceiver(mBatteryReceiver, batteryFilter);
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
context.registerReceiver(mSettingsRestored,
|
||||
new IntentFilter(Intent.ACTION_SETTING_RESTORED));
|
||||
context.registerReceiver(new UserSwitchedReceiver(), filter, null, mHandler);
|
||||
context.registerReceiver(mOnShutdown,
|
||||
new IntentFilter(Intent.ACTION_SHUTDOWN));
|
||||
updateConfigurationLocked();
|
||||
applyConfigurationExternallyLocked();
|
||||
}
|
||||
@@ -405,6 +411,21 @@ final class UiModeManagerService extends SystemService {
|
||||
publishLocalService(UiModeManagerInternal.class, mLocalService);
|
||||
}
|
||||
|
||||
private final BroadcastReceiver mOnShutdown = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (mNightMode == MODE_NIGHT_AUTO) {
|
||||
persistComputedNightMode(mCurrentUser);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void persistComputedNightMode(int userId) {
|
||||
Secure.putIntForUser(getContext().getContentResolver(),
|
||||
Secure.UI_NIGHT_MODE_LAST_COMPUTED, mComputedNightMode ? 1 : 0,
|
||||
userId);
|
||||
}
|
||||
|
||||
private final BroadcastReceiver mSettingsRestored = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@@ -506,6 +527,10 @@ final class UiModeManagerService extends SystemService {
|
||||
Secure.getLongForUser(context.getContentResolver(),
|
||||
Secure.DARK_THEME_CUSTOM_END_TIME,
|
||||
DEFAULT_CUSTOM_NIGHT_END_TIME.toNanoOfDay() / 1000L, userId) * 1000);
|
||||
if (mNightMode == MODE_NIGHT_AUTO) {
|
||||
mComputedNightMode = Secure.getIntForUser(context.getContentResolver(),
|
||||
Secure.UI_NIGHT_MODE_LAST_COMPUTED, 0, userId) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
return oldNightMode != mNightMode;
|
||||
@@ -1596,18 +1621,4 @@ final class UiModeManagerService extends SystemService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class UserSwitchedReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
synchronized (mLock) {
|
||||
final int currentId = intent.getIntExtra(
|
||||
Intent.EXTRA_USER_HANDLE, USER_SYSTEM);
|
||||
// only update if the value is actually changed
|
||||
if (updateNightModeFromSettingsLocked(context, context.getResources(), currentId)) {
|
||||
updateLocked(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user