Clear error when permission is granted

This commit is contained in:
Mygod
2021-06-11 01:34:53 +08:00
parent edca8ed013
commit 282fc71814
2 changed files with 6 additions and 2 deletions

View File

@@ -109,6 +109,7 @@ class BluetoothTethering(context: Context, val stateListener: () -> Unit) :
private val receiver = broadcastReceiver { _, _ -> stateListener() }
fun ensureInit(context: Context) {
activeFailureCause = null
if (pan == null) try {
pan = pan(context, this)
} catch (e: ReflectiveOperationException) {

View File

@@ -297,11 +297,14 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
parent.viewLifecycleOwner.lifecycle.addObserver(this)
}
fun ensureInit(context: Context) = tethering.ensureInit(context)
fun ensureInit(context: Context) {
tethering.ensureInit(context)
onTetheringStarted() // force flush
}
override fun onResume(owner: LifecycleOwner) {
if (!BuildCompat.isAtLeastS() || parent.requireContext().checkSelfPermission(
Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
ensureInit(parent.requireContext())
tethering.ensureInit(parent.requireContext())
} else if (parent.shouldShowRequestPermissionRationale(Manifest.permission.BLUETOOTH_CONNECT)) {
parent.requestBluetooth.launch(Manifest.permission.BLUETOOTH_CONNECT)
}