Handle fallback Bluetooth starting
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user