summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorRaj Yengisetty <rajesh@cyngn.com>2015-07-08 16:00:37 -0700
committerRaj Yengisetty <rajesh@cyngn.com>2015-07-08 16:00:40 -0700
commit9abe70951b1cc559f82bbf803a1f4893105c27c9 (patch)
treec6491c45d9fbdb2c79c26a0c09ba54f47d2c9529 /src/com
parent7a90da166119c940c583dc86d61c135d669bf570 (diff)
downloadandroid_packages_apps_Gallery2-9abe70951b1cc559f82bbf803a1f4893105c27c9.tar.gz
android_packages_apps_Gallery2-9abe70951b1cc559f82bbf803a1f4893105c27c9.tar.bz2
android_packages_apps_Gallery2-9abe70951b1cc559f82bbf803a1f4893105c27c9.zip
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
Diffstat (limited to 'src/com')
-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 fc54fb6e8..854433776 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(