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

Commit 83fad0a3 authored by Adrian Roos's avatar Adrian Roos
Browse files

Perf: Fix RemoteViews memory leak

Fixes an issue where the context wrapper created in
RemoteViews leaks the RemoteViews instance through the
implicit this pointer of anonymous inner classes.

Fixed by replacing with a static inner class.

Bug: 37630958
Test: m droid (this change is not testable)
Change-Id: Ia149b3d91f134f0c308200b46880e7f87542a338
parent 9870d0be
Loading
Loading
Loading
Loading
+25 −14
Original line number Diff line number Diff line
@@ -413,6 +413,30 @@ public class RemoteViews implements Parcelable, Filter {
        recalculateMemoryUsage();
    }

    private static class RemoteViewsContextWrapper extends ContextWrapper {
        private final Context mContextForResources;

        RemoteViewsContextWrapper(Context context, Context contextForResources) {
            super(context);
            mContextForResources = contextForResources;
        }

        @Override
        public Resources getResources() {
            return mContextForResources.getResources();
        }

        @Override
        public Resources.Theme getTheme() {
            return mContextForResources.getTheme();
        }

        @Override
        public String getPackageName() {
            return mContextForResources.getPackageName();
        }
    }

    private class SetEmptyView extends Action {
        int viewId;
        int emptyViewId;
@@ -3240,20 +3264,7 @@ public class RemoteViews implements Parcelable, Filter {
        // still returns the current users userId so settings like data / time formats
        // are loaded without requiring cross user persmissions.
        final Context contextForResources = getContextForResources(context);
        Context inflationContext = new ContextWrapper(context) {
            @Override
            public Resources getResources() {
                return contextForResources.getResources();
            }
            @Override
            public Resources.Theme getTheme() {
                return contextForResources.getTheme();
            }
            @Override
            public String getPackageName() {
                return contextForResources.getPackageName();
            }
        };
        Context inflationContext = new RemoteViewsContextWrapper(context, contextForResources);

        LayoutInflater inflater = (LayoutInflater)
                context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);