Commit 223968ac authored by Mygod's avatar Mygod

Improve quick settings tile reliability

Android apparently can decide to kill TileService when there are too many. Therefore, let's check if our service is connected before doing anything.

Source: https://android.googlesource.com/platform/frameworks/base/+/e1d13c9/packages/SystemUI/src/com/android/systemui/qs/external/TileServices.java#52
parent 2224bd3b
......@@ -39,6 +39,7 @@ class TileService : BaseTileService(), ShadowsocksConnection.Interface {
private val iconBusy by lazy { Icon.createWithResource(this, R.drawable.ic_service_busy) }
private val iconConnected by lazy { Icon.createWithResource(this, R.drawable.ic_service_active) }
private val keyguard by lazy { getSystemService<KeyguardManager>()!! }
private var tapPending = false
override val serviceCallback: IShadowsocksServiceCallback.Stub by lazy {
@RequiresApi(24)
......@@ -69,16 +70,21 @@ class TileService : BaseTileService(), ShadowsocksConnection.Interface {
}
}
override fun onServiceConnected(service: IShadowsocksService) =
override fun onServiceConnected(service: IShadowsocksService) {
serviceCallback.stateChanged(service.state, service.profileName, null)
if (tapPending) {
tapPending = false
onClick()
}
}
override fun onStartListening() {
super.onStartListening()
connection.connect()
}
override fun onStopListening() {
super.onStopListening()
connection.disconnect()
super.onStopListening()
}
override fun onClick() {
......@@ -86,8 +92,8 @@ class TileService : BaseTileService(), ShadowsocksConnection.Interface {
}
private fun toggle() {
val service = connection.service ?: return
when (service.state) {
val service = connection.service
if (service == null) tapPending = true else when (service.state) {
BaseService.STOPPED -> Core.startService()
BaseService.CONNECTED -> Core.stopService()
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment