Code cleanup and minor fixes

Still need to address custom repo toggling not being saved

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/230/head
androidacy-user 2 years ago
parent b6077f2256
commit 7c934e9987

@ -185,4 +185,15 @@
int getSafeInsetRight();
int getSafeInsetTop();
android.graphics.Insets getWaterfallInsets();
}
}
# Silence some warnings
-dontwarn android.os.SystemProperties
-dontwarn android.view.ThreadedRenderer
-dontwarn cyanogenmod.providers.CMSettings$Secure
-dontwarn lineageos.providers.LineageSettings$System
-dontwarn lineageos.style.StyleInterface
-dontwarn me.weishu.reflection.Reflection
-dontwarn org.lsposed.hiddenapibypass.HiddenApiBypass
-dontwarn rikka.core.res.ResourcesCompatLayoutInflaterListener
-dontwarn rikka.core.util.ResourceUtils

@ -30,11 +30,6 @@ public final class CustomRepoData extends RepoData {
this.id : this.override;
}
@Override
public boolean isLimited() {
return true;
}
public void quickPrePopulate() throws IOException, JSONException {
JSONObject jsonObject = new JSONObject(
new String(Http.doHttpGet(this.getUrl(),

@ -27,7 +27,6 @@ import java.util.Iterator;
import java.util.List;
public class RepoData extends XRepo {
private static final String TAG = "RepoData";
private final Object populateLock = new Object();
public final String url;
public final String id;
@ -54,7 +53,10 @@ public class RepoData extends XRepo {
.getBoolean("pref_" + this.id + "_enabled", this.isEnabledByDefault());
this.defaultWebsite = "https://" + Uri.parse(url).getHost() + "/";
if (!this.cacheRoot.isDirectory()) {
this.cacheRoot.mkdirs();
boolean mkdirs = this.cacheRoot.mkdirs();
if (!mkdirs) {
throw new RuntimeException("Failed to create cache directory");
}
} else {
if (this.metaDataCache.exists()) {
this.lastUpdate = metaDataCache.lastModified();
@ -70,7 +72,10 @@ public class RepoData extends XRepo {
}
}
} catch (Exception e) {
this.metaDataCache.delete();
boolean delete = this.metaDataCache.delete();
if (!delete) {
throw new RuntimeException("Failed to delete invalid cache file");
}
}
}
}
@ -140,7 +145,10 @@ public class RepoData extends XRepo {
while (moduleInfoIterator.hasNext()) {
RepoModule repoModule = moduleInfoIterator.next();
if (!repoModule.processed) {
new File(this.cacheRoot, repoModule.id + ".prop").delete();
boolean delete = new File(this.cacheRoot, repoModule.id + ".prop").delete();
if (!delete) {
throw new RuntimeException("Failed to delete module metadata");
}
moduleInfoIterator.remove();
} else {
repoModule.moduleInfo.verify();
@ -179,7 +187,10 @@ public class RepoData extends XRepo {
}
return true;
} catch (Exception ignored) {
file.delete();
boolean delete = file.delete();
if (!delete) {
throw new RuntimeException("Failed to delete invalid metadata file");
}
}
}
repoModule.moduleInfo.flags |= ModuleInfo.FLAG_METADATA_INVALID;
@ -208,10 +219,6 @@ public class RepoData extends XRepo {
return this.url;
}
public boolean isLimited() {
return false;
}
public String getPreferenceId() {
return this.id;
}

@ -2,7 +2,6 @@ package com.fox2code.mmm.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
@ -15,17 +14,12 @@ import android.webkit.WebSettings;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.fox2code.foxcompat.FoxActivity;
import com.fox2code.foxcompat.internal.FoxCompat;
import com.fox2code.mmm.BuildConfig;
import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.R;
import com.fox2code.mmm.androidacy.AndroidacyUtil;
import com.fox2code.mmm.installer.InstallerInitializer;
import com.fox2code.mmm.repo.RepoManager;
import com.fox2code.mmm.settings.SettingsActivity;
import com.google.android.gms.net.CronetProviderInstaller;
import com.google.android.material.snackbar.Snackbar;
import com.google.net.cronet.okhttptransport.CronetInterceptor;
import org.chromium.net.CronetEngine;
@ -34,7 +28,6 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.net.Proxy;
import java.net.UnknownHostException;
@ -54,7 +47,6 @@ import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.Dns;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
@ -70,10 +62,7 @@ public class Http {
private static final OkHttpClient httpClientDoH;
private static final OkHttpClient httpClientWithCache;
private static final OkHttpClient httpClientWithCacheDoH;
private static final OkHttpClient httpClientNoRedirect;
private static final OkHttpClient httpClientNoRedirectDoH;
private static final FallBackDNS fallbackDNS;
private static final CDNCookieJar cookieJar;
private static final String androidacyUA;
private static final boolean hasWebView;
private static String needCaptchaAndroidacyHost;
@ -153,26 +142,33 @@ public class Http {
// Add cronet interceptor
// install cronet
try {
CronetProviderInstaller.installProvider(mainApplication);
// Detect if cronet is installed
CronetProviderInstaller.installProvider(mainApplication);
} catch (Exception e) {
Log.e(TAG, "Failed to install cronet", e);
}
// init cronet
try {
CronetEngine engine = new CronetEngine.Builder(mainApplication).build();
CronetEngine.Builder builder = new CronetEngine.Builder(mainApplication);
builder.enableBrotli(true);
builder.enableHttp2(true);
builder.enableQuic(true);
CronetEngine engine =
builder.build();
httpclientBuilder.addInterceptor(CronetInterceptor.newBuilder(engine).build());
} catch (Exception e) {
Log.e(TAG, "Failed to init cronet", e);
// Gracefully fallback to okhttp
}
// Fallback DNS cache responses in case request fail but already succeeded once in the past
fallbackDNS = new FallBackDNS(mainApplication, dns, "github.com", "api.github.com", "raw.githubusercontent.com", "camo.githubusercontent.com", "user-images.githubusercontent.com", "cdn.jsdelivr.net", "img.shields.io", "magisk-modules-repo.github.io", "www.androidacy.com", "api.androidacy.com", "production-api.androidacy.com");
httpclientBuilder.cookieJar(cookieJar = new CDNCookieJar(cookieManager));
httpclientBuilder.cookieJar(new CDNCookieJar(cookieManager));
httpclientBuilder.dns(Dns.SYSTEM);
httpClient = followRedirects(httpclientBuilder, true).build();
httpClientNoRedirect = followRedirects(httpclientBuilder, false).build();
followRedirects(httpclientBuilder, false).build();
httpclientBuilder.dns(fallbackDNS);
httpClientDoH = followRedirects(httpclientBuilder, true).build();
httpClientNoRedirectDoH = followRedirects(httpclientBuilder, false).build();
followRedirects(httpclientBuilder, false).build();
httpclientBuilder.cache(new Cache(new File(mainApplication.getCacheDir(), "http_cache"), 16L * 1024L * 1024L)); // 16Mib of cache
httpclientBuilder.dns(Dns.SYSTEM);
httpClientWithCache = followRedirects(httpclientBuilder, true).build();
@ -190,10 +186,6 @@ public class Http {
return doh ? httpClientDoH : httpClient;
}
public static OkHttpClient getHttpClientNoRedirect() {
return doh ? httpClientNoRedirectDoH : httpClientNoRedirect;
}
public static OkHttpClient getHttpClientWithCache() {
return doh ? httpClientWithCacheDoH : httpClientWithCache;
}
@ -236,7 +228,6 @@ public class Http {
if (response.code() != 200 && response.code() != 204 && (response.code() != 304 || !allowCache)) {
checkNeedCaptchaAndroidacy(url, response.code());
// If it's a 401, and an androidacy link, it's probably an invalid token
MainApplication mainApplication = MainApplication.getINSTANCE();
if (response.code() == 401 && AndroidacyUtil.isAndroidacyLink(url)) {
throw new HttpException("Androidacy token is invalid", 401);
}
@ -252,18 +243,14 @@ public class Http {
}
public static byte[] doHttpPost(String url, String data, boolean allowCache) throws IOException {
return (byte[]) doHttpPostRaw(url, data, allowCache, false);
}
public static String doHttpPostRedirect(String url, String data, boolean allowCache) throws IOException {
return (String) doHttpPostRaw(url, data, allowCache, true);
return (byte[]) doHttpPostRaw(url, data, allowCache);
}
@SuppressWarnings("resource")
private static Object doHttpPostRaw(String url, String data, boolean allowCache, boolean isRedirect) throws IOException {
private static Object doHttpPostRaw(String url, String data, boolean allowCache) throws IOException {
checkNeedBlockAndroidacyRequest(url);
Response response = (isRedirect ? getHttpClientNoRedirect() : allowCache ? getHttpClientWithCache() : getHttpClient()).newCall(new Request.Builder().url(url).post(JsonRequestBody.from(data)).header("Content-Type", "application/json").build()).execute();
if (isRedirect && response.isRedirect()) {
Response response = (allowCache ? getHttpClientWithCache() : getHttpClient()).newCall(new Request.Builder().url(url).post(JsonRequestBody.from(data)).header("Content-Type", "application/json").build()).execute();
if (response.isRedirect()) {
return response.request().url().uri().toString();
}
// 200/204 == success, 304 == cache valid
@ -329,61 +316,15 @@ public class Http {
return androidacyUA;
}
public static String getMagiskUA() {
return "Magisk/" + InstallerInitializer.peekMagiskVersion();
}
public static void setDoh(boolean doh) {
Log.d(TAG, "DoH: " + Http.doh + " -> " + doh);
Http.doh = doh;
}
public static String getAndroidacyCookies(String url) {
if (!AndroidacyUtil.isAndroidacyLink(url)) return "";
return cookieJar.getAndroidacyCookies(url);
}
public static boolean hasWebView() {
return hasWebView;
}
/**
* Change URL to appropriate url and force Magisk link to use latest version.
*/
public static String updateLink(String string) {
if (string.startsWith("https://cdn.jsdelivr.net/gh/Magisk-Modules-Repo/")) {
String tmp = string.substring(48);
int start = tmp.lastIndexOf('@'), end = tmp.lastIndexOf('/');
if ((end - 8) <= start) return string; // Skip if not a commit id
return "https://raw.githubusercontent.com/" + tmp.substring(0, start) + "/master" + string.substring(end);
}
if (string.startsWith("https://github.com/Magisk-Modules-Repo/")) {
int i = string.lastIndexOf("/archive/");
if (i != -1 && string.indexOf('/', i + 9) == -1)
return string.substring(0, i + 9) + "master.zip";
}
return string;
}
/**
* Change GitHub user-content url to jsdelivr url
* (Unused but kept as a documentation)
*/
public static String cdnIfyLink(String string) {
if (string.startsWith("https://raw.githubusercontent.com/")) {
String[] tokens = string.substring(34).split("/", 4);
if (tokens.length != 4) return string;
return "https://cdn.jsdelivr.net/gh/" + tokens[0] + "/" + tokens[1] + "@" + tokens[2] + "/" + tokens[3];
}
if (string.startsWith("https://github.com/")) {
int i = string.lastIndexOf("/archive/");
if (i == -1 || string.indexOf('/', i + 9) != -1) return string; // Not an archive link
String[] tokens = string.substring(19).split("/", 4);
return "https://cdn.jsdelivr.net/gh/" + tokens[0] + "/" + tokens[1] + "@" + tokens[2] + "/" + tokens[3];
}
return string;
}
public interface ProgressListener {
void onUpdate(int downloaded, int total, boolean done);
}
@ -471,17 +412,6 @@ public class Http {
}
}
String getAndroidacyCookies(String url) {
if (this.cookieManager != null) {
return this.cookieManager.getCookie(url);
}
StringBuilder stringBuilder = new StringBuilder();
for (Cookie cookie : this.androidacyCookies) {
stringBuilder.append(cookie.toString()).append("; ");
}
stringBuilder.setLength(stringBuilder.length() - 2);
return stringBuilder.toString();
}
}
/**

@ -10,7 +10,7 @@ buildscript {
project.ext.hasSentryConfig = sentryConfigFile.exists()
project.ext.sentryCli = [
logLevel: "debug",
flavorAware: false
flavorAware: true
]
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'

Loading…
Cancel
Save