@@ -562,7 +562,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
562
562
// required so this is just reshowing the instructions, or it was automated but that's not
563
563
// working for some reason, in which case manual setup is a best-effort fallback.
564
564
app.trackEvent(" Setup" , " cert-install-failed" )
565
- launch { promptToManuallyInstallCert(currentProxyConfig!! .certificate) }
565
+ launch { promptToManuallyInstallCert(currentProxyConfig!! .certificate, repeatPrompt = true ) }
566
566
} else {
567
567
Sentry .capture(" Non-OK result $resultCode for requestCode $requestCode " )
568
568
mainState = MainState .FAILED
@@ -660,30 +660,33 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
660
660
}
661
661
662
662
@RequiresApi(Build .VERSION_CODES .Q )
663
- private suspend fun promptToManuallyInstallCert (cert : Certificate ) {
664
- // Get ready to save the cert to downloads:
665
- val downloadsUri = MediaStore .Downloads .getContentUri(MediaStore .VOLUME_EXTERNAL_PRIMARY )
666
-
667
- val contentDetails = ContentValues ().apply {
668
- put(MediaStore .Downloads .DISPLAY_NAME , " HTTP Toolkit Certificate.crt" )
669
- put(MediaStore .Downloads .MIME_TYPE , " application/x-x509-ca-cert" )
670
- put(MediaStore .Downloads .IS_PENDING , 1 )
671
- }
663
+ private suspend fun promptToManuallyInstallCert (cert : Certificate , repeatPrompt : Boolean = false) {
664
+ if (! repeatPrompt) {
665
+ // Get ready to save the cert to downloads:
666
+ val downloadsUri =
667
+ MediaStore .Downloads .getContentUri(MediaStore .VOLUME_EXTERNAL_PRIMARY )
668
+
669
+ val contentDetails = ContentValues ().apply {
670
+ put(MediaStore .Downloads .DISPLAY_NAME , " HTTP Toolkit Certificate.crt" )
671
+ put(MediaStore .Downloads .MIME_TYPE , " application/x-x509-ca-cert" )
672
+ put(MediaStore .Downloads .IS_PENDING , 1 )
673
+ }
672
674
673
- val certUri = contentResolver.insert(downloadsUri, contentDetails)
674
- ? : throw RuntimeException (" Could not get download cert URI" )
675
+ val certUri = contentResolver.insert(downloadsUri, contentDetails)
676
+ ? : throw RuntimeException (" Could not get download cert URI" )
675
677
676
- // Write cert contents to a file:
677
- withContext(Dispatchers .IO ) {
678
- contentResolver.openFileDescriptor(certUri, " w" , null ).use { f ->
679
- ParcelFileDescriptor .AutoCloseOutputStream (f).write(cert.encoded)
678
+ // Write cert contents to a file:
679
+ withContext(Dispatchers .IO ) {
680
+ contentResolver.openFileDescriptor(certUri, " w" , null ).use { f ->
681
+ ParcelFileDescriptor .AutoCloseOutputStream (f).write(cert.encoded)
682
+ }
680
683
}
681
- }
682
684
683
- // All done, mark it as such:
684
- contentDetails.clear()
685
- contentDetails.put(MediaStore .Downloads .IS_PENDING , 0 )
686
- contentResolver.update(certUri, contentDetails, null , null )
685
+ // All done, mark it as such:
686
+ contentDetails.clear()
687
+ contentDetails.put(MediaStore .Downloads .IS_PENDING , 0 )
688
+ contentResolver.update(certUri, contentDetails, null , null )
689
+ }
687
690
688
691
withContext(Dispatchers .Main ) {
689
692
MaterialAlertDialogBuilder (this @MainActivity)
0 commit comments