From eb46a3a56ff485247aa3234ac059de0483c8d93c Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Thu, 6 Apr 2023 21:34:31 -0400 Subject: [PATCH] (chore) require webview for online functionality if no current webview is found, foxmmm should revert to an offline only module manager - allowing install from storage and to remove modules, but no update checks or online repo functionality will work quite a bit of the http stack now relies on webview and will crash or not work as well without it so better to avoid any issues and besides, everything since at least 4.4 has webview built-in Signed-off-by: androidacy-user --- .../java/com/fox2code/mmm/MainActivity.java | 24 ++++++++++++------- .../com/fox2code/mmm/utils/io/net/Http.java | 23 +++++++++++++++++- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/fox2code/mmm/MainActivity.java b/app/src/main/java/com/fox2code/mmm/MainActivity.java index 39ca8a2..63d9c18 100644 --- a/app/src/main/java/com/fox2code/mmm/MainActivity.java +++ b/app/src/main/java/com/fox2code/mmm/MainActivity.java @@ -54,7 +54,6 @@ import com.google.android.material.progressindicator.LinearProgressIndicator; import org.chromium.net.CronetEngine; import java.net.URL; -import java.util.Map; import java.util.Objects; import timber.log.Timber; @@ -262,7 +261,10 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe // Check Http for WebView availability moduleViewListBuilder.addNotification(NotificationType.NO_WEB_VIEW); // disable online tab - bottomNavigationView.getMenu().removeItem(R.id.online_menu_item); + runOnUiThread(() -> { + bottomNavigationView.getMenu().getItem(1).setEnabled(false); + bottomNavigationView.setSelectedItemId(R.id.installed_menu_item); + }); } moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter); runOnUiThread(() -> { @@ -291,21 +293,25 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe AppUpdateManager.getAppUpdateManager().checkUpdateCompat(); if (BuildConfig.DEBUG) Timber.i("Check Update"); // update repos - RepoManager.getINSTANCE().update(value -> runOnUiThread(max == 0 ? () -> progressIndicator.setProgressCompat((int) (value * PRECISION), true) : () -> progressIndicator.setProgressCompat((int) (value * PRECISION * 0.75F), true))); + if (Http.hasWebView()) { + RepoManager.getINSTANCE().update(value -> runOnUiThread(max == 0 ? () -> progressIndicator.setProgressCompat((int) (value * PRECISION), true) : () -> progressIndicator.setProgressCompat((int) (value * PRECISION * 0.75F), true))); + } // various notifications NotificationType.NEED_CAPTCHA_ANDROIDACY.autoAdd(moduleViewListBuilder); NotificationType.NEED_CAPTCHA_ANDROIDACY.autoAdd(moduleViewListBuilderOnline); NotificationType.DEBUG.autoAdd(moduleViewListBuilder); NotificationType.DEBUG.autoAdd(moduleViewListBuilderOnline); - if (!NotificationType.REPO_UPDATE_FAILED.shouldRemove()) { + if (Http.hasWebView() && !NotificationType.REPO_UPDATE_FAILED.shouldRemove()) { moduleViewListBuilder.addNotification(NotificationType.REPO_UPDATE_FAILED); } else { if (!Http.hasWebView()) { - progressIndicator.setProgressCompat(PRECISION, true); - progressIndicator.setVisibility(View.GONE); - searchView.setEnabled(true); - setActionBarBackground(null); - updateScreenInsets(getResources().getConfiguration()); + runOnUiThread(() -> { + progressIndicator.setProgressCompat(PRECISION, true); + progressIndicator.setVisibility(View.GONE); + searchView.setEnabled(true); + setActionBarBackground(null); + updateScreenInsets(getResources().getConfiguration()); + }); return; } // Compatibility data still needs to be updated diff --git a/app/src/main/java/com/fox2code/mmm/utils/io/net/Http.java b/app/src/main/java/com/fox2code/mmm/utils/io/net/Http.java index 7413718..c63a119 100644 --- a/app/src/main/java/com/fox2code/mmm/utils/io/net/Http.java +++ b/app/src/main/java/com/fox2code/mmm/utils/io/net/Http.java @@ -4,6 +4,7 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; +import android.content.pm.PackageInfo; import android.net.Uri; import android.os.Build; import android.os.Handler; @@ -16,6 +17,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.webkit.WebViewCompat; import com.fox2code.mmm.BuildConfig; import com.fox2code.mmm.MainActivity; @@ -105,7 +107,26 @@ public enum Http { Context context = mainApplication.getApplicationContext(); MainActivity.getFoxActivity(context).runOnUiThread(() -> Toast.makeText(mainApplication, R.string.error_creating_cookie_database, Toast.LENGTH_LONG).show()); } - hasWebView = cookieManager != null; + // get webview version + String webviewVersion = "0.0.0"; + PackageInfo pi = WebViewCompat.getCurrentWebViewPackage(mainApplication); + if (pi != null) { + webviewVersion = pi.versionName; + } + // webviewVersionMajor is the everything before the first dot + int webviewVersionCode; + // parse webview version + // get the first dot + int dot = webviewVersion.indexOf('.'); + if (dot == -1) { + // no dot, use the whole string + webviewVersionCode = Integer.parseInt(webviewVersion); + } else { + // use the first dot + webviewVersionCode = Integer.parseInt(webviewVersion.substring(0, dot)); + } + Timber.d("Webview version: %s (%d)", webviewVersion, webviewVersionCode); + hasWebView = cookieManager != null && webviewVersionCode >= 83; // 83 is the first version Androidacy supports due to errors in 82 OkHttpClient.Builder httpclientBuilder = new OkHttpClient.Builder(); // Default is 10, extend it a bit for slow mobile connections. httpclientBuilder.connectTimeout(5, TimeUnit.SECONDS);