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.
This commit is contained in:
Seb3thehacker committed 2026-10-23 23:08:09 -07:00
1 parent 456dda897e
commit 75d0df19c3
2 files changed
+19 -5

No files matched your search

@@ -125,7 +125,7 @@ class GearslipActivity : ComponentActivity(), Projection {
val address = approvingCar ?: return@registerForActivityResult val address = approvingCar ?: return@registerForActivityResult
approvingCar = null approvingCar = null
if (result.resultCode == RESULT_OK) app.seb3thehacker.gearslip.wireless.WirelessAuto.approved(this, address) 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. */ /** Setting Gearslip as the phone's caller ID and spam app - what lets it decline a ringing call. */
@@ -37,7 +37,9 @@ object WirelessAuto {
/** /**
* Called whenever the driver connects to [device] by hand. Asks Android once per car; a car * 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") @SuppressLint("MissingPermission")
fun connectedByHand(context: Context, device: BluetoothDevice) { fun connectedByHand(context: Context, device: BluetoothDevice) {
@@ -47,9 +49,10 @@ object WirelessAuto {
watch(context, address) watch(context, address)
return return
} }
val prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE) if (context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getBoolean(address, false)) {
if (prefs.getBoolean(address, false)) return log.i("auto-connect: already asked about this car and it was declined; connect by hand")
prefs.edit().putBoolean(address, true).apply() return
}
val request = AssociationRequest.Builder() val request = AssociationRequest.Builder()
.addDeviceFilter(BluetoothDeviceFilter.Builder().setAddress(address).build()) .addDeviceFilter(BluetoothDeviceFilter.Builder().setAddress(address).build())
@@ -72,9 +75,20 @@ object WirelessAuto {
/** The driver allowed it in Android's dialog. */ /** The driver allowed it in Android's dialog. */
fun approved(context: Context, address: String) { fun approved(context: Context, address: String) {
log.i("auto-connect: allowed") log.i("auto-connect: allowed")
answered(context, address)
watch(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") @SuppressLint("MissingPermission")
private fun watch(context: Context, address: String) { private fun watch(context: Context, address: String) {
val manager = context.getSystemService(CompanionDeviceManager::class.java) ?: return val manager = context.getSystemService(CompanionDeviceManager::class.java) ?: return