From c1613ec944f18dabeedeb6e1d96fb9bd413726b5 Mon Sep 17 00:00:00 2001 From: Fox2Code Date: Thu, 2 Jun 2022 15:05:53 +0200 Subject: [PATCH] Expand interface for XPosed modules --- .../main/java/com/fox2code/mmm/XHooks.java | 11 +++++++++++ app/src/main/java/com/fox2code/mmm/XRepo.java | 19 +++++++++++++++++++ .../java/com/fox2code/mmm/repo/RepoData.java | 14 +++++++++----- 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/com/fox2code/mmm/XRepo.java diff --git a/app/src/main/java/com/fox2code/mmm/XHooks.java b/app/src/main/java/com/fox2code/mmm/XHooks.java index 4a4e896..d22cc5b 100644 --- a/app/src/main/java/com/fox2code/mmm/XHooks.java +++ b/app/src/main/java/com/fox2code/mmm/XHooks.java @@ -8,6 +8,7 @@ import android.webkit.WebView; import androidx.annotation.Keep; import com.fox2code.mmm.manager.ModuleManager; +import com.fox2code.mmm.repo.RepoManager; /** * Class made to expose some manager functions to xposed modules. @@ -38,4 +39,14 @@ public class XHooks { public static void onWebViewInitialize(WebView webView,boolean allowInstall) { if (webView == null) throw new NullPointerException("WebView is null!"); } + + @Keep + public static XRepo addXRepo(String url, String fallbackName) { + return RepoManager.getINSTANCE().addOrGet(url); + } + + @Keep + public static XRepo getXRepo(String url) { + return RepoManager.getINSTANCE().get(url); + } } diff --git a/app/src/main/java/com/fox2code/mmm/XRepo.java b/app/src/main/java/com/fox2code/mmm/XRepo.java new file mode 100644 index 0000000..fccb032 --- /dev/null +++ b/app/src/main/java/com/fox2code/mmm/XRepo.java @@ -0,0 +1,19 @@ +package com.fox2code.mmm; + +import androidx.annotation.Keep; + +/** + * Class made to expose some repo functions to xposed modules. + * It will not be obfuscated on release builds + */ +@Keep +public abstract class XRepo { + @Keep + public abstract boolean isEnabledByDefault(); + + @Keep + public abstract boolean isEnabled(); + + @Keep + public abstract void setEnabled(boolean enabled); +} diff --git a/app/src/main/java/com/fox2code/mmm/repo/RepoData.java b/app/src/main/java/com/fox2code/mmm/repo/RepoData.java index c768002..649c990 100644 --- a/app/src/main/java/com/fox2code/mmm/repo/RepoData.java +++ b/app/src/main/java/com/fox2code/mmm/repo/RepoData.java @@ -5,6 +5,7 @@ import android.content.SharedPreferences; import com.fox2code.mmm.BuildConfig; import com.fox2code.mmm.MainApplication; import com.fox2code.mmm.R; +import com.fox2code.mmm.XRepo; import com.fox2code.mmm.manager.ModuleInfo; import com.fox2code.mmm.utils.Files; import com.fox2code.mmm.utils.PropUtils; @@ -21,7 +22,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; -public class RepoData { +public class RepoData extends XRepo { private static final String TAG = "RepoData"; private final Object populateLock = new Object(); public final String url; @@ -43,7 +44,7 @@ public class RepoData { this.moduleHashMap = new HashMap<>(); this.name = this.url; // Set url as default name this.enabled = MainApplication.getSharedPreferences() - .getBoolean("pref_" + this.id + "_enabled", this.isEnabledByDefault(this.id)); + .getBoolean("pref_" + this.id + "_enabled", this.isEnabledByDefault()); if (!this.cacheRoot.isDirectory()) { this.cacheRoot.mkdirs(); } else { @@ -136,8 +137,9 @@ public class RepoData { return newModules; } - protected boolean isEnabledByDefault(String id) { - return !BuildConfig.DISABLED_REPOS.contains(id); + @Override + public boolean isEnabledByDefault() { + return !BuildConfig.DISABLED_REPOS.contains(this.id); } public void storeMetadata(RepoModule repoModule,byte[] data) throws IOException { @@ -170,10 +172,12 @@ public class RepoData { fallback : this.name; } + @Override public boolean isEnabled() { return this.enabled; } + @Override public void setEnabled(boolean enabled) { this.enabled = enabled; MainApplication.getSharedPreferences().edit() @@ -182,6 +186,6 @@ public class RepoData { public void updateEnabledState() { this.enabled = MainApplication.getSharedPreferences() - .getBoolean("pref_" + this.id + "_enabled", this.isEnabledByDefault(this.id)); + .getBoolean("pref_" + this.id + "_enabled", this.isEnabledByDefault()); } }