Merge "Fixes a bug where the asynctask wasn't removed when inflating" into oc-dev

This commit is contained in:
Selim Cinek
2017-04-28 17:48:55 +00:00
committed by Android (Google) Code Review
3 changed files with 20 additions and 1 deletions

View File

@@ -222,11 +222,21 @@ public class NotificationData {
for (AsyncTask task : mRunningTasks) { for (AsyncTask task : mRunningTasks) {
task.cancel(true /* mayInterruptIfRunning */); task.cancel(true /* mayInterruptIfRunning */);
} }
mRunningTasks.clear();
} }
public void addInflationTask(AsyncTask asyncInflationTask) { public void addInflationTask(AsyncTask asyncInflationTask) {
mRunningTasks.add(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<>(); private final ArrayMap<String, Entry> mEntries = new ArrayMap<>();

View File

@@ -325,6 +325,7 @@ public class NotificationInflater {
@Override @Override
protected void onPostExecute(Notification.Builder builder) { protected void onPostExecute(Notification.Builder builder) {
mRow.getEntry().onInflationTaskFinished(this);
if (mError == null) { if (mError == null) {
finishInflation(mReInflateFlags, builder, mPackageContext); finishInflation(mReInflateFlags, builder, mPackageContext);
} else { } else {

View File

@@ -115,13 +115,21 @@ public class NotificationInflaterTest {
public void testInflationThrowsErrorDoesntCallUpdated() throws Exception { public void testInflationThrowsErrorDoesntCallUpdated() throws Exception {
mRow.getPrivateLayout().removeAllViews(); mRow.getPrivateLayout().removeAllViews();
mRow.getStatusBarNotification().getNotification().contentView mRow.getStatusBarNotification().getNotification().contentView
= new RemoteViews(mContext.getPackageName(), R.layout.status_bar);; = new RemoteViews(mContext.getPackageName(), R.layout.status_bar);
runThenWaitForInflation(() -> mNotificationInflater.inflateNotificationViews(), runThenWaitForInflation(() -> mNotificationInflater.inflateNotificationViews(),
true /* expectingException */, mNotificationInflater); true /* expectingException */, mNotificationInflater);
Assert.assertTrue(mRow.getPrivateLayout().getChildCount() == 0); Assert.assertTrue(mRow.getPrivateLayout().getChildCount() == 0);
verify(mRow, times(0)).onNotificationUpdated(); 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, public static void runThenWaitForInflation(Runnable block,
NotificationInflater inflater) throws Exception { NotificationInflater inflater) throws Exception {
runThenWaitForInflation(block, false /* expectingException */, inflater); runThenWaitForInflation(block, false /* expectingException */, inflater);