From dc1231c3b9fd72790f767a605136e3f05a2af3e2 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Thu, 27 Apr 2017 17:30:50 -0700 Subject: [PATCH] Fixes a bug where the asynctask wasn't removed when inflating Test: runtest systemui Bug: 36561228 Change-Id: I9b5099d4a32be1f18db2ab1f8c94fe6f35a51b18 --- .../android/systemui/statusbar/NotificationData.java | 10 ++++++++++ .../statusbar/notification/NotificationInflater.java | 1 + .../notification/NotificationInflaterTest.java | 10 +++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java index b5f7ee637f404..4d47e6b04aa98 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java @@ -222,11 +222,21 @@ public class NotificationData { for (AsyncTask task : mRunningTasks) { task.cancel(true /* mayInterruptIfRunning */); } + mRunningTasks.clear(); } public void addInflationTask(AsyncTask asyncInflationTask) { mRunningTasks.add(asyncInflationTask); } + + public void onInflationTaskFinished(AsyncTask asyncInflationTask) { + mRunningTasks.remove(asyncInflationTask); + } + + @VisibleForTesting + public ArraySet getRunningTasks() { + return mRunningTasks; + } } private final ArrayMap mEntries = new ArrayMap<>(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java index 6c6dfa45a9583..7cfc767f89b7b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java @@ -325,6 +325,7 @@ public class NotificationInflater { @Override protected void onPostExecute(Notification.Builder builder) { + mRow.getEntry().onInflationTaskFinished(this); if (mError == null) { finishInflation(mReInflateFlags, builder, mPackageContext); } else { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationInflaterTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationInflaterTest.java index 65e056830ea0c..fbb25e5484bac 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationInflaterTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationInflaterTest.java @@ -115,13 +115,21 @@ public class NotificationInflaterTest { public void testInflationThrowsErrorDoesntCallUpdated() throws Exception { mRow.getPrivateLayout().removeAllViews(); mRow.getStatusBarNotification().getNotification().contentView - = new RemoteViews(mContext.getPackageName(), R.layout.status_bar);; + = new RemoteViews(mContext.getPackageName(), R.layout.status_bar); runThenWaitForInflation(() -> mNotificationInflater.inflateNotificationViews(), true /* expectingException */, mNotificationInflater); Assert.assertTrue(mRow.getPrivateLayout().getChildCount() == 0); verify(mRow, times(0)).onNotificationUpdated(); } + @Test + public void testAsyncTaskRemoved() throws Exception { + mRow.getEntry().abortInflation(); + runThenWaitForInflation(() -> mNotificationInflater.inflateNotificationViews(), + mNotificationInflater); + Assert.assertTrue(mRow.getEntry().getRunningTasks().size() == 0); + } + public static void runThenWaitForInflation(Runnable block, NotificationInflater inflater) throws Exception { runThenWaitForInflation(block, false /* expectingException */, inflater);