Skip to content

Commit

Permalink
Fix shizuku permission issue
Browse files Browse the repository at this point in the history
Check if shizuku binder is alive and subsequently check for permission if so. This fixes the issue with changing installer type
  • Loading branch information
Iamlooker committed Sep 22, 2023
1 parent 2c6c2e5 commit 140ab61
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ class ShizukuPermissionHandler(
Shizuku.removeBinderReceivedListener(listener)
Shizuku.removeBinderDeadListener(deadListener)
}
}.flowOn(Dispatchers.Default).conflate()
}.flowOn(Dispatchers.Default).distinctUntilChanged().conflate()

private val isGranted: Flow<Boolean> = callbackFlow {
send(false)
val isGranted: Flow<Boolean> = callbackFlow {
if (Shizuku.pingBinder()) {
send(Shizuku.checkSelfPermission() == PackageManager.PERMISSION_GRANTED)
} else {
send(false)
}
val listener = Shizuku.OnRequestPermissionResultListener { requestCode, grantResult ->
if (requestCode == SHIZUKU_PERMISSION_REQUEST_CODE) {
trySend(grantResult == PackageManager.PERMISSION_GRANTED)
Expand All @@ -43,7 +47,7 @@ class ShizukuPermissionHandler(
awaitClose {
Shizuku.removeRequestPermissionResultListener(listener)
}
}.flowOn(Dispatchers.Default).conflate()
}.flowOn(Dispatchers.Default).distinctUntilChanged().conflate()

fun requestPermission() {
if (Shizuku.shouldShowRequestPermissionRationale()) {
Expand All @@ -57,7 +61,7 @@ class ShizukuPermissionHandler(
isGranted
) { isInstalled, isAlive, isGranted ->
State(isGranted, isAlive, isInstalled)
}
}.distinctUntilChanged()

companion object {
private const val SHIZUKU_PERMISSION_REQUEST_CODE = 87263
Expand Down

0 comments on commit 140ab61

Please sign in to comment.