From 27fc60d4370457fe700df218197b47b65592ff25 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Tue, 23 Apr 2024 14:35:28 -0400 Subject: [PATCH 1/3] Fix "illegal encoding" error (#1563), Remove foreground requirement for Shizuku (#1561) --- lib/app_sources/html.dart | 41 +++++++++++++++++++--------- lib/providers/apps_provider.dart | 47 ++++++++++++++++++++++---------- 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/lib/app_sources/html.dart b/lib/app_sources/html.dart index 6ebee0a5..b089d6ed 100644 --- a/lib/app_sources/html.dart +++ b/lib/app_sources/html.dart @@ -243,19 +243,28 @@ class HTML extends AppSource { if ((additionalSettings['customLinkFilterRegex'] as String?)?.isNotEmpty == true) { var reg = RegExp(additionalSettings['customLinkFilterRegex']); - links = allLinks - .where((element) => reg.hasMatch( - filterLinkByText ? element.value : Uri.decodeFull(element.key))) - .toList(); + links = allLinks.where((element) { + var link = element.key; + try { + link = Uri.decodeFull(element.key); + } catch (e) { + // Some links may not have valid encoding + } + return reg.hasMatch(filterLinkByText ? element.value : link); + }).toList(); } else { - links = allLinks - .where((element) => Uri.parse(filterLinkByText - ? element.value - : Uri.decodeFull(element.key)) - .path - .toLowerCase() - .endsWith('.apk')) - .toList(); + links = allLinks.where((element) { + var link = element.key; + try { + link = Uri.decodeFull(element.key); + } catch (e) { + // Some links may not have valid encoding + } + return Uri.parse(filterLinkByText ? element.value : link) + .path + .toLowerCase() + .endsWith('.apk'); + }).toList(); } if (!skipSort) { links.sort((a, b) => additionalSettings['sortByLastLinkSegment'] == true @@ -310,13 +319,19 @@ class HTML extends AppSource { links = [MapEntry(currentUrl, currentUrl)]; } var rel = links.last.key; + var relDecoded = rel; + try { + relDecoded = Uri.decodeFull(rel); + } catch (e) { + // Some links may not have valid encoding + } String? version; version = extractVersion( additionalSettings['versionExtractionRegEx'] as String?, additionalSettings['matchGroupToUse'] as String?, additionalSettings['versionExtractWholePage'] == true ? versionExtractionWholePageString - : Uri.decodeFull(rel)); + : relDecoded); version ??= additionalSettings['defaultPseudoVersioningMethod'] == 'APKLinkHash' ? rel.hashCode.toString() diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index ac780f97..f2c15311 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -525,10 +525,11 @@ class AppsProvider with ChangeNotifier { ?.installingPackageName : (await pm.getInstallerPackageName(packageName: app.id)); } catch (e) { - return false; // App probably not installed + return false; // App probably not installed } - int? targetSDK = (await getInstalledInfo(app.id))?.applicationInfo?.targetSdkVersion; + int? targetSDK = + (await getInstalledInfo(app.id))?.applicationInfo?.targetSdkVersion; // The APK should target a new enough API // https://developer.android.com/reference/android/content/pm/PackageInstaller.SessionParams#setRequireUserAction(int) if (!(targetSDK != null && targetSDK >= (osInfo.version.sdkInt - 3))) { @@ -571,7 +572,8 @@ class AppsProvider with ChangeNotifier { Future installXApkDir( DownloadedXApkDir dir, BuildContext? firstTimeWithContext, - {bool needsBGWorkaround = false, bool shizukuPretendToBeGooglePlay = false}) async { + {bool needsBGWorkaround = false, + bool shizukuPretendToBeGooglePlay = false}) async { // We don't know which APKs in an XAPK are supported by the user's device // So we try installing all of them and assume success if at least one installed // If 0 APKs installed, throw the first install error encountered @@ -610,7 +612,8 @@ class AppsProvider with ChangeNotifier { Future installApk( DownloadedApk file, BuildContext? firstTimeWithContext, - {bool needsBGWorkaround = false, bool shizukuPretendToBeGooglePlay = false}) async { + {bool needsBGWorkaround = false, + bool shizukuPretendToBeGooglePlay = false}) async { if (firstTimeWithContext != null && settingsProvider.beforeNewInstallsShareToAppVerifier && (await getInstalledInfo('dev.soupslurpr.appverifier')) != null) { @@ -651,7 +654,8 @@ class AppsProvider with ChangeNotifier { } int? code; if (!settingsProvider.useShizuku) { - code = await AndroidPackageInstaller.installApk(apkFilePath: file.file.path); + code = + await AndroidPackageInstaller.installApk(apkFilePath: file.file.path); } else { code = await ShizukuApkInstaller.installAPK(file.file.uri.toString(), shizukuPretendToBeGooglePlay ? "com.android.vending" : ""); @@ -828,7 +832,7 @@ class AppsProvider with ChangeNotifier { throw ObtainiumError(tr('cancelled')); } } else { - switch((await ShizukuApkInstaller.checkPermission())!){ + switch ((await ShizukuApkInstaller.checkPermission())!) { case 'binder_not_found': throw ObtainiumError(tr('shizukuBinderNotFound')); case 'old_shizuku': @@ -839,7 +843,7 @@ class AppsProvider with ChangeNotifier { throw ObtainiumError(tr('cancelled')); } } - if (!willBeSilent && context != null) { + if (!willBeSilent && context != null && !settingsProvider.useShizuku) { // ignore: use_build_context_synchronously await waitForUserToReturnToForeground(context); } @@ -850,31 +854,46 @@ class AppsProvider with ChangeNotifier { bool sayInstalled = true; var contextIfNewInstall = apps[id]?.installedInfo == null ? context : null; - bool needBGWorkaround = willBeSilent && context == null && !settingsProvider.useShizuku; + bool needBGWorkaround = + willBeSilent && context == null && !settingsProvider.useShizuku; if (downloadedFile != null) { if (needBGWorkaround) { // ignore: use_build_context_synchronously - installApk(downloadedFile, contextIfNewInstall, needsBGWorkaround: true); + installApk(downloadedFile, contextIfNewInstall, + needsBGWorkaround: true); } else { // ignore: use_build_context_synchronously - sayInstalled = await installApk(downloadedFile, contextIfNewInstall, shizukuPretendToBeGooglePlay: apps[id]!.app.additionalSettings['shizukuPretendToBeGooglePlay'] == true); + sayInstalled = await installApk( + downloadedFile, contextIfNewInstall, + shizukuPretendToBeGooglePlay: + apps[id]!.app.additionalSettings[ + 'shizukuPretendToBeGooglePlay'] == + true); } } else { if (needBGWorkaround) { // ignore: use_build_context_synchronously - installXApkDir(downloadedDir!, contextIfNewInstall, needsBGWorkaround: true); + installXApkDir(downloadedDir!, contextIfNewInstall, + needsBGWorkaround: true); } else { // ignore: use_build_context_synchronously - sayInstalled = await installXApkDir(downloadedDir!, contextIfNewInstall, shizukuPretendToBeGooglePlay: apps[id]!.app.additionalSettings['shizukuPretendToBeGooglePlay'] == true); + sayInstalled = await installXApkDir( + downloadedDir!, contextIfNewInstall, + shizukuPretendToBeGooglePlay: + apps[id]!.app.additionalSettings[ + 'shizukuPretendToBeGooglePlay'] == + true); } } if (willBeSilent && context == null) { if (!settingsProvider.useShizuku) { notificationsProvider?.notify(SilentUpdateAttemptNotification( - [apps[id]!.app], id: id.hashCode)); + [apps[id]!.app], + id: id.hashCode)); } else { notificationsProvider?.notify(SilentUpdateNotification( - [apps[id]!.app], sayInstalled, id: id.hashCode)); + [apps[id]!.app], sayInstalled, + id: id.hashCode)); } } if (sayInstalled) { From b7de627c7bdb86582312b36892352086b2c00a18 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Tue, 23 Apr 2024 14:43:37 -0400 Subject: [PATCH 2/3] Share apps.obtainium.imranr.dev config links instead of HTML raw (#1553) --- lib/pages/apps.dart | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/pages/apps.dart b/lib/pages/apps.dart index 7da0e2b8..f26ca9ae 100644 --- a/lib/pages/apps.dart +++ b/lib/pages/apps.dart @@ -882,11 +882,10 @@ class AppsPageState extends State { onPressed: selectedAppIds.isEmpty ? null : () { - String urls = - '

${tr('customLinkMessage')}:

\n\n
    \n'; + String urls = ''; for (var a in selectedApps) { urls += - '
  • ${a.name}
  • \n'; + }))}\n\n'; } - urls += - '
