Do not store redundant copy of bluetooth adapter
This commit is contained in:
@@ -19,19 +19,19 @@ class BluetoothTethering(context: Context) : BluetoothProfile.ServiceListener, A
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val adapter = BluetoothAdapter.getDefaultAdapter()
|
|
||||||
private var pan: BluetoothProfile? = null
|
private var pan: BluetoothProfile? = 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() {
|
||||||
val pan = pan ?: return null
|
val pan = pan ?: return null
|
||||||
return adapter?.state == BluetoothAdapter.STATE_ON && isTetheringOn.invoke(pan) as Boolean
|
return BluetoothAdapter.getDefaultAdapter()?.state == BluetoothAdapter.STATE_ON &&
|
||||||
|
isTetheringOn.invoke(pan) as Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
try {
|
try {
|
||||||
adapter?.getProfileProxy(context, this, PAN)
|
BluetoothAdapter.getDefaultAdapter()?.getProfileProxy(context, this, PAN)
|
||||||
} catch (e: SecurityException) {
|
} catch (e: SecurityException) {
|
||||||
Timber.w(e)
|
Timber.w(e)
|
||||||
SmartSnackbar.make(e).show()
|
SmartSnackbar.make(e).show()
|
||||||
@@ -45,7 +45,7 @@ class BluetoothTethering(context: Context) : BluetoothProfile.ServiceListener, A
|
|||||||
pan = proxy
|
pan = proxy
|
||||||
}
|
}
|
||||||
override fun close() {
|
override fun close() {
|
||||||
adapter?.closeProfileProxy(PAN, pan)
|
BluetoothAdapter.getDefaultAdapter()?.closeProfileProxy(PAN, pan)
|
||||||
pan = null
|
pan = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user