Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update dependencies #772

Merged
merged 6 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ android {
ndkVersion flutter.ndkVersion

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
Expand All @@ -48,6 +49,7 @@ android {
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}

buildTypes {
Expand Down Expand Up @@ -81,4 +83,11 @@ dependencies {
implementation("org.microg:cronet-common:$cronetVersion")
implementation("org.microg:cronet-native:$cronetVersion")

// Core libraries
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'

// Window
implementation 'androidx.window:window:1.0.0'
implementation 'androidx.window:window-java:1.0.0'

}
17 changes: 12 additions & 5 deletions lib/services/github_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:revanced_manager/models/patch.dart';
@lazySingleton
class GithubAPI {
late Dio _dio = Dio();

final _cacheOptions = CacheOptions(
store: MemCacheStore(),
maxStale: const Duration(days: 1),
Expand Down Expand Up @@ -73,7 +73,9 @@ class GithubAPI {
}
}

Future<Map<String, dynamic>?> getLatestRelease(String repoName) async {
Future<Map<String, dynamic>?> getLatestRelease(
String repoName,
) async {
try {
final response = await _dio.get(
'/repos/$repoName/releases',
Expand Down Expand Up @@ -119,9 +121,13 @@ class GithubAPI {
return [];
}

Future<File?> getLatestReleaseFile(String extension, String repoName) async {
Future<File?> getLatestReleaseFile(
String extension,
String repoName,
) async {
try {
final Map<String, dynamic>? release = await getLatestRelease(repoName);
final Map<String, dynamic>? release =
await getLatestRelease(repoName);
if (release != null) {
final Map<String, dynamic>? asset =
(release['assets'] as List<dynamic>).firstWhereOrNull(
Expand Down Expand Up @@ -160,7 +166,8 @@ class GithubAPI {

Future<String> getLastestReleaseVersion(String repoName) async {
try {
final Map<String, dynamic>? release = await getLatestRelease(repoName);
final Map<String, dynamic>? release =
await getLatestRelease(repoName);
if (release != null) {
return release['tag_name'];
} else {
Expand Down
68 changes: 49 additions & 19 deletions lib/services/manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class ManagerAPI {
Future<void> initialize() async {
_prefs = await SharedPreferences.getInstance();
storedPatchesFile =
(await getApplicationDocumentsDirectory()).path + storedPatchesFile;
(await getApplicationDocumentsDirectory()).path +
storedPatchesFile;
}

String getApiUrl() {
Expand Down Expand Up @@ -78,7 +79,8 @@ class ManagerAPI {
}

String getIntegrationsRepo() {
return _prefs.getString('integrationsRepo') ?? defaultIntegrationsRepo;
return _prefs.getString('integrationsRepo') ??
defaultIntegrationsRepo;
}

Future<void> setIntegrationsRepo(String value) async {
Expand Down Expand Up @@ -146,10 +148,14 @@ class ManagerAPI {

List<PatchedApplication> getPatchedApps() {
final List<String> apps = _prefs.getStringList('patchedApps') ?? [];
return apps.map((a) => PatchedApplication.fromJson(jsonDecode(a))).toList();
return apps
.map((a) => PatchedApplication.fromJson(jsonDecode(a)))
.toList();
}

Future<void> setPatchedApps(List<PatchedApplication> patchedApps) async {
Future<void> setPatchedApps(
List<PatchedApplication> patchedApps,
) async {
if (patchedApps.length > 1) {
patchedApps.sort((a, b) => a.name.compareTo(b.name));
}
Expand Down Expand Up @@ -251,15 +257,24 @@ class ManagerAPI {
}

Future<File?> downloadManager() async {
return await _revancedAPI.getLatestReleaseFile('.apk', defaultManagerRepo);
return await _revancedAPI.getLatestReleaseFile(
'.apk',
defaultManagerRepo,
);
}

Future<String?> getLatestPatcherReleaseTime() async {
return await _revancedAPI.getLatestReleaseTime('.gz', defaultPatcherRepo);
return await _revancedAPI.getLatestReleaseTime(
'.gz',
defaultPatcherRepo,
);
}

Future<String?> getLatestManagerReleaseTime() async {
return await _revancedAPI.getLatestReleaseTime('.apk', defaultManagerRepo);
return await _revancedAPI.getLatestReleaseTime(
'.apk',
defaultManagerRepo,
);
}

Future<String?> getLatestManagerVersion() async {
Expand Down Expand Up @@ -313,10 +328,12 @@ class ManagerAPI {
final List<PatchedApplication> unsavedApps = [];
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
if (hasRootPermissions) {
final List<String> installedApps = await _rootAPI.getInstalledApps();
final List<String> installedApps =
await _rootAPI.getInstalledApps();
for (final String packageName in installedApps) {
if (!patchedApps.any((app) => app.packageName == packageName)) {
final ApplicationWithIcon? application = await DeviceApps.getApp(
final ApplicationWithIcon? application =
await DeviceApps.getApp(
packageName,
true,
) as ApplicationWithIcon?;
Expand All @@ -342,8 +359,10 @@ class ManagerAPI {
for (final Application app in userApps) {
if (app.packageName.startsWith('app.revanced') &&
!app.packageName.startsWith('app.revanced.manager.') &&
!patchedApps.any((uapp) => uapp.packageName == app.packageName)) {
final ApplicationWithIcon? application = await DeviceApps.getApp(
!patchedApps
.any((uapp) => uapp.packageName == app.packageName)) {
final ApplicationWithIcon? application =
await DeviceApps.getApp(
app.packageName,
true,
) as ApplicationWithIcon?;
Expand Down Expand Up @@ -386,8 +405,9 @@ class ManagerAPI {
final int currentInstalledVersionInt = int.parse(
currentInstalledVersion.replaceAll(RegExp('[^0-9]'), ''),
);
final int currentSavedVersionInt =
int.parse(currentSavedVersion.replaceAll(RegExp('[^0-9]'), ''));
final int currentSavedVersionInt = int.parse(
currentSavedVersion.replaceAll(RegExp('[^0-9]'), ''),
);
if (currentInstalledVersionInt > currentSavedVersionInt) {
app.hasUpdates = true;
}
Expand All @@ -399,9 +419,11 @@ class ManagerAPI {

Future<bool> isAppUninstalled(PatchedApplication app) async {
bool existsRoot = false;
final bool existsNonRoot = await DeviceApps.isAppInstalled(app.packageName);
final bool existsNonRoot =
await DeviceApps.isAppInstalled(app.packageName);
if (app.isRooted) {
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
final bool hasRootPermissions =
await _rootAPI.hasRootPermissions();
if (hasRootPermissions) {
existsRoot = await _rootAPI.isAppInstalled(app.packageName);
}
Expand All @@ -410,7 +432,10 @@ class ManagerAPI {
return !existsNonRoot;
}

Future<bool> hasAppUpdates(String packageName, DateTime patchDate) async {
Future<bool> hasAppUpdates(
String packageName,
DateTime patchDate,
) async {
final List<String> commits = await _githubAPI.getCommits(
packageName,
getPatchesRepo(),
Expand Down Expand Up @@ -448,9 +473,13 @@ class ManagerAPI {
return app != null && app.isSplit;
}

Future<void> setSelectedPatches(String app, List<String> patches) async {
Future<void> setSelectedPatches(
String app,
List<String> patches,
) async {
final File selectedPatchesFile = File(storedPatchesFile);
final Map<String, dynamic> patchesMap = await readSelectedPatchesFile();
final Map<String, dynamic> patchesMap =
await readSelectedPatchesFile();
if (patches.isEmpty) {
patchesMap.remove(app);
} else {
Expand All @@ -460,7 +489,8 @@ class ManagerAPI {
}

Future<List<String>> getSelectedPatches(String app) async {
final Map<String, dynamic> patchesMap = await readSelectedPatchesFile();
final Map<String, dynamic> patchesMap =
await readSelectedPatchesFile();
return List.from(patchesMap.putIfAbsent(app, () => List.empty()));
}

Expand Down
42 changes: 29 additions & 13 deletions lib/services/patcher_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class PatcherAPI {
onlyAppsWithLaunchIntent: true,
);
for (final pkg in allPackages) {
if (!filteredApps.any((app) => app.packageName == pkg.packageName)) {
if (!filteredApps
.any((app) => app.packageName == pkg.packageName)) {
final appInfo = await DeviceApps.getApp(
pkg.packageName,
true,
Expand All @@ -83,7 +84,8 @@ class PatcherAPI {
for (final Patch patch in _patches) {
for (final Package package in patch.compatiblePackages) {
try {
if (!filteredApps.any((app) => app.packageName == package.name)) {
if (!filteredApps
.any((app) => app.packageName == package.name)) {
final ApplicationWithIcon? app = await DeviceApps.getApp(
package.name,
true,
Expand Down Expand Up @@ -118,13 +120,17 @@ class PatcherAPI {
return filteredPatches[packageName];
}

Future<List<Patch>> getAppliedPatches(List<String> appliedPatches) async {
Future<List<Patch>> getAppliedPatches(
List<String> appliedPatches,
) async {
return _patches
.where((patch) => appliedPatches.contains(patch.name))
.toList();
}

Future<bool> needsResourcePatching(List<Patch> selectedPatches) async {
Future<bool> needsResourcePatching(
List<Patch> selectedPatches,
) async {
return selectedPatches.any(
(patch) => patch.dependencies.any(
(dep) => dep.contains('resource-'),
Expand All @@ -145,7 +151,8 @@ class PatcherAPI {
String originalFilePath,
) async {
try {
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
final bool hasRootPermissions =
await _rootAPI.hasRootPermissions();
if (hasRootPermissions) {
originalFilePath = await _rootAPI.getOriginalFilePath(
packageName,
Expand All @@ -166,13 +173,15 @@ class PatcherAPI {
String originalFilePath,
List<Patch> selectedPatches,
) async {
final bool includeSettings = await needsSettingsPatch(selectedPatches);
final bool includeSettings =
await needsSettingsPatch(selectedPatches);
if (includeSettings) {
try {
final Patch? settingsPatch = _patches.firstWhereOrNull(
(patch) =>
patch.name.contains('settings') &&
patch.compatiblePackages.any((pack) => pack.name == packageName),
patch.compatiblePackages
.any((pack) => pack.name == packageName),
);
if (settingsPatch != null) {
selectedPatches.add(settingsPatch);
Expand All @@ -184,7 +193,8 @@ class PatcherAPI {
}
}
final File? patchBundleFile = await _managerAPI.downloadPatches();
final File? integrationsFile = await _managerAPI.downloadIntegrations();
final File? integrationsFile =
await _managerAPI.downloadIntegrations();
if (patchBundleFile != null) {
_dataDir.createSync();
_tmpDir.createSync();
Expand All @@ -207,7 +217,8 @@ class PatcherAPI {
'patchedFilePath': patchedFile.path,
'outFilePath': _outFile!.path,
'integrationsPath': integrationsFile!.path,
'selectedPatches': selectedPatches.map((p) => p.name).toList(),
'selectedPatches':
selectedPatches.map((p) => p.name).toList(),
'cacheDirPath': cacheDir.path,
'keyStoreFilePath': _keyStoreFile.path,
'keystorePassword': _managerAPI.getKeystorePassword(),
Expand All @@ -225,7 +236,8 @@ class PatcherAPI {
if (_outFile != null) {
try {
if (patchedApp.isRooted) {
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
final bool hasRootPermissions =
await _rootAPI.hasRootPermissions();
if (hasRootPermissions) {
return _rootAPI.installApp(
patchedApp.packageName,
Expand All @@ -235,7 +247,9 @@ class PatcherAPI {
}
} else {
await AppInstaller.installApk(_outFile!.path);
return await DeviceApps.isAppInstalled(patchedApp.packageName);
return await DeviceApps.isAppInstalled(
patchedApp.packageName,
);
}
} on Exception catch (e) {
if (kDebugMode) {
Expand Down Expand Up @@ -307,7 +321,8 @@ class PatcherAPI {
String getRecommendedVersion(String packageName) {
final Map<String, int> versions = {};
for (final Patch patch in _patches) {
final Package? package = patch.compatiblePackages.firstWhereOrNull(
final Package? package =
patch.compatiblePackages.firstWhereOrNull(
(pack) => pack.name == packageName,
);
if (package != null) {
Expand All @@ -326,7 +341,8 @@ class PatcherAPI {
versions
..clear()
..addEntries(entries);
versions.removeWhere((key, value) => value != versions.values.last);
versions
.removeWhere((key, value) => value != versions.values.last);
return (versions.keys.toList()..sort()).last;
}
return '';
Expand Down
7 changes: 5 additions & 2 deletions lib/services/revanced_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'package:timeago/timeago.dart';
@lazySingleton
class RevancedAPI {
late Dio _dio = Dio();

final _cacheOptions = CacheOptions(
store: MemCacheStore(),
maxStale: const Duration(days: 1),
Expand Down Expand Up @@ -142,7 +142,10 @@ class RevancedAPI {
return null;
}

Future<File?> getLatestReleaseFile(String extension, String repoName) async {
Future<File?> getLatestReleaseFile(
String extension,
String repoName,
) async {
try {
final Map<String, dynamic>? release = await _getLatestRelease(
extension,
Expand Down
Loading