From 862e985cc4de8e8adc1102117065604a606379e2 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 27 Jun 2018 23:13:21 +0200 Subject: [PATCH] the current app is not always available when requesting uninstall Since there are many ways to uninstall an app, including from Google Play, {@code adb uninstall}, or Settings -> Apps, this method cannot ever be sure that the app isn't already being uninstalled. So it needs to check that we can actually get info on the installed app, otherwise, just call it interrupted and quit. closes #1435 --- .../java/org/fdroid/fdroid/AppDetails2.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/AppDetails2.java b/app/src/main/java/org/fdroid/fdroid/AppDetails2.java index a2fbf06cb..3019ace1e 100644 --- a/app/src/main/java/org/fdroid/fdroid/AppDetails2.java +++ b/app/src/main/java/org/fdroid/fdroid/AppDetails2.java @@ -765,18 +765,29 @@ public class AppDetails2 extends AppCompatActivity installApk(apkToInstall); } + /** + * Uninstall the app from the current screen. Since there are many ways + * to uninstall an app, including from Google Play, {@code adb uninstall}, + * or Settings -> Apps, this method cannot ever be sure that the app isn't + * already being uninstalled. So it needs to check that we can actually + * get info on the installed app, otherwise, just call it interrupted and + * quit. + * + * @see issue #1435 + */ @Override public void uninstallApk() { Apk apk = app.installedApk; if (apk == null) { - // TODO ideally, app would be refreshed immediately after install, then this - // workaround would be unnecessary - unless it is a media file apk = app.getMediaApkifInstalled(getApplicationContext()); if (apk == null) { // When the app isn't a media file - the above workaround refers to this. apk = app.getInstalledApk(this); if (apk == null) { - throw new IllegalStateException("Couldn't find installed apk for " + app.packageName); + Log.d(TAG, "Couldn't find installed apk for " + app.packageName); + Toast.makeText(this, R.string.uninstall_error_unknown, Toast.LENGTH_SHORT).show(); + uninstallReceiver.onReceive(this, new Intent(Installer.ACTION_UNINSTALL_INTERRUPTED)); + return; } } app.installedApk = apk;