Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 4ba30cf

Browse files
committed
Improved workaround for Androidacy issue
1 parent 94a0cca commit 4ba30cf

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

app/src/main/java/com/fox2code/mmm/AppUpdateManager.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020

2121
// See https://docs.github.com/en/rest/reference/repos#releases
2222
public class AppUpdateManager {
23-
public static int FLAG_COMPAT_LOW_QUALITY = 0x01;
24-
public static int FLAG_COMPAT_NO_EXT = 0x02;
25-
public static int FLAG_COMPAT_MAGISK_CMD = 0x04;
26-
public static int FLAG_COMPAT_NEED_32BIT = 0x08;
27-
public static int FLAG_COMPAT_MALWARE = 0x10;
28-
public static int FLAG_COMPAT_NO_ANSI = 0x20;
29-
public static int FLAG_COMPAT_FORCE_ANSI = 0x40;
23+
public static final int FLAG_COMPAT_LOW_QUALITY = 0x01;
24+
public static final int FLAG_COMPAT_NO_EXT = 0x02;
25+
public static final int FLAG_COMPAT_MAGISK_CMD = 0x04;
26+
public static final int FLAG_COMPAT_NEED_32BIT = 0x08;
27+
public static final int FLAG_COMPAT_MALWARE = 0x10;
28+
public static final int FLAG_COMPAT_NO_ANSI = 0x20;
29+
public static final int FLAG_COMPAT_FORCE_ANSI = 0x40;
30+
public static final int FLAG_COMPAT_FORCE_HIDE = 0x80;
3031
private static final String TAG = "AppUpdateManager";
3132
private static final AppUpdateManager INSTANCE = new AppUpdateManager();
3233
private static final String RELEASES_API_URL =
@@ -209,6 +210,9 @@ private void parseCompatibilityFlags(InputStream inputStream) throws IOException
209210
case "forceANSI":
210211
value |= FLAG_COMPAT_FORCE_ANSI;
211212
break;
213+
case "forceHide":
214+
value |= FLAG_COMPAT_FORCE_HIDE;
215+
break;
212216
}
213217
}
214218
compatDataId.put(line.substring(0, i), value);
@@ -223,4 +227,12 @@ public int getCompatibilityFlags(String moduleId) {
223227
public static int getFlagsForModule(String moduleId) {
224228
return INSTANCE.getCompatibilityFlags(moduleId);
225229
}
230+
231+
public static boolean shouldForceHide(String repoId) {
232+
if (BuildConfig.DEBUG || repoId.startsWith("repo_") ||
233+
repoId.equals("magisk_alt_repo")) return false;
234+
return !repoId.startsWith("repo_") &&
235+
(INSTANCE.getCompatibilityFlags(repoId) &
236+
FLAG_COMPAT_FORCE_HIDE) != 0;
237+
}
226238
}

app/src/main/java/com/fox2code/mmm/MainActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public void commonNext() {
182182
if (RepoManager.getINSTANCE().getCustomRepoManager().needUpdate()) {
183183
Log.w(TAG, "Need update on create?");
184184
}
185+
AppUpdateManager.getAppUpdateManager().checkUpdateCompat();
185186
RepoManager.getINSTANCE().update(value -> runOnUiThread(max == 0 ? () ->
186187
progressIndicator.setProgressCompat(
187188
(int) (value * PRECISION), true) :() ->
@@ -194,8 +195,6 @@ public void commonNext() {
194195
AppUpdateManager appUpdateManager = AppUpdateManager.getAppUpdateManager();
195196
if (BuildConfig.ENABLE_AUTO_UPDATER && appUpdateManager.checkUpdate(true))
196197
moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE);
197-
if (!BuildConfig.ENABLE_AUTO_UPDATER || appUpdateManager.isLastCheckSuccess())
198-
AppUpdateManager.getAppUpdateManager().checkUpdateCompat();
199198
if (max != 0) {
200199
int current = 0;
201200
for (LocalModuleInfo localModuleInfo :

app/src/main/java/com/fox2code/mmm/repo/RepoData.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import androidx.annotation.NonNull;
77

8+
import com.fox2code.mmm.AppUpdateManager;
89
import com.fox2code.mmm.BuildConfig;
910
import com.fox2code.mmm.MainApplication;
1011
import com.fox2code.mmm.R;
@@ -38,7 +39,7 @@ public class RepoData extends XRepo {
3839
protected String defaultName, defaultWebsite,
3940
defaultSupport, defaultDonate, defaultSubmitModule;
4041
public String name, website, support, donate, submitModule;
41-
private boolean enabled; // Cache for speed
42+
private boolean forceHide, enabled; // Cache for speed
4243

4344
protected RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences) {
4445
this.url = url;
@@ -48,7 +49,8 @@ protected RepoData(String url, File cacheRoot, SharedPreferences cachedPreferenc
4849
this.metaDataCache = new File(cacheRoot, "modules.json");
4950
this.moduleHashMap = new HashMap<>();
5051
this.defaultName = url; // Set url as default name
51-
this.enabled = !this.isLimited() && MainApplication.getSharedPreferences()
52+
this.forceHide = AppUpdateManager.shouldForceHide(this.id);
53+
this.enabled = (!this.forceHide) && MainApplication.getSharedPreferences()
5254
.getBoolean("pref_" + this.id + "_enabled", this.isEnabledByDefault());
5355
this.defaultWebsite = "https://" + Uri.parse(url).getHost() + "/";
5456
if (!this.cacheRoot.isDirectory()) {
@@ -189,13 +191,14 @@ public boolean isEnabled() {
189191

190192
@Override
191193
public void setEnabled(boolean enabled) {
192-
this.enabled = enabled;
194+
this.enabled = enabled && !this.forceHide;
193195
MainApplication.getSharedPreferences().edit()
194196
.putBoolean("pref_" + this.getPreferenceId() + "_enabled", enabled).apply();
195197
}
196198

197199
public void updateEnabledState() {
198-
this.enabled = MainApplication.getSharedPreferences()
200+
this.forceHide = AppUpdateManager.shouldForceHide(this.id);
201+
this.enabled = (!this.forceHide) && MainApplication.getSharedPreferences()
199202
.getBoolean("pref_" + this.getPreferenceId() + "_enabled", this.isEnabledByDefault());
200203
}
201204

@@ -251,4 +254,8 @@ public String getSubmitModule() {
251254
return this.submitModule;
252255
return this.defaultSubmitModule;
253256
}
257+
258+
public final boolean isForceHide() {
259+
return this.forceHide;
260+
}
254261
}

app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ private void setRepoData(String url) {
431431
}
432432

433433
private void setRepoData(final RepoData repoData, String preferenceName) {
434-
if (repoData == null) {
434+
if (repoData == null || repoData.isForceHide()) {
435435
hideRepoData(preferenceName);
436436
return;
437437
}

0 commit comments

Comments
 (0)