mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-13 13:26:43 +02:00
No delay when already has permission
This commit is contained in:
@ -30,19 +30,20 @@ class MainActivity: FlutterActivity() {
|
||||
private var installersChannel: MethodChannel? = null
|
||||
private val SHIZUKU_PERMISSION_REQUEST_CODE = (10..200).random()
|
||||
|
||||
private fun shizukuCheckPermission() {
|
||||
private fun shizukuCheckPermission(result: Result) {
|
||||
try {
|
||||
if (Shizuku.isPreV11()) { // Unsupported
|
||||
installersChannel!!.invokeMethod("resPermShizuku", mapOf("res" to -1))
|
||||
result.success(-1)
|
||||
} else if (Shizuku.checkSelfPermission() == PackageManager.PERMISSION_GRANTED) {
|
||||
installersChannel!!.invokeMethod("resPermShizuku", mapOf("res" to 1))
|
||||
result.success(1)
|
||||
} else if (Shizuku.shouldShowRequestPermissionRationale()) { // Deny and don't ask again
|
||||
installersChannel!!.invokeMethod("resPermShizuku", mapOf("res" to 0))
|
||||
result.success(0)
|
||||
} else {
|
||||
Shizuku.requestPermission(SHIZUKU_PERMISSION_REQUEST_CODE)
|
||||
result.success(-2)
|
||||
}
|
||||
} catch (_: Exception) { // If shizuku not running
|
||||
installersChannel!!.invokeMethod("resPermShizuku", mapOf("res" to -1))
|
||||
result.success(-1)
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,8 +151,7 @@ class MainActivity: FlutterActivity() {
|
||||
installersChannel!!.setMethodCallHandler {
|
||||
call, result ->
|
||||
if (call.method == "checkPermissionShizuku") {
|
||||
shizukuCheckPermission()
|
||||
result.success(0)
|
||||
shizukuCheckPermission(result)
|
||||
} else if (call.method == "checkPermissionRoot") {
|
||||
rootCheckPermission(result)
|
||||
} else if (call.method == "installWithShizuku") {
|
||||
|
@ -7,7 +7,7 @@ class Installers {
|
||||
static int _resPermShizuku = -2; // not set
|
||||
|
||||
static Future waitWhile(bool Function() test,
|
||||
[Duration pollInterval = const Duration(milliseconds: 100)]) {
|
||||
[Duration pollInterval = const Duration(milliseconds: 250)]) {
|
||||
var completer = Completer();
|
||||
check() {
|
||||
if (test()) {
|
||||
@ -31,10 +31,12 @@ class Installers {
|
||||
_channel.setMethodCallHandler(handleCalls);
|
||||
_callbacksApplied = true;
|
||||
}
|
||||
await _channel.invokeMethod('checkPermissionShizuku');
|
||||
int res = await _channel.invokeMethod('checkPermissionShizuku');
|
||||
if(res == -2) {
|
||||
await waitWhile(() => _resPermShizuku == -2);
|
||||
int res = _resPermShizuku;
|
||||
res = _resPermShizuku;
|
||||
_resPermShizuku = -2;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user