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

Commit 5f44892

Browse files
committed
Block request to Androidacy when the Androidacy repo is disabled
(Mainly for paranoid peoples, since the app already don't do any requests to Androidacy when the Androidacy repo is disabled)
1 parent 6e5b53b commit 5f44892

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,13 @@ public CustomRepoManager getCustomRepoManager() {
373373
public Collection<XRepo> getXRepos() {
374374
return new LinkedHashSet<>(this.repoData.values());
375375
}
376+
377+
/**
378+
* Safe way to do {@code RepoManager.getInstance().androidacyRepoData.isEnabled()}
379+
* without initializing RepoManager
380+
*/
381+
public static boolean isAndroidacyRepoEnabled() {
382+
return INSTANCE != null && INSTANCE.androidacyRepoData != null &&
383+
INSTANCE.androidacyRepoData.isEnabled();
384+
}
376385
}

app/src/main/java/com/fox2code/mmm/utils/Http.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
import com.fox2code.mmm.BuildConfig;
1616
import com.fox2code.mmm.MainApplication;
17+
import com.fox2code.mmm.androidacy.AndroidacyUtil;
1718
import com.fox2code.mmm.installer.InstallerInitializer;
19+
import com.fox2code.mmm.repo.RepoManager;
1820

1921
import java.io.ByteArrayOutputStream;
2022
import java.io.File;
@@ -193,7 +195,12 @@ public static OkHttpClient getHttpClientWithCache() {
193195
return doh ? httpClientWithCacheDoH : httpClientWithCache;
194196
}
195197

198+
@SuppressWarnings("resource")
196199
public static byte[] doHttpGet(String url,boolean allowCache) throws IOException {
200+
if (!RepoManager.isAndroidacyRepoEnabled() &&
201+
AndroidacyUtil.isAndroidacyLink(url)) {
202+
throw new IOException("Androidacy repo is disabled, blocking url: " + url);
203+
}
197204
Response response = (allowCache ? getHttpClientWithCache() : getHttpClient()).newCall(
198205
new Request.Builder().url(url).get().build()
199206
).execute();
@@ -220,8 +227,13 @@ public static String doHttpPostRedirect(String url, String data, boolean allowCa
220227
return (String) doHttpPostRaw(url, data, allowCache, true);
221228
}
222229

230+
@SuppressWarnings("resource")
223231
private static Object doHttpPostRaw(String url,String data, boolean allowCache,
224232
boolean isRedirect) throws IOException {
233+
if (!RepoManager.isAndroidacyRepoEnabled() &&
234+
AndroidacyUtil.isAndroidacyLink(url)) {
235+
throw new IOException("Androidacy repo is disabled, blocking url: " + url);
236+
}
225237
Response response = (isRedirect ? getHttpClientNoRedirect() :
226238
allowCache ? getHttpClientWithCache() : getHttpClient()).newCall(
227239
new Request.Builder().url(url).post(JsonRequestBody.from(data))
@@ -248,6 +260,10 @@ private static Object doHttpPostRaw(String url,String data, boolean allowCache,
248260

249261
public static byte[] doHttpGet(String url,ProgressListener progressListener) throws IOException {
250262
Log.d("Http", "Progress URL: " + url);
263+
if (!RepoManager.isAndroidacyRepoEnabled() &&
264+
AndroidacyUtil.isAndroidacyLink(url)) {
265+
throw new IOException("Androidacy repo is disabled, blocking url: " + url);
266+
}
251267
Response response = getHttpClient().newCall(
252268
new Request.Builder().url(url).get().build()).execute();
253269
if (response.code() != 200 && response.code() != 204) {

0 commit comments

Comments
 (0)