Reset pendingCallback on failure

This commit is contained in:
Mygod
2021-06-11 01:54:22 +08:00
parent 54c9ae0cec
commit 6f81f8a6ff

View File

@@ -125,8 +125,7 @@ class BluetoothTethering(context: Context, val stateListener: () -> Unit) :
*/ */
@RequiresApi(24) @RequiresApi(24)
fun start(callback: TetheringManager.StartTetheringCallback) { fun start(callback: TetheringManager.StartTetheringCallback) {
if (pendingCallback != null) return if (pendingCallback == null) try {
try {
if (adapter?.state == BluetoothAdapter.STATE_OFF) { if (adapter?.state == BluetoothAdapter.STATE_OFF) {
registerBluetoothStateListener(BluetoothTethering) registerBluetoothStateListener(BluetoothTethering)
pendingCallback = callback pendingCallback = callback
@@ -134,6 +133,7 @@ class BluetoothTethering(context: Context, val stateListener: () -> Unit) :
} else TetheringManager.startTethering(TetheringManager.TETHERING_BLUETOOTH, true, callback) } else TetheringManager.startTethering(TetheringManager.TETHERING_BLUETOOTH, true, callback)
} catch (e: SecurityException) { } catch (e: SecurityException) {
SmartSnackbar.make(e.readableMessage).shortToast().show() SmartSnackbar.make(e.readableMessage).shortToast().show()
pendingCallback = null
} }
} }
@RequiresApi(24) @RequiresApi(24)