catch NameNotFoundException when looking up installer name

If an application was installed via ADB, then it won't have an installer
package/name set.  Therefore, looking up the label will cause a
NameNotFoundException, which should be ignored and not passed to the method
that called App() since it does not refer to the packageName that the
method is trying to look up, but instead the packageName of the missing
installer app.
This commit is contained in:
Hans-Christoph Steiner 2014-05-06 23:15:51 -04:00
parent 2aa39311c2
commit 2848b50f8b

View File

@ -188,11 +188,19 @@ public class App extends ValueObject implements Comparable<App> {
String installerPackageName = pm.getInstallerPackageName(packageName);
ApplicationInfo installerAppInfo = pm.getApplicationInfo(installerPackageName,
PackageManager.GET_META_DATA);
CharSequence installerPackageLabel = installerAppInfo.loadLabel(pm);
CharSequence installerPackageLabel = null;
if (!TextUtils.isEmpty(installerPackageName)) {
try {
ApplicationInfo installerAppInfo = pm.getApplicationInfo(installerPackageName,
PackageManager.GET_META_DATA);
installerPackageLabel = installerAppInfo.loadLabel(pm);
} catch (NameNotFoundException e) {
Log.d(getClass().getCanonicalName(), e.getMessage());
}
}
if (TextUtils.isEmpty(installerPackageLabel))
installerPackageLabel = installerPackageName;
CharSequence appDescription = appInfo.loadDescription(pm);
if (TextUtils.isEmpty(appDescription))
this.summary = "(installed by " + installerPackageLabel + ")";