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

Commit aee9b022 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Add SmartReplyView internals to StatusBar dump

Also, optimize gotEnoughSmartReplies for the typical case when an experiment isn't running.

Bug: 205657774
Test: adb shell dumpsys activity service com.android.systemui/.SystemUIService StatusBarGoogle
Change-Id: Ibeb432ec5cfd66ebde46d9d328a323f572b2337e
parent 1731cd2d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static android.service.notification.NotificationListenerService.REASON_CA
import static com.android.systemui.statusbar.notification.row.NotificationContentView.VISIBLE_TYPE_HEADSUP;
import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_PUBLIC;

import android.Manifest;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
@@ -50,7 +49,6 @@ import android.os.Build;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.permission.PermissionManager;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.util.ArraySet;
@@ -3368,6 +3366,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
                }
                ipw.decreaseIndent();
                ipw.println("}");
            } else if (mPrivateLayout != null) {
                mPrivateLayout.dumpSmartReplies(ipw);
            }
        });
    }
+17 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.os.Build;
import android.provider.Settings;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Pair;
import android.view.LayoutInflater;
@@ -2004,6 +2005,22 @@ public class NotificationContentView extends FrameLayout {
        pw.println();
    }

    /** Add any existing SmartReplyView to the dump */
    public void dumpSmartReplies(IndentingPrintWriter pw) {
        if (mHeadsUpSmartReplyView != null) {
            pw.println("HeadsUp SmartReplyView:");
            pw.increaseIndent();
            mHeadsUpSmartReplyView.dump(pw);
            pw.decreaseIndent();
        }
        if (mExpandedSmartReplyView != null) {
            pw.println("Expanded SmartReplyView:");
            pw.increaseIndent();
            mExpandedSmartReplyView.dump(pw);
            pw.decreaseIndent();
        }
    }

    public RemoteInputView getExpandedRemoteInput() {
        return mExpandedRemoteInput;
    }
+80 −3
Original line number Diff line number Diff line
package com.android.systemui.statusbar.policy;

import static java.lang.Float.NaN;

