Handle fallback Bluetooth starting
This commit is contained in:
@@ -110,12 +110,13 @@ class BluetoothTethering(context: Context, private val adapter: BluetoothAdapter
|
|||||||
*/
|
*/
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
@RequiresApi(24)
|
@RequiresApi(24)
|
||||||
fun start(callback: TetheringManager.StartTetheringCallback) {
|
fun start(callback: TetheringManager.StartTetheringCallback, context: Context) {
|
||||||
if (pendingCallback == null) try {
|
if (pendingCallback == null) try {
|
||||||
if (adapter.state == BluetoothAdapter.STATE_OFF) {
|
if (adapter.state == BluetoothAdapter.STATE_OFF) {
|
||||||
registerBluetoothStateListener(BluetoothTethering)
|
registerBluetoothStateListener(BluetoothTethering)
|
||||||
pendingCallback = callback
|
pendingCallback = callback
|
||||||
adapter.enable()
|
@Suppress("DEPRECATION")
|
||||||
|
if (!adapter.enable()) context.startActivity(Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE))
|
||||||
} 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()
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
|
|||||||
if (tethering.active == null) tethering.activeFailureCause?.readableMessage else null,
|
if (tethering.active == null) tethering.activeFailureCause?.readableMessage else null,
|
||||||
baseError).joinToString("\n")
|
baseError).joinToString("\n")
|
||||||
|
|
||||||
override fun start() = tethering.start(this)
|
override fun start() = tethering.start(this, parent.requireContext())
|
||||||
override fun stop() {
|
override fun stop() {
|
||||||
tethering.stop(this::onException)
|
tethering.stop(this::onException)
|
||||||
onTetheringStarted() // force flush state
|
onTetheringStarted() // force flush state
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ sealed class TetheringTileService : IpNeighbourMonitoringTileService(), Tetherin
|
|||||||
override val labelString get() = R.string.tethering_manage_bluetooth
|
override val labelString get() = R.string.tethering_manage_bluetooth
|
||||||
override val tetherType get() = TetherType.BLUETOOTH
|
override val tetherType get() = TetherType.BLUETOOTH
|
||||||
|
|
||||||
override fun start() = tethering!!.start(this)
|
override fun start() = tethering!!.start(this, this)
|
||||||
override fun stop() {
|
override fun stop() {
|
||||||
tethering!!.stop(this::onException)
|
tethering!!.stop(this::onException)
|
||||||
onTetheringStarted() // force flush state
|
onTetheringStarted() // force flush state
|
||||||
|
|||||||
Reference in New Issue
Block a user