mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 20:57:36 +02:00
fix: Improve root installations management to fix patching of already patched apps
This commit is contained in:
@ -198,7 +198,10 @@ class ManagerAPI {
|
||||
Future<bool> isAppUninstalled(PatchedApplication app) async {
|
||||
bool existsRoot = false;
|
||||
if (app.isRooted) {
|
||||
existsRoot = await _rootAPI.isAppInstalled(app.packageName);
|
||||
bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
||||
if (hasRootPermissions) {
|
||||
existsRoot = await _rootAPI.isAppInstalled(app.packageName);
|
||||
}
|
||||
}
|
||||
bool existsNonRoot = await DeviceApps.isAppInstalled(app.packageName);
|
||||
return !existsRoot && !existsNonRoot;
|
||||
|
@ -82,9 +82,31 @@ class PatcherAPI {
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<void> runPatcher(
|
||||
Future<String> copyOriginalApk(
|
||||
String packageName,
|
||||
String originalFilePath,
|
||||
) async {
|
||||
bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
||||
if (hasRootPermissions) {
|
||||
String originalRootPath = await _rootAPI.getOriginalFilePath(packageName);
|
||||
if (File(originalRootPath).existsSync()) {
|
||||
originalFilePath = originalRootPath;
|
||||
}
|
||||
}
|
||||
String backupFilePath = '${_tmpDir.path}/$packageName.apk';
|
||||
await patcherChannel.invokeMethod(
|
||||
'copyOriginalApk',
|
||||
{
|
||||
'originalFilePath': originalFilePath,
|
||||
'backupFilePath': backupFilePath,
|
||||
},
|
||||
);
|
||||
return backupFilePath;
|
||||
}
|
||||
|
||||
Future<void> runPatcher(
|
||||
String packageName,
|
||||
String inputFilePath,
|
||||
List<Patch> selectedPatches,
|
||||
) async {
|
||||
bool mergeIntegrations = selectedPatches.any(
|
||||
@ -118,7 +140,6 @@ class PatcherAPI {
|
||||
if (patchBundleFile != null) {
|
||||
_tmpDir.createSync();
|
||||
Directory workDir = _tmpDir.createTempSync('tmp-');
|
||||
File inputFile = File('${workDir.path}/base.apk');
|
||||
File patchedFile = File('${workDir.path}/patched.apk');
|
||||
_outFile = File('${workDir.path}/out.apk');
|
||||
Directory cacheDir = Directory('${workDir.path}/cache');
|
||||
@ -127,8 +148,7 @@ class PatcherAPI {
|
||||
'runPatcher',
|
||||
{
|
||||
'patchBundleFilePath': patchBundleFile.path,
|
||||
'originalFilePath': originalFilePath,
|
||||
'inputFilePath': inputFile.path,
|
||||
'inputFilePath': inputFilePath,
|
||||
'patchedFilePath': patchedFile.path,
|
||||
'outFilePath': _outFile!.path,
|
||||
'integrationsPath': mergeIntegrations ? integrationsFile!.path : '',
|
||||
@ -153,8 +173,6 @@ class PatcherAPI {
|
||||
patchedApp.apkFilePath,
|
||||
_outFile!.path,
|
||||
);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
await AppInstaller.installApk(_outFile!.path);
|
||||
@ -179,19 +197,6 @@ class PatcherAPI {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> checkOldPatch(PatchedApplication patchedApp) async {
|
||||
if (patchedApp.isRooted) {
|
||||
return await _rootAPI.isAppInstalled(patchedApp.packageName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> deleteOldPatch(PatchedApplication patchedApp) async {
|
||||
if (patchedApp.isRooted) {
|
||||
await _rootAPI.deleteApp(patchedApp.packageName, patchedApp.apkFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
void shareLog(String logs) {
|
||||
ShareExtend.share(logs, 'text');
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:root/root.dart';
|
||||
|
||||
class RootAPI {
|
||||
final String _managerDirPath = '/data/adb/revanced_manager';
|
||||
final String _managerDirPath = '/data/adb/revanced-manager';
|
||||
final String _postFsDataDirPath = '/data/adb/post-fs-data.d';
|
||||
final String _serviceDDirPath = '/data/adb/service.d';
|
||||
|
||||
@ -72,13 +72,15 @@ class RootAPI {
|
||||
String patchedFilePath,
|
||||
) async {
|
||||
try {
|
||||
await deleteApp(packageName, originalFilePath);
|
||||
await Root.exec(
|
||||
cmd: 'mkdir -p "$_managerDirPath/$packageName"',
|
||||
);
|
||||
installServiceDScript(packageName);
|
||||
installPostFsDataScript(packageName);
|
||||
installApk(packageName, patchedFilePath);
|
||||
mountApk(packageName, originalFilePath, patchedFilePath);
|
||||
await saveOriginalFilePath(packageName, originalFilePath);
|
||||
await installServiceDScript(packageName);
|
||||
await installPostFsDataScript(packageName);
|
||||
await installApk(packageName, patchedFilePath);
|
||||
await mountApk(packageName, originalFilePath);
|
||||
return true;
|
||||
} on Exception {
|
||||
return false;
|
||||
@ -129,11 +131,7 @@ class RootAPI {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> mountApk(
|
||||
String packageName,
|
||||
String originalFilePath,
|
||||
String patchedFilePath,
|
||||
) async {
|
||||
Future<void> mountApk(String packageName, String originalFilePath) async {
|
||||
String newPatchedFilePath = '$_managerDirPath/$packageName/base.apk';
|
||||
await Root.exec(
|
||||
cmd: 'am force-stop "$packageName"',
|
||||
@ -145,4 +143,18 @@ class RootAPI {
|
||||
cmd: 'su -mm -c "mount -o bind $newPatchedFilePath $originalFilePath"',
|
||||
);
|
||||
}
|
||||
|
||||
Future<String> getOriginalFilePath(String packageName) async {
|
||||
return '$_managerDirPath/$packageName/original.apk';
|
||||
}
|
||||
|
||||
Future<void> saveOriginalFilePath(
|
||||
String packageName,
|
||||
String originalFilePath,
|
||||
) async {
|
||||
String originalRootPath = '$_managerDirPath/$packageName/original.apk';
|
||||
await Root.exec(
|
||||
cmd: 'cp "$originalFilePath" "$originalRootPath"',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user