mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-31 05:23:28 +01:00 
			
		
		
		
	Root install
This commit is contained in:
		| @@ -90,6 +90,12 @@ flutter { | |||||||
|     source '../..' |     source '../..' | ||||||
| } | } | ||||||
|  |  | ||||||
|  | repositories { | ||||||
|  |     maven { url 'https://jitpack.io' } | ||||||
|  | } | ||||||
|  |  | ||||||
| dependencies { | dependencies { | ||||||
|     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" |     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 | package dev.imranr.obtainium | ||||||
|  |  | ||||||
| import io.flutter.embedding.android.FlutterActivity | 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() { | 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:android_intent_plus/android_intent.dart'; | ||||||
| import 'package:flutter_archive/flutter_archive.dart'; | import 'package:flutter_archive/flutter_archive.dart'; | ||||||
| import 'package:shared_storage/shared_storage.dart' as saf; | import 'package:shared_storage/shared_storage.dart' as saf; | ||||||
|  | import 'installers_provider.dart'; | ||||||
|  |  | ||||||
| final pm = AndroidPackageManager(); | final pm = AndroidPackageManager(); | ||||||
|  |  | ||||||
| @@ -515,8 +516,14 @@ class AppsProvider with ChangeNotifier { | |||||||
|       await saveApps([apps[file.appId]!.app], |       await saveApps([apps[file.appId]!.app], | ||||||
|           attemptToCorrectInstallStatus: false); |           attemptToCorrectInstallStatus: false); | ||||||
|     } |     } | ||||||
|     int? code = |     int? code; | ||||||
|         await AndroidPackageInstaller.installApk(apkFilePath: file.file.path); |     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; |     bool installed = false; | ||||||
|     if (code != null && code != 0 && code != 3) { |     if (code != null && code != 0 && code != 3) { | ||||||
|       throw InstallError(code); |       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