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)
pull/27/head
Fox2Code 3 years ago
parent 6e5b53bf83
commit 5f44892c46

@ -373,4 +373,13 @@ public final class RepoManager extends SyncManager {
public Collection<XRepo> getXRepos() { public Collection<XRepo> getXRepos() {
return new LinkedHashSet<>(this.repoData.values()); 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();
}
} }

@ -14,7 +14,9 @@ import androidx.annotation.Nullable;
import com.fox2code.mmm.BuildConfig; import com.fox2code.mmm.BuildConfig;
import com.fox2code.mmm.MainApplication; import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.androidacy.AndroidacyUtil;
import com.fox2code.mmm.installer.InstallerInitializer; import com.fox2code.mmm.installer.InstallerInitializer;
import com.fox2code.mmm.repo.RepoManager;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
@ -193,7 +195,12 @@ public class Http {
return doh ? httpClientWithCacheDoH : httpClientWithCache; return doh ? httpClientWithCacheDoH : httpClientWithCache;
} }
@SuppressWarnings("resource")
public static byte[] doHttpGet(String url,boolean allowCache) throws IOException { 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( Response response = (allowCache ? getHttpClientWithCache() : getHttpClient()).newCall(
new Request.Builder().url(url).get().build() new Request.Builder().url(url).get().build()
).execute(); ).execute();
@ -220,8 +227,13 @@ public class Http {
return (String) doHttpPostRaw(url, data, allowCache, true); return (String) doHttpPostRaw(url, data, allowCache, true);
} }
@SuppressWarnings("resource")
private static Object doHttpPostRaw(String url,String data, boolean allowCache, private static Object doHttpPostRaw(String url,String data, boolean allowCache,
boolean isRedirect) throws IOException { boolean isRedirect) throws IOException {
if (!RepoManager.isAndroidacyRepoEnabled() &&
AndroidacyUtil.isAndroidacyLink(url)) {
throw new IOException("Androidacy repo is disabled, blocking url: " + url);
}
Response response = (isRedirect ? getHttpClientNoRedirect() : Response response = (isRedirect ? getHttpClientNoRedirect() :
allowCache ? getHttpClientWithCache() : getHttpClient()).newCall( allowCache ? getHttpClientWithCache() : getHttpClient()).newCall(
new Request.Builder().url(url).post(JsonRequestBody.from(data)) 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 { public static byte[] doHttpGet(String url,ProgressListener progressListener) throws IOException {
Log.d("Http", "Progress URL: " + url); 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( Response response = getHttpClient().newCall(
new Request.Builder().url(url).get().build()).execute(); new Request.Builder().url(url).get().build()).execute();
if (response.code() != 200 && response.code() != 204) { if (response.code() != 200 && response.code() != 204) {

Loading…
Cancel
Save