Propagate Bluetooth error message out to UI

This commit is contained in:
Mygod
2020-05-29 18:23:39 -04:00
parent 8a04abd1cf
commit 9686645c03
2 changed files with 10 additions and 2 deletions

View File

@@ -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
}