disable tile when off

This commit is contained in:
lucky 2022-01-14 10:50:38 +03:00
parent de385837c1
commit 218012b8fc
2 changed files with 8 additions and 3 deletions

View File

@ -86,6 +86,7 @@
android:icon="@android:drawable/ic_lock_lock"
android:label="@string/tile_label"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
android:enabled="false"
android:exported="true">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />

View File

@ -169,6 +169,7 @@ open class MainActivity : AppCompatActivity() {
}
prefs.isServiceEnabled = true
setCodeReceiverState(prefs.isCodeEnabled)
setTileState(true)
shortcut.push()
}
@ -184,6 +185,7 @@ open class MainActivity : AppCompatActivity() {
prefs.isServiceEnabled = false
setCodeReceiverState(false)
setWipeOnInactivityComponentsState(false)
setTileState(false)
shortcut.remove()
admin.remove()
}
@ -191,11 +193,13 @@ open class MainActivity : AppCompatActivity() {
private fun requestAdmin() = requestAdminPolicy.launch(admin.makeRequestIntent())
private fun makeCode(): String = UUID.randomUUID().toString()
private fun setCodeReceiverState(value: Boolean) =
setReceiverState(CodeReceiver::class.java, value)
setComponentState(CodeReceiver::class.java, value)
private fun setRestartReceiverState(value: Boolean) =
setReceiverState(RestartReceiver::class.java, value)
setComponentState(RestartReceiver::class.java, value)
private fun setTileState(value: Boolean) =
setComponentState(QSTileService::class.java, value)
private fun setReceiverState(cls: Class<*>, value: Boolean) {
private fun setComponentState(cls: Class<*>, value: Boolean) {
packageManager.setComponentEnabledSetting(
ComponentName(this, cls),
if (value) PackageManager.COMPONENT_ENABLED_STATE_ENABLED else