diff options
author | Raj Yengisetty <rajesh@cyngn.com> | 2015-07-08 16:00:37 -0700 |
---|---|---|
committer | Michael Bestas <mikeioannina@cyanogenmod.org> | 2016-06-09 22:16:58 +0300 |
commit | 3f928cb8e72f8d599998d49939164127a7fb3309 (patch) | |
tree | 685849c8095d8d3a291f530c1d9e064be0b840eb | |
parent | e584c92e44b5de567ccc4a31cfd5d4c402c71964 (diff) | |
download | android_packages_apps_Gallery2-3f928cb8e72f8d599998d49939164127a7fb3309.tar.gz android_packages_apps_Gallery2-3f928cb8e72f8d599998d49939164127a7fb3309.tar.bz2 android_packages_apps_Gallery2-3f928cb8e72f8d599998d49939164127a7fb3309.zip |
Gallery2: 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: I79466a11b528b1b1af0650927b7054837b631878
-rw-r--r-- | src/com/android/gallery3d/gadget/WidgetService.java | 8 |
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 751aaef9d..ca79a9f79 100644 --- a/src/com/android/gallery3d/gadget/WidgetService.java +++ b/src/com/android/gallery3d/gadget/WidgetService.java @@ -82,7 +82,7 @@ public class WidgetService extends RemoteViewsService { } @Override - public void onDestroy() { + public synchronized void onDestroy() { mSource.close(); mSource = null; } @@ -117,7 +117,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); boolean isDrm = false; |