diff options
author | Alexander Martinz <amartinz@shiftphones.com> | 2018-06-12 16:40:26 +0200 |
---|---|---|
committer | Alexander Martinz <alex@amartinz.at> | 2018-06-18 10:07:53 +0200 |
commit | ea105311e95c192490c998baf9d0392a6055663b (patch) | |
tree | 426d2bb54de0fd0f074acee6b669e81eb9396599 | |
parent | aa8b6a1fca0c4ce41a8ca21e8f11fea5a5e79891 (diff) | |
download | android_packages_apps_Trebuchet-ea105311e95c192490c998baf9d0392a6055663b.tar.gz android_packages_apps_Trebuchet-ea105311e95c192490c998baf9d0392a6055663b.tar.bz2 android_packages_apps_Trebuchet-ea105311e95c192490c998baf9d0392a6055663b.zip |
IconCache: fix nullpointer exceptions
LauncherActivityInfo's or resolved activities can be null.
Example crash:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.ComponentName android.content.pm.LauncherActivityInfo.getComponentName()' on a null object reference
at com.android.launcher3.IconCache.getCacheEntry(IconCache.java:392)
at com.android.launcher3.Launcher.startEdit(Launcher.java:3988)
at com.android.launcher3.popup.SystemShortcut$AppEdit.lambda$-com_android_launcher3_popup_SystemShortcut$AppEdit_4399(SystemShortcut.java:115)
at com.android.launcher3.popup.-$Lambda$_SMHeS1Apq5nUPo60kvmkZszeNE.$m$0
at com.android.launcher3.popup.-$Lambda$_SMHeS1Apq5nUPo60kvmkZszeNE.onClick
at android.view.View.performClick(View.java:6320)
at android.view.View$PerformClick.run(View.java:25087)
at android.os.Handler.handleCallback(Handler.java:869)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:206)
at android.app.ActivityThread.main(ActivityThread.java:6733)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:845)
Issue: SHIFTOS-SW-31
Change-Id: If5f027e3146b358036b1ac1a1e973467d4fca2c4
Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
-rw-r--r-- | src/com/android/launcher3/IconCache.java | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index 137265262..453e3834e 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -300,6 +300,10 @@ public class IconCache { while (c.moveToNext()) { String cn = c.getString(indexComponent); ComponentName component = ComponentName.unflattenFromString(cn); + if (component == null) { + continue; + } + PackageInfo info = pkgInfoMap.get(component.getPackageName()); if (info == null) { if (!ignorePackages.contains(component.getPackageName())) { @@ -389,9 +393,12 @@ public class IconCache { } CacheEntry getCacheEntry(LauncherActivityInfo app) { + if (app == null) { + return null; + } final ComponentKey key = new ComponentKey(app.getComponentName(), app.getUser()); return mCache.get(key); - } + } public void clearIconDataBase() { mIconDb.clearDB(); @@ -399,6 +406,10 @@ public class IconCache { public void addCustomInfoToDataBase(Drawable icon, ItemInfo info, CharSequence title) { LauncherActivityInfo app = mLauncherApps.resolveActivity(info.getIntent(), info.user); + if (app == null) { + return; + } + final ComponentKey key = new ComponentKey(app.getComponentName(), app.getUser()); CacheEntry entry = mCache.get(key); PackageInfo packageInfo = null; @@ -410,7 +421,7 @@ public class IconCache { // We can't reuse the entry if the high-res icon is not present. if (entry == null || entry.isLowResIcon || entry.icon == null) { entry = new CacheEntry(); - } + } entry.icon = ((BitmapDrawable) icon).getBitmap(); entry.title = title != null ? title : app.getLabel(); entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, app.getUser()); @@ -418,12 +429,12 @@ public class IconCache { Bitmap lowResIcon = generateLowResIcon(entry.icon); ContentValues values = newContentValues(entry.icon, lowResIcon, entry.title.toString(), - app.getApplicationInfo().packageName); + app.getApplicationInfo().packageName); if (packageInfo != null) { addIconToDB(values, app.getComponentName(), packageInfo, mUserManager.getSerialNumberForUser(app.getUser())); - } } + } /** * Updates {@param values} to contain versioning information and adds it to the DB. |