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

Commit 4c980fe0 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Cleaning up listener when task completes

The caller can hold on the Cancellation signal even after the task
completes which stores a reference of the original RemoteViews and
all the resources associated with it.

Bug: 145829442
Test: Verified Appwidget functionality
Change-Id: I6998980b5bf64dd59fa1b53240440b29df0fb866
parent 654af761
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -3473,18 +3473,10 @@ public class RemoteViews implements Parcelable, Filter {
        return applyAsync(context, parent, executor, listener, null);
    }

    private CancellationSignal startTaskOnExecutor(AsyncApplyTask task, Executor executor) {
        CancellationSignal cancelSignal = new CancellationSignal();
        cancelSignal.setOnCancelListener(task);

        task.executeOnExecutor(executor == null ? AsyncTask.THREAD_POOL_EXECUTOR : executor);
        return cancelSignal;
    }

    /** @hide */
    public CancellationSignal applyAsync(Context context, ViewGroup parent,
            Executor executor, OnViewAppliedListener listener, OnClickHandler handler) {
        return startTaskOnExecutor(getAsyncApplyTask(context, parent, listener, handler), executor);
        return getAsyncApplyTask(context, parent, listener, handler).startTaskOnExecutor(executor);
    }

    private AsyncApplyTask getAsyncApplyTask(Context context, ViewGroup parent,
@@ -3495,6 +3487,7 @@ public class RemoteViews implements Parcelable, Filter {

    private class AsyncApplyTask extends AsyncTask<Void, Void, ViewTree>
            implements CancellationSignal.OnCancelListener {
        final CancellationSignal mCancelSignal = new CancellationSignal();
        final RemoteViews mRV;
        final ViewGroup mParent;
        final Context mContext;
@@ -3545,6 +3538,7 @@ public class RemoteViews implements Parcelable, Filter {

        @Override
        protected void onPostExecute(ViewTree viewTree) {
            mCancelSignal.setOnCancelListener(null);
            if (mError == null) {
                if (mListener != null) {
                    mListener.onViewInflated(viewTree.mRoot);
@@ -3581,6 +3575,13 @@ public class RemoteViews implements Parcelable, Filter {
        @Override
        public void onCancel() {
            cancel(true);
            mCancelSignal.setOnCancelListener(null);
        }

        private CancellationSignal startTaskOnExecutor(Executor executor) {
            mCancelSignal.setOnCancelListener(this);
            executeOnExecutor(executor == null ? AsyncTask.THREAD_POOL_EXECUTOR : executor);
            return mCancelSignal;
        }
    }

@@ -3646,8 +3647,8 @@ public class RemoteViews implements Parcelable, Filter {
            }
        }

        return startTaskOnExecutor(new AsyncApplyTask(rvToApply, (ViewGroup) v.getParent(),
                context, listener, handler, v), executor);
        return new AsyncApplyTask(rvToApply, (ViewGroup) v.getParent(),
                context, listener, handler, v).startTaskOnExecutor(executor);
    }

    private void performApply(View v, ViewGroup parent, OnClickHandler handler) {