Skip to content

Commit

Permalink
优先使用XSharedPreferences读取配置文件
Browse files Browse the repository at this point in the history
  • Loading branch information
kooritea committed Apr 24, 2024
1 parent bc5d0c3 commit 5fd9893
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<meta-data
android:name="xposedminversion"
android:value="93" />
<meta-data
android:name="xposedsharedprefs"
android:value="true" />
<meta-data
android:name="xposedscope"
android:resource="@array/xposed_scope" />
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/kooritea/fcmfix/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -229,6 +230,23 @@ private void deleteAppInAllowList(String packageName){
}

private void updateConfig(){
try {
SharedPreferences pref;
try {
pref = this.getSharedPreferences("config", Context.MODE_WORLD_READABLE);
} catch (SecurityException ignored) {
pref = null;
}
if(pref != null){
SharedPreferences.Editor sharedPreferencesEditor = pref.edit();
sharedPreferencesEditor.putBoolean("init", true);
sharedPreferencesEditor.putStringSet("allowList", this.allowList);
sharedPreferencesEditor.putBoolean("disableAutoCleanNotification", this.config.getBoolean("disableAutoCleanNotification"));
sharedPreferencesEditor.commit();
}
} catch (Exception e) {
e.printStackTrace();
}
try {
FileOutputStream fos = this.openFileOutput("config.json", Context.MODE_PRIVATE);
this.config.put("allowList", new JSONArray(this.allowList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected void beforeHookedMethod(MethodHookParam methodHookParam) {
methodHookParam.args[finalAppOp_args_index] = 11;
}
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
printLog("Send Forced Start Broadcast: " + target);
printLog("Send Forced Start Broadcast: " + target, true);
}
}
}
Expand Down
19 changes: 17 additions & 2 deletions app/src/main/java/com/kooritea/fcmfix/xposed/XposedModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Set;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
Expand Down Expand Up @@ -163,16 +164,30 @@ private static void onUpdateConfig(){
@Override
public void run() {
super.run();
try{
XSharedPreferences pref = new XSharedPreferences("com.kooritea.fcmfix", "config");
if(pref.getBoolean("init", false)){
allowList = pref.getStringSet("allowList", null);
if(allowList != null && "android".equals(context.getPackageName())){
printLog( "[XSharedPreferences Mode]onUpdateConfig allowList size: " + allowList.size());
}
disableAutoCleanNotification = pref.getBoolean("disableAutoCleanNotification", false);
loadConfigThread = null;
return;
}
}catch (Exception e){
printLog("直接读取应用配置失败,将唤醒fcmfix本体进行读取: " + e.getMessage());
}
try{
ContentProviderHelper contentProviderHelper = new ContentProviderHelper(context,"content://com.kooritea.fcmfix.provider/config");
allowList = contentProviderHelper.getStringSet("allowList");
if(allowList != null && "android".equals(context.getPackageName())){
printLog( "onUpdateConfig allowList size: " + allowList.size());
printLog( "[ContentProvider Mode]onUpdateConfig allowList size: " + allowList.size());
}
disableAutoCleanNotification = contentProviderHelper.getBoolean("disableAutoCleanNotification", false);
contentProviderHelper.close();
}catch (Exception e){
printLog(e.getMessage());
printLog("唤醒fcmfix应用读取配置失败: " + e.getMessage());
}
loadConfigThread = null;
}
Expand Down

0 comments on commit 5fd9893

Please sign in to comment.