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
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. */
@@ -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