Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9abe7095 authored by Raj Yengisetty's avatar Raj Yengisetty
Browse files

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
parent 7a90da16
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -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(