OSDN Git Service

Fixes a bug where the asynctask wasn't removed when inflating
authorSelim Cinek <cinek@google.com>
Fri, 28 Apr 2017 00:30:50 +0000 (17:30 -0700)
committerSelim Cinek <cinek@google.com>
Fri, 28 Apr 2017 01:01:26 +0000 (18:01 -0700)
Test: runtest systemui
Bug: 36561228
Change-Id: I9b5099d4a32be1f18db2ab1f8c94fe6f35a51b18

packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java
packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java
packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationInflaterTest.java

index b5f7ee6..4d47e6b 100644 (file)
@@ -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<AsyncTask> getRunningTasks() {
+            return mRunningTasks;
+        }
     }
 
     private final ArrayMap<String, Entry> mEntries = new ArrayMap<>();
index 6c6dfa4..7cfc767 100644 (file)
@@ -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 {
index 65e0568..fbb25e5 100644 (file)
@@ -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);