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

Commit 226b035e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add SmartReplyView internals to StatusBar dump" into sc-v2-dev

parents 9ee57dca b8b2f899
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -3345,6 +3345,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
                }
                }
                ipw.decreaseIndent();
                ipw.decreaseIndent();
                ipw.println("}");
                ipw.println("}");
            } else if (mPrivateLayout != null) {
                mPrivateLayout.dumpSmartReplies(ipw);
            }
            }
        });
        });
    }
    }
+17 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import android.os.Build;
import android.provider.Settings;
import android.provider.Settings;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Log;
import android.util.Pair;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
@@ -1955,6 +1956,22 @@ public class NotificationContentView extends FrameLayout {
        pw.println();
        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() {
    public RemoteInputView getExpandedRemoteInput() {
        return mExpandedRemoteInput;
        return mExpandedRemoteInput;
    }
    }
+80 −3
Original line number Original line Diff line number Diff line
package com.android.systemui.statusbar.policy;
package com.android.systemui.statusbar.policy;


import static java.lang.Float.NaN;

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


import androidx.annotation.NonNull;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ContrastColorUtil;
import com.android.internal.util.ContrastColorUtil;
import com.android.systemui.R;
import com.android.systemui.R;
@@ -89,6 +94,13 @@ public class SmartReplyView extends ViewGroup {
    private int mMaxNumActions;
    private int mMaxNumActions;
    private int mMinNumSystemGeneratedReplies;
    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) {
    public SmartReplyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        super(context, attrs);


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


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


        if (!mCandidateButtonQueueForSqueezing.isEmpty()) {
        if (!mCandidateButtonQueueForSqueezing.isEmpty()) {
            Log.wtf(TAG, "Single line button queue leaked between onMeasure calls");
            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 (mSmartRepliesGeneratedByAssistant) {
            if (!gotEnoughSmartReplies(smartReplies)) {
            if (!gotEnoughSmartReplies(smartReplies)) {
                // We don't have enough smart replies - hide all of them.
                // 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
                // Reset our measures back to when we had only added actions (before adding
                // replies).
                // replies).
                accumulatedMeasures = actionsMeasures;
                accumulatedMeasures = actionsMeasures;
                mDidHideSystemReplies = true;
            }
            }
        }
        }


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


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


    /**
    /**