Handle fallback Bluetooth starting

This commit is contained in:
Mygod
2022-07-11 17:13:48 -04:00
parent ac452813aa
commit b5d7e64bc4
3 changed files with 5 additions and 4 deletions

View File

@@ -110,12 +110,13 @@ class BluetoothTethering(context: Context, private val adapter: BluetoothAdapter
*/
@SuppressLint("MissingPermission")
@RequiresApi(24)
fun start(callback: TetheringManager.StartTetheringCallback) {
fun start(callback: TetheringManager.StartTetheringCallback, context: Context) {
if (pendingCallback == null) try {
if (adapter.state == BluetoothAdapter.STATE_OFF) {
registerBluetoothStateListener(BluetoothTethering)
pendingCallback = callback
adapter.enable()
@Suppress("DEPRECATION")
if (!adapter.enable()) context.startActivity(Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE))
} else TetheringManager.startTethering(TetheringManager.TETHERING_BLUETOOTH, true, callback)
} catch (e: SecurityException) {
SmartSnackbar.make(e.readableMessage).shortToast().show()

View File

@@ -334,7 +334,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
if (tethering.active == null) tethering.activeFailureCause?.readableMessage else null,
baseError).joinToString("\n")
override fun start() = tethering.start(this)
override fun start() = tethering.start(this, parent.requireContext())
override fun stop() {
tethering.stop(this::onException)
onTetheringStarted() // force flush state

View File

@@ -153,7 +153,7 @@ sealed class TetheringTileService : IpNeighbourMonitoringTileService(), Tetherin
override val labelString get() = R.string.tethering_manage_bluetooth
override val tetherType get() = TetherType.BLUETOOTH
override fun start() = tethering!!.start(this)
override fun start() = tethering!!.start(this, this)
override fun stop() {
tethering!!.stop(this::onException)
onTetheringStarted() // force flush state