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-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-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;
|
|
|
|
import android.webkit.WebSettings;
|
|
|
|
import android.webkit.WebView;
|
|
|
|
|
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-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-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;
|
|
|
|
import com.fox2code.mmm.compat.CompatActivity;
|
|
|
|
import com.fox2code.mmm.utils.Http;
|
|
|
|
import com.fox2code.mmm.utils.IntentHelper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Per Androidacy repo implementation agreement, no request of this WebView shall be modified.
|
|
|
|
*/
|
2022-01-28 21:47:41 +00:00
|
|
|
public class AndroidacyActivity extends CompatActivity {
|
2022-02-05 17:07:36 +00:00
|
|
|
private static final String REFERRER = "utm_source=FoxMMM&utm_medium=app";
|
|
|
|
|
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;
|
|
|
|
boolean backOnResume;
|
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) ||
|
|
|
|
(uri = intent.getData()) == null ||
|
|
|
|
!uri.getHost().endsWith(".androidacy.com")) {
|
2022-01-28 18:27:16 +00:00
|
|
|
this.forceBackPressed();
|
|
|
|
return;
|
|
|
|
}
|
2022-02-05 17:07:36 +00:00
|
|
|
String url = uri.toString();
|
|
|
|
int i;
|
|
|
|
if (!url.startsWith("https://") || // Checking twice
|
|
|
|
(i = url.indexOf("/", 8)) == -1 ||
|
|
|
|
!url.substring(8, i).endsWith(".androidacy.com")) {
|
|
|
|
this.forceBackPressed();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!url.endsWith(REFERRER) && (url.startsWith("https://www.androidacy.com/") ||
|
2022-02-05 21:10:33 +00:00
|
|
|
url.startsWith("https://api.androidacy.com/magisk/"))) {
|
2022-02-05 17:07:36 +00:00
|
|
|
if (url.lastIndexOf('/') < url.lastIndexOf('?')) {
|
|
|
|
url = url + '&' + REFERRER;
|
|
|
|
} else {
|
|
|
|
url = url + '?' + REFERRER;
|
|
|
|
}
|
|
|
|
}
|
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-01-28 18:27:16 +00:00
|
|
|
this.setContentView(R.layout.webview);
|
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
|
|
|
|
this.setTitle(title);
|
|
|
|
this.setDisplayHomeAsUpEnabled(true);
|
|
|
|
if (config != null && !config.isEmpty()) {
|
|
|
|
String configPkg = IntentHelper.getPackageOfConfig(config);
|
|
|
|
try {
|
|
|
|
this.getPackageManager().getPackageInfo(configPkg, 0);
|
|
|
|
this.setActionBarExtraMenuButton(R.drawable.ic_baseline_app_settings_alt_24,
|
|
|
|
menu -> {
|
|
|
|
IntentHelper.openConfig(this, config);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
} catch (PackageManager.NameNotFoundException ignored) {}
|
|
|
|
}
|
|
|
|
}
|
2022-01-28 18:27:16 +00:00
|
|
|
this.webView = this.findViewById(R.id.webView);
|
|
|
|
WebSettings webSettings = this.webView.getSettings();
|
|
|
|
webSettings.setUserAgentString(Http.getAndroidacyUA());
|
|
|
|
webSettings.setDomStorageEnabled(true);
|
|
|
|
webSettings.setJavaScriptEnabled(true);
|
2022-01-30 15:54:26 +00:00
|
|
|
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);
|
2022-01-30 22:32:10 +00:00
|
|
|
} else if (WebViewFeature.isFeatureSupported(WebViewFeature.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-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-01-28 21:47:41 +00:00
|
|
|
// Don't open non andoridacy urls inside WebView
|
|
|
|
if (request.isForMainFrame() && !(request.getUrl().getScheme().equals("intent") ||
|
|
|
|
request.getUrl().getHost().endsWith(".androidacy.com"))) {
|
2022-01-28 18:27:16 +00:00
|
|
|
IntentHelper.openUrl(view.getContext(), request.getUrl().toString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2022-01-30 21:14:36 +00:00
|
|
|
this.webView.setWebChromeClient(new WebChromeClient() {
|
|
|
|
@Override
|
|
|
|
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
|
|
|
|
FileChooserParams fileChooserParams) {
|
|
|
|
CompatActivity.getCompatActivity(webView).startActivityForResult(
|
|
|
|
fileChooserParams.createIntent(), (code, data) ->
|
|
|
|
filePathCallback.onReceiveValue(
|
|
|
|
FileChooserParams.parseResult(code, data)));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2022-01-30 15:54:26 +00:00
|
|
|
this.webView.addJavascriptInterface(
|
|
|
|
new AndroidacyWebAPI(this, allowInstall), "mmm");
|
2022-02-05 17:07:36 +00:00
|
|
|
this.webView.loadUrl(url);
|
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-01-28 18:27:16 +00:00
|
|
|
}
|