feat: Improve experience of rooted patched app installations (#59)

This commit is contained in:
Alberto Ponces
2022-09-06 14:40:49 +01:00
committed by GitHub
parent 9e178ba584
commit 27ef74b561
22 changed files with 203 additions and 299 deletions

View File

@ -65,14 +65,6 @@ class ManagerAPI {
await _prefs.setBool('useDarkTheme', value);
}
bool? isRooted() {
return _prefs.getBool('isRooted');
}
Future<void> setIsRooted(bool value) async {
await _prefs.setBool('isRooted', value);
}
List<PatchedApplication> getPatchedApps() {
List<String> apps = _prefs.getStringList('patchedApps') ?? [];
return apps
@ -109,11 +101,10 @@ class ManagerAPI {
}
Future<void> reAssessSavedApps() async {
bool isRooted = this.isRooted() ?? false;
List<PatchedApplication> patchedApps = getPatchedApps();
List<PatchedApplication> toRemove = [];
for (PatchedApplication app in patchedApps) {
bool isRemove = await isAppUninstalled(app, isRooted);
bool isRemove = await isAppUninstalled(app);
if (isRemove) {
toRemove.add(app);
} else {
@ -139,9 +130,9 @@ class ManagerAPI {
await setPatchedApps(patchedApps);
}
Future<bool> isAppUninstalled(PatchedApplication app, bool isRooted) async {
Future<bool> isAppUninstalled(PatchedApplication app) async {
bool existsRoot = false;
if (isRooted) {
if (app.isRooted) {
existsRoot = await _rootAPI.isAppInstalled(app.packageName);
}
bool existsNonRoot = await DeviceApps.isAppInstalled(app.packageName);

View File

@ -147,11 +147,16 @@ class PatcherAPI {
if (_outFile != null) {
try {
if (patchedApp.isRooted) {
return _rootAPI.installApp(
patchedApp.packageName,
patchedApp.apkFilePath,
_outFile!.path,
);
bool hasRootPermissions = await _rootAPI.hasRootPermissions();
if (hasRootPermissions) {
return _rootAPI.installApp(
patchedApp.packageName,
patchedApp.apkFilePath,
_outFile!.path,
);
} else {
return false;
}
} else {
await AppInstaller.installApk(_outFile!.path);
return await DeviceApps.isAppInstalled(patchedApp.packageName);
@ -163,14 +168,15 @@ class PatcherAPI {
return false;
}
bool sharePatchedFile(String appName, String version) {
void sharePatchedFile(String appName, String version) {
if (_outFile != null) {
String prefix = appName.toLowerCase().replaceAll(' ', '-');
File share = _outFile!.renameSync('$prefix-revanced_v$version.apk');
String newName = '$prefix-revanced_v$version.apk';
int lastSeparator = _outFile!.path.lastIndexOf('/');
File share = _outFile!.renameSync(
_outFile!.path.substring(0, lastSeparator + 1) + newName,
);
ShareExtend.share(share.path, 'file');
return true;
} else {
return false;
}
}
@ -186,4 +192,8 @@ class PatcherAPI {
await _rootAPI.deleteApp(patchedApp.packageName, patchedApp.apkFilePath);
}
}
void shareLog(String logs) {
ShareExtend.share(logs, 'text');
}
}

View File

@ -5,6 +5,11 @@ class RootAPI {
final String _postFsDataDirPath = '/data/adb/post-fs-data.d';
final String _serviceDDirPath = '/data/adb/service.d';
Future<bool> hasRootPermissions() async {
bool? isRooted = await Root.isRooted();
return isRooted != null && isRooted;
}
Future<bool> isAppInstalled(String packageName) async {
if (packageName.isNotEmpty) {
String? res = await Root.exec(