Propagate Bluetooth error message out to UI
This commit is contained in:
@@ -84,14 +84,17 @@ class BluetoothTethering(context: Context, val stateListener: (Int) -> Unit) :
|
||||
}
|
||||
|
||||
private var pan: BluetoothProfile? = null
|
||||
var activeFailureCause: Throwable? = null
|
||||
/**
|
||||
* Based on: https://android.googlesource.com/platform/packages/apps/Settings/+/78d5efd/src/com/android/settings/TetherSettings.java
|
||||
*/
|
||||
val active: Boolean? get() {
|
||||
activeFailureCause = null
|
||||
val pan = pan ?: return null
|
||||
return BluetoothAdapter.getDefaultAdapter()?.state == BluetoothAdapter.STATE_ON && try {
|
||||
isTetheringOn.invoke(pan) as Boolean
|
||||
} catch (e: InvocationTargetException) {
|
||||
activeFailureCause = e
|
||||
if (e.cause is SecurityException && BuildCompat.isAtLeastR()) Timber.d(e) else Timber.w(e)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -109,9 +109,11 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
|
||||
return e.readableMessage
|
||||
})
|
||||
}
|
||||
protected open fun makeErrorMessage(errored: List<String>): CharSequence = errored
|
||||
.filter { TetherType.ofInterface(it) == tetherType }
|
||||
.joinToString("\n") { "$it: ${getErrorMessage(it)}" }
|
||||
fun updateErrorMessage(errored: List<String>) {
|
||||
data.text = errored.filter { TetherType.ofInterface(it) == tetherType }
|
||||
.joinToString("\n") { "$it: ${getErrorMessage(it)}" }
|
||||
data.text = makeErrorMessage(errored)
|
||||
data.notifyChange()
|
||||
}
|
||||
|
||||
@@ -149,6 +151,9 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
|
||||
override val isStarted get() = tethering.active == true
|
||||
|
||||
override fun onException() = ManageBar.start(parent.context ?: app)
|
||||
override fun makeErrorMessage(errored: List<String>) = listOfNotNull(
|
||||
if (tethering.active == null) tethering.activeFailureCause?.readableMessage else null,
|
||||
super.makeErrorMessage(errored).let { if (it.isEmpty()) null else it }).joinToString("\n")
|
||||
|
||||
override fun start() = BluetoothTethering.start(this)
|
||||
override fun stop() {
|
||||
|
||||
Reference in New Issue
Block a user