Do not update tile state when unsure
This commit is contained in:
@@ -24,9 +24,9 @@ class BluetoothTethering(context: Context) : BluetoothProfile.ServiceListener, A
|
|||||||
/**
|
/**
|
||||||
* 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
|
val pan = pan ?: return null
|
||||||
return adapter?.state == BluetoothAdapter.STATE_ON && pan != null && isTetheringOn.invoke(pan) as Boolean
|
return adapter?.state == BluetoothAdapter.STATE_ON && isTetheringOn.invoke(pan) as Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class LocalOnlyHotspotTileService : TetherListeningTileService() {
|
|||||||
|
|
||||||
override fun updateTile() {
|
override fun updateTile() {
|
||||||
qsTile?.run {
|
qsTile?.run {
|
||||||
state = if (binder?.iface == null) Tile.STATE_INACTIVE else Tile.STATE_ACTIVE
|
state = if ((binder ?: return).iface == null) Tile.STATE_INACTIVE else Tile.STATE_ACTIVE
|
||||||
icon = tile
|
icon = tile
|
||||||
label = getText(R.string.tethering_temp_hotspot)
|
label = getText(R.string.tethering_temp_hotspot)
|
||||||
updateTile()
|
updateTile()
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class RepeaterTileService : KillableTileService() {
|
|||||||
|
|
||||||
private fun updateTile(group: WifiP2pGroup? = binder?.group) {
|
private fun updateTile(group: WifiP2pGroup? = binder?.group) {
|
||||||
qsTile?.run {
|
qsTile?.run {
|
||||||
when (binder?.service?.status) {
|
when ((binder ?: return).service.status) {
|
||||||
RepeaterService.Status.IDLE -> {
|
RepeaterService.Status.IDLE -> {
|
||||||
state = Tile.STATE_INACTIVE
|
state = Tile.STATE_INACTIVE
|
||||||
label = getText(R.string.title_repeater)
|
label = getText(R.string.title_repeater)
|
||||||
@@ -66,7 +66,7 @@ class RepeaterTileService : KillableTileService() {
|
|||||||
state = Tile.STATE_ACTIVE
|
state = Tile.STATE_ACTIVE
|
||||||
label = group?.networkName
|
label = group?.networkName
|
||||||
}
|
}
|
||||||
else -> { // STARTING, null or DESTROYED, which should never occur
|
else -> { // STARTING or DESTROYED, which should never occur
|
||||||
state = Tile.STATE_UNAVAILABLE
|
state = Tile.STATE_UNAVAILABLE
|
||||||
label = getText(R.string.title_repeater)
|
label = getText(R.string.title_repeater)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ abstract class TetherListeningTileService : KillableTileService() {
|
|||||||
|
|
||||||
override fun onStartListening() {
|
override fun onStartListening() {
|
||||||
super.onStartListening()
|
super.onStartListening()
|
||||||
registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))
|
tethered = TetheringManager.getTetheredIfaces(registerReceiver(
|
||||||
|
receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))?.extras ?: return)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStopListening() {
|
override fun onStopListening() {
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
|
|||||||
override val title get() = parent.getString(R.string.tethering_manage_bluetooth)
|
override val title get() = parent.getString(R.string.tethering_manage_bluetooth)
|
||||||
override val tetherType get() = TetherType.BLUETOOTH
|
override val tetherType get() = TetherType.BLUETOOTH
|
||||||
override val type get() = VIEW_TYPE_BLUETOOTH
|
override val type get() = VIEW_TYPE_BLUETOOTH
|
||||||
override val isStarted get() = tethering.active
|
override val isStarted get() = tethering.active == true
|
||||||
|
|
||||||
override fun start() = TetheringManager.start(TetheringManager.TETHERING_BLUETOOTH, true, this)
|
override fun start() = TetheringManager.start(TetheringManager.TETHERING_BLUETOOTH, true, this)
|
||||||
override fun stop() {
|
override fun stop() {
|
||||||
|
|||||||
@@ -61,8 +61,9 @@ sealed class TetheringTileService : TetherListeningTileService(), TetheringManag
|
|||||||
state = Tile.STATE_INACTIVE
|
state = Tile.STATE_INACTIVE
|
||||||
icon = tileOff
|
icon = tileOff
|
||||||
} else {
|
} else {
|
||||||
|
val binder = binder ?: return
|
||||||
state = Tile.STATE_ACTIVE
|
state = Tile.STATE_ACTIVE
|
||||||
icon = if (interested.all { binder?.isActive(it) == true }) tileOn else tileOff
|
icon = if (interested.all { binder.isActive(it) }) tileOn else tileOff
|
||||||
}
|
}
|
||||||
label = getText(labelString)
|
label = getText(labelString)
|
||||||
updateTile()
|
updateTile()
|
||||||
@@ -141,29 +142,37 @@ sealed class TetheringTileService : TetherListeningTileService(), TetheringManag
|
|||||||
|
|
||||||
override fun updateTile() {
|
override fun updateTile() {
|
||||||
qsTile?.run {
|
qsTile?.run {
|
||||||
if (tethering?.active == true) {
|
when (tethering?.active) {
|
||||||
state = Tile.STATE_ACTIVE
|
true -> {
|
||||||
val interested = interested
|
val binder = binder ?: return
|
||||||
icon = if (interested.isNotEmpty() && interested.all { binder?.isActive(it) == true })
|
state = Tile.STATE_ACTIVE
|
||||||
tileOn else tileOff
|
val interested = interested
|
||||||
} else {
|
icon = if (interested.isNotEmpty() && interested.all { binder.isActive(it) }) tileOn else tileOff
|
||||||
state = Tile.STATE_INACTIVE
|
}
|
||||||
icon = tileOff
|
false -> {
|
||||||
|
state = Tile.STATE_INACTIVE
|
||||||
|
icon = tileOff
|
||||||
|
}
|
||||||
|
null -> return
|
||||||
}
|
}
|
||||||
label = getText(labelString)
|
label = getText(labelString)
|
||||||
updateTile()
|
updateTile()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClick() = if (tethering?.active == true) {
|
override fun onClick() = when (tethering?.active) {
|
||||||
val binder = binder
|
true -> {
|
||||||
if (binder == null) tapPending = true else {
|
val binder = binder
|
||||||
val inactive = interested.filter { !binder.isActive(it) }
|
if (binder == null) tapPending = true else {
|
||||||
if (inactive.isEmpty()) safeInvoker { stop() }
|
val inactive = interested.filter { !binder.isActive(it) }
|
||||||
else ContextCompat.startForegroundService(this, Intent(this, TetheringService::class.java)
|
if (inactive.isEmpty()) safeInvoker { stop() }
|
||||||
.putExtra(TetheringService.EXTRA_ADD_INTERFACES, inactive.toTypedArray()))
|
else ContextCompat.startForegroundService(this, Intent(this, TetheringService::class.java)
|
||||||
|
.putExtra(TetheringService.EXTRA_ADD_INTERFACES, inactive.toTypedArray()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else safeInvoker { start() }
|
false -> safeInvoker { start() }
|
||||||
|
else -> tapPending = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
|
|||||||
Reference in New Issue
Block a user