add toast when admin disabled from settings and wasted is on

This commit is contained in:
lucky 2022-01-07 07:33:13 +03:00
parent e25b9351de
commit 70d516ed64
2 changed files with 14 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import android.os.UserHandle import android.os.UserHandle
import android.widget.Toast
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
class DeviceAdminReceiver : DeviceAdminReceiver() { class DeviceAdminReceiver : DeviceAdminReceiver() {
@ -20,6 +21,17 @@ class DeviceAdminReceiver : DeviceAdminReceiver() {
onPasswordFailedInternal(context) onPasswordFailedInternal(context)
} }
override fun onDisabled(context: Context, intent: Intent) {
super.onDisabled(context, intent)
if (Preferences(context).isServiceEnabled) {
Toast.makeText(
context,
context.getString(R.string.service_unavailable_popup),
Toast.LENGTH_SHORT,
).show()
}
}
private fun onPasswordFailedInternal(ctx: Context) { private fun onPasswordFailedInternal(ctx: Context) {
val prefs = Preferences(ctx) val prefs = Preferences(ctx)
if (!prefs.isServiceEnabled || prefs.maxFailedPasswordAttempts == 0) return if (!prefs.isServiceEnabled || prefs.maxFailedPasswordAttempts == 0) return

View File

@ -111,10 +111,10 @@ open class MainActivity : AppCompatActivity() {
} }
private fun setOff() { private fun setOff() {
admin.remove() prefs.isServiceEnabled = false
setCodeReceiverState(this, false) setCodeReceiverState(this, false)
shortcut.remove() shortcut.remove()
prefs.isServiceEnabled = false admin.remove()
} }
private fun requestAdmin() = requestAdminPolicy.launch(admin.makeRequestIntent()) private fun requestAdmin() = requestAdminPolicy.launch(admin.makeRequestIntent())