Merge "Rememeber the last dark mode before shutdown when in auto mode" into rvc-qpr-dev am: 9be043388a
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12819439 Change-Id: I97a361d1f6e43f82ee2f560f91b7e7a1344234a7
This commit is contained in:
@@ -7896,6 +7896,12 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public static final String UI_NIGHT_MODE_OVERRIDE_ON = "ui_night_mode_override_on";
|
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
|
* The current night mode that has been overridden to turn off by the system. Owned
|
||||||
* and controlled by UiModeManagerService. Constants are as per
|
* and controlled by UiModeManagerService. Constants are as per
|
||||||
|
|||||||
@@ -327,6 +327,13 @@ final class UiModeManagerService extends SystemService {
|
|||||||
mCurrentUser = userHandle;
|
mCurrentUser = userHandle;
|
||||||
getContext().getContentResolver().unregisterContentObserver(mSetupWizardObserver);
|
getContext().getContentResolver().unregisterContentObserver(mSetupWizardObserver);
|
||||||
verifySetupWizardCompleted();
|
verifySetupWizardCompleted();
|
||||||
|
synchronized (mLock) {
|
||||||
|
// only update if the value is actually changed
|
||||||
|
if (updateNightModeFromSettingsLocked(getContext(), getContext().getResources(),
|
||||||
|
mCurrentUser)) {
|
||||||
|
updateLocked(0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -354,11 +361,10 @@ final class UiModeManagerService extends SystemService {
|
|||||||
new IntentFilter(Intent.ACTION_DOCK_EVENT));
|
new IntentFilter(Intent.ACTION_DOCK_EVENT));
|
||||||
IntentFilter batteryFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
IntentFilter batteryFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||||
context.registerReceiver(mBatteryReceiver, batteryFilter);
|
context.registerReceiver(mBatteryReceiver, batteryFilter);
|
||||||
IntentFilter filter = new IntentFilter();
|
|
||||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
|
||||||
context.registerReceiver(mSettingsRestored,
|
context.registerReceiver(mSettingsRestored,
|
||||||
new IntentFilter(Intent.ACTION_SETTING_RESTORED));
|
new IntentFilter(Intent.ACTION_SETTING_RESTORED));
|
||||||
context.registerReceiver(new UserSwitchedReceiver(), filter, null, mHandler);
|
context.registerReceiver(mOnShutdown,
|
||||||
|
new IntentFilter(Intent.ACTION_SHUTDOWN));
|
||||||
updateConfigurationLocked();
|
updateConfigurationLocked();
|
||||||
applyConfigurationExternallyLocked();
|
applyConfigurationExternallyLocked();
|
||||||
}
|
}
|
||||||
@@ -405,6 +411,21 @@ final class UiModeManagerService extends SystemService {
|
|||||||
publishLocalService(UiModeManagerInternal.class, mLocalService);
|
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() {
|
private final BroadcastReceiver mSettingsRestored = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@@ -506,6 +527,10 @@ final class UiModeManagerService extends SystemService {
|
|||||||
Secure.getLongForUser(context.getContentResolver(),
|
Secure.getLongForUser(context.getContentResolver(),
|
||||||
Secure.DARK_THEME_CUSTOM_END_TIME,
|
Secure.DARK_THEME_CUSTOM_END_TIME,
|
||||||
DEFAULT_CUSTOM_NIGHT_END_TIME.toNanoOfDay() / 1000L, userId) * 1000);
|
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;
|
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