diff --git a/README.md b/README.md index e2de8fe..28f62c3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ - 允许fcm唤醒选中的应用来发送通知 - 解除miui12对后台应用的通知限制(非miui系统没影响)(仅作用于在fcmfix中选中的应用) - 修复在国内网络下出现重连服务出现负数问题(貌似是miui优化的问题) -- 固定心跳间隔(默认117s,更改需要编辑配置文件/data/data/com.google.android.gms/shared_prefs/fcmfix_config.xml) +- 固定心跳间隔(默认不开启,更改需要编辑配置文件/data/data/com.google.android.gms/shared_prefs/fcmfix_config.xml,最小值为1000L) --- @@ -24,11 +24,7 @@ fcmfix的主要目的就是为了让即使不在后台的app也能顺利接收 ## 注意 -~~在国内版miui上,除了在本应用中勾选目标应用之外,还要给予目标应用自启动权限中的允许系统唤醒权限(eu版和国际版则不需要给自启动权限)~~ - -从0.4.0开始已经不再需要,感谢来自 @MinaMichita 的方法 [https://blog.minamigo.moe/archives/747](https://blog.minamigo.moe/archives/747) - -miui13国内版 还是需要打开目标应用自启动权限中的允许系统唤醒权限 +miui13 需要给目标应用自启动权限(因为我没有miui13的机器所以没适配) --- @@ -39,7 +35,7 @@ miui13国内版 还是需要打开目标应用自启动权限中的允许系统 --- ## SafetyNet 和 Widevine DRM等级 -这个模块一般不会影响这两个检测,我的安卓11、miui12、magisk hide勾选gms、lsposed +这个模块一般不会影响这两个检测,我的安卓11、miui12.5、magisk hide勾选gms、lsposed 安装了fcmfix之后能够通过SafetyNet检测且Widevine DRM等级为L1。 SafetyNet不通过请检查有没有科学上网 diff --git a/app/build.gradle b/app/build.gradle index 08408dc..a31339f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.kooritea.fcmfix" minSdkVersion 29 targetSdkVersion 30 - versionCode 24 - versionName "0.4.5" + versionCode 25 + versionName "0.4.6" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/kooritea/fcmfix/MainActivity.java b/app/src/main/java/com/kooritea/fcmfix/MainActivity.java index c9f8c51..e967cfc 100644 --- a/app/src/main/java/com/kooritea/fcmfix/MainActivity.java +++ b/app/src/main/java/com/kooritea/fcmfix/MainActivity.java @@ -6,7 +6,6 @@ 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; @@ -25,6 +24,17 @@ import android.widget.ListView; import android.widget.TextView; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.text.Collator; import java.util.ArrayList; import java.util.Collections; @@ -34,14 +44,12 @@ import java.util.List; import java.util.Locale; -import java.util.Objects; import java.util.Set; public class MainActivity extends AppCompatActivity { private AppListAdapter appListAdapter; - SharedPreferences sharedPreferences; - SharedPreferences.Editor sharedPreferencesEditor; - Set allowList; + Set allowList = new HashSet(); + JSONObject config = new JSONObject(); private class AppInfo { public String name; @@ -143,14 +151,31 @@ public View getView(int position, View convertView, ViewGroup parent) { } } - @SuppressLint({"WrongConstant", "CommitPrefEdits"}) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - this.sharedPreferences = this.getSharedPreferences("config",Context.MODE_PRIVATE); - this.sharedPreferencesEditor = this.sharedPreferences.edit(); - this.allowList = new HashSet<>(Objects.requireNonNull(this.sharedPreferences.getStringSet("allowList", new HashSet()))); + try { + FileInputStream fis = this.openFileInput("config.json"); + InputStreamReader inputStreamReader = new InputStreamReader(fis, StandardCharsets.UTF_8); + StringBuilder stringBuilder = new StringBuilder(); + BufferedReader reader = new BufferedReader(inputStreamReader); + String line = reader.readLine(); + while (line != null) { + stringBuilder.append(line).append('\n'); + line = reader.readLine(); + } + this.config = new JSONObject(stringBuilder.toString()); + JSONArray jsonAllowList = this.config.getJSONArray("allowList"); + for(int i = 0; i < jsonAllowList.length(); i++){ + this.allowList.add(jsonAllowList.getString(i)); + } + if(this.config.isNull("heartbeatInterval")){ + this.config.put("heartbeatInterval", "0L"); + } + } catch (IOException | JSONException e) { + e.printStackTrace(); + } final ListView listView = findViewById(R.id.listView); this.appListAdapter = new AppListAdapter(this); listView.setAdapter(this.appListAdapter); @@ -181,8 +206,13 @@ private void deleteAppInAllowList(String packageName){ } private void updateAllowList(){ - this.sharedPreferencesEditor.putStringSet("allowList",this.allowList); - this.sharedPreferencesEditor.commit(); + try { + FileOutputStream fos = this.openFileOutput("config.json", Context.MODE_PRIVATE); + this.config.put("allowList", new JSONArray(this.allowList)); + fos.write(this.config.toString(2).getBytes()); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } this.sendBroadcast(new Intent("com.kooritea.fcmfix.update.config")); } } \ No newline at end of file diff --git a/app/src/main/java/com/kooritea/fcmfix/XposedProvider.java b/app/src/main/java/com/kooritea/fcmfix/XposedProvider.java index 8c62311..5887280 100644 --- a/app/src/main/java/com/kooritea/fcmfix/XposedProvider.java +++ b/app/src/main/java/com/kooritea/fcmfix/XposedProvider.java @@ -2,20 +2,23 @@ import android.content.ContentProvider; import android.content.ContentValues; -import android.content.Context; -import android.content.SharedPreferences; import android.content.UriMatcher; import android.database.Cursor; import android.database.MatrixCursor; import android.net.Uri; -import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; public class XposedProvider extends ContentProvider { @@ -48,18 +51,37 @@ public String getType(@NonNull Uri uri) { @Override public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) { //这里填写查询逻辑 - SharedPreferences sharedPreferences = getContext().getSharedPreferences("config", Context.MODE_PRIVATE); + JSONObject config = new JSONObject(); + try { + FileInputStream fis = getContext().openFileInput("config.json"); + InputStreamReader inputStreamReader = new InputStreamReader(fis, StandardCharsets.UTF_8); + StringBuilder stringBuilder = new StringBuilder(); + BufferedReader reader = new BufferedReader(inputStreamReader); + String line = reader.readLine(); + while (line != null) { + stringBuilder.append(line).append('\n'); + line = reader.readLine(); + } + config = new JSONObject(stringBuilder.toString()); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } String[] COLUMN_NAME = { "key", "value" }; MatrixCursor data = new MatrixCursor(COLUMN_NAME); - switch (selection){ - case "heartbeatInterval": - data.addRow(new Object[]{"heartbeatInterval",sharedPreferences.getLong("heartbeatInterval",117000L)}); - break; - case "allowList": - for(String item : sharedPreferences.getStringSet("allowList",new HashSet())){ - data.addRow(new Object[]{"allowList",item}); - } - break; + try{ + switch (selection){ + case "heartbeatInterval": + data.addRow(new Object[]{"heartbeatInterval", config.isNull("heartbeatInterval") ? config.getLong("heartbeatInterval") : 0L}); + break; + case "allowList": + JSONArray jsonAllowList = config.getJSONArray("allowList"); + for(int i = 0; i < jsonAllowList.length(); i++){ + data.addRow(new Object[]{"allowList",jsonAllowList.getString(i)}); + } + break; + } + } catch (JSONException e) { + e.printStackTrace(); } return data; }