Allow App downgrades if com.berdik.letmedowngrade installed

This commit is contained in:
Imran Remtulla
2022-11-12 10:05:46 -05:00
parent 55cae0620b
commit 0e0a39a40f

View File

@@ -182,6 +182,15 @@ class AppsProvider with ChangeNotifier {
}
}
Future<bool> canDowngradeApps() async {
try {
await InstalledApps.getAppInfo('com.berdik.letmedowngrade');
return true;
} catch (e) {
return false;
}
}
// Unfortunately this 'await' does not actually wait for the APK to finish installing
// So we only know that the install prompt was shown, but the user could still cancel w/o us knowing
// If appropriate criteria are met, the update (never a fresh install) happens silently in the background
@@ -195,7 +204,8 @@ class AppsProvider with ChangeNotifier {
// OK
}
if (appInfo != null &&
int.parse(newInfo.buildNumber) < appInfo.versionCode!) {
int.parse(newInfo.buildNumber) < appInfo.versionCode! &&
!(await canDowngradeApps())) {
throw DowngradeError();
}
if (appInfo == null ||