summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaj Yengisetty <rajesh@cyngn.com>2015-07-08 23:00:37 (GMT)
committerRaj Yengisetty <rajesh@cyngn.com>2015-07-08 23:00:40 (GMT)
commit9abe70951b1cc559f82bbf803a1f4893105c27c9 (patch)
treec6491c45d9fbdb2c79c26a0c09ba54f47d2c9529
parent7a90da166119c940c583dc86d61c135d669bf570 (diff)
downloadandroid_packages_apps_Gallery2-9abe70951b1cc559f82bbf803a1f4893105c27c9.zip
android_packages_apps_Gallery2-9abe70951b1cc559f82bbf803a1f4893105c27c9.tar.gz
android_packages_apps_Gallery2-9abe70951b1cc559f82bbf803a1f4893105c27c9.tar.bz2
Photo Gallery widget: fix NPE in getViewAt
Repro: - Add Photo Gallery widget to a home screen - Select "Shuffle all images" - Immediately drag widget to "Remove" - Observe NPE The remote view is destroyed and the reference to mSource is null. By making onDestroy and getViewAt synchronized methods, we ensure that destroy cannot be executed to null out mSource while getViewAt is being called. Change-Id: I470f9f6227f437039cf111071c905268db1bd62e
-rw-r--r--src/com/android/gallery3d/gadget/WidgetService.java8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/com/android/gallery3d/gadget/WidgetService.java b/src/com/android/gallery3d/gadget/WidgetService.java
index fc54fb6..8544337 100644
--- a/src/com/android/gallery3d/gadget/WidgetService.java
+++ b/src/com/android/gallery3d/gadget/WidgetService.java
@@ -80,7 +80,7 @@ public class WidgetService extends RemoteViewsService {
}
@Override
- public void onDestroy() {
+ public synchronized void onDestroy() {
mSource.close();
mSource = null;
}
@@ -115,7 +115,11 @@ public class WidgetService extends RemoteViewsService {
}
@Override
- public RemoteViews getViewAt(int position) {
+ public synchronized RemoteViews getViewAt(int position) {
+ if (mSource == null) {
+ // This instance has been destroyed, exit out
+ return null;
+ }
Bitmap bitmap = mSource.getImage(position);
if (bitmap == null) return getLoadingView();
RemoteViews views = new RemoteViews(