From 75d0df19c3cf79781df93979eeff725471022eb8 Mon Sep 17 00:00:00 2001 From: Seb3thehacker Date: Fri, 23 Oct 2026 23:08:09 -0700 Subject: [PATCH] wireless: count a car as asked about only once the driver answers Android's dialog A dialog that never showed, or was swiped away, used to stop Gearslip from ever asking again. --- .../gearslip/GearslipActivity.kt | 2 +- .../gearslip/wireless/WirelessAuto.kt | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/GearslipActivity.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/GearslipActivity.kt index ca15dd6..56f9e23 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/GearslipActivity.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/GearslipActivity.kt @@ -125,7 +125,7 @@ class GearslipActivity : ComponentActivity(), Projection { val address = approvingCar ?: return@registerForActivityResult approvingCar = null if (result.resultCode == RESULT_OK) app.seb3thehacker.gearslip.wireless.WirelessAuto.approved(this, address) - else GearslipLog.w("auto-connect: declined in Android's dialog") + else app.seb3thehacker.gearslip.wireless.WirelessAuto.declined(this, address) } /** Setting Gearslip as the phone's caller ID and spam app - what lets it decline a ringing call. */ diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/wireless/WirelessAuto.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/wireless/WirelessAuto.kt index 2bef63a..824138a 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/wireless/WirelessAuto.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/wireless/WirelessAuto.kt @@ -37,7 +37,9 @@ object WirelessAuto { /** * Called whenever the driver connects to [device] by hand. Asks Android once per car; a car - * already approved only has its presence watched again, in case Android forgot. + * already approved only has its presence watched again, in case Android forgot. A car only + * counts as asked once the driver has answered the dialog: if it never showed, the next + * connection by hand asks again. */ @SuppressLint("MissingPermission") fun connectedByHand(context: Context, device: BluetoothDevice) { @@ -47,9 +49,10 @@ object WirelessAuto { watch(context, address) return } - val prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE) - if (prefs.getBoolean(address, false)) return - prefs.edit().putBoolean(address, true).apply() + if (context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getBoolean(address, false)) { + log.i("auto-connect: already asked about this car and it was declined; connect by hand") + return + } val request = AssociationRequest.Builder() .addDeviceFilter(BluetoothDeviceFilter.Builder().setAddress(address).build()) @@ -72,9 +75,20 @@ object WirelessAuto { /** The driver allowed it in Android's dialog. */ fun approved(context: Context, address: String) { log.i("auto-connect: allowed") + answered(context, address) watch(context, address) } + /** The driver said no in Android's dialog: this car isn't asked about again. */ + fun declined(context: Context, address: String) { + log.w("auto-connect: declined in Android's dialog") + answered(context, address) + } + + private fun answered(context: Context, address: String) { + context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putBoolean(address, true).apply() + } + @SuppressLint("MissingPermission") private fun watch(context: Context, address: String) { val manager = context.getSystemService(CompanionDeviceManager::class.java) ?: return