Commit 18de60f6 authored by LoveSy's avatar LoveSy Committed by John Wu

Fix NPE of `SuRequestViewModel`

countdown timer may have not initialized when backpressed
parent 18933591
...@@ -73,7 +73,7 @@ class SuRequestViewModel( ...@@ -73,7 +73,7 @@ class SuRequestViewModel(
val itemBinding = ItemBinding.of<String>(BR.item, R.layout.item_spinner) val itemBinding = ItemBinding.of<String>(BR.item, R.layout.item_spinner)
private val handler = SuRequestHandler(AppContext.packageManager, policyDB) private val handler = SuRequestHandler(AppContext.packageManager, policyDB)
private lateinit var timer: CountDownTimer private var timer: CountDownTimer? = null
fun grantPressed() { fun grantPressed() {
cancelTimer() cancelTimer()
...@@ -121,7 +121,7 @@ class SuRequestViewModel( ...@@ -121,7 +121,7 @@ class SuRequestViewModel(
} }
private fun respond(action: Int) { private fun respond(action: Int) {
timer.cancel() timer?.cancel()
val pos = selectedItemPosition val pos = selectedItemPosition
timeoutPrefs.edit().putInt(handler.policy.packageName, pos).apply() timeoutPrefs.edit().putInt(handler.policy.packageName, pos).apply()
...@@ -132,7 +132,7 @@ class SuRequestViewModel( ...@@ -132,7 +132,7 @@ class SuRequestViewModel(
} }
private fun cancelTimer() { private fun cancelTimer() {
timer.cancel() timer?.cancel()
denyText.seconds = 0 denyText.seconds = 0
} }
......
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