Skip to content

Commit 7c69057

Browse files
committed
Show a warning about system interception on Android 14+
1 parent 42fbbee commit 7c69057

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

app/src/main/java/tech/httptoolkit/android/HttpToolkitApplication.kt

+12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ private const val VPN_START_TIME_PREF = "vpn-start-time"
2626
private const val LAST_UPDATE_CHECK_TIME_PREF = "update-check-time"
2727
private const val APP_CRASHED_PREF = "app-crashed"
2828
private const val FIRST_RUN_PREF = "is-first-run"
29+
private const val SEEN_ANDROID_14_WARNING_PREF = "seen-android-14-warning"
2930

3031
private val isProbablyEmulator =
3132
Build.FINGERPRINT.startsWith("generic")
@@ -96,6 +97,17 @@ class HttpToolkitApplication : Application() {
9697
}
9798
}
9899

100+
/**
101+
* Check if the Android 14 warning has already been seen. This returns the value,
102+
* and sets it to true if it was not already, so this will only return 'false'
103+
* the first time it is ever called.
104+
*/
105+
fun popAndroid14WarningState(): Boolean {
106+
val hasSeenWarning = prefs.getBoolean(SEEN_ANDROID_14_WARNING_PREF, false)
107+
prefs.edit().putBoolean(SEEN_ANDROID_14_WARNING_PREF, true).apply()
108+
return hasSeenWarning
109+
}
110+
99111
/**
100112
* Grab any first run params, drop them for future usage, and return them.
101113
* This will return first-run params at most once (per install).

app/src/main/java/tech/httptoolkit/android/MainActivity.kt

+27
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
105105

106106
Log.i(TAG, "Main activity created")
107107

108+
if (
109+
// Should the real value later on
110+
Build.VERSION.RELEASE == "14" ||
111+
Build.VERSION.RELEASE == "15" || // Reasonable guess for the future
112+
// Or, while it's still in beta:
113+
Build.VERSION.RELEASE_OR_CODENAME == "UpsideDownCake"
114+
) {
115+
val hasSeenWarningAlready = app.popAndroid14WarningState()
116+
if (!hasSeenWarningAlready) showAndroid14Alert()
117+
}
118+
108119
// Are we being opened by an intent? I.e. a barcode scan/URL elsewhere on the device
109120
if (intent != null) {
110121
onNewIntent(intent)
@@ -937,6 +948,22 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
937948
.show()
938949
}
939950

951+
private fun showAndroid14Alert() {
952+
MaterialAlertDialogBuilder(this)
953+
.setTitle("System interception is not available on Android 14+")
954+
.setIcon(R.drawable.ic_exclamation_triangle)
955+
.setMessage(
956+
"Android 14 includes some changes which make system interception impossible." +
957+
"\n\n" +
958+
"This is a general issue that blocks system interception by HTTP Toolkit and all " +
959+
"similar tools." +
960+
"\n\n" +
961+
"To use system interception, you will need to use Android 13 or older."
962+
)
963+
.setNeutralButton("Ok") { _, _ -> }
964+
.show()
965+
}
966+
940967
private fun tryStartActivity(intent: Intent): Boolean {
941968
return try {
942969
startActivity(intent)

0 commit comments

Comments
 (0)