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);