import android.annotation.ColorInt;
import android.annotation.NonNull;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.RemoteInput;
@@ -14,10 +15,12 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.RippleDrawable;
import android.os.SystemClock;
import android.text.Layout;
import android.text.TextPaint;
import android.text.method.TransformationMethod;
import android.util.AttributeSet;
import android.util.IndentingPrintWriter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -25,6 +28,8 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ContrastColorUtil;
import com.android.systemui.R;
@@ -89,6 +94,13 @@ public class SmartReplyView extends ViewGroup {
    private int mMaxNumActions;
    private int mMinNumSystemGeneratedReplies;

    // DEBUG variables tracked for the dump()
    private long mLastDrawChildTime;
    private long mLastDispatchDrawTime;
    private long mLastMeasureTime;
    private int mTotalSqueezeRemeasureAttempts;
    private boolean mDidHideSystemReplies;

    public SmartReplyView(Context context, AttributeSet attrs) {
        super(context, attrs);

@@ -217,6 +229,7 @@ public class SmartReplyView extends ViewGroup {

        // Mark all buttons as hidden and un-squeezed.
        resetButtonsLayoutParams();
        mTotalSqueezeRemeasureAttempts = 0;

        if (!mCandidateButtonQueueForSqueezing.isEmpty()) {
            Log.wtf(TAG, "Single line button queue leaked between onMeasure calls");
@@ -329,6 +342,7 @@ public class SmartReplyView extends ViewGroup {
            }
        }

        mDidHideSystemReplies = false;
        if (mSmartRepliesGeneratedByAssistant) {
            if (!gotEnoughSmartReplies(smartReplies)) {
                // We don't have enough smart replies - hide all of them.
@@ -339,6 +353,7 @@ public class SmartReplyView extends ViewGroup {
                // Reset our measures back to when we had only added actions (before adding
                // replies).
                accumulatedMeasures = actionsMeasures;
                mDidHideSystemReplies = true;
            }
        }

@@ -356,6 +371,7 @@ public class SmartReplyView extends ViewGroup {
                                     accumulatedMeasures.mMeasuredWidth),
                            widthMeasureSpec),
                resolveSize(buttonHeight, heightMeasureSpec));
        mLastMeasureTime = SystemClock.elapsedRealtime();
    }

    // TODO: this should be replaced, and instead, setMinSystemGenerated... should be invoked
@@ -371,6 +387,53 @@ public class SmartReplyView extends ViewGroup {
        }
    }

    /** Dump internal state for debugging */
    public void dump(IndentingPrintWriter pw) {
        pw.println(this);
        pw.increaseIndent();
        pw.print("mMaxSqueezeRemeasureAttempts=");
        pw.println(mMaxSqueezeRemeasureAttempts);
        pw.print("mTotalSqueezeRemeasureAttempts=");
        pw.println(mTotalSqueezeRemeasureAttempts);
        pw.print("mMaxNumActions=");
        pw.println(mMaxNumActions);
        pw.print("mSmartRepliesGeneratedByAssistant=");
        pw.println(mSmartRepliesGeneratedByAssistant);
        pw.print("mMinNumSystemGeneratedReplies=");
        pw.println(mMinNumSystemGeneratedReplies);
        pw.print("mHeightUpperLimit=");
        pw.println(mHeightUpperLimit);
        pw.print("mDidHideSystemReplies=");
        pw.println(mDidHideSystemReplies);
        long now = SystemClock.elapsedRealtime();
        pw.print("lastMeasureAge (s)=");
        pw.println(mLastMeasureTime == 0 ? NaN : (now - mLastMeasureTime) / 1000.0f);
        pw.print("lastDrawChildAge (s)=");
        pw.println(mLastDrawChildTime == 0 ? NaN : (now - mLastDrawChildTime) / 1000.0f);
        pw.print("lastDispatchDrawAge (s)=");
        pw.println(mLastDispatchDrawTime == 0 ? NaN : (now - mLastDispatchDrawTime) / 1000.0f);
        int numChildren = getChildCount();
        pw.print("children: num=");
        pw.println(numChildren);
        pw.increaseIndent();
        for (int i = 0; i < numChildren; i++) {
            View child = getChildAt(i);
            LayoutParams lp = (LayoutParams) child.getLayoutParams();
            pw.print("[");
            pw.print(i);
            pw.print("] type=");
            pw.print(lp.mButtonType);
            pw.print(" squeezeStatus=");
            pw.print(lp.squeezeStatus);
            pw.print(" show=");
            pw.print(lp.show);
            pw.print(" view=");
            pw.println(child);
        }
        pw.decreaseIndent();
        pw.decreaseIndent();
    }

    /**
     * Fields we keep track of inside onMeasure() to correctly measure the SmartReplyView depending
     * on which suggestions are added.
@@ -393,8 +456,11 @@ public class SmartReplyView extends ViewGroup {
     * Returns whether our notification contains at least N smart replies (or 0) where N is
     * determined by {@link SmartReplyConstants}.
     */
    // TODO: we probably sholdn't make this deliberation in the View
    private boolean gotEnoughSmartReplies(List<View> smartReplies) {
        if (mMinNumSystemGeneratedReplies <= 1) {
            // Count is irrelevant, do not bother.
            return true;
        }
        int numShownReplies = 0;
        for (View smartReplyButton : smartReplies) {
            final LayoutParams lp = (LayoutParams) smartReplyButton.getLayoutParams();
@@ -474,6 +540,7 @@ public class SmartReplyView extends ViewGroup {
            final boolean moveLeft = initialLeftTextWidth > initialRightTextWidth;
            final int maxSqueezeRemeasureAttempts = mMaxSqueezeRemeasureAttempts;
            for (int i = 0; i < maxSqueezeRemeasureAttempts; i++) {
                mTotalSqueezeRemeasureAttempts++;
                final int newPosition =
                        moveLeft ? mBreakIterator.previous() : mBreakIterator.next();
                if (newPosition == BreakIterator.DONE) {
@@ -613,7 +680,17 @@ public class SmartReplyView extends ViewGroup {
    @Override
    protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        return lp.show && super.drawChild(canvas, child, drawingTime);
        if (!lp.show) {
            return false;
        }
        mLastDrawChildTime = SystemClock.elapsedRealtime();
        return super.drawChild(canvas, child, drawingTime);
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        mLastDispatchDrawTime = SystemClock.elapsedRealtime();
    }

    /**