2022-08-25 01:51:47 +02:00
|
|
|
import 'dart:convert';
|
2022-08-01 21:05:11 +02:00
|
|
|
import 'dart:io';
|
2023-02-21 13:21:56 +01:00
|
|
|
|
2022-08-25 01:51:47 +02:00
|
|
|
import 'package:device_apps/device_apps.dart';
|
|
|
|
import 'package:injectable/injectable.dart';
|
2022-08-18 18:32:58 +02:00
|
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
2022-11-09 08:36:04 +01:00
|
|
|
import 'package:path_provider/path_provider.dart';
|
2022-09-12 02:41:53 +02:00
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
2022-09-11 03:01:06 +02:00
|
|
|
import 'package:revanced_manager/models/patch.dart';
|
2022-08-25 01:51:47 +02:00
|
|
|
import 'package:revanced_manager/models/patched_application.dart';
|
2022-08-09 01:01:06 +02:00
|
|
|
import 'package:revanced_manager/services/github_api.dart';
|
2022-09-11 03:01:06 +02:00
|
|
|
import 'package:revanced_manager/services/revanced_api.dart';
|
2022-08-25 01:51:47 +02:00
|
|
|
import 'package:revanced_manager/services/root_api.dart';
|
2022-10-14 20:05:33 +02:00
|
|
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
2022-08-25 01:51:47 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-07-31 21:46:27 +02:00
|
|
|
|
2022-08-25 01:51:47 +02:00
|
|
|
@lazySingleton
|
2022-08-02 10:06:35 +02:00
|
|
|
class ManagerAPI {
|
2022-09-12 02:41:53 +02:00
|
|
|
final RevancedAPI _revancedAPI = locator<RevancedAPI>();
|
|
|
|
final GithubAPI _githubAPI = locator<GithubAPI>();
|
2023-02-21 13:21:56 +01:00
|
|
|
final SharedPreferences _prefs = locator<SharedPreferences>();
|
2022-08-25 01:51:47 +02:00
|
|
|
final RootAPI _rootAPI = RootAPI();
|
2022-09-07 03:37:25 +02:00
|
|
|
final String patcherRepo = 'revanced-patcher';
|
|
|
|
final String cliRepo = 'revanced-cli';
|
2023-01-30 13:03:55 +01:00
|
|
|
String storedPatchesFile = '/selected-patches.json';
|
2022-10-30 22:57:12 +01:00
|
|
|
String defaultApiUrl = 'https://releases.revanced.app/';
|
2022-12-09 13:10:43 +01:00
|
|
|
String defaultRepoUrl = 'https://api.github.com';
|
2022-09-07 03:37:25 +02:00
|
|
|
String defaultPatcherRepo = 'revanced/revanced-patcher';
|
|
|
|
String defaultPatchesRepo = 'revanced/revanced-patches';
|
|
|
|
String defaultIntegrationsRepo = 'revanced/revanced-integrations';
|
|
|
|
String defaultCliRepo = 'revanced/revanced-cli';
|
|
|
|
String defaultManagerRepo = 'revanced/revanced-manager';
|
2022-08-25 01:51:47 +02:00
|
|
|
|
|
|
|
Future<void> initialize() async {
|
2022-11-09 08:36:04 +01:00
|
|
|
storedPatchesFile =
|
|
|
|
(await getApplicationDocumentsDirectory()).path + storedPatchesFile;
|
2022-08-25 01:51:47 +02:00
|
|
|
}
|
2022-08-02 10:06:35 +02:00
|
|
|
|
2022-09-18 19:42:30 +02:00
|
|
|
String getApiUrl() {
|
|
|
|
return _prefs.getString('apiUrl') ?? defaultApiUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> setApiUrl(String url) async {
|
|
|
|
if (url.isEmpty || url == ' ') {
|
|
|
|
url = defaultApiUrl;
|
|
|
|
}
|
2022-09-19 01:28:26 +02:00
|
|
|
await _revancedAPI.initialize(url);
|
|
|
|
await _revancedAPI.clearAllCache();
|
2022-09-18 19:42:30 +02:00
|
|
|
await _prefs.setString('apiUrl', url);
|
|
|
|
}
|
2022-12-09 13:10:43 +01:00
|
|
|
|
|
|
|
String getRepoUrl() {
|
|
|
|
return _prefs.getString('repoUrl') ?? defaultRepoUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> setRepoUrl(String url) async {
|
|
|
|
if (url.isEmpty || url == ' ') {
|
|
|
|
url = defaultRepoUrl;
|
|
|
|
}
|
|
|
|
await _prefs.setString('repoUrl', url);
|
|
|
|
}
|
2022-09-18 19:42:30 +02:00
|
|
|
|
2022-09-07 03:37:25 +02:00
|
|
|
String getPatchesRepo() {
|
|
|
|
return _prefs.getString('patchesRepo') ?? defaultPatchesRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> setPatchesRepo(String value) async {
|
2022-09-07 12:14:54 +02:00
|
|
|
if (value.isEmpty || value.startsWith('/') || value.endsWith('/')) {
|
2022-09-07 03:37:25 +02:00
|
|
|
value = defaultPatchesRepo;
|
|
|
|
}
|
|
|
|
await _prefs.setString('patchesRepo', value);
|
|
|
|
}
|
|
|
|
|
|
|
|
String getIntegrationsRepo() {
|
|
|
|
return _prefs.getString('integrationsRepo') ?? defaultIntegrationsRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> setIntegrationsRepo(String value) async {
|
2022-09-07 12:14:54 +02:00
|
|
|
if (value.isEmpty || value.startsWith('/') || value.endsWith('/')) {
|
2022-09-07 03:37:25 +02:00
|
|
|
value = defaultIntegrationsRepo;
|
|
|
|
}
|
|
|
|
await _prefs.setString('integrationsRepo', value);
|
|
|
|
}
|
|
|
|
|
2022-09-05 04:32:36 +02:00
|
|
|
bool getUseDynamicTheme() {
|
|
|
|
return _prefs.getBool('useDynamicTheme') ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> setUseDynamicTheme(bool value) async {
|
|
|
|
await _prefs.setBool('useDynamicTheme', value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool getUseDarkTheme() {
|
|
|
|
return _prefs.getBool('useDarkTheme') ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> setUseDarkTheme(bool value) async {
|
|
|
|
await _prefs.setBool('useDarkTheme', value);
|
|
|
|
}
|
|
|
|
|
2022-11-12 16:55:33 +01:00
|
|
|
bool isSentryEnabled() {
|
|
|
|
return _prefs.getBool('sentryEnabled') ?? true;
|
|
|
|
}
|
2022-10-14 22:22:10 +02:00
|
|
|
|
2022-11-12 16:55:33 +01:00
|
|
|
Future<void> setSentryStatus(bool value) async {
|
|
|
|
await _prefs.setBool('sentryEnabled', value);
|
|
|
|
}
|
2022-10-14 22:22:10 +02:00
|
|
|
|
2022-12-15 19:05:45 +01:00
|
|
|
bool areUniversalPatchesEnabled() {
|
|
|
|
return _prefs.getBool('universalPatchesEnabled') ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> enableUniversalPatchesStatus(bool value) async {
|
|
|
|
await _prefs.setBool('universalPatchesEnabled', value);
|
|
|
|
}
|
|
|
|
|
2022-11-01 10:56:15 +01:00
|
|
|
bool areExperimentalPatchesEnabled() {
|
|
|
|
return _prefs.getBool('experimentalPatchesEnabled') ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> enableExperimentalPatchesStatus(bool value) async {
|
|
|
|
await _prefs.setBool('experimentalPatchesEnabled', value);
|
|
|
|
}
|
|
|
|
|
2022-10-16 21:11:20 +02:00
|
|
|
Future<void> deleteTempFolder() async {
|
|
|
|
final Directory dir = Directory('/data/local/tmp/revanced-manager');
|
|
|
|
if (await dir.exists()) {
|
|
|
|
await dir.delete(recursive: true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-16 20:52:07 +02:00
|
|
|
Future<void> deleteKeystore() async {
|
|
|
|
final File keystore = File(
|
2023-01-30 13:35:06 +01:00
|
|
|
'/sdcard/Android/data/app.revanced.manager.flutter/files/revanced-manager.keystore',
|
|
|
|
);
|
2022-10-16 20:52:07 +02:00
|
|
|
if (await keystore.exists()) {
|
|
|
|
await keystore.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:51:47 +02:00
|
|
|
List<PatchedApplication> getPatchedApps() {
|
2023-01-30 13:35:06 +01:00
|
|
|
final List<String> apps = _prefs.getStringList('patchedApps') ?? [];
|
2022-09-11 03:01:06 +02:00
|
|
|
return apps.map((a) => PatchedApplication.fromJson(jsonDecode(a))).toList();
|
2022-08-25 01:51:47 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 03:07:28 +02:00
|
|
|
Future<void> setPatchedApps(List<PatchedApplication> patchedApps) async {
|
2022-09-03 16:28:22 +02:00
|
|
|
if (patchedApps.length > 1) {
|
|
|
|
patchedApps.sort((a, b) => a.name.compareTo(b.name));
|
|
|
|
}
|
2023-01-30 13:35:06 +01:00
|
|
|
await _prefs.setStringList(
|
|
|
|
'patchedApps',
|
|
|
|
patchedApps.map((a) => json.encode(a.toJson())).toList(),
|
|
|
|
);
|
2022-08-25 01:51:47 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 03:07:28 +02:00
|
|
|
Future<void> savePatchedApp(PatchedApplication app) async {
|
2023-01-30 13:35:06 +01:00
|
|
|
final List<PatchedApplication> patchedApps = getPatchedApps();
|
2022-08-25 01:51:47 +02:00
|
|
|
patchedApps.removeWhere((a) => a.packageName == app.packageName);
|
2023-01-30 13:35:06 +01:00
|
|
|
final ApplicationWithIcon? installed = await DeviceApps.getApp(
|
2022-09-20 02:07:36 +02:00
|
|
|
app.packageName,
|
|
|
|
true,
|
|
|
|
) as ApplicationWithIcon?;
|
2022-09-01 14:52:51 +02:00
|
|
|
if (installed != null) {
|
|
|
|
app.name = installed.appName;
|
|
|
|
app.version = installed.versionName!;
|
|
|
|
app.icon = installed.icon;
|
|
|
|
}
|
2022-08-25 01:51:47 +02:00
|
|
|
patchedApps.add(app);
|
2022-08-30 03:07:28 +02:00
|
|
|
await setPatchedApps(patchedApps);
|
2022-08-25 01:51:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-05 14:43:13 +02:00
|
|
|
Future<void> deletePatchedApp(PatchedApplication app) async {
|
2023-01-30 13:35:06 +01:00
|
|
|
final List<PatchedApplication> patchedApps = getPatchedApps();
|
2022-09-05 14:43:13 +02:00
|
|
|
patchedApps.removeWhere((a) => a.packageName == app.packageName);
|
|
|
|
await setPatchedApps(patchedApps);
|
|
|
|
}
|
|
|
|
|
2023-01-30 13:35:06 +01:00
|
|
|
Future<void> clearAllData() async {
|
2022-10-14 20:05:33 +02:00
|
|
|
try {
|
|
|
|
_revancedAPI.clearAllCache();
|
|
|
|
_githubAPI.clearAllCache();
|
|
|
|
} on Exception catch (e, s) {
|
2023-02-21 13:21:56 +01:00
|
|
|
Sentry.captureException(e, stackTrace: s).ignore();
|
2022-10-14 20:05:33 +02:00
|
|
|
}
|
2022-09-11 03:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<Map<String, List<dynamic>>> getContributors() async {
|
2022-09-19 01:28:26 +02:00
|
|
|
return await _revancedAPI.getContributors();
|
2022-09-11 03:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<List<Patch>> getPatches() async {
|
2022-10-14 20:05:33 +02:00
|
|
|
try {
|
2023-01-30 13:35:06 +01:00
|
|
|
final String repoName = getPatchesRepo();
|
2022-10-14 20:05:33 +02:00
|
|
|
if (repoName == defaultPatchesRepo) {
|
|
|
|
return await _revancedAPI.getPatches();
|
|
|
|
} else {
|
|
|
|
return await _githubAPI.getPatches(repoName);
|
|
|
|
}
|
|
|
|
} on Exception catch (e, s) {
|
2023-02-21 13:21:56 +01:00
|
|
|
Sentry.captureException(e, stackTrace: s).ignore();
|
2022-10-14 20:05:33 +02:00
|
|
|
return [];
|
2022-09-11 03:01:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<File?> downloadPatches() async {
|
2022-10-14 20:05:33 +02:00
|
|
|
try {
|
2023-01-30 13:35:06 +01:00
|
|
|
final String repoName = getPatchesRepo();
|
2022-10-14 20:05:33 +02:00
|
|
|
if (repoName == defaultPatchesRepo) {
|
|
|
|
return await _revancedAPI.getLatestReleaseFile(
|
|
|
|
'.jar',
|
|
|
|
defaultPatchesRepo,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return await _githubAPI.getLatestReleaseFile('.jar', repoName);
|
|
|
|
}
|
|
|
|
} on Exception catch (e, s) {
|
2023-02-21 13:21:56 +01:00
|
|
|
Sentry.captureException(e, stackTrace: s).ignore();
|
2022-10-14 20:05:33 +02:00
|
|
|
return null;
|
2022-09-11 03:01:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<File?> downloadIntegrations() async {
|
2022-10-14 20:05:33 +02:00
|
|
|
try {
|
2023-01-30 13:35:06 +01:00
|
|
|
final String repoName = getIntegrationsRepo();
|
2022-10-14 20:05:33 +02:00
|
|
|
if (repoName == defaultIntegrationsRepo) {
|
|
|
|
return await _revancedAPI.getLatestReleaseFile(
|
|
|
|
'.apk',
|
|
|
|
defaultIntegrationsRepo,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return await _githubAPI.getLatestReleaseFile('.apk', repoName);
|
|
|
|
}
|
|
|
|
} on Exception catch (e, s) {
|
2023-02-21 13:21:56 +01:00
|
|
|
Sentry.captureException(e, stackTrace: s).ignore();
|
2022-10-14 20:05:33 +02:00
|
|
|
return null;
|
2022-09-11 03:01:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<File?> downloadManager() async {
|
2022-09-19 01:28:26 +02:00
|
|
|
return await _revancedAPI.getLatestReleaseFile('.apk', defaultManagerRepo);
|
2022-09-11 03:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<String?> getLatestPatcherReleaseTime() async {
|
2022-09-19 01:28:26 +02:00
|
|
|
return await _revancedAPI.getLatestReleaseTime('.gz', defaultPatcherRepo);
|
2022-09-11 03:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<String?> getLatestManagerReleaseTime() async {
|
2022-09-19 01:28:26 +02:00
|
|
|
return await _revancedAPI.getLatestReleaseTime('.apk', defaultManagerRepo);
|
2022-09-11 03:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<String?> getLatestManagerVersion() async {
|
|
|
|
return await _revancedAPI.getLatestReleaseVersion(
|
|
|
|
'.apk',
|
|
|
|
defaultManagerRepo,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-16 22:10:16 +02:00
|
|
|
Future<String?> getLatestPatchesVersion() async {
|
|
|
|
return await _revancedAPI.getLatestReleaseVersion(
|
|
|
|
'.json',
|
|
|
|
defaultPatchesRepo,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-11 03:01:06 +02:00
|
|
|
Future<String> getCurrentManagerVersion() async {
|
2023-01-30 13:35:06 +01:00
|
|
|
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
2022-09-11 03:01:06 +02:00
|
|
|
return packageInfo.version;
|
|
|
|
}
|
|
|
|
|
2022-09-17 20:29:46 +02:00
|
|
|
Future<List<PatchedApplication>> getAppsToRemove(
|
|
|
|
List<PatchedApplication> patchedApps,
|
|
|
|
) async {
|
2023-01-30 13:35:06 +01:00
|
|
|
final List<PatchedApplication> toRemove = [];
|
|
|
|
for (final PatchedApplication app in patchedApps) {
|
|
|
|
final bool isRemove = await isAppUninstalled(app);
|
2022-08-29 16:01:51 +02:00
|
|
|
if (isRemove) {
|
2022-08-26 03:01:53 +02:00
|
|
|
toRemove.add(app);
|
2022-09-17 20:29:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return toRemove;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<List<PatchedApplication>> getUnsavedApps(
|
|
|
|
List<PatchedApplication> patchedApps,
|
|
|
|
) async {
|
2023-01-30 13:35:06 +01:00
|
|
|
final List<PatchedApplication> unsavedApps = [];
|
|
|
|
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
2022-09-18 02:54:25 +02:00
|
|
|
if (hasRootPermissions) {
|
2023-01-30 13:35:06 +01:00
|
|
|
final List<String> installedApps = await _rootAPI.getInstalledApps();
|
|
|
|
for (final String packageName in installedApps) {
|
2022-09-18 02:54:25 +02:00
|
|
|
if (!patchedApps.any((app) => app.packageName == packageName)) {
|
2023-01-30 13:35:06 +01:00
|
|
|
final ApplicationWithIcon? application = await DeviceApps.getApp(
|
2022-09-20 02:07:36 +02:00
|
|
|
packageName,
|
|
|
|
true,
|
|
|
|
) as ApplicationWithIcon?;
|
2022-09-18 02:54:25 +02:00
|
|
|
if (application != null) {
|
|
|
|
unsavedApps.add(
|
|
|
|
PatchedApplication(
|
|
|
|
name: application.appName,
|
|
|
|
packageName: application.packageName,
|
2022-10-10 15:15:58 +02:00
|
|
|
originalPackageName: application.packageName,
|
2022-09-18 02:54:25 +02:00
|
|
|
version: application.versionName!,
|
|
|
|
apkFilePath: application.apkFilePath,
|
|
|
|
icon: application.icon,
|
|
|
|
patchDate: DateTime.now(),
|
|
|
|
isRooted: true,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-09-17 20:29:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-30 13:35:06 +01:00
|
|
|
final List<Application> userApps =
|
|
|
|
await DeviceApps.getInstalledApplications();
|
|
|
|
for (final Application app in userApps) {
|
2022-09-17 20:29:46 +02:00
|
|
|
if (app.packageName.startsWith('app.revanced') &&
|
2022-09-18 05:44:44 +02:00
|
|
|
!app.packageName.startsWith('app.revanced.manager.') &&
|
|
|
|
!patchedApps.any((uapp) => uapp.packageName == app.packageName)) {
|
2023-01-30 13:35:06 +01:00
|
|
|
final ApplicationWithIcon? application = await DeviceApps.getApp(
|
2022-09-20 02:07:36 +02:00
|
|
|
app.packageName,
|
|
|
|
true,
|
|
|
|
) as ApplicationWithIcon?;
|
2022-09-17 20:29:46 +02:00
|
|
|
if (application != null) {
|
|
|
|
unsavedApps.add(
|
|
|
|
PatchedApplication(
|
|
|
|
name: application.appName,
|
|
|
|
packageName: application.packageName,
|
2022-10-10 15:15:58 +02:00
|
|
|
originalPackageName: application.packageName,
|
2022-09-17 20:29:46 +02:00
|
|
|
version: application.versionName!,
|
|
|
|
apkFilePath: application.apkFilePath,
|
|
|
|
icon: application.icon,
|
|
|
|
patchDate: DateTime.now(),
|
|
|
|
),
|
|
|
|
);
|
2022-09-01 14:23:24 +02:00
|
|
|
}
|
2022-08-25 01:51:47 +02:00
|
|
|
}
|
|
|
|
}
|
2022-09-17 20:29:46 +02:00
|
|
|
return unsavedApps;
|
|
|
|
}
|
|
|
|
|
2022-10-11 16:57:29 +02:00
|
|
|
Future<void> reAssessSavedApps() async {
|
2023-01-30 13:35:06 +01:00
|
|
|
final List<PatchedApplication> patchedApps = getPatchedApps();
|
|
|
|
final List<PatchedApplication> unsavedApps =
|
|
|
|
await getUnsavedApps(patchedApps);
|
2022-10-11 16:57:29 +02:00
|
|
|
patchedApps.addAll(unsavedApps);
|
2023-01-30 13:35:06 +01:00
|
|
|
final List<PatchedApplication> toRemove =
|
|
|
|
await getAppsToRemove(patchedApps);
|
2022-10-11 16:57:29 +02:00
|
|
|
patchedApps.removeWhere((a) => toRemove.contains(a));
|
2023-01-30 13:35:06 +01:00
|
|
|
for (final PatchedApplication app in patchedApps) {
|
2022-10-11 16:57:29 +02:00
|
|
|
app.hasUpdates =
|
|
|
|
await hasAppUpdates(app.originalPackageName, app.patchDate);
|
|
|
|
app.changelog =
|
|
|
|
await getAppChangelog(app.originalPackageName, app.patchDate);
|
|
|
|
if (!app.hasUpdates) {
|
2023-01-30 13:35:06 +01:00
|
|
|
final String? currentInstalledVersion =
|
2022-10-11 16:57:29 +02:00
|
|
|
(await DeviceApps.getApp(app.packageName))?.versionName;
|
|
|
|
if (currentInstalledVersion != null) {
|
2023-01-30 13:35:06 +01:00
|
|
|
final String currentSavedVersion = app.version;
|
|
|
|
final int currentInstalledVersionInt = int.parse(
|
|
|
|
currentInstalledVersion.replaceAll(RegExp('[^0-9]'), ''),
|
|
|
|
);
|
|
|
|
final int currentSavedVersionInt =
|
2022-10-11 16:57:29 +02:00
|
|
|
int.parse(currentSavedVersion.replaceAll(RegExp('[^0-9]'), ''));
|
|
|
|
if (currentInstalledVersionInt > currentSavedVersionInt) {
|
|
|
|
app.hasUpdates = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await setPatchedApps(patchedApps);
|
|
|
|
}
|
|
|
|
|
2022-09-06 15:40:49 +02:00
|
|
|
Future<bool> isAppUninstalled(PatchedApplication app) async {
|
2022-08-29 16:01:51 +02:00
|
|
|
bool existsRoot = false;
|
2023-01-30 13:35:06 +01:00
|
|
|
final bool existsNonRoot = await DeviceApps.isAppInstalled(app.packageName);
|
2022-09-06 15:40:49 +02:00
|
|
|
if (app.isRooted) {
|
2023-01-30 13:35:06 +01:00
|
|
|
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
2022-09-13 17:54:43 +02:00
|
|
|
if (hasRootPermissions) {
|
|
|
|
existsRoot = await _rootAPI.isAppInstalled(app.packageName);
|
|
|
|
}
|
2022-09-18 02:54:25 +02:00
|
|
|
return !existsRoot || !existsNonRoot;
|
2022-08-29 16:01:51 +02:00
|
|
|
}
|
2022-09-18 02:54:25 +02:00
|
|
|
return !existsNonRoot;
|
2022-08-18 18:32:58 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 03:07:28 +02:00
|
|
|
Future<bool> hasAppUpdates(String packageName, DateTime patchDate) async {
|
2023-01-30 13:35:06 +01:00
|
|
|
final List<String> commits = await _githubAPI.getCommits(
|
2022-09-07 03:37:25 +02:00
|
|
|
packageName,
|
|
|
|
getPatchesRepo(),
|
2022-09-11 03:01:06 +02:00
|
|
|
patchDate,
|
2022-09-07 03:37:25 +02:00
|
|
|
);
|
2022-09-11 03:01:06 +02:00
|
|
|
return commits.isNotEmpty;
|
2022-08-30 03:07:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<List<String>> getAppChangelog(
|
2023-01-30 13:35:06 +01:00
|
|
|
String packageName,
|
|
|
|
DateTime patchDate,
|
|
|
|
) async {
|
2022-09-11 03:01:06 +02:00
|
|
|
List<String> newCommits = await _githubAPI.getCommits(
|
2022-09-07 03:37:25 +02:00
|
|
|
packageName,
|
|
|
|
getPatchesRepo(),
|
2022-09-11 03:01:06 +02:00
|
|
|
patchDate,
|
2022-09-07 03:37:25 +02:00
|
|
|
);
|
2022-08-30 03:07:28 +02:00
|
|
|
if (newCommits.isEmpty) {
|
2022-09-11 03:01:06 +02:00
|
|
|
newCommits = await _githubAPI.getCommits(
|
|
|
|
packageName,
|
|
|
|
getPatchesRepo(),
|
2022-10-08 18:36:45 +02:00
|
|
|
patchDate,
|
2022-09-11 03:01:06 +02:00
|
|
|
);
|
2022-08-29 16:01:51 +02:00
|
|
|
}
|
2022-08-30 03:07:28 +02:00
|
|
|
return newCommits;
|
2022-08-02 09:55:01 +02:00
|
|
|
}
|
2022-09-23 16:31:24 +02:00
|
|
|
|
|
|
|
Future<bool> isSplitApk(PatchedApplication patchedApp) async {
|
|
|
|
Application? app;
|
|
|
|
if (patchedApp.isFromStorage) {
|
|
|
|
app = await DeviceApps.getAppFromStorage(patchedApp.apkFilePath);
|
|
|
|
} else {
|
|
|
|
app = await DeviceApps.getApp(patchedApp.packageName);
|
|
|
|
}
|
|
|
|
return app != null && app.isSplit;
|
|
|
|
}
|
2022-11-09 08:36:04 +01:00
|
|
|
|
|
|
|
Future<void> setSelectedPatches(String app, List<String> patches) async {
|
|
|
|
final File selectedPatchesFile = File(storedPatchesFile);
|
2023-01-30 13:35:06 +01:00
|
|
|
final Map<String, dynamic> patchesMap = await readSelectedPatchesFile();
|
2022-11-09 08:36:04 +01:00
|
|
|
if (patches.isEmpty) {
|
|
|
|
patchesMap.remove(app);
|
|
|
|
} else {
|
|
|
|
patchesMap[app] = patches;
|
|
|
|
}
|
|
|
|
selectedPatchesFile.writeAsString(jsonEncode(patchesMap));
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<List<String>> getSelectedPatches(String app) async {
|
2023-01-30 13:35:06 +01:00
|
|
|
final Map<String, dynamic> patchesMap = await readSelectedPatchesFile();
|
2023-01-30 13:03:55 +01:00
|
|
|
return List.from(patchesMap.putIfAbsent(app, () => List.empty()));
|
2022-11-09 08:36:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<Map<String, dynamic>> readSelectedPatchesFile() async {
|
|
|
|
final File selectedPatchesFile = File(storedPatchesFile);
|
2023-01-30 13:35:06 +01:00
|
|
|
if (!selectedPatchesFile.existsSync()) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
final String string = selectedPatchesFile.readAsStringSync();
|
|
|
|
if (string.trim().isEmpty) {
|
|
|
|
return {};
|
|
|
|
}
|
2023-01-30 13:03:55 +01:00
|
|
|
return jsonDecode(string);
|
2022-11-09 08:36:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> resetLastSelectedPatches() async {
|
|
|
|
final File selectedPatchesFile = File(storedPatchesFile);
|
|
|
|
selectedPatchesFile.deleteSync();
|
|
|
|
}
|
2022-08-01 21:05:11 +02:00
|
|
|
}
|