diff --git a/app/src/main/aidl/it/dhd/oxygencustomizer/IRootProviderProxy.aidl b/app/src/main/aidl/it/dhd/oxygencustomizer/IRootProviderProxy.aidl index 57b6e7736..e66d4b1d3 100644 --- a/app/src/main/aidl/it/dhd/oxygencustomizer/IRootProviderProxy.aidl +++ b/app/src/main/aidl/it/dhd/oxygencustomizer/IRootProviderProxy.aidl @@ -10,4 +10,5 @@ interface IRootProviderProxy { */ String[] runCommand(String command); void extractSubject(in Bitmap input, String resultPath); + void applyTheme(in String theme); } \ No newline at end of file diff --git a/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/uistyle/UiStyle.java b/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/uistyle/UiStyle.java index 894838905..8ec052964 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/uistyle/UiStyle.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/uistyle/UiStyle.java @@ -1,6 +1,7 @@ package it.dhd.oxygencustomizer.ui.fragments.uistyle; import static it.dhd.oxygencustomizer.utils.Dynamic.TOTAL_ANDROID_THEMES; +import static it.dhd.oxygencustomizer.utils.PreferenceHelper.getModulePrefs; import static it.dhd.oxygencustomizer.utils.overlay.OverlayUtil.getStringFromOverlay; import android.os.Bundle; @@ -18,6 +19,8 @@ import it.dhd.oxygencustomizer.ui.adapters.ThemeAdapter; import it.dhd.oxygencustomizer.ui.base.BaseFragment; import it.dhd.oxygencustomizer.ui.dialogs.LoadingDialog; +import it.dhd.oxygencustomizer.utils.PrefManager; +import it.dhd.oxygencustomizer.utils.Prefs; public class UiStyle extends BaseFragment { @@ -45,6 +48,9 @@ private ThemeAdapter initThemesItems() { for (int i = 0; i enabledOverlays, String pkgName) public static void enableOverlay(String pkgName) { Prefs.putBoolean(pkgName, true); + if (getModulePrefs() != null) { + getModulePrefs().edit().putBoolean(pkgName, true).apply(); + } Shell.cmd("cmd overlay enable --user current " + pkgName, "cmd overlay set-priority " + pkgName + " highest").submit(); } @@ -83,6 +89,9 @@ public static void enableOverlaysExclusiveInCategory(String... pkgNames) { public static void disableOverlay(String pkgName) { Prefs.putBoolean(pkgName, false); + if (getModulePrefs() != null) { + getModulePrefs().edit().putBoolean(pkgName, false).apply(); + } Shell.cmd("cmd overlay disable --user current " + pkgName).submit(); } diff --git a/app/src/main/java/it/dhd/oxygencustomizer/xposed/ModPacks.java b/app/src/main/java/it/dhd/oxygencustomizer/xposed/ModPacks.java index a4240f3ee..a0cf562fc 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/xposed/ModPacks.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/xposed/ModPacks.java @@ -19,6 +19,7 @@ import it.dhd.oxygencustomizer.xposed.hooks.systemui.OpUtils; import it.dhd.oxygencustomizer.xposed.hooks.systemui.PulseViewHook; import it.dhd.oxygencustomizer.xposed.hooks.systemui.SettingsLibUtilsProvider; +import it.dhd.oxygencustomizer.xposed.hooks.systemui.ThemeEnabler; import it.dhd.oxygencustomizer.xposed.hooks.systemui.VolumePanel; import it.dhd.oxygencustomizer.xposed.hooks.systemui.aod.AodClock; import it.dhd.oxygencustomizer.xposed.hooks.systemui.lockscreen.DepthWallpaper; @@ -54,6 +55,9 @@ public static ArrayList> getMods(String packageName) } case SYSTEM_UI -> { if (!XPLauncher.isChildProcess) { + // Theme Enabler + modPacks.add(ThemeEnabler.class); + // Battery Data Provider modPacks.add(BatteryDataProvider.class); diff --git a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/ThemeEnabler.java b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/ThemeEnabler.java new file mode 100644 index 000000000..0918b4580 --- /dev/null +++ b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/ThemeEnabler.java @@ -0,0 +1,63 @@ +package it.dhd.oxygencustomizer.xposed.hooks.systemui; + +import static de.robv.android.xposed.XposedBridge.hookAllMethods; +import static de.robv.android.xposed.XposedBridge.log; +import static de.robv.android.xposed.XposedHelpers.findClass; +import static it.dhd.oxygencustomizer.utils.Constants.Packages.SYSTEM_UI; +import static it.dhd.oxygencustomizer.utils.Dynamic.TOTAL_ANDROID_THEMES; +import static it.dhd.oxygencustomizer.xposed.XPrefs.Xprefs; + +import android.content.Context; + +import de.robv.android.xposed.XC_MethodHook; +import de.robv.android.xposed.callbacks.XC_LoadPackage; +import it.dhd.oxygencustomizer.xposed.XPLauncher; +import it.dhd.oxygencustomizer.xposed.XposedMods; + +public class ThemeEnabler extends XposedMods { + + private static final String listenPackage = SYSTEM_UI; + private int themeNum; + + public ThemeEnabler(Context context) { + super(context); + } + + @Override + public void updatePrefs(String... Key) { + if (Xprefs == null) return; + log("ThemeEnabler Updating Prefs " + Xprefs.getInt("UiStylesThemes", 0)); + for (int i = 0; i ScrimController = findClass("com.android.systemui.statusbar.phone.ScrimController", lpparam.classLoader); + hookAllMethods(ScrimController, "updateThemeColors", new XC_MethodHook() { + @Override + protected void afterHookedMethod(MethodHookParam param) throws Throwable { + log("ThemeEnabler ScrimController updateThemeColors"); + enableTheme(); + } + }); + + } + + private void enableTheme() { + log("ThemeEnabler Enabling Themes " + themeNum); + XPLauncher.enqueueProxyCommand(proxy -> proxy.applyTheme("OxygenCustomizerComponentTH" + themeNum + ".overlay")); + } + + @Override + public boolean listensTo(String packageName) { + return listenPackage.equals(packageName); + } +}