diff --git a/app/src/main/java/tech/httptoolkit/android/HttpToolkitApplication.kt b/app/src/main/java/tech/httptoolkit/android/HttpToolkitApplication.kt index 468d726..95a0241 100644 --- a/app/src/main/java/tech/httptoolkit/android/HttpToolkitApplication.kt +++ b/app/src/main/java/tech/httptoolkit/android/HttpToolkitApplication.kt @@ -26,6 +26,7 @@ private const val VPN_START_TIME_PREF = "vpn-start-time" private const val LAST_UPDATE_CHECK_TIME_PREF = "update-check-time" private const val APP_CRASHED_PREF = "app-crashed" private const val FIRST_RUN_PREF = "is-first-run" +private const val SEEN_ANDROID_14_WARNING_PREF = "seen-android-14-warning" private val isProbablyEmulator = Build.FINGERPRINT.startsWith("generic") @@ -96,6 +97,17 @@ class HttpToolkitApplication : Application() { } } + /** + * Check if the Android 14 warning has already been seen. This returns the value, + * and sets it to true if it was not already, so this will only return 'false' + * the first time it is ever called. + */ + fun popAndroid14WarningState(): Boolean { + val hasSeenWarning = prefs.getBoolean(SEEN_ANDROID_14_WARNING_PREF, false) + prefs.edit().putBoolean(SEEN_ANDROID_14_WARNING_PREF, true).apply() + return hasSeenWarning + } + /** * Grab any first run params, drop them for future usage, and return them. * This will return first-run params at most once (per install). diff --git a/app/src/main/java/tech/httptoolkit/android/MainActivity.kt b/app/src/main/java/tech/httptoolkit/android/MainActivity.kt index 074530e..e5d67dc 100644 --- a/app/src/main/java/tech/httptoolkit/android/MainActivity.kt +++ b/app/src/main/java/tech/httptoolkit/android/MainActivity.kt @@ -105,6 +105,17 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() { Log.i(TAG, "Main activity created") + if ( + // Should the real value later on + Build.VERSION.RELEASE == "14" || + Build.VERSION.RELEASE == "15" || // Reasonable guess for the future + // Or, while it's still in beta: + Build.VERSION.RELEASE_OR_CODENAME == "UpsideDownCake" + ) { + val hasSeenWarningAlready = app.popAndroid14WarningState() + if (!hasSeenWarningAlready) showAndroid14Alert() + } + // Are we being opened by an intent? I.e. a barcode scan/URL elsewhere on the device if (intent != null) { onNewIntent(intent) @@ -937,6 +948,22 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() { .show() } + private fun showAndroid14Alert() { + MaterialAlertDialogBuilder(this) + .setTitle("System interception is not available on Android 14+") + .setIcon(R.drawable.ic_exclamation_triangle) + .setMessage( + "Android 14 includes some changes which make system interception impossible." + + "\n\n" + + "This is a general issue that blocks system interception by HTTP Toolkit and all " + + "similar tools." + + "\n\n" + + "To use system interception, you will need to use Android 13 or older." + ) + .setNeutralButton("Ok") { _, _ -> } + .show() + } + private fun tryStartActivity(intent: Intent): Boolean { return try { startActivity(intent)