Skip to content

Commit

Permalink
Merge pull request #1567 from ImranR98/dev
Browse files Browse the repository at this point in the history
- Share apps.obtainium.imranr.dev config links instead of HTML raw (#1553)
- Remove foreground requirement for Shizuku (#1561)
- Fix "illegal encoding" error (#1563)
  • Loading branch information
ImranR98 authored Apr 23, 2024
2 parents ec240f9 + f76637a commit d33ca09
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 51 deletions.
41 changes: 28 additions & 13 deletions lib/app_sources/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 3 additions & 6 deletions lib/pages/apps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -882,11 +882,10 @@ class AppsPageState extends State<AppsPage> {
onPressed: selectedAppIds.isEmpty
? null
: () {
String urls =
'<p>${tr('customLinkMessage')}:</p>\n\n<ul>\n';
String urls = '';
for (var a in selectedApps) {
urls +=
' <li><a href="obtainium://app/${Uri.encodeComponent(jsonEncode({
'https://apps.obtainium.imranr.dev/redirect?r=obtainium://app/${Uri.encodeComponent(jsonEncode({
'id': a.id,
'url': a.url,
'author': a.author,
Expand All @@ -895,10 +894,8 @@ class AppsPageState extends State<AppsPage> {
a.preferredApkIndex,
'additionalSettings':
jsonEncode(a.additionalSettings)
}))}">${a.name}</a></li>\n';
}))}\n\n';
}
urls +=
'</ul>\n\n<p><a href="$obtainiumUrl">${tr('about')}</a></p>';
Share.share(urls,
subject:
'Obtainium - ${tr('appsString')}');
Expand Down
47 changes: 33 additions & 14 deletions lib/providers/apps_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down Expand Up @@ -571,7 +572,8 @@ class AppsProvider with ChangeNotifier {

Future<bool> 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
Expand Down Expand Up @@ -610,7 +612,8 @@ class AppsProvider with ChangeNotifier {

Future<bool> 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) {
Expand Down Expand Up @@ -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" : "");
Expand Down Expand Up @@ -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':
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down
32 changes: 16 additions & 16 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d33ca09

Please sign in to comment.