mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-30 04:53:28 +01:00 
			
		
		
		
	Root install
This commit is contained in:
		| @@ -90,6 +90,12 @@ flutter { | ||||
|     source '../..' | ||||
| } | ||||
|  | ||||
| repositories { | ||||
|     maven { url 'https://jitpack.io' } | ||||
| } | ||||
|  | ||||
| dependencies { | ||||
|     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||||
|     def libsuVersion = '5.2.2' | ||||
|     implementation "com.github.topjohnwu.libsu:core:${libsuVersion}" | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,39 @@ | ||||
| package dev.imranr.obtainium | ||||
|  | ||||
| import io.flutter.embedding.android.FlutterActivity | ||||
| import io.flutter.embedding.engine.FlutterEngine | ||||
| import io.flutter.plugin.common.MethodChannel | ||||
| import io.flutter.plugin.common.MethodChannel.Result | ||||
| import androidx.annotation.NonNull | ||||
| import com.topjohnwu.superuser.Shell | ||||
|  | ||||
| class MainActivity: FlutterActivity() { | ||||
|     private val installersChannel = "installers" | ||||
|  | ||||
|     private fun installWithRoot(apkFilePath: String, result: Result) { | ||||
|         Shell.sh("pm install -r -t " + apkFilePath).submit { out -> | ||||
|             val builder = StringBuilder() | ||||
|             for (data in out.getOut()) { | ||||
|                 builder.append(data) | ||||
|             } | ||||
|             result.success(if (builder.toString().endsWith("Success")) 0 else 1) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun installWithShizuku(apkFilePath: String, result: Result) { | ||||
|         val a = 1 | ||||
|     } | ||||
|  | ||||
|     override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { | ||||
|         super.configureFlutterEngine(flutterEngine) | ||||
|         MethodChannel(flutterEngine.dartExecutor.binaryMessenger, installersChannel).setMethodCallHandler { | ||||
|             call, result -> | ||||
|             var apkFilePath: String? = call.argument("apkFilePath") | ||||
|             if (call.method == "installWithShizuku") { | ||||
|                 installWithShizuku(apkFilePath.toString(), result) | ||||
|             } else if (call.method == "installWithRoot") { | ||||
|                 installWithRoot(apkFilePath.toString(), result) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -33,6 +33,7 @@ import 'package:http/http.dart'; | ||||
| import 'package:android_intent_plus/android_intent.dart'; | ||||
| import 'package:flutter_archive/flutter_archive.dart'; | ||||
| import 'package:shared_storage/shared_storage.dart' as saf; | ||||
| import 'installers_provider.dart'; | ||||
|  | ||||
| final pm = AndroidPackageManager(); | ||||
|  | ||||
| @@ -515,8 +516,14 @@ class AppsProvider with ChangeNotifier { | ||||
|       await saveApps([apps[file.appId]!.app], | ||||
|           attemptToCorrectInstallStatus: false); | ||||
|     } | ||||
|     int? code = | ||||
|         await AndroidPackageInstaller.installApk(apkFilePath: file.file.path); | ||||
|     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); | ||||
|     } | ||||
|     bool installed = false; | ||||
|     if (code != null && code != 0 && code != 3) { | ||||
|       throw InstallError(code); | ||||
|   | ||||
							
								
								
									
										14
									
								
								lib/providers/installers_provider.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								lib/providers/installers_provider.dart
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| import 'dart:async'; | ||||
| import 'package:flutter/services.dart'; | ||||
|  | ||||
| class Installers { | ||||
|   static const MethodChannel _channel = MethodChannel('installers'); | ||||
|  | ||||
|   static Future<int?> installWithShizuku({required String apkFilePath}) async { | ||||
|     return await _channel.invokeMethod('installWithShizuku', {'apkFilePath': apkFilePath}); | ||||
|   } | ||||
|  | ||||
|   static Future<int?> installWithRoot({required String apkFilePath}) async { | ||||
|     return await _channel.invokeMethod('installWithRoot', {'apkFilePath': apkFilePath}); | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user