From 89bedfda13b8753e5354898904ba9ff6594a907f Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 11 Mar 2015 18:12:02 +0100 Subject: [PATCH] Do not crash on app uninstall MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Immediately after an app uninstall, the associated App will be updated by a call to reset() in the AppObserver.onChange(). But before receiving this event, the activity and the fragments resume, leading to a call to getInstalledStatus(…). At this stage, we don't know that the app has been removed yet, but the package manager already removed it. Therefore, PackageManager.getInstallerPackageName(…) throws an IllegalArgumentException. In that case, consider that the application has been uninstalled. Should fix issue #167 https://gitlab.com/fdroid/fdroidclient/issues/167 --- F-Droid/src/org/fdroid/fdroid/AppDetails.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/F-Droid/src/org/fdroid/fdroid/AppDetails.java b/F-Droid/src/org/fdroid/fdroid/AppDetails.java index 87a822607..8199391bb 100644 --- a/F-Droid/src/org/fdroid/fdroid/AppDetails.java +++ b/F-Droid/src/org/fdroid/fdroid/AppDetails.java @@ -184,7 +184,13 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A return getString(R.string.inst); } // Installed the same version, but from someplace else. - final String installerPkgName = mPm.getInstallerPackageName(app.id); + final String installerPkgName; + try { + installerPkgName = mPm.getInstallerPackageName(app.id); + } catch (IllegalArgumentException e) { + Log.w(TAG, "Application " + app.id + " is not installed anymore"); + return getString(R.string.not_inst); + } if (installerPkgName != null && installerPkgName.length() > 0) { final String installerLabel = InstalledAppProvider .getApplicationLabel(mctx, installerPkgName);