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 var installersChannel: MethodChannel? = null
|
||||||
private val SHIZUKU_PERMISSION_REQUEST_CODE = (10..200).random()
|
private val SHIZUKU_PERMISSION_REQUEST_CODE = (10..200).random()
|
||||||
|
|
||||||
private fun shizukuCheckPermission() {
|
private fun shizukuCheckPermission(result: Result) {
|
||||||
try {
|
try {
|
||||||
if (Shizuku.isPreV11()) { // Unsupported
|
if (Shizuku.isPreV11()) { // Unsupported
|
||||||
installersChannel!!.invokeMethod("resPermShizuku", mapOf("res" to -1))
|
result.success(-1)
|
||||||
} else if (Shizuku.checkSelfPermission() == PackageManager.PERMISSION_GRANTED) {
|
} 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
|
} else if (Shizuku.shouldShowRequestPermissionRationale()) { // Deny and don't ask again
|
||||||
installersChannel!!.invokeMethod("resPermShizuku", mapOf("res" to 0))
|
result.success(0)
|
||||||
} else {
|
} else {
|
||||||
Shizuku.requestPermission(SHIZUKU_PERMISSION_REQUEST_CODE)
|
Shizuku.requestPermission(SHIZUKU_PERMISSION_REQUEST_CODE)
|
||||||
|
result.success(-2)
|
||||||
}
|
}
|
||||||
} catch (_: Exception) { // If shizuku not running
|
} 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 {
|
installersChannel!!.setMethodCallHandler {
|
||||||
call, result ->
|
call, result ->
|
||||||
if (call.method == "checkPermissionShizuku") {
|
if (call.method == "checkPermissionShizuku") {
|
||||||
shizukuCheckPermission()
|
shizukuCheckPermission(result)
|
||||||
result.success(0)
|
|
||||||
} else if (call.method == "checkPermissionRoot") {
|
} else if (call.method == "checkPermissionRoot") {
|
||||||
rootCheckPermission(result)
|
rootCheckPermission(result)
|
||||||
} else if (call.method == "installWithShizuku") {
|
} else if (call.method == "installWithShizuku") {
|
||||||
|
@ -7,7 +7,7 @@ class Installers {
|
|||||||
static int _resPermShizuku = -2; // not set
|
static int _resPermShizuku = -2; // not set
|
||||||
|
|
||||||
static Future waitWhile(bool Function() test,
|
static Future waitWhile(bool Function() test,
|
||||||
[Duration pollInterval = const Duration(milliseconds: 100)]) {
|
[Duration pollInterval = const Duration(milliseconds: 250)]) {
|
||||||
var completer = Completer();
|
var completer = Completer();
|
||||||
check() {
|
check() {
|
||||||
if (test()) {
|
if (test()) {
|
||||||
@ -31,10 +31,12 @@ class Installers {
|
|||||||
_channel.setMethodCallHandler(handleCalls);
|
_channel.setMethodCallHandler(handleCalls);
|
||||||
_callbacksApplied = true;
|
_callbacksApplied = true;
|
||||||
}
|
}
|
||||||
await _channel.invokeMethod('checkPermissionShizuku');
|
int res = await _channel.invokeMethod('checkPermissionShizuku');
|
||||||
await waitWhile(() => _resPermShizuku == -2);
|
if(res == -2) {
|
||||||
int res = _resPermShizuku;
|
await waitWhile(() => _resPermShizuku == -2);
|
||||||
_resPermShizuku = -2;
|
res = _resPermShizuku;
|
||||||
|
_resPermShizuku = -2;
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user