Skip to content

Commit d53ffd7

Browse files
agxproPMS22
authored andcommitted
Improve applying Accent colors
- apply & refresh colors instantly - match color hex from settings & restore on boot if necessary and also set colors prop on first boot only Signed-off-by: AnkitGourav <Ankitgourav035@gmail.com> Signed-off-by: Joey Huab <joey@evolution-x.org> Change-Id: Ie7d00238da0ed219d16a0bdb369949c5e386731a
1 parent 9032219 commit d53ffd7

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

services/core/java/com/android/server/UiModeManagerService.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import android.content.Context;
3131
import android.content.Intent;
3232
import android.content.IntentFilter;
33+
import android.content.om.IOverlayManager;
3334
import android.content.pm.PackageManager;
3435
import android.content.res.Configuration;
3536
import android.content.res.Resources;
@@ -77,6 +78,7 @@ final class UiModeManagerService extends SystemService {
7778
private static final boolean ENABLE_LAUNCH_DESK_DOCK_APP = true;
7879
private static final String SYSTEM_PROPERTY_DEVICE_THEME = "persist.sys.theme";
7980

81+
private IOverlayManager mOverlayManager;
8082
private static final String ACCENT_COLOR_PROP = "persist.sys.evolution.accent_color";
8183

8284
final Object mLock = new Object();
@@ -276,10 +278,7 @@ public void onChange(boolean selfChange, Uri uri) {
276278
@Override
277279
public void onChange(boolean selfChange, Uri uri) {
278280
if (uri.equals(System.getUriFor(System.ACCENT_COLOR))) {
279-
final int intColor = System.getIntForUser(getContext().getContentResolver(),
280-
System.ACCENT_COLOR, 0xFF1A73E8, UserHandle.USER_CURRENT);
281-
String colorHex = String.format("%08x", (0xFFFFFFFF & intColor));
282-
SystemProperties.set(ACCENT_COLOR_PROP, colorHex);
281+
applyAccentColor();
283282
}
284283
}
285284
};
@@ -347,6 +346,10 @@ public void onStart() {
347346

348347
updateNightModeFromSettings(context, res, UserHandle.getCallingUserId());
349348

349+
mOverlayManager = IOverlayManager.Stub
350+
.asInterface(ServiceManager.getService(Context.OVERLAY_SERVICE));
351+
applyAccentColor();
352+
350353
// Update the initial, static configurations.
351354
SystemServerInitThreadPool.get().submit(() -> {
352355
synchronized (mLock) {
@@ -365,7 +368,7 @@ public void onStart() {
365368
context.getContentResolver().registerContentObserver(Secure.getUriFor(Secure.UI_NIGHT_MODE),
366369
false, mDarkThemeObserver, 0);
367370
context.getContentResolver().registerContentObserver(System.getUriFor(System.ACCENT_COLOR),
368-
false, mAccentObserver, 0);
371+
false, mAccentObserver, UserHandle.USER_ALL);
369372
}
370373

371374
@VisibleForTesting
@@ -422,6 +425,22 @@ private boolean updateNightModeFromSettings(Context context, Resources res, int
422425
return oldNightMode != mNightMode;
423426
}
424427

428+
private void applyAccentColor() {
429+
final Context context = getContext();
430+
int intColor = System.getIntForUser(context.getContentResolver(),
431+
System.ACCENT_COLOR, 0xFFB30000, UserHandle.USER_CURRENT);
432+
String colorHex = String.format("%08x", (0xFFFFFFFF & intColor));
433+
String accentVal = SystemProperties.get(ACCENT_COLOR_PROP);
434+
if (!accentVal.equals(colorHex)) {
435+
SystemProperties.set(ACCENT_COLOR_PROP, colorHex);
436+
try {
437+
mOverlayManager.reloadAndroidAssets(UserHandle.USER_CURRENT);
438+
mOverlayManager.reloadAssets("com.android.settings", UserHandle.USER_CURRENT);
439+
mOverlayManager.reloadAssets("com.android.systemui", UserHandle.USER_CURRENT);
440+
} catch (Exception e) { }
441+
}
442+
}
443+
425444
private void registerScreenOffEvent() {
426445
mWaitForScreenOff = true;
427446
final IntentFilter intentFilter =

0 commit comments

Comments
 (0)