Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01d3da63 authored by Selim Cinek's avatar Selim Cinek
Browse files

Moving the inflation to the background

The inflation of the notifications is moved to
the background. This should improve the general
performance when adding / removing groups and alike.

Test: runtest systemui
Fixes: 34888292
Change-Id: Ieb19a09a5a97d496d9319d917a5e317a3ad76fc4
parent f323e3a5
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ public class NotificationData {
        public List<SnoozeCriterion> snoozeCriteria;
        private int mCachedContrastColor = COLOR_INVALID;
        private int mCachedContrastColorIsFor = COLOR_INVALID;
        private ArraySet<AsyncTask> mRunningTasks = new ArraySet();
        private NotificationInflater.AsyncInflationTask mRunningTask = null;

        public Entry(StatusBarNotification n) {
            this.key = n.getKey();
@@ -219,23 +219,25 @@ public class NotificationData {
         * Abort all existing inflation tasks
         */
        public void abortInflation() {
            for (AsyncTask task : mRunningTasks) {
                task.cancel(true /* mayInterruptIfRunning */);
            if (mRunningTask != null) {
                mRunningTask.abort();
                mRunningTask = null;
            }
            mRunningTasks.clear();
        }

        public void addInflationTask(AsyncTask asyncInflationTask) {
            mRunningTasks.add(asyncInflationTask);
        public void setInflationTask(NotificationInflater.AsyncInflationTask asyncInflationTask) {
            // abort any existing inflation
            abortInflation();
            mRunningTask = asyncInflationTask;
        }

        public void onInflationTaskFinished(AsyncTask asyncInflationTask) {
            mRunningTasks.remove(asyncInflationTask);
        public void onInflationTaskFinished() {
           mRunningTask = null;
        }

        @VisibleForTesting
        public ArraySet<AsyncTask> getRunningTasks() {
            return mRunningTasks;
        public AsyncTask getRunningTask() {
            return mRunningTask;
        }
    }

+372 −130

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -1610,7 +1610,7 @@ public class StatusBar extends SystemUI implements DemoMode,
    }

    @Override
    public void handleInflationException(StatusBarNotification notification, InflationException e) {
    public void handleInflationException(StatusBarNotification notification, Exception e) {
        handleNotificationError(notification, e.getMessage());
    }

+6 −4
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.app.Notification;
import android.content.Context;
import android.service.notification.StatusBarNotification;
import android.support.test.InstrumentationRegistry;
import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.widget.RemoteViews;
@@ -41,7 +42,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.CountDownLatch;
import java.util.function.Function;

@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -67,7 +67,7 @@ public class NotificationInflaterTest {
        mNotificationInflater.setInflationCallback(new NotificationInflater.InflationCallback() {
            @Override
            public void handleInflationException(StatusBarNotification notification,
                    InflationException e) {
                    Exception e) {
            }

            @Override
@@ -77,6 +77,7 @@ public class NotificationInflaterTest {
    }

    @Test
    @UiThreadTest
    public void testIncreasedHeadsUpBeingUsed() {
        mNotificationInflater.setUsesIncreasedHeadsUpHeight(true);
        Notification.Builder builder = spy(mBuilder);
@@ -85,6 +86,7 @@ public class NotificationInflaterTest {
    }

    @Test
    @UiThreadTest
    public void testIncreasedHeightBeingUsed() {
        mNotificationInflater.setUsesIncreasedHeight(true);
        Notification.Builder builder = spy(mBuilder);
@@ -127,7 +129,7 @@ public class NotificationInflaterTest {
        mRow.getEntry().abortInflation();
        runThenWaitForInflation(() -> mNotificationInflater.inflateNotificationViews(),
                mNotificationInflater);
        Assert.assertTrue(mRow.getEntry().getRunningTasks().size() == 0);
        Assert.assertNull(mRow.getEntry().getRunningTask() );
    }

    public static void runThenWaitForInflation(Runnable block,
@@ -143,7 +145,7 @@ public class NotificationInflaterTest {
        inflater.setInflationCallback(new NotificationInflater.InflationCallback() {
            @Override
            public void handleInflationException(StatusBarNotification notification,
                    InflationException e) {
                    Exception e) {
                if (!expectingException) {
                    exceptionHolder.setException(e);
                }