summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2019-12-09 11:08:48 -0800
committerSunny Goyal <sunnygoyal@google.com>2019-12-09 11:21:02 -0800
commit4c980fe0e08adcee7213dc2af3972d9a19a9051f (patch)
tree89683206c34e8a1f7450375784f2a7d20fd4c178 /core/java
parent654af7615bc0ab6941e28131efccf8d23840c253 (diff)
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
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/widget/RemoteViews.java23
1 files changed, 12 insertions, 11 deletions
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index c571737cec8f..7cec440dd80b 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -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) {