Skip to content

Commit 78d8d87

Browse files
committed
More accurately track received setup intents
1 parent a830ec0 commit 78d8d87

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
141141
override fun onNewIntent(intent: Intent) {
142142
super.onNewIntent(intent)
143143

144-
app.trackEvent("Setup", "action-view")
145-
146144
// RC intents are intents that have passed the RC permission requirement in the manifest.
147145
// Implicit intents with the matching actions will always use the RC activity, this check
148146
// protects against explicit intents targeting MainActivity. RC intents are known to be
@@ -153,6 +151,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
153151
// ACTION_VIEW means that somebody had the app installed, and scanned the barcode with
154152
// a separate barcode app anyway (or opened the QR code URL in a browser)
155153
intent.action == Intent.ACTION_VIEW -> {
154+
app.trackEvent("Setup", "action-view")
156155
if (app.lastProxy != null && isVpnConfigured()) {
157156
Log.i(TAG, "Showing prompt for ACTION_VIEW intent")
158157

@@ -184,14 +183,17 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
184183
// RC setup API, used by ADB to enable/disable without prompts.
185184
// Permission required, checked for via activity-alias in the manifest
186185
isRCIntent && intent.action == ACTIVATE_INTENT -> {
186+
app.trackEvent("Setup", "rc-activate")
187187
launch { connectToVpnFromUrl(intent.data!!) }
188188
}
189189
isRCIntent && intent.action == DEACTIVATE_INTENT -> {
190+
app.trackEvent("Setup", "rc-deactivate")
190191
disconnect()
191192
}
192193

193194
intent.action == "android.intent.action.MAIN" -> {
194195
// The app is being opened - nothing to do here
196+
app.trackEvent("Setup", "ui-opened")
195197
}
196198

197199
else -> Log.w(TAG, "Ignoring unknown intent. Action ${
@@ -505,7 +507,8 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
505507
}
506508

507509
private fun ensureCertificateTrusted(proxyConfig: ProxyConfig) {
508-
if (whereIsCertTrusted(proxyConfig) == null) {
510+
val existingTrust = whereIsCertTrusted(proxyConfig)
511+
if (existingTrust == null) {
509512
app.trackEvent("Setup", "installing-cert")
510513
Log.i(TAG, "Certificate not trusted, prompting to install")
511514

@@ -517,7 +520,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
517520
certInstallIntent.putExtra(EXTRA_CERTIFICATE, proxyConfig.certificate.encoded)
518521
startActivityForResult(certInstallIntent, INSTALL_CERT_REQUEST)
519522
} else {
520-
app.trackEvent("Setup", "existing-cert")
523+
app.trackEvent("Setup", "existing-$existingTrust-cert")
521524
Log.i(TAG, "Certificate already trusted, continuing")
522525
onActivityResult(INSTALL_CERT_REQUEST, RESULT_OK, null)
523526
}

0 commit comments

Comments
 (0)