Extract DebugDrawable from NPVC into its own class

Bug: 254890199
Test: existing tests
Change-Id: I88d88663c530c80f9e74829e51f0f336a7f30fed
diff --git a/packages/SystemUI/src/com/android/systemui/shade/DebugDrawable.java b/packages/SystemUI/src/com/android/systemui/shade/DebugDrawable.java
new file mode 100644
index 0000000..ae303eb
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/shade/DebugDrawable.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2022 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.shade;
+
+import android.annotation.NonNull;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.ColorFilter;
+import android.graphics.Paint;
+import android.graphics.PixelFormat;
+import android.graphics.drawable.Drawable;
+
+import com.android.keyguard.LockIconViewController;
+import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Drawable for NotificationPanelViewController.
+ */
+public class DebugDrawable extends Drawable {
+
+    private final NotificationPanelViewController mNotificationPanelViewController;
+    private final NotificationPanelView mView;
+    private final NotificationStackScrollLayoutController mNotificationStackScrollLayoutController;
+    private final LockIconViewController mLockIconViewController;
+    private final Set<Integer> mDebugTextUsedYPositions;
+    private final Paint mDebugPaint;
+
+    public DebugDrawable(
+            NotificationPanelViewController notificationPanelViewController,
+            NotificationPanelView notificationPanelView,
+            NotificationStackScrollLayoutController notificationStackScrollLayoutController,
+            LockIconViewController lockIconViewController
+    ) {
+        mNotificationPanelViewController = notificationPanelViewController;
+        mView = notificationPanelView;
+        mNotificationStackScrollLayoutController = notificationStackScrollLayoutController;
+        mLockIconViewController = lockIconViewController;
+        mDebugTextUsedYPositions = new HashSet<>();
+        mDebugPaint = new Paint();
+    }
+
+    @Override
+    public void draw(@androidx.annotation.NonNull @NonNull Canvas canvas) {
+        mDebugTextUsedYPositions.clear();
+
+        mDebugPaint.setColor(Color.RED);
+        mDebugPaint.setStrokeWidth(2);
+        mDebugPaint.setStyle(Paint.Style.STROKE);
+        mDebugPaint.setTextSize(24);
+        String headerDebugInfo = mNotificationPanelViewController.getHeaderDebugInfo();
+        if (headerDebugInfo != null) canvas.drawText(headerDebugInfo, 50, 100, mDebugPaint);
+
+        drawDebugInfo(canvas, mNotificationPanelViewController.getMaxPanelHeight(),
+                Color.RED, "getMaxPanelHeight()");
+        drawDebugInfo(canvas, (int) mNotificationPanelViewController.getExpandedHeight(),
+                Color.BLUE, "getExpandedHeight()");
+        drawDebugInfo(canvas, mNotificationPanelViewController.calculatePanelHeightQsExpanded(),
+                Color.GREEN, "calculatePanelHeightQsExpanded()");
+        drawDebugInfo(canvas, mNotificationPanelViewController.calculatePanelHeightQsExpanded(),
+                Color.YELLOW, "calculatePanelHeightShade()");
+        drawDebugInfo(canvas,
+                (int) mNotificationPanelViewController.calculateNotificationsTopPadding(),
+                Color.MAGENTA, "calculateNotificationsTopPadding()");
+        drawDebugInfo(canvas, mNotificationPanelViewController.getClockPositionResult().clockY,
+                Color.GRAY, "mClockPositionResult.clockY");
+        drawDebugInfo(canvas, (int) mLockIconViewController.getTop(), Color.GRAY,
+                "mLockIconViewController.getTop()");
+
+        if (mNotificationPanelViewController.getKeyguardShowing()) {
+            // Notifications have the space between those two lines.
+            drawDebugInfo(canvas,
+                    mNotificationStackScrollLayoutController.getTop()
+                            + (int) mNotificationPanelViewController
+                            .getKeyguardNotificationTopPadding(),
+                    Color.RED, "NSSL.getTop() + mKeyguardNotificationTopPadding");
+
+            drawDebugInfo(canvas, mNotificationStackScrollLayoutController.getBottom()
+                            - (int) mNotificationPanelViewController
+                            .getKeyguardNotificationBottomPadding(),
+                    Color.RED, "NSSL.getBottom() - mKeyguardNotificationBottomPadding");
+        }
+
+        mDebugPaint.setColor(Color.CYAN);
+        canvas.drawLine(0,
+                mNotificationPanelViewController.getClockPositionResult().stackScrollerPadding,
+                mView.getWidth(), mNotificationStackScrollLayoutController.getTopPadding(),
+                mDebugPaint);
+    }
+
+    private void drawDebugInfo(Canvas canvas, int y, int color, String label) {
+        mDebugPaint.setColor(color);
+        canvas.drawLine(/* startX= */ 0, /* startY= */ y, /* stopX= */ mView.getWidth(),
+                /* stopY= */ y, mDebugPaint);
+        canvas.drawText(label + " = " + y + "px", /* x= */ 0,
+                /* y= */ computeDebugYTextPosition(y), mDebugPaint);
+    }
+
+    private int computeDebugYTextPosition(int lineY) {
+        if (lineY - mDebugPaint.getTextSize() < 0) {
+            // Avoiding drawing out of bounds
+            lineY += mDebugPaint.getTextSize();
+        }
+        int textY = lineY;
+        while (mDebugTextUsedYPositions.contains(textY)) {
+            textY = (int) (textY + mDebugPaint.getTextSize());
+        }
+        mDebugTextUsedYPositions.add(textY);
+        return textY;
+    }
+
+    @Override
+    public void setAlpha(int alpha) {
+
+    }
+
+    @Override
+    public void setColorFilter(ColorFilter colorFilter) {
+
+    }
+
+    @Override
+    public int getOpacity() {
+        return PixelFormat.UNKNOWN;
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
index 7262b80..8defaf2 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
@@ -56,15 +56,10 @@
 import android.content.ContentResolver;
 import android.content.res.Resources;
 import android.database.ContentObserver;
-import android.graphics.Canvas;
 import android.graphics.Color;
-import android.graphics.ColorFilter;
 import android.graphics.Insets;
-import android.graphics.Paint;
-import android.graphics.PixelFormat;
 import android.graphics.Rect;
 import android.graphics.Region;
-import android.graphics.drawable.Drawable;
 import android.hardware.biometrics.SensorLocationInternal;
 import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
 import android.os.Bundle;
@@ -229,10 +224,8 @@
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Optional;
-import java.util.Set;
 import java.util.function.Consumer;
 
 import javax.inject.Inject;
@@ -899,7 +892,8 @@
         mView.setOnApplyWindowInsetsListener((v, insets) -> onApplyShadeWindowInsets(insets));
 
         if (DEBUG_DRAWABLE) {
-            mView.getOverlay().add(new DebugDrawable());
+            mView.getOverlay().add(new DebugDrawable(this, mView,
+                    mNotificationStackScrollLayoutController, mLockIconViewController));
         }
 
         mKeyguardUnfoldTransition = unfoldComponent.map(
@@ -1509,6 +1503,10 @@
         updateClock();
     }
 
+    public KeyguardClockPositionAlgorithm.Result getClockPositionResult() {
+        return mClockPositionResult;
+    }
+
     @ClockSize
     private int computeDesiredClockSize() {
         if (mSplitShadeEnabled) {
@@ -2973,7 +2971,7 @@
         }
     }
 
-    private float calculateNotificationsTopPadding() {
+    float calculateNotificationsTopPadding() {
         if (mSplitShadeEnabled) {
             return mKeyguardShowing ? getKeyguardNotificationStaticPadding() : 0;
         }
@@ -3007,6 +3005,18 @@
         }
     }
 
+    public boolean getKeyguardShowing() {
+        return mKeyguardShowing;
+    }
+
+    public float getKeyguardNotificationTopPadding() {
+        return mKeyguardNotificationTopPadding;
+    }
+
+    public float getKeyguardNotificationBottomPadding() {
+        return mKeyguardNotificationBottomPadding;
+    }
+
     /** Returns the topPadding of notifications when on keyguard not respecting QS expansion. */
     private int getKeyguardNotificationStaticPadding() {
         if (!mKeyguardShowing) {
@@ -3276,7 +3286,6 @@
         return !mSplitShadeEnabled && (isInSettings() || mIsPanelCollapseOnQQS);
     }
 
-    @VisibleForTesting
     int getMaxPanelHeight() {
         int min = mStatusBarMinHeight;
         if (!(mBarState == KEYGUARD)
@@ -3402,7 +3411,7 @@
         }
     }
 
-    private int calculatePanelHeightQsExpanded() {
+    int calculatePanelHeightQsExpanded() {
         float
                 notificationHeight =
                 mNotificationStackScrollLayoutController.getHeight()
@@ -4366,6 +4375,10 @@
         if (DEBUG_DRAWABLE) mHeaderDebugInfo = text;
     }
 
+    public String getHeaderDebugInfo() {
+        return mHeaderDebugInfo;
+    }
+
     public void onThemeChanged() {
         mConfigurationListener.onThemeChanged();
     }
@@ -4815,7 +4828,6 @@
         setExpandedHeight(getMaxPanelTransitionDistance() * frac);
     }
 
-    @VisibleForTesting
     float getExpandedHeight() {
         return mExpandedHeight;
     }
@@ -5517,89 +5529,6 @@
         }
     }
 
-    private final class DebugDrawable extends Drawable {
-        private final Set<Integer> mDebugTextUsedYPositions = new HashSet<>();
-        private final Paint mDebugPaint = new Paint();
-
-        @Override
-        public void draw(@NonNull Canvas canvas) {
-            mDebugTextUsedYPositions.clear();
-
-            mDebugPaint.setColor(Color.RED);
-            mDebugPaint.setStrokeWidth(2);
-            mDebugPaint.setStyle(Paint.Style.STROKE);
-            mDebugPaint.setTextSize(24);
-            if (mHeaderDebugInfo != null) canvas.drawText(mHeaderDebugInfo, 50, 100, mDebugPaint);
-
-            drawDebugInfo(canvas, getMaxPanelHeight(), Color.RED, "getMaxPanelHeight()");
-            drawDebugInfo(canvas, (int) getExpandedHeight(), Color.BLUE, "getExpandedHeight()");
-            drawDebugInfo(canvas, calculatePanelHeightQsExpanded(), Color.GREEN,
-                    "calculatePanelHeightQsExpanded()");
-            drawDebugInfo(canvas, calculatePanelHeightShade(), Color.YELLOW,
-                    "calculatePanelHeightShade()");
-            drawDebugInfo(canvas, (int) calculateNotificationsTopPadding(), Color.MAGENTA,
-                    "calculateNotificationsTopPadding()");
-            drawDebugInfo(canvas, mClockPositionResult.clockY, Color.GRAY,
-                    "mClockPositionResult.clockY");
-            drawDebugInfo(canvas, (int) mLockIconViewController.getTop(), Color.GRAY,
-                    "mLockIconViewController.getTop()");
-
-            if (mKeyguardShowing) {
-                // Notifications have the space between those two lines.
-                drawDebugInfo(canvas,
-                        mNotificationStackScrollLayoutController.getTop() +
-                                (int) mKeyguardNotificationTopPadding,
-                        Color.RED,
-                        "NSSL.getTop() + mKeyguardNotificationTopPadding");
-
-                drawDebugInfo(canvas, mNotificationStackScrollLayoutController.getBottom() -
-                                (int) mKeyguardNotificationBottomPadding,
-                        Color.RED,
-                        "NSSL.getBottom() - mKeyguardNotificationBottomPadding");
-            }
-
-            mDebugPaint.setColor(Color.CYAN);
-            canvas.drawLine(0, mClockPositionResult.stackScrollerPadding, mView.getWidth(),
-                    mNotificationStackScrollLayoutController.getTopPadding(), mDebugPaint);
-        }
-
-        private void drawDebugInfo(Canvas canvas, int y, int color, String label) {
-            mDebugPaint.setColor(color);
-            canvas.drawLine(/* startX= */ 0, /* startY= */ y, /* stopX= */ mView.getWidth(),
-                    /* stopY= */ y, mDebugPaint);
-            canvas.drawText(label + " = " + y + "px", /* x= */ 0,
-                    /* y= */ computeDebugYTextPosition(y), mDebugPaint);
-        }
-
-        private int computeDebugYTextPosition(int lineY) {
-            if (lineY - mDebugPaint.getTextSize() < 0) {
-                // Avoiding drawing out of bounds
-                lineY += mDebugPaint.getTextSize();
-            }
-            int textY = lineY;
-            while (mDebugTextUsedYPositions.contains(textY)) {
-                textY = (int) (textY + mDebugPaint.getTextSize());
-            }
-            mDebugTextUsedYPositions.add(textY);
-            return textY;
-        }
-
-        @Override
-        public void setAlpha(int alpha) {
-
-        }
-
-        @Override
-        public void setColorFilter(ColorFilter colorFilter) {
-
-        }
-
-        @Override
-        public int getOpacity() {
-            return PixelFormat.UNKNOWN;
-        }
-    }
-
     @NonNull
     private WindowInsets onApplyShadeWindowInsets(WindowInsets insets) {
         // the same types of insets that are handled in NotificationShadeWindowView