\n\n

${tr('about')}

'; Share.share(urls, subject: 'Obtainium - ${tr('appsString')}'); From f76637a2e1c4dc06a25a52948d1ad92905158935 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Tue, 23 Apr 2024 14:47:13 -0400 Subject: [PATCH 3/3] Update packages, increment version --- pubspec.lock | 32 ++++++++++++++++---------------- pubspec.yaml | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 86884926..e2ca3043 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -79,10 +79,10 @@ packages: dependency: "direct main" description: name: background_fetch - sha256: dbffec0317ccdef6e2014cb543e147f52441e29c4fcb53dfd23558c4d92ddece + sha256: "81d0d4eeecd17c971335438a5a55554c8302f479f92c7f7bc7f147f75d3f6074" url: "https://pub.dev" source: hosted - version: "1.3.2" + version: "1.3.3" boolean_selector: dependency: transitive description: @@ -135,10 +135,10 @@ packages: dependency: "direct main" description: name: connectivity_plus - sha256: ebe15d94de9dd7c31dc2ac54e42780acdf3384b1497c69290c9f3c5b0279fc57 + sha256: db7a4e143dc72cc3cb2044ef9b052a7ebfe729513e6a82943bc3526f784365b8 url: "https://pub.dev" source: hosted - version: "6.0.2" + version: "6.0.3" connectivity_plus_platform_interface: dependency: transitive description: @@ -223,10 +223,10 @@ packages: dependency: "direct main" description: name: easy_localization - sha256: c145aeb6584aedc7c862ab8c737c3277788f47488bfdf9bae0fe112bd0a4789c + sha256: "432698c31a488dd64c56d4759f20d04844baba5e9e4f2cb1abb9676257918b17" url: "https://pub.dev" source: hosted - version: "3.0.5" + version: "3.0.6" easy_logger: dependency: transitive description: @@ -271,10 +271,10 @@ packages: dependency: "direct main" description: name: file_picker - sha256: b6283d7387310ad83bc4f3bc245b75d223a032ae6eba275afcd585de2b9a1476 + sha256: "45c70b43df893027e441a6fa0aacc8f484fb9f9c60c746dc8f1dc4f774cf55cd" url: "https://pub.dev" source: hosted - version: "8.0.1" + version: "8.0.2" fixnum: dependency: transitive description: @@ -340,10 +340,10 @@ packages: dependency: "direct main" description: name: flutter_local_notifications - sha256: a701df4866f9a38bb8e4450a54c143bbeeb0ce2381e7df5a36e1006f3b43bb28 + sha256: "8cdc719114ab1c86c64bb7a86d3a679674c3637edd229e3a994797d4a1504ce4" url: "https://pub.dev" source: hosted - version: "17.0.1" + version: "17.1.0" flutter_local_notifications_linux: dependency: transitive description: @@ -356,10 +356,10 @@ packages: dependency: transitive description: name: flutter_local_notifications_platform_interface - sha256: "7cf643d6d5022f3baed0be777b0662cce5919c0a7b86e700299f22dc4ae660ef" + sha256: "340abf67df238f7f0ef58f4a26d2a83e1ab74c77ab03cd2b2d5018ac64db30b7" url: "https://pub.dev" source: hosted - version: "7.0.0+1" + version: "7.1.0" flutter_localizations: dependency: transitive description: flutter @@ -715,18 +715,18 @@ packages: dependency: "direct main" description: name: share_plus - sha256: fb5319f3aab4c5dda5ebb92dca978179ba21f8c783ee4380910ef4c1c6824f51 + sha256: ef3489a969683c4f3d0239010cc8b7a2a46543a8d139e111c06c558875083544 url: "https://pub.dev" source: hosted - version: "8.0.3" + version: "9.0.0" share_plus_platform_interface: dependency: transitive description: name: share_plus_platform_interface - sha256: "251eb156a8b5fa9ce033747d73535bf53911071f8d3b6f4f0b578505ce0d4496" + sha256: "0f9e4418835d1b2c3ae78fdb918251959106cefdbc4dd43526e182f80e82f6d4" url: "https://pub.dev" source: hosted - version: "3.4.0" + version: "4.0.0" shared_preferences: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index d4ea3a2e..417c745a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.1.5+2262 +version: 1.1.6+2263 environment: sdk: '>=3.0.0 <4.0.0' @@ -56,7 +56,7 @@ dependencies: url: https://github.com/ImranR98/android_package_installer ref: main android_package_manager: ^0.7.0 - share_plus: ^8.0.2 + share_plus: ^9.0.0 sqflite: ^2.2.0+3 easy_localization: ^3.0.1 android_intent_plus: ^5.0.1