From f947d62f31126e5b450f88c741107dfb9e2f0442 Mon Sep 17 00:00:00 2001 From: DHD2280 Date: Mon, 6 May 2024 22:07:40 +0200 Subject: [PATCH] Update Prefs in framework only if something changed --- .../oxygencustomizer/ui/fragments/Mods.java | 18 ++++++++ .../ui/fragments/mods/Buttons.java | 7 +++- .../xposed/hooks/framework/Buttons.java | 12 ++++-- .../hooks/framework/PhoneWindowManager.java | 41 +++++++++++++++++++ 4 files changed, 73 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/Mods.java b/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/Mods.java index 7bdc0b577..3f450f8cf 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/Mods.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/Mods.java @@ -6,7 +6,10 @@ import static it.dhd.oxygencustomizer.ui.activity.MainActivity.backButtonDisabled; import static it.dhd.oxygencustomizer.ui.activity.MainActivity.prefsList; import static it.dhd.oxygencustomizer.ui.activity.MainActivity.replaceFragment; +import static it.dhd.oxygencustomizer.utils.Constants.Packages.FRAMEWORK; +import static it.dhd.oxygencustomizer.utils.Constants.Packages.SYSTEM_UI; +import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.util.Log; @@ -225,6 +228,21 @@ public boolean hasMenu() { public String[] getScopes() { return new String[]{Constants.Packages.SCREENSHOT}; } + + @Override + public void updateScreen(String key) { + super.updateScreen(key); + Intent broadcast = new Intent(Constants.ACTION_SETTINGS_CHANGED); + + broadcast.putExtra("packageName", FRAMEWORK); + broadcast.putExtra("className", it.dhd.oxygencustomizer.xposed.hooks.framework.PhoneWindowManager.class.getSimpleName()); + + broadcast.setPackage(FRAMEWORK); + + if (getContext() != null) + getContext().sendBroadcast(broadcast); + + } } public static class PackageManager extends ControlledPreferenceFragmentCompat { diff --git a/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/mods/Buttons.java b/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/mods/Buttons.java index 80ec3cf3d..f07231903 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/mods/Buttons.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/mods/Buttons.java @@ -1,5 +1,6 @@ package it.dhd.oxygencustomizer.ui.fragments.mods; +import static it.dhd.oxygencustomizer.utils.Constants.Packages.FRAMEWORK; import static it.dhd.oxygencustomizer.utils.Constants.Packages.SYSTEM_UI; import android.content.Intent; @@ -36,11 +37,13 @@ public String[] getScopes() { @Override public void updateScreen(String key) { + super.updateScreen(key); Intent broadcast = new Intent(Constants.ACTION_SETTINGS_CHANGED); - broadcast.putExtra("packageName", SYSTEM_UI); + broadcast.putExtra("packageName", FRAMEWORK); + broadcast.putExtra("className", it.dhd.oxygencustomizer.xposed.hooks.framework.Buttons.class.getSimpleName()); - broadcast.setPackage(SYSTEM_UI); + broadcast.setPackage(FRAMEWORK); if (getContext() != null) getContext().sendBroadcast(broadcast); diff --git a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/framework/Buttons.java b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/framework/Buttons.java index 5f6e0b24a..98e339e30 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/framework/Buttons.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/framework/Buttons.java @@ -27,6 +27,7 @@ import android.os.SystemClock; import android.os.VibrationAttributes; import android.os.VibrationEffect; +import android.text.TextUtils; import android.view.KeyEvent; import android.view.ViewConfiguration; @@ -85,9 +86,14 @@ public void updatePrefs(String... Key) { public void onReceive(Context context, Intent intent) { try { String action = intent.getAction(); - if (action.equals(Constants.ACTION_AUTH_SUCCESS_SHOW_ADVANCED_REBOOT)) { - settingsUpdated = false; - updatePrefs(); + if (action == null) return; + String className = intent.getStringExtra("class"); + if (action.equals(Constants.ACTION_SETTINGS_CHANGED)) { + if (!TextUtils.isEmpty(className) && this.getClass().getSimpleName().contains(className)) { + log("Buttons: Intent received - will update preferences"); + settingsUpdated = false; + updatePrefs(); + } } } catch (Throwable t) { log("Oxygen Customizer - Buttons: " + t.getMessage()); diff --git a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/framework/PhoneWindowManager.java b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/framework/PhoneWindowManager.java index 90fa2ac79..fd686157f 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/framework/PhoneWindowManager.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/framework/PhoneWindowManager.java @@ -1,5 +1,6 @@ package it.dhd.oxygencustomizer.xposed.hooks.framework; +import static android.content.Context.RECEIVER_EXPORTED; import static de.robv.android.xposed.XposedBridge.hookMethod; import static de.robv.android.xposed.XposedBridge.log; import static it.dhd.oxygencustomizer.utils.Constants.Packages.FRAMEWORK; @@ -7,8 +8,12 @@ import static it.dhd.oxygencustomizer.xposed.utils.Deoptimizer.deoptimizeMethod; import android.annotation.SuppressLint; +import android.content.BroadcastReceiver; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.os.Build; +import android.text.TextUtils; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -17,12 +22,15 @@ import de.robv.android.xposed.XC_MethodHook; import de.robv.android.xposed.callbacks.XC_LoadPackage; +import it.dhd.oxygencustomizer.utils.Constants; import it.dhd.oxygencustomizer.xposed.XposedMods; public class PhoneWindowManager extends XposedMods { private final static String TAG = "Oxygen Customizer - PhoneWindowManager: "; private boolean mDisableSecure = false, mDisableScreenshotObserver = false; + private boolean settingsUpdated = false; + private boolean broadcastRegistered = false; public PhoneWindowManager(Context context) { super(context); @@ -30,13 +38,46 @@ public PhoneWindowManager(Context context) { @Override public void updatePrefs(String... Key) { + if (Xprefs == null) return; + + if (settingsUpdated) return; + mDisableSecure = Xprefs.getBoolean("disable_secure_screenshot", false); mDisableScreenshotObserver = Xprefs.getBoolean("disable_screenshot_observer", false); + + settingsUpdated = true; } + final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + try { + String action = intent.getAction(); + if (action == null) return; + String className = intent.getStringExtra("className"); + if (action.equals(Constants.ACTION_SETTINGS_CHANGED)) { + if (!TextUtils.isEmpty(className) && this.getClass().getSimpleName().contains(className)) { + settingsUpdated = false; + updatePrefs(); + } + } + } catch (Throwable t) { + log("Oxygen Customizer - PhoneWindowManager: " + t.getMessage()); + } + } + }; + @Override public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable { + if (!broadcastRegistered) { + broadcastRegistered = true; + + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(Constants.ACTION_SETTINGS_CHANGED); + mContext.registerReceiver(broadcastReceiver, intentFilter, RECEIVER_EXPORTED); //for Android 14, receiver flag is mandatory + } + if (mDisableSecure) { try { hookSecureScreenshot(lpparam);