Apply Dark theme changes when screen off only
this change waits to apply ui changes after screen off battery manager sends updates and continuously updates the ui mode this change also applies external changes to ui configurations when the mode is actually changed. this resolves some perfromance regression issues Fixes: 145694649 Fixes: 145161355 Fixes: 145776479 Test: atest UiModeManagerService Change-Id: Ib769df4302d1c09166e2dc456b8ced35daa4d0b7 Merged-In: Ib769df4302d1c09166e2dc456b8ced35daa4d0b7
This commit is contained in:
committed by
Jay Aliomer
parent
c32c015715
commit
30b412cab7
@@ -659,6 +659,22 @@ public final class Settings {
|
|||||||
public static final String ACTION_NIGHT_DISPLAY_SETTINGS =
|
public static final String ACTION_NIGHT_DISPLAY_SETTINGS =
|
||||||
"android.settings.NIGHT_DISPLAY_SETTINGS";
|
"android.settings.NIGHT_DISPLAY_SETTINGS";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activity Action: Show settings to allow configuration of Dark theme.
|
||||||
|
* <p>
|
||||||
|
* In some cases, a matching Activity may not exist, so ensure you
|
||||||
|
* safeguard against this.
|
||||||
|
* <p>
|
||||||
|
* Input: Nothing.
|
||||||
|
* <p>
|
||||||
|
* Output: Nothing.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
|
||||||
|
public static final String ACTION_DARK_THEME_SETTINGS =
|
||||||
|
"android.settings.DARK_THEME_SETTINGS";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity Action: Show settings to allow configuration of locale.
|
* Activity Action: Show settings to allow configuration of locale.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class UiModeNightTile extends QSTileImpl<QSTile.BooleanState> implements
|
|||||||
boolean nightMode = (mContext.getResources().getConfiguration().uiMode
|
boolean nightMode = (mContext.getResources().getConfiguration().uiMode
|
||||||
& Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
|
& Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
|
||||||
|
|
||||||
if (isAuto) {
|
if (isAuto && !powerSave) {
|
||||||
state.secondaryLabel = mContext.getResources().getString(nightMode
|
state.secondaryLabel = mContext.getResources().getString(nightMode
|
||||||
? R.string.quick_settings_dark_mode_secondary_label_until_sunrise
|
? R.string.quick_settings_dark_mode_secondary_label_until_sunrise
|
||||||
: R.string.quick_settings_dark_mode_secondary_label_on_at_sunset);
|
: R.string.quick_settings_dark_mode_secondary_label_on_at_sunset);
|
||||||
@@ -121,7 +121,7 @@ public class UiModeNightTile extends QSTileImpl<QSTile.BooleanState> implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Intent getLongClickIntent() {
|
public Intent getLongClickIntent() {
|
||||||
return new Intent(Settings.ACTION_DISPLAY_SETTINGS);
|
return new Intent(Settings.ACTION_DARK_THEME_SETTINGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.android.server;
|
package com.android.server;
|
||||||
|
|
||||||
import static android.content.Intent.ACTION_SCREEN_OFF;
|
|
||||||
|
|
||||||
import android.annotation.IntRange;
|
import android.annotation.IntRange;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@@ -98,6 +96,10 @@ final class UiModeManagerService extends SystemService {
|
|||||||
private boolean mCarModeEnabled = false;
|
private boolean mCarModeEnabled = false;
|
||||||
private boolean mCharging = false;
|
private boolean mCharging = false;
|
||||||
private boolean mPowerSave = false;
|
private boolean mPowerSave = false;
|
||||||
|
// Do not change configuration now. wait until screen turns off.
|
||||||
|
// This prevents jank and activity restart when the user
|
||||||
|
// is actively using the device
|
||||||
|
private boolean mWaitForScreenOff = false;
|
||||||
private int mDefaultUiModeType;
|
private int mDefaultUiModeType;
|
||||||
private boolean mCarModeKeepsScreenOn;
|
private boolean mCarModeKeepsScreenOn;
|
||||||
private boolean mDeskModeKeepsScreenOn;
|
private boolean mDeskModeKeepsScreenOn;
|
||||||
@@ -213,25 +215,24 @@ final class UiModeManagerService extends SystemService {
|
|||||||
if (mCar) {
|
if (mCar) {
|
||||||
updateLocked(0, 0);
|
updateLocked(0, 0);
|
||||||
} else {
|
} else {
|
||||||
final IntentFilter intentFilter =
|
registerScreenOffEvent();
|
||||||
new IntentFilter(ACTION_SCREEN_OFF);
|
|
||||||
getContext().registerReceiver(mOnScreenOffHandler, intentFilter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DO NOT USE DIRECTLY
|
||||||
|
* see register registerScreenOffEvent and unregisterScreenOffEvent
|
||||||
|
*/
|
||||||
private final BroadcastReceiver mOnScreenOffHandler = new BroadcastReceiver() {
|
private final BroadcastReceiver mOnScreenOffHandler = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
|
// must unregister first before updating
|
||||||
|
unregisterScreenOffEvent();
|
||||||
updateLocked(0, 0);
|
updateLocked(0, 0);
|
||||||
try {
|
|
||||||
getContext().unregisterReceiver(mOnScreenOffHandler);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
// we ignore this exception if the receiver is unregistered already.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -270,7 +271,7 @@ final class UiModeManagerService extends SystemService {
|
|||||||
int mode = Secure.getIntForUser(getContext().getContentResolver(), Secure.UI_NIGHT_MODE,
|
int mode = Secure.getIntForUser(getContext().getContentResolver(), Secure.UI_NIGHT_MODE,
|
||||||
mNightMode, 0);
|
mNightMode, 0);
|
||||||
mode = mode == UiModeManager.MODE_NIGHT_AUTO
|
mode = mode == UiModeManager.MODE_NIGHT_AUTO
|
||||||
? UiModeManager.MODE_NIGHT_YES : UiModeManager.MODE_NIGHT_NO;
|
? UiModeManager.MODE_NIGHT_YES : mode;
|
||||||
SystemProperties.set(SYSTEM_PROPERTY_DEVICE_THEME, Integer.toString(mode));
|
SystemProperties.set(SYSTEM_PROPERTY_DEVICE_THEME, Integer.toString(mode));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -342,7 +343,7 @@ final class UiModeManagerService extends SystemService {
|
|||||||
SystemServerInitThreadPool.get().submit(() -> {
|
SystemServerInitThreadPool.get().submit(() -> {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
updateConfigurationLocked();
|
updateConfigurationLocked();
|
||||||
sendConfigurationLocked();
|
applyConfigurationExternallyLocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
}, TAG + ".onStart");
|
}, TAG + ".onStart");
|
||||||
@@ -411,6 +412,22 @@ final class UiModeManagerService extends SystemService {
|
|||||||
return oldNightMode != mNightMode;
|
return oldNightMode != mNightMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerScreenOffEvent() {
|
||||||
|
mWaitForScreenOff = true;
|
||||||
|
final IntentFilter intentFilter =
|
||||||
|
new IntentFilter(Intent.ACTION_SCREEN_OFF);
|
||||||
|
getContext().registerReceiver(mOnScreenOffHandler, intentFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unregisterScreenOffEvent() {
|
||||||
|
mWaitForScreenOff = false;
|
||||||
|
try {
|
||||||
|
getContext().unregisterReceiver(mOnScreenOffHandler);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// we ignore this exception if the receiver is unregistered already.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final IUiModeManager.Stub mService = new IUiModeManager.Stub() {
|
private final IUiModeManager.Stub mService = new IUiModeManager.Stub() {
|
||||||
@Override
|
@Override
|
||||||
public void enableCarMode(@UiModeManager.EnableCarMode int flags,
|
public void enableCarMode(@UiModeManager.EnableCarMode int flags,
|
||||||
@@ -532,28 +549,21 @@ final class UiModeManagerService extends SystemService {
|
|||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (mNightMode != mode) {
|
if (mNightMode != mode) {
|
||||||
if (mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
|
if (mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
|
||||||
try {
|
unregisterScreenOffEvent();
|
||||||
getContext().unregisterReceiver(mOnScreenOffHandler);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
// we ignore this exception if the receiver is unregistered already.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Only persist setting if not in car mode
|
|
||||||
if (!mCarModeEnabled) {
|
|
||||||
Secure.putIntForUser(getContext().getContentResolver(),
|
|
||||||
Secure.UI_NIGHT_MODE, mode, user);
|
|
||||||
Secure.putIntForUser(getContext().getContentResolver(),
|
|
||||||
OVERRIDE_NIGHT_MODE, mNightModeOverride, user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mNightMode = mode;
|
mNightMode = mode;
|
||||||
mNightModeOverride = mode;
|
mNightModeOverride = mode;
|
||||||
//on screen off will update configuration instead
|
|
||||||
|
// Only persist setting if not in car mode
|
||||||
|
if (!mCarModeEnabled) {
|
||||||
|
persistNightMode(user);
|
||||||
|
}
|
||||||
|
// on screen off will update configuration instead
|
||||||
if (mNightMode != UiModeManager.MODE_NIGHT_AUTO || mCar) {
|
if (mNightMode != UiModeManager.MODE_NIGHT_AUTO || mCar) {
|
||||||
updateLocked(0, 0);
|
updateLocked(0, 0);
|
||||||
} else {
|
} else {
|
||||||
getContext().registerReceiver(
|
registerScreenOffEvent();
|
||||||
mOnScreenOffHandler, new IntentFilter(ACTION_SCREEN_OFF));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -598,13 +608,11 @@ final class UiModeManagerService extends SystemService {
|
|||||||
@Override
|
@Override
|
||||||
public boolean setNightModeActivated(boolean active) {
|
public boolean setNightModeActivated(boolean active) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
|
final int user = UserHandle.getCallingUserId();
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
if (mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
|
if (mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
|
||||||
try {
|
unregisterScreenOffEvent();
|
||||||
getContext().unregisterReceiver(mOnScreenOffHandler);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
}
|
|
||||||
mNightModeOverride = active
|
mNightModeOverride = active
|
||||||
? UiModeManager.MODE_NIGHT_YES : UiModeManager.MODE_NIGHT_NO;
|
? UiModeManager.MODE_NIGHT_YES : UiModeManager.MODE_NIGHT_NO;
|
||||||
} else if (mNightMode == UiModeManager.MODE_NIGHT_NO
|
} else if (mNightMode == UiModeManager.MODE_NIGHT_NO
|
||||||
@@ -615,7 +623,8 @@ final class UiModeManagerService extends SystemService {
|
|||||||
mNightMode = UiModeManager.MODE_NIGHT_NO;
|
mNightMode = UiModeManager.MODE_NIGHT_NO;
|
||||||
}
|
}
|
||||||
updateConfigurationLocked();
|
updateConfigurationLocked();
|
||||||
sendConfigurationLocked();
|
applyConfigurationExternallyLocked();
|
||||||
|
persistNightMode(user);
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(ident);
|
Binder.restoreCallingIdentity(ident);
|
||||||
@@ -825,6 +834,13 @@ final class UiModeManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void persistNightMode(int user) {
|
||||||
|
Secure.putIntForUser(getContext().getContentResolver(),
|
||||||
|
Secure.UI_NIGHT_MODE, mNightMode, user);
|
||||||
|
Secure.putIntForUser(getContext().getContentResolver(),
|
||||||
|
OVERRIDE_NIGHT_MODE, mNightModeOverride, user);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateConfigurationLocked() {
|
private void updateConfigurationLocked() {
|
||||||
int uiMode = mDefaultUiModeType;
|
int uiMode = mDefaultUiModeType;
|
||||||
if (mUiModeLocked) {
|
if (mUiModeLocked) {
|
||||||
@@ -870,15 +886,14 @@ final class UiModeManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mCurUiMode = uiMode;
|
mCurUiMode = uiMode;
|
||||||
if (!mHoldingConfiguration) {
|
if (!mHoldingConfiguration || !mWaitForScreenOff) {
|
||||||
mConfiguration.uiMode = uiMode;
|
mConfiguration.uiMode = uiMode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendConfigurationLocked() {
|
private void applyConfigurationExternallyLocked() {
|
||||||
if (mSetUiMode != mConfiguration.uiMode) {
|
if (mSetUiMode != mConfiguration.uiMode) {
|
||||||
mSetUiMode = mConfiguration.uiMode;
|
mSetUiMode = mConfiguration.uiMode;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ActivityTaskManager.getService().updateConfiguration(mConfiguration);
|
ActivityTaskManager.getService().updateConfiguration(mConfiguration);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@@ -1058,7 +1073,7 @@ final class UiModeManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send the new configuration.
|
// Send the new configuration.
|
||||||
sendConfigurationLocked();
|
applyConfigurationExternallyLocked();
|
||||||
|
|
||||||
// If we did not start a dock app, then start dreaming if supported.
|
// If we did not start a dock app, then start dreaming if supported.
|
||||||
if (category != null && !dockAppStarted) {
|
if (category != null && !dockAppStarted) {
|
||||||
@@ -1136,7 +1151,6 @@ final class UiModeManagerService extends SystemService {
|
|||||||
final int user = UserHandle.getCallingUserId();
|
final int user = UserHandle.getCallingUserId();
|
||||||
Secure.putIntForUser(getContext().getContentResolver(),
|
Secure.putIntForUser(getContext().getContentResolver(),
|
||||||
OVERRIDE_NIGHT_MODE, mNightModeOverride, user);
|
OVERRIDE_NIGHT_MODE, mNightModeOverride, user);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user