Replace captcha webview with warning

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/27/head
androidacy-user 3 years ago
parent 414bd5d340
commit 2171364db8

@ -387,6 +387,8 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
@SuppressLint({"RestrictedApi", "UnspecifiedImmutableFlag"})
public void onCreatePreferencesAndroidacy() {
// Bind the pref_show_captcha_webview to captchaWebview('https://production-api.androidacy.com/')
// Also require dev modeowCaptchaWebview.setVisible(false);
Preference androidacyTestMode = Objects.requireNonNull(findPreference("pref_androidacy_test_mode"));
if (!MainApplication.isDeveloper()) {
androidacyTestMode.setVisible(false);

@ -1,24 +1,23 @@
package com.fox2code.mmm.utils;
import static com.fox2code.mmm.MainApplication.getInstance;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.system.ErrnoException;
import android.system.Os;
import android.util.Log;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
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;
@ -57,7 +56,6 @@ import okhttp3.dnsoverhttps.DnsOverHttps;
import okio.BufferedSink;
public class Http {
private static final MainApplication mainApplication = getInstance();
private static final String TAG = "Http";
private static final OkHttpClient httpClient;
private static final OkHttpClient httpClientDoH;
@ -177,25 +175,6 @@ public class Http {
return doh ? httpClientWithCacheDoH : httpClientWithCache;
}
@SuppressLint("SetJavaScriptEnabled")
public static void captchaWebview(String url) {
if (hasWebView) {
// Open the specified url in a webview
WebView webView = new WebView(mainApplication);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setUserAgentString(androidacyUA);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
// Open the url in the webview
webView.loadUrl(url);
// Show the webview
webView.setVisibility(View.VISIBLE);
} else {
// Throw an exception if the webview is not available
throw new IllegalStateException("Webview is not available");
}
}
@SuppressWarnings("resource")
public static byte[] doHttpGet(String url, boolean allowCache) throws IOException {
if (!RepoManager.isAndroidacyRepoEnabled() && AndroidacyUtil.isAndroidacyLink(url)) {
@ -206,7 +185,8 @@ public class Http {
if (response.code() == 403 && AndroidacyUtil.isAndroidacyLink(url)) {
// Open webview to solve captcha
Log.e(TAG, "Received 403 error code, opening webview to solve captcha");
captchaWebview(url);
// Show toast on main thread
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(MainApplication.getInstance(), R.string.androidacy_server_down, Toast.LENGTH_LONG).show());
} else if (response.code() != 200 && response.code() != 204 && (response.code() != 304 || !allowCache)) {
throw new IOException("Received error code: " + response.code());
}
@ -240,7 +220,8 @@ public class Http {
if (response.code() == 403 && AndroidacyUtil.isAndroidacyLink(url)) {
// Open webview to solve captcha
Log.e(TAG, "Received 403 error code, opening webview to solve captcha");
captchaWebview(url);
// Show toast on main thread
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(MainApplication.getInstance(), R.string.androidacy_server_down, Toast.LENGTH_LONG).show());
} else if (response.code() != 200 && response.code() != 204 && (response.code() != 304 || !allowCache)) {
throw new IOException("Received error code: " + response.code());
}

@ -179,4 +179,5 @@
<string name="androidacy_failed_to_parse_token">Could not retrieve token from Androidacy. Please try again later.</string>
<string name="androidacy_failed_to_validate_token">Could not validate token for Androidacy. Please try again later.</string>
<string name="androidacy_server_down">Unable to contact Androidacy server. Check your connection and try again.</string>
<string name="show_captcha">Test the captcha webview implementation</string>
</resources>

@ -81,6 +81,11 @@
app:icon="@drawable/ic_baseline_upload_file_24"
app:title="@string/submit_modules"
app:singleLineTitle="false" />
<!-- <Preference
app:key="pref_show_captcha_webview"
app:icon="@drawable/ic_baseline_vpn_key_24"
app:title="@string/show_captcha"
app:singleLineTitle="false" /> -->
<Preference
app:key="pref_androidacy_ads_disclaimer"
app:icon="@drawable/ic_baseline_info_24"

Loading…
Cancel
Save