mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-13 02:18:10 +02:00
Change background shizuku logic
This commit is contained in:
@@ -509,9 +509,6 @@ class AppsProvider with ChangeNotifier {
|
|||||||
.isNotEmpty;
|
.isNotEmpty;
|
||||||
|
|
||||||
Future<bool> canInstallSilently(App app) async {
|
Future<bool> canInstallSilently(App app) async {
|
||||||
if (app.id == obtainiumId) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!settingsProvider.enableBackgroundUpdates) {
|
if (!settingsProvider.enableBackgroundUpdates) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -519,8 +516,7 @@ class AppsProvider with ChangeNotifier {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (app.apkUrls.length > 1) {
|
if (app.apkUrls.length > 1) {
|
||||||
// Manual API selection means silent install is not possible
|
return false; // Manual API selection means silent install is not possible
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var osInfo = await DeviceInfoPlugin().androidInfo;
|
var osInfo = await DeviceInfoPlugin().androidInfo;
|
||||||
@@ -531,20 +527,29 @@ class AppsProvider with ChangeNotifier {
|
|||||||
?.installingPackageName
|
?.installingPackageName
|
||||||
: (await pm.getInstallerPackageName(packageName: app.id));
|
: (await pm.getInstallerPackageName(packageName: app.id));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Probably not installed - ignore
|
return false; // App probably not installed
|
||||||
}
|
}
|
||||||
if (installerPackageName != obtainiumId) {
|
|
||||||
// If we did not install the app (or it isn't installed), silent install is not possible
|
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))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int? targetSDK =
|
|
||||||
(await getInstalledInfo(app.id))?.applicationInfo?.targetSdkVersion;
|
|
||||||
|
|
||||||
// The OS must also be new enough and the APK should target a new enough API
|
if (settingsProvider.useShizuku) {
|
||||||
return osInfo.version.sdkInt >= 31 &&
|
return true;
|
||||||
targetSDK != null &&
|
}
|
||||||
targetSDK >= // https://developer.android.com/reference/android/content/pm/PackageInstaller.SessionParams#setRequireUserAction(int)
|
|
||||||
(osInfo.version.sdkInt - 3);
|
if (app.id == obtainiumId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (installerPackageName != obtainiumId) {
|
||||||
|
// If we did not install the app, silent install is not possible
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// The OS must also be new enough
|
||||||
|
return osInfo.version.sdkInt >= 31;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> waitForUserToReturnToForeground(BuildContext context) async {
|
Future<void> waitForUserToReturnToForeground(BuildContext context) async {
|
||||||
@@ -634,7 +639,7 @@ class AppsProvider with ChangeNotifier {
|
|||||||
!(await canDowngradeApps())) {
|
!(await canDowngradeApps())) {
|
||||||
throw DowngradeError();
|
throw DowngradeError();
|
||||||
}
|
}
|
||||||
if (needsBGWorkaround && !settingsProvider.useShizuku) {
|
if (needsBGWorkaround) {
|
||||||
// The below 'await' will never return if we are in a background process
|
// The below 'await' will never return if we are in a background process
|
||||||
// To work around this, we should assume the install will be successful
|
// To work around this, we should assume the install will be successful
|
||||||
// So we update the app's installed version first as we will never get to the later code
|
// So we update the app's installed version first as we will never get to the later code
|
||||||
@@ -837,7 +842,7 @@ class AppsProvider with ChangeNotifier {
|
|||||||
throw ObtainiumError(tr('cancelled'));
|
throw ObtainiumError(tr('cancelled'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!willBeSilent && context != null && !settingsProvider.useShizuku) {
|
if (!willBeSilent && context != null) {
|
||||||
// ignore: use_build_context_synchronously
|
// ignore: use_build_context_synchronously
|
||||||
await waitForUserToReturnToForeground(context);
|
await waitForUserToReturnToForeground(context);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user