2022-01-28 18:27:16 +00:00
|
|
|
package com.fox2code.mmm.androidacy;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.content.Intent;
|
2022-01-30 21:14:36 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2022-02-06 17:06:26 +00:00
|
|
|
import android.graphics.Bitmap;
|
2022-01-28 18:27:16 +00:00
|
|
|
import android.net.Uri;
|
2022-01-30 15:54:26 +00:00
|
|
|
import android.os.Build;
|
2022-01-28 18:27:16 +00:00
|
|
|
import android.os.Bundle;
|
2022-02-22 00:45:56 +00:00
|
|
|
import android.util.Log;
|
2022-07-16 19:29:25 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.webkit.ConsoleMessage;
|
2022-01-30 21:14:36 +00:00
|
|
|
import android.webkit.ValueCallback;
|
|
|
|
import android.webkit.WebChromeClient;
|
2022-01-28 18:27:16 +00:00
|
|
|
import android.webkit.WebResourceRequest;
|
2022-07-29 13:12:56 +00:00
|
|
|
import android.webkit.WebResourceResponse;
|
2022-01-28 18:27:16 +00:00
|
|
|
import android.webkit.WebSettings;
|
|
|
|
import android.webkit.WebView;
|
2022-07-16 19:29:25 +00:00
|
|
|
import android.widget.TextView;
|
2022-02-06 17:06:26 +00:00
|
|
|
import android.widget.Toast;
|
2022-01-28 18:27:16 +00:00
|
|
|
|
2022-01-30 22:32:10 +00:00
|
|
|
import androidx.annotation.NonNull;
|
2022-01-28 18:27:16 +00:00
|
|
|
import androidx.annotation.Nullable;
|
2022-02-06 17:06:26 +00:00
|
|
|
import androidx.webkit.WebResourceErrorCompat;
|
2022-01-30 22:32:10 +00:00
|
|
|
import androidx.webkit.WebSettingsCompat;
|
|
|
|
import androidx.webkit.WebViewClientCompat;
|
|
|
|
import androidx.webkit.WebViewFeature;
|
2022-01-28 18:27:16 +00:00
|
|
|
|
2022-07-16 14:13:58 +00:00
|
|
|
import com.fox2code.foxcompat.FoxActivity;
|
2022-01-28 22:12:32 +00:00
|
|
|
import com.fox2code.mmm.BuildConfig;
|
2022-01-30 15:54:26 +00:00
|
|
|
import com.fox2code.mmm.Constants;
|
2022-01-28 21:47:41 +00:00
|
|
|
import com.fox2code.mmm.MainApplication;
|
2022-01-28 18:27:16 +00:00
|
|
|
import com.fox2code.mmm.R;
|
2022-03-26 19:39:47 +00:00
|
|
|
import com.fox2code.mmm.XHooks;
|
2022-01-28 18:27:16 +00:00
|
|
|
import com.fox2code.mmm.utils.Http;
|
|
|
|
import com.fox2code.mmm.utils.IntentHelper;
|
|
|
|
|
2022-07-28 11:31:25 +00:00
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2022-07-29 13:12:56 +00:00
|
|
|
import java.io.ByteArrayInputStream;
|
2022-07-28 11:31:25 +00:00
|
|
|
import java.io.IOException;
|
2022-06-07 17:01:58 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
2022-01-28 18:27:16 +00:00
|
|
|
/**
|
|
|
|
* Per Androidacy repo implementation agreement, no request of this WebView shall be modified.
|
|
|
|
*/
|
2022-07-29 13:12:56 +00:00
|
|
|
public final class AndroidacyActivity extends FoxActivity {
|
2022-02-22 00:45:56 +00:00
|
|
|
private static final String TAG = "AndroidacyActivity";
|
2022-02-05 17:07:36 +00:00
|
|
|
|
2022-01-28 22:12:32 +00:00
|
|
|
static {
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
WebView.setWebContentsDebuggingEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-30 22:32:10 +00:00
|
|
|
WebView webView;
|
2022-07-16 19:29:25 +00:00
|
|
|
TextView webViewNote;
|
2022-02-22 00:45:56 +00:00
|
|
|
AndroidacyWebAPI androidacyWebAPI;
|
2022-01-30 22:32:10 +00:00
|
|
|
boolean backOnResume;
|
2022-01-28 18:27:16 +00:00
|
|
|
|
2022-09-14 17:34:01 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2022-01-28 18:27:16 +00:00
|
|
|
@Override
|
2022-01-28 21:47:41 +00:00
|
|
|
@SuppressLint({"SetJavaScriptEnabled", "JavascriptInterface"})
|
2022-01-28 18:27:16 +00:00
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
Intent intent = this.getIntent();
|
|
|
|
Uri uri;
|
2022-01-28 21:47:41 +00:00
|
|
|
if (!MainApplication.checkSecret(intent) ||
|
2022-02-22 00:45:56 +00:00
|
|
|
(uri = intent.getData()) == null) {
|
|
|
|
Log.w(TAG, "Impersonation detected");
|
2022-01-28 18:27:16 +00:00
|
|
|
this.forceBackPressed();
|
|
|
|
return;
|
|
|
|
}
|
2022-02-05 17:07:36 +00:00
|
|
|
String url = uri.toString();
|
2022-02-22 00:45:56 +00:00
|
|
|
if (!AndroidacyUtil.isAndroidacyLink(url, uri)) {
|
|
|
|
Log.w(TAG, "Calling non androidacy link in secure WebView: " + url);
|
2022-02-05 17:07:36 +00:00
|
|
|
this.forceBackPressed();
|
|
|
|
return;
|
|
|
|
}
|
2022-04-12 16:01:47 +00:00
|
|
|
if (!Http.hasWebView()) {
|
|
|
|
Log.w(TAG, "No WebView found to load url: " + url);
|
|
|
|
this.forceBackPressed();
|
|
|
|
return;
|
|
|
|
}
|
2022-07-25 17:36:45 +00:00
|
|
|
if (!url.contains(AndroidacyUtil.REFERRER)) {
|
2022-02-05 17:07:36 +00:00
|
|
|
if (url.lastIndexOf('/') < url.lastIndexOf('?')) {
|
2022-06-07 15:50:37 +00:00
|
|
|
url = url + '&' + AndroidacyUtil.REFERRER;
|
2022-02-05 17:07:36 +00:00
|
|
|
} else {
|
2022-06-07 15:50:37 +00:00
|
|
|
url = url + '?' + AndroidacyUtil.REFERRER;
|
2022-02-05 17:07:36 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-30 15:54:26 +00:00
|
|
|
boolean allowInstall = intent.getBooleanExtra(
|
|
|
|
Constants.EXTRA_ANDROIDACY_ALLOW_INSTALL, false);
|
2022-01-30 21:14:36 +00:00
|
|
|
String title = intent.getStringExtra(Constants.EXTRA_ANDROIDACY_ACTIONBAR_TITLE);
|
|
|
|
String config = intent.getStringExtra(Constants.EXTRA_ANDROIDACY_ACTIONBAR_CONFIG);
|
2022-03-25 01:00:12 +00:00
|
|
|
int compatLevel = intent.getIntExtra(Constants.EXTRA_ANDROIDACY_COMPAT_LEVEL, 0);
|
2022-01-28 18:27:16 +00:00
|
|
|
this.setContentView(R.layout.webview);
|
2022-02-23 20:30:51 +00:00
|
|
|
setActionBarBackground(null);
|
|
|
|
this.setDisplayHomeAsUpEnabled(true);
|
|
|
|
if (title == null || title.isEmpty()) {
|
|
|
|
this.setTitle("Androidacy");
|
2022-03-02 21:20:41 +00:00
|
|
|
} else {
|
|
|
|
this.setTitle(title);
|
2022-02-23 20:30:51 +00:00
|
|
|
}
|
2022-01-30 22:32:10 +00:00
|
|
|
if (allowInstall || title == null || title.isEmpty()) {
|
2022-01-30 21:14:36 +00:00
|
|
|
this.hideActionBar();
|
|
|
|
} else { // Only used for note section
|
|
|
|
if (config != null && !config.isEmpty()) {
|
|
|
|
String configPkg = IntentHelper.getPackageOfConfig(config);
|
|
|
|
try {
|
2022-03-26 19:39:47 +00:00
|
|
|
XHooks.checkConfigTargetExists(this, configPkg, config);
|
2022-01-30 21:14:36 +00:00
|
|
|
this.setActionBarExtraMenuButton(R.drawable.ic_baseline_app_settings_alt_24,
|
|
|
|
menu -> {
|
|
|
|
IntentHelper.openConfig(this, config);
|
|
|
|
return true;
|
|
|
|
});
|
2022-09-14 17:34:01 +00:00
|
|
|
} catch (PackageManager.NameNotFoundException ignored) {
|
|
|
|
}
|
2022-01-30 21:14:36 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-28 18:27:16 +00:00
|
|
|
this.webView = this.findViewById(R.id.webView);
|
2022-07-16 19:29:25 +00:00
|
|
|
this.webViewNote = this.findViewById(R.id.webViewNote);
|
2022-01-28 18:27:16 +00:00
|
|
|
WebSettings webSettings = this.webView.getSettings();
|
|
|
|
webSettings.setUserAgentString(Http.getAndroidacyUA());
|
|
|
|
webSettings.setDomStorageEnabled(true);
|
|
|
|
webSettings.setJavaScriptEnabled(true);
|
2022-02-24 19:27:10 +00:00
|
|
|
webSettings.setAllowFileAccess(false);
|
2022-09-14 17:34:01 +00:00
|
|
|
// If API level is .= 33, allow setAlgorithmicDarkeningAllowed
|
|
|
|
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.TIRAMISU) {
|
|
|
|
try {
|
|
|
|
webSettings.setAlgorithmicDarkeningAllowed(true);
|
|
|
|
} catch (NoSuchMethodError ignored) {
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { // Make website follow app theme
|
|
|
|
webSettings.setForceDark(MainApplication.getINSTANCE().isLightTheme() ?
|
|
|
|
WebSettings.FORCE_DARK_OFF : WebSettings.FORCE_DARK_ON);
|
|
|
|
} else if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
|
|
|
|
// If api level is < 32, use force dark
|
|
|
|
WebSettingsCompat.setForceDark(webSettings, MainApplication.getINSTANCE().isLightTheme() ?
|
|
|
|
WebSettingsCompat.FORCE_DARK_OFF : WebSettingsCompat.FORCE_DARK_ON);
|
|
|
|
}
|
2022-01-30 15:54:26 +00:00
|
|
|
}
|
2022-01-30 22:32:10 +00:00
|
|
|
this.webView.setWebViewClient(new WebViewClientCompat() {
|
2022-02-06 17:06:26 +00:00
|
|
|
private String pageUrl;
|
|
|
|
|
2022-01-28 18:27:16 +00:00
|
|
|
@Override
|
2022-01-30 22:32:10 +00:00
|
|
|
public boolean shouldOverrideUrlLoading(
|
|
|
|
@NonNull WebView view, @NonNull WebResourceRequest request) {
|
2022-02-22 00:45:56 +00:00
|
|
|
// Don't open non Androidacy urls inside WebView
|
2022-03-03 12:59:39 +00:00
|
|
|
if (request.isForMainFrame() &&
|
|
|
|
!AndroidacyUtil.isAndroidacyLink(request.getUrl())) {
|
2022-07-28 11:31:25 +00:00
|
|
|
Log.i(TAG, "Exiting WebView " + // hideToken in case isAndroidacyLink fail.
|
|
|
|
AndroidacyUtil.hideToken(request.getUrl().toString()));
|
2022-03-03 12:59:39 +00:00
|
|
|
IntentHelper.openUri(view.getContext(), request.getUrl().toString());
|
2022-01-28 18:27:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2022-02-06 17:06:26 +00:00
|
|
|
|
2022-07-29 13:12:56 +00:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public WebResourceResponse shouldInterceptRequest(
|
|
|
|
WebView view, WebResourceRequest request) {
|
|
|
|
if (AndroidacyActivity.this.megaIntercept(
|
|
|
|
this.pageUrl, request.getUrl().toString())) {
|
|
|
|
// Block request as Androidacy doesn't allow duplicate requests
|
|
|
|
return new WebResourceResponse("text/plain", "UTF-8",
|
|
|
|
new ByteArrayInputStream(new byte[0]));
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-02-06 17:06:26 +00:00
|
|
|
@Override
|
|
|
|
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
|
|
this.pageUrl = url;
|
|
|
|
}
|
|
|
|
|
2022-07-16 19:29:25 +00:00
|
|
|
@Override
|
|
|
|
public void onPageFinished(WebView view, String url) {
|
|
|
|
webViewNote.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onReceivedError(String url, int errorCode) {
|
2022-09-14 17:34:01 +00:00
|
|
|
if ((url.startsWith("https://production-api.androidacy.com/magisk/") ||
|
2022-07-28 11:31:25 +00:00
|
|
|
url.startsWith("https://staging-api.androidacy.com/magisk/") ||
|
2022-03-30 19:25:08 +00:00
|
|
|
url.equals(pageUrl)) && (errorCode == 419 || errorCode == 429 || errorCode == 503)) {
|
2022-02-06 17:06:26 +00:00
|
|
|
Toast.makeText(AndroidacyActivity.this,
|
|
|
|
"Too many requests!", Toast.LENGTH_LONG).show();
|
|
|
|
AndroidacyActivity.this.runOnUiThread(AndroidacyActivity.this::onBackPressed);
|
2022-07-16 19:29:25 +00:00
|
|
|
} else if (url.equals(this.pageUrl)) {
|
|
|
|
postOnUiThread(() ->
|
|
|
|
webViewNote.setVisibility(View.VISIBLE));
|
2022-02-06 17:06:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
|
|
|
this.onReceivedError(failingUrl, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceivedError(@NonNull WebView view, @NonNull WebResourceRequest request,
|
|
|
|
@NonNull WebResourceErrorCompat error) {
|
|
|
|
if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_RESOURCE_ERROR_GET_CODE)) {
|
|
|
|
this.onReceivedError(request.getUrl().toString(), error.getErrorCode());
|
|
|
|
}
|
|
|
|
}
|
2022-01-28 18:27:16 +00:00
|
|
|
});
|
2022-01-30 21:14:36 +00:00
|
|
|
this.webView.setWebChromeClient(new WebChromeClient() {
|
|
|
|
@Override
|
|
|
|
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
|
|
|
|
FileChooserParams fileChooserParams) {
|
2022-07-16 14:13:58 +00:00
|
|
|
FoxActivity.getFoxActivity(webView).startActivityForResult(
|
2022-01-30 21:14:36 +00:00
|
|
|
fileChooserParams.createIntent(), (code, data) ->
|
|
|
|
filePathCallback.onReceiveValue(
|
|
|
|
FileChooserParams.parseResult(code, data)));
|
|
|
|
return true;
|
|
|
|
}
|
2022-07-16 19:29:25 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
|
2022-07-28 11:31:25 +00:00
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
switch (consoleMessage.messageLevel()) {
|
|
|
|
case TIP:
|
|
|
|
Log.v(TAG, consoleMessage.message());
|
|
|
|
break;
|
|
|
|
case LOG:
|
|
|
|
Log.i(TAG, consoleMessage.message());
|
|
|
|
break;
|
|
|
|
case WARNING:
|
|
|
|
Log.w(TAG, consoleMessage.message());
|
|
|
|
break;
|
|
|
|
case ERROR:
|
|
|
|
Log.e(TAG, consoleMessage.message());
|
|
|
|
break;
|
|
|
|
case DEBUG:
|
|
|
|
Log.d(TAG, consoleMessage.message());
|
|
|
|
break;
|
|
|
|
}
|
2022-07-16 19:29:25 +00:00
|
|
|
}
|
|
|
|
return super.onConsoleMessage(consoleMessage);
|
|
|
|
}
|
2022-01-30 21:14:36 +00:00
|
|
|
});
|
2022-03-25 01:00:12 +00:00
|
|
|
this.webView.setDownloadListener((
|
|
|
|
downloadUrl, userAgent, contentDisposition, mimetype, contentLength) -> {
|
2022-07-28 11:31:25 +00:00
|
|
|
if (AndroidacyUtil.isAndroidacyLink(downloadUrl) && !this.backOnResume) {
|
2022-03-25 01:00:12 +00:00
|
|
|
AndroidacyWebAPI androidacyWebAPI = this.androidacyWebAPI;
|
|
|
|
if (androidacyWebAPI != null) {
|
2022-07-28 11:31:25 +00:00
|
|
|
if (!androidacyWebAPI.downloadMode) {
|
2022-07-29 13:12:56 +00:00
|
|
|
// Native module popup may cause download after consumed action
|
2022-07-28 11:31:25 +00:00
|
|
|
if (androidacyWebAPI.consumedAction)
|
2022-07-29 13:12:56 +00:00
|
|
|
return;
|
|
|
|
// Workaround Androidacy bug
|
|
|
|
final String moduleId = moduleIdOfUrl(downloadUrl);
|
|
|
|
if (moduleId != null) {
|
2022-07-28 11:31:25 +00:00
|
|
|
webView.evaluateJavascript("document.querySelector(" +
|
|
|
|
"\"#download-form input[name=_token]\").value",
|
2022-09-14 17:34:01 +00:00
|
|
|
result -> new Thread("Androidacy popup workaround thread") {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (androidacyWebAPI.consumedAction) return;
|
|
|
|
try {
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
jsonObject.put("moduleId", moduleId);
|
|
|
|
jsonObject.put("token", AndroidacyRepoData
|
|
|
|
.getInstance().getToken());
|
|
|
|
jsonObject.put("_token", result);
|
|
|
|
String realUrl = Http.doHttpPostRedirect(downloadUrl,
|
|
|
|
jsonObject.toString(), true);
|
|
|
|
if (downloadUrl.equals(realUrl)) {
|
|
|
|
Log.e(TAG, "Failed to resolve URL from " +
|
|
|
|
downloadUrl);
|
|
|
|
AndroidacyActivity.this.megaIntercept(
|
|
|
|
webView.getUrl(), downloadUrl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Log.i(TAG, "Got url: " + realUrl);
|
|
|
|
androidacyWebAPI.openNativeModuleDialogRaw(realUrl,
|
|
|
|
moduleId, "", androidacyWebAPI.canInstall());
|
|
|
|
} catch (IOException | JSONException e) {
|
|
|
|
Log.e(TAG, "Failed redirect intercept", e);
|
2022-07-28 11:31:25 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-14 17:34:01 +00:00
|
|
|
}.start());
|
2022-07-28 11:31:25 +00:00
|
|
|
return;
|
2022-07-29 13:12:56 +00:00
|
|
|
} else if (this.megaIntercept(webView.getUrl(), downloadUrl))
|
|
|
|
return;
|
2022-03-25 01:00:12 +00:00
|
|
|
}
|
|
|
|
androidacyWebAPI.consumedAction = true;
|
|
|
|
androidacyWebAPI.downloadMode = false;
|
2022-07-28 11:31:25 +00:00
|
|
|
}
|
2022-03-25 01:00:12 +00:00
|
|
|
this.backOnResume = true;
|
2022-07-28 11:31:25 +00:00
|
|
|
Log.i(TAG, "Exiting WebView " +
|
|
|
|
AndroidacyUtil.hideToken(downloadUrl));
|
|
|
|
for (String prefix : new String[]{
|
2022-09-14 17:34:01 +00:00
|
|
|
"https://production-api.androidacy.com/magisk/download/",
|
2022-07-28 11:31:25 +00:00
|
|
|
"https://staging-api.androidacy.com/magisk/download/"
|
|
|
|
}) {
|
|
|
|
if (downloadUrl.startsWith(prefix)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-03-25 01:00:12 +00:00
|
|
|
IntentHelper.openCustomTab(this, downloadUrl);
|
|
|
|
}
|
|
|
|
});
|
2022-07-28 11:51:03 +00:00
|
|
|
this.androidacyWebAPI = new AndroidacyWebAPI(this, allowInstall);
|
2022-03-26 19:39:47 +00:00
|
|
|
XHooks.onWebViewInitialize(this.webView, allowInstall);
|
2022-07-28 11:51:03 +00:00
|
|
|
this.webView.addJavascriptInterface(this.androidacyWebAPI, "mmm");
|
2022-03-25 01:00:12 +00:00
|
|
|
if (compatLevel != 0) androidacyWebAPI.notifyCompatModeRaw(compatLevel);
|
2022-06-07 17:01:58 +00:00
|
|
|
HashMap<String, String> headers = new HashMap<>();
|
|
|
|
headers.put("Accept-Language", this.getResources()
|
|
|
|
.getConfiguration().locale.toLanguageTag());
|
|
|
|
this.webView.loadUrl(url, headers);
|
2022-01-28 18:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
WebView webView = this.webView;
|
|
|
|
if (webView != null && webView.canGoBack()) {
|
|
|
|
webView.goBack();
|
|
|
|
} else {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
}
|
2022-01-30 22:32:10 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (this.backOnResume) {
|
|
|
|
this.backOnResume = false;
|
|
|
|
this.forceBackPressed();
|
2022-02-22 00:45:56 +00:00
|
|
|
} else if (this.androidacyWebAPI != null) {
|
|
|
|
this.androidacyWebAPI.consumedAction = false;
|
2022-01-30 22:32:10 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-29 13:12:56 +00:00
|
|
|
|
|
|
|
private String moduleIdOfUrl(String url) {
|
|
|
|
for (String prefix : new String[]{
|
2022-09-14 17:34:01 +00:00
|
|
|
"https://production-api.androidacy.com/magisk/download/",
|
2022-07-29 13:12:56 +00:00
|
|
|
"https://staging-api.androidacy.com/magisk/download/",
|
2022-09-14 17:34:01 +00:00
|
|
|
"https://production-api.androidacy.com/magisk/readme/",
|
2022-07-29 13:12:56 +00:00
|
|
|
"https://staging-api.androidacy.com/magisk/readme/",
|
2022-09-14 17:34:01 +00:00
|
|
|
"https://prodiuction-api.androidacy.com/magisk/info/",
|
2022-07-29 13:12:56 +00:00
|
|
|
"https://staging-api.androidacy.com/magisk/info/"
|
|
|
|
}) { // Make both staging and non staging act the same
|
2022-09-14 17:34:01 +00:00
|
|
|
int i = url.indexOf('?', prefix.length());
|
|
|
|
if (i == -1) i = url.length();
|
2022-07-29 13:12:56 +00:00
|
|
|
if (url.startsWith(prefix)) return url.substring(prefix.length(), i);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isFileUrl(String url) {
|
|
|
|
for (String prefix : new String[]{
|
2022-09-14 17:34:01 +00:00
|
|
|
"https://production-api.androidacy.com/magisk/file/",
|
2022-07-29 13:12:56 +00:00
|
|
|
"https://staging-api.androidacy.com/magisk/file/"
|
|
|
|
}) { // Make both staging and non staging act the same
|
|
|
|
if (url.startsWith(prefix)) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean megaIntercept(String pageUrl, String fileUrl) {
|
|
|
|
if (pageUrl == null || fileUrl == null) return false;
|
|
|
|
if (this.isFileUrl(fileUrl)) {
|
|
|
|
Log.d(TAG, "megaIntercept(" +
|
|
|
|
AndroidacyUtil.hideToken(pageUrl) + ", " +
|
|
|
|
AndroidacyUtil.hideToken(fileUrl) + ")");
|
|
|
|
}
|
|
|
|
final AndroidacyWebAPI androidacyWebAPI = this.androidacyWebAPI;
|
|
|
|
final String moduleId = this.moduleIdOfUrl(pageUrl);
|
|
|
|
if (moduleId == null || !this.isFileUrl(fileUrl)) return false;
|
|
|
|
androidacyWebAPI.openNativeModuleDialogRaw(fileUrl,
|
|
|
|
moduleId, "", androidacyWebAPI.canInstall());
|
|
|
|
return true;
|
|
|
|
}
|
2022-01-28 18:27:16 +00:00
|
|
|
}
|