diff --git a/app/src/main/java/com/fox2code/mmm/repo/RepoManager.java b/app/src/main/java/com/fox2code/mmm/repo/RepoManager.java index f3444cc..39b7703 100644 --- a/app/src/main/java/com/fox2code/mmm/repo/RepoManager.java +++ b/app/src/main/java/com/fox2code/mmm/repo/RepoManager.java @@ -373,4 +373,13 @@ public final class RepoManager extends SyncManager { public Collection getXRepos() { return new LinkedHashSet<>(this.repoData.values()); } + + /** + * Safe way to do {@code RepoManager.getInstance().androidacyRepoData.isEnabled()} + * without initializing RepoManager + */ + public static boolean isAndroidacyRepoEnabled() { + return INSTANCE != null && INSTANCE.androidacyRepoData != null && + INSTANCE.androidacyRepoData.isEnabled(); + } } diff --git a/app/src/main/java/com/fox2code/mmm/utils/Http.java b/app/src/main/java/com/fox2code/mmm/utils/Http.java index 90bf375..fa8f40b 100644 --- a/app/src/main/java/com/fox2code/mmm/utils/Http.java +++ b/app/src/main/java/com/fox2code/mmm/utils/Http.java @@ -14,7 +14,9 @@ import androidx.annotation.Nullable; import com.fox2code.mmm.BuildConfig; import com.fox2code.mmm.MainApplication; +import com.fox2code.mmm.androidacy.AndroidacyUtil; import com.fox2code.mmm.installer.InstallerInitializer; +import com.fox2code.mmm.repo.RepoManager; import java.io.ByteArrayOutputStream; import java.io.File; @@ -193,7 +195,12 @@ public class Http { return doh ? httpClientWithCacheDoH : httpClientWithCache; } + @SuppressWarnings("resource") public static byte[] doHttpGet(String url,boolean allowCache) throws IOException { + if (!RepoManager.isAndroidacyRepoEnabled() && + AndroidacyUtil.isAndroidacyLink(url)) { + throw new IOException("Androidacy repo is disabled, blocking url: " + url); + } Response response = (allowCache ? getHttpClientWithCache() : getHttpClient()).newCall( new Request.Builder().url(url).get().build() ).execute(); @@ -220,8 +227,13 @@ public class Http { return (String) doHttpPostRaw(url, data, allowCache, true); } + @SuppressWarnings("resource") private static Object doHttpPostRaw(String url,String data, boolean allowCache, boolean isRedirect) throws IOException { + if (!RepoManager.isAndroidacyRepoEnabled() && + AndroidacyUtil.isAndroidacyLink(url)) { + throw new IOException("Androidacy repo is disabled, blocking url: " + url); + } Response response = (isRedirect ? getHttpClientNoRedirect() : allowCache ? getHttpClientWithCache() : getHttpClient()).newCall( new Request.Builder().url(url).post(JsonRequestBody.from(data)) @@ -248,6 +260,10 @@ public class Http { public static byte[] doHttpGet(String url,ProgressListener progressListener) throws IOException { Log.d("Http", "Progress URL: " + url); + if (!RepoManager.isAndroidacyRepoEnabled() && + AndroidacyUtil.isAndroidacyLink(url)) { + throw new IOException("Androidacy repo is disabled, blocking url: " + url); + } Response response = getHttpClient().newCall( new Request.Builder().url(url).get().build()).execute(); if (response.code() != 200 && response.code() != 204) {