Skip to content

Commit

Permalink
Update Prefs in framework only if something changed
Browse files Browse the repository at this point in the history
  • Loading branch information
DHD2280 committed May 6, 2024
1 parent aa00ed1 commit f947d62
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 5 deletions.
18 changes: 18 additions & 0 deletions app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/Mods.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
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;
import static it.dhd.oxygencustomizer.xposed.XPrefs.Xprefs;
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;
Expand All @@ -17,26 +22,62 @@

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);
}

@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);
Expand Down

0 comments on commit f947d62

Please sign in to comment.