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

Commit 21039fc6 authored by Ibrahim Yilmaz's avatar Ibrahim Yilmaz
Browse files

Inflate ENR inflation syncronously

ENR inflation is happening on the background thread and sometimes it takes than 1 sec and it causes a test failure.

This CL inflates ENR on main in the test scope.

Bug: 355093232
Change-Id: Ic8b5b808d6cd8b37e2d0df2aff7859aae1d037c2
Test: Presubmit
Flag: TEST_ONLY
parent 1a56b984
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.notification.row;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

@@ -89,10 +90,59 @@ public class RowInflaterTask implements InflationTask, AsyncLayoutInflater.OnInf
        inflater.inflate(R.layout.status_bar_notification_row, parent, listenerExecutor, this);
    }

    /**
     * Inflates a new notificationView synchronously.
     * This method is only for testing-purpose.
     */
    @VisibleForTesting
    public ExpandableNotificationRow inflateSynchronously(@NonNull Context context,
            @Nullable ViewGroup parent, @NonNull NotificationEntry entry) {
        final LayoutInflater inflater = new BasicRowInflater(context);
        inflater.setFactory2(makeRowInflater(entry));
        final ExpandableNotificationRow inflate = (ExpandableNotificationRow) inflater.inflate(
                R.layout.status_bar_notification_row,
                parent /* root */,
                false /* attachToRoot */);
        return inflate;
    }

    private RowAsyncLayoutInflater makeRowInflater(NotificationEntry entry) {
        return new RowAsyncLayoutInflater(entry, mSystemClock, mLogger);
    }

    /**
     * A {@link LayoutInflater} that is copy of BasicLayoutInflater.
     */
    private static class BasicRowInflater extends LayoutInflater {
        private static final String[] sClassPrefixList =
                {"android.widget.", "android.webkit.", "android.app."};
        BasicRowInflater(Context context) {
            super(context);
        }

        @Override
        public LayoutInflater cloneInContext(Context newContext) {
            return new BasicRowInflater(newContext);
        }

        @Override
        protected View onCreateView(String name, AttributeSet attrs) throws ClassNotFoundException {
            for (String prefix : sClassPrefixList) {
                try {
                    View view = createView(name, prefix, attrs);
                    if (view != null) {
                        return view;
                    }
                } catch (ClassNotFoundException e) {
                    // In this case we want to let the base class take a crack
                    // at it.
                }
            }

            return super.onCreateView(name, attrs);
        }
    }

    @VisibleForTesting
    public static class RowAsyncLayoutInflater implements AsyncLayoutFactory {
        private final NotificationEntry mEntry;
+1 −6
Original line number Diff line number Diff line
@@ -319,14 +319,9 @@ class ExpandableNotificationRowBuilder(
        // NOTE: This flag is read when the ExpandableNotificationRow is inflated, so it needs to be
        //  set, but we do not want to override an existing value that is needed by a specific test.

        val rowFuture: SettableFuture<ExpandableNotificationRow> = SettableFuture.create()
        val rowInflaterTask =
            RowInflaterTask(mFakeSystemClock, Mockito.mock(RowInflaterTaskLogger::class.java))
        rowInflaterTask.inflate(context, null, entry, MoreExecutors.directExecutor()) { inflatedRow
            ->
            rowFuture.set(inflatedRow)
        }
        val row = rowFuture.get(1, TimeUnit.SECONDS)
        val row = rowInflaterTask.inflateSynchronously(context, null, entry)

        entry.row = row
        mIconManager.createIcons(entry)