summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaj Yengisetty <rajesh@cyngn.com>2015-07-08 16:00:37 -0700
committerArne Coucheron <arco68@gmail.com>2017-03-10 07:19:40 +0100
commit9b7a13a66bb4b55eba855567432bff1f718cc35d (patch)
tree39ebccaef4db504ac1bca84027cbcba0b96fa2b5
parent211c51b8c840bbe10b0558d69f8715f4ae33c4ab (diff)
downloadandroid_packages_apps_Gallery2-9b7a13a66bb4b55eba855567432bff1f718cc35d.tar.gz
android_packages_apps_Gallery2-9b7a13a66bb4b55eba855567432bff1f718cc35d.tar.bz2
android_packages_apps_Gallery2-9b7a13a66bb4b55eba855567432bff1f718cc35d.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.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 dd05b6732..c62e47f13 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;