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