Skip to content

Commit

Permalink
Show a warning about system interception on Android 14+
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Aug 8, 2023
1 parent 42fbbee commit 7c69057
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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).
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/tech/httptoolkit/android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

3 comments on commit 7c69057

@kasnder
Copy link

@kasnder kasnder commented on 7c69057 Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite a big change by Google.. Do you happen to have a link with more information about this change? I checked Google's change docs, but didn't see any additional information there.

@pimterry
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet! It is indeed going to be quite the problem: basically the changes related to https://www.esper.io/blog/android-14-updatable-certificates also mean all known techniques for modifying the certificate store no longer work, and every obvious translation of them that I've tried is also non-functional.

Technically Android 14 is still in beta for now, so this could change before the final release, but I haven't seen any indication of that. I'm currently writing up the details to publish about this more widely - I'll share those via httptoolkit.com/blog/ once that's done, so you can subscribe there to read that when it's available.

If you have any info on this yourself, or any suggestions at all, do get in touch at tim @ httptoolkit.com, I'm definitely very interested in too.

@kasnder
Copy link

@kasnder kasnder commented on 7c69057 Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! really interesting, and indeed problematic.. i'll discuss this with a few colleagues, and see if they have ideas on working around this.

Please sign in to comment.