mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-31 05:23:28 +01:00 
			
		
		
		
	Now it looks good
This commit is contained in:
		| @@ -505,7 +505,8 @@ class AppsProvider with ChangeNotifier { | ||||
|         !(await canDowngradeApps())) { | ||||
|       throw DowngradeError(); | ||||
|     } | ||||
|     if (needsBGWorkaround) { | ||||
|     if (needsBGWorkaround && | ||||
|         settingsProvider.installMethod == InstallMethodSettings.normal) { | ||||
|       // The below 'await' will never return if we are in a background process | ||||
|       // To work around this, we should assume the install will be successful | ||||
|       // So we update the app's installed version first as we will never get to the later code | ||||
| @@ -517,12 +518,13 @@ class AppsProvider with ChangeNotifier { | ||||
|           attemptToCorrectInstallStatus: false); | ||||
|     } | ||||
|     int? code; | ||||
|     if (settingsProvider.installMethod == InstallMethodSettings.normal) { | ||||
|       code = await AndroidPackageInstaller.installApk(apkFilePath: file.file.path); | ||||
|     } else if (settingsProvider.installMethod == InstallMethodSettings.shizuku) { | ||||
|       code = await Installers.installWithShizuku(apkFilePath: file.file.path); | ||||
|     } else if (settingsProvider.installMethod == InstallMethodSettings.root) { | ||||
|       code = await Installers.installWithRoot(apkFilePath: file.file.path); | ||||
|     switch (settingsProvider.installMethod) { | ||||
|       case InstallMethodSettings.normal: | ||||
|         code = await AndroidPackageInstaller.installApk(apkFilePath: file.file.path); | ||||
|       case InstallMethodSettings.shizuku: | ||||
|         code = (await Installers.installWithShizuku(apkFileUri: file.file.uri.toString())) ? 0 : 1; | ||||
|       case InstallMethodSettings.root: | ||||
|         code = (await Installers.installWithRoot(apkFilePath: file.file.path)) ? 0 : 1; | ||||
|     } | ||||
|     bool installed = false; | ||||
|     if (code != null && code != 0 && code != 3) { | ||||
| @@ -679,8 +681,22 @@ class AppsProvider with ChangeNotifier { | ||||
|         } | ||||
|         var appId = downloadedFile?.appId ?? downloadedDir!.appId; | ||||
|         bool willBeSilent = await canInstallSilently(apps[appId]!.app); | ||||
|         if (!(await settingsProvider.getInstallPermission(enforce: false))) { | ||||
|           throw ObtainiumError(tr('cancelled')); | ||||
|         switch (settingsProvider.installMethod) { | ||||
|           case InstallMethodSettings.normal: | ||||
|             if (!(await settingsProvider.getInstallPermission(enforce: false))) { | ||||
|               throw ObtainiumError(tr('cancelled')); | ||||
|             } | ||||
|           case InstallMethodSettings.shizuku: | ||||
|             int code = await Installers.checkPermissionShizuku(); | ||||
|             if (code == -1) { | ||||
|               throw ObtainiumError(tr('shizukuBinderNotFound')); | ||||
|             } else if (code == 0) { | ||||
|               throw ObtainiumError(tr('cancelled')); | ||||
|             } | ||||
|           case InstallMethodSettings.root: | ||||
|             if (!(await Installers.checkPermissionRoot())) { | ||||
|               throw ObtainiumError(tr('cancelled')); | ||||
|             } | ||||
|         } | ||||
|         if (!willBeSilent && context != null) { | ||||
|           // ignore: use_build_context_synchronously | ||||
|   | ||||
| @@ -3,12 +3,52 @@ import 'package:flutter/services.dart'; | ||||
|  | ||||
| class Installers { | ||||
|   static const MethodChannel _channel = MethodChannel('installers'); | ||||
|   static bool _callbacksApplied = false; | ||||
|   static int _resPermShizuku = -2;  // not set | ||||
|  | ||||
|   static Future<int?> installWithShizuku({required String apkFilePath}) async { | ||||
|     return await _channel.invokeMethod('installWithShizuku', {'apkFilePath': apkFilePath}); | ||||
|   static Future waitWhile(bool Function() test, | ||||
|       [Duration pollInterval = const Duration(milliseconds: 100)]) { | ||||
|     var completer = Completer(); | ||||
|     check() { | ||||
|       if (test()) { | ||||
|         Timer(pollInterval, check); | ||||
|       } else { | ||||
|         completer.complete(); | ||||
|       } | ||||
|     } | ||||
|     check(); | ||||
|     return completer.future; | ||||
|   } | ||||
|  | ||||
|   static Future<int?> installWithRoot({required String apkFilePath}) async { | ||||
|     return await _channel.invokeMethod('installWithRoot', {'apkFilePath': apkFilePath}); | ||||
|   static Future handleCalls(MethodCall call) async { | ||||
|     if (call.method == 'resPermShizuku') { | ||||
|       _resPermShizuku = call.arguments['res']; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   static Future<int> checkPermissionShizuku() async { | ||||
|     if (!_callbacksApplied) { | ||||
|       _channel.setMethodCallHandler(handleCalls); | ||||
|       _callbacksApplied = true; | ||||
|     } | ||||
|     await _channel.invokeMethod('checkPermissionShizuku'); | ||||
|     await waitWhile(() => _resPermShizuku == -2); | ||||
|     int res = _resPermShizuku; | ||||
|     _resPermShizuku = -2; | ||||
|     return res; | ||||
|   } | ||||
|  | ||||
|   static Future<bool> checkPermissionRoot() async { | ||||
|     return await _channel.invokeMethod('checkPermissionRoot'); | ||||
|   } | ||||
|  | ||||
|   static Future<bool> installWithShizuku({required String apkFileUri}) async { | ||||
|     return await _channel.invokeMethod( | ||||
|         'installWithShizuku', {'apkFileUri': apkFileUri}); | ||||
|   } | ||||
|  | ||||
|   static Future<bool> installWithRoot({required String apkFilePath}) async { | ||||
|     return await _channel.invokeMethod( | ||||
|         'installWithRoot', {'apkFilePath': apkFilePath}); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user