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

Commit d66b81b9 authored by Julia Tuttle's avatar Julia Tuttle
Browse files

Add logging to RowInflaterTask

Note that the overall change that adds a dedicated thread for
notification inflation *is* flagged, but this logging is for code that
*doesn't* use the new thread, so it's *not* flagged.

Bug: 308967184
Flag: NA
Test: manual
Change-Id: Idccbb2ffb3b3228952220c69ef0912a7a8347ebd
parent b693882e
Loading
Loading
Loading
Loading
+35 −6
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import androidx.asynclayoutinflater.view.AsyncLayoutInflater;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.InflationTask;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.util.time.SystemClock;

import javax.inject.Inject;

@@ -46,9 +47,14 @@ public class RowInflaterTask implements InflationTask, AsyncLayoutInflater.OnInf
    private NotificationEntry mEntry;
    private boolean mCancelled;
    private Throwable mInflateOrigin;
    private final SystemClock mSystemClock;
    private final RowInflaterTaskLogger mLogger;
    private long mInflateStartTimeMs;

    @Inject
    public RowInflaterTask() {
    public RowInflaterTask(SystemClock systemClock, RowInflaterTaskLogger logger) {
        mSystemClock = systemClock;
        mLogger = logger;
    }

    /**
@@ -61,31 +67,51 @@ public class RowInflaterTask implements InflationTask, AsyncLayoutInflater.OnInf
        }
        mListener = listener;
        AsyncLayoutInflater inflater = com.android.systemui.Flags.notificationRowUserContext()
                ? new AsyncLayoutInflater(context, new RowAsyncLayoutInflater(entry))
                ? new AsyncLayoutInflater(context, makeRowInflater(entry))
                : new AsyncLayoutInflater(context);
        mEntry = entry;
        entry.setInflationTask(this);

        mLogger.logInflateStart(entry);
        mInflateStartTimeMs = mSystemClock.elapsedRealtime();
        inflater.inflate(R.layout.status_bar_notification_row, parent, this);
    }

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

    @VisibleForTesting
    static class RowAsyncLayoutInflater implements AsyncLayoutFactory {
        private final NotificationEntry mEntry;
        private final SystemClock mSystemClock;
        private final RowInflaterTaskLogger mLogger;

        RowAsyncLayoutInflater(NotificationEntry entry) {
        RowAsyncLayoutInflater(NotificationEntry entry, SystemClock systemClock,
                RowInflaterTaskLogger logger) {
            mEntry = entry;
            mSystemClock = systemClock;
            mLogger = logger;
        }

        @Nullable
        @Override
        public View onCreateView(@Nullable View parent, @NonNull String name,
                @NonNull Context context, @NonNull AttributeSet attrs) {
            if (name.equals(ExpandableNotificationRow.class.getName())) {
                return new ExpandableNotificationRow(context, attrs, mEntry);
            }
            if (!name.equals(ExpandableNotificationRow.class.getName())) {
                return null;
            }

            final long startMs = mSystemClock.elapsedRealtime();
            final ExpandableNotificationRow row =
                    new ExpandableNotificationRow(context, attrs, mEntry);
            final long elapsedMs = mSystemClock.elapsedRealtime() - startMs;

            mLogger.logCreatedRow(mEntry, elapsedMs);

            return row;
        }

        @Nullable
        @Override
        public View onCreateView(@NonNull String name, @NonNull Context context,
@@ -101,6 +127,9 @@ public class RowInflaterTask implements InflationTask, AsyncLayoutInflater.OnInf

    @Override
    public void onInflateFinished(View view, int resid, ViewGroup parent) {
        final long elapsedMs = mSystemClock.elapsedRealtime() - mInflateStartTimeMs;
        mLogger.logInflateFinish(mEntry, elapsedMs, mCancelled);

        if (!mCancelled) {
            try {
                mEntry.onInflationTaskFinished();
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.notification.row

import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.dagger.NotifInflationLog
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.logKey
import javax.inject.Inject

class RowInflaterTaskLogger @Inject constructor(@NotifInflationLog private val buffer: LogBuffer) {
    fun logInflateStart(entry: NotificationEntry) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            { str1 = entry.logKey },
            { "started row inflation for $str1" }
        )
    }

    fun logCreatedRow(entry: NotificationEntry, elapsedMs: Long) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = entry.logKey
                long1 = elapsedMs
            },
            { "created row in $long1 ms for $str1" }
        )
    }

    fun logInflateFinish(entry: NotificationEntry, elapsedMs: Long, cancelled: Boolean) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = entry.logKey
                long1 = elapsedMs
                bool1 = cancelled
            },
            { "finished ${if (bool1) "cancelled " else ""}row inflation in $long1 ms for $str1" }
        )
    }
}

private const val TAG = "RowInflaterTask"
+9 −1
Original line number Diff line number Diff line
@@ -89,6 +89,8 @@ import com.android.systemui.statusbar.policy.InflatedSmartReplyViewHolder;
import com.android.systemui.statusbar.policy.SmartReplyConstants;
import com.android.systemui.statusbar.policy.SmartReplyStateInflater;
import com.android.systemui.statusbar.policy.dagger.RemoteInputViewSubcomponent;
import com.android.systemui.util.time.SystemClock;
import com.android.systemui.util.time.SystemClockImpl;
import com.android.systemui.wmshell.BubblesManager;
import com.android.systemui.wmshell.BubblesTestActivity;

@@ -136,6 +138,8 @@ public class NotificationTestHelper {
    public final Runnable mFutureDismissalRunnable;
    private @InflationFlag int mDefaultInflationFlags;
    private final FakeFeatureFlags mFeatureFlags;
    private final SystemClock mSystemClock;
    private final RowInflaterTaskLogger mRowInflaterTaskLogger;

    public NotificationTestHelper(
            Context context,
@@ -199,6 +203,9 @@ public class NotificationTestHelper {
        mFutureDismissalRunnable = mock(Runnable.class);
        when(mOnUserInteractionCallback.registerFutureDismissal(any(), anyInt()))
                .thenReturn(mFutureDismissalRunnable);

        mSystemClock = new SystemClockImpl();
        mRowInflaterTaskLogger = mock(RowInflaterTaskLogger.class);
    }

    public void setDefaultInflationFlags(@InflationFlag int defaultInflationFlags) {
@@ -572,7 +579,8 @@ public class NotificationTestHelper {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        if (com.android.systemui.Flags.notificationRowUserContext()) {
            inflater.setFactory2(new RowInflaterTask.RowAsyncLayoutInflater(entry));
            inflater.setFactory2(new RowInflaterTask.RowAsyncLayoutInflater(entry, mSystemClock,
                    mRowInflaterTaskLogger));
        }
        mRow = (ExpandableNotificationRow) inflater.inflate(
                R.layout.status_bar_notification_row,