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

Commit 01f68fb8 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Notif Screenshot Tests] Inflate ENR synchronously on the main thread" into main

parents 99819e1b 2ddb1f58
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)