Merge "Fixing tiling divider rounded corners and spec colors" into main
diff --git a/libs/WindowManager/Shell/res/values/colors.xml b/libs/WindowManager/Shell/res/values/colors.xml
index d754243..8d18f95 100644
--- a/libs/WindowManager/Shell/res/values/colors.xml
+++ b/libs/WindowManager/Shell/res/values/colors.xml
@@ -68,4 +68,8 @@
     <color name="desktop_mode_caption_button_on_hover_light">#11000000</color>
     <color name="desktop_mode_caption_button_on_hover_dark">#11FFFFFF</color>
     <color name="desktop_mode_caption_button">#00000000</color>
+    <color name="tiling_divider_background_light">#C9C7B6</color>
+    <color name="tiling_divider_background_dark">#4A4739</color>
+    <color name="tiling_handle_background_light">#000000</color>
+    <color name="tiling_handle_background_dark">#FFFFFF</color>
 </resources>
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerHandleView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerHandleView.java
index 6c04e2a..d304e20 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerHandleView.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerHandleView.java
@@ -80,7 +80,19 @@
     private int mHoveringWidth;
     private int mHoveringHeight;
     private boolean mIsLeftRightSplit;
+    private boolean mIsSplitScreen;
 
+    /**
+     * Notifies the divider of ui mode change.
+     *
+     * @param isDarkMode Whether the mode is ui dark mode.
+     */
+    public void onUiModeChange(boolean isDarkMode) {
+        if (!mIsSplitScreen) {
+            mPaint.setColor(getTilingHandleColor(isDarkMode));
+            invalidate();
+        }
+    }
     public DividerHandleView(Context context, @Nullable AttributeSet attrs) {
         super(context, attrs);
         mPaint.setColor(getResources().getColor(R.color.docked_divider_handle, null));
@@ -103,6 +115,27 @@
         mHoveringHeight = mHeight > mWidth ? ((int) (mHeight * 1.5f)) : mHeight;
     }
 
+    /**
+     * Used by tiling infrastructure to specify display light/dark mode and
+     * whether handle colors should be overridden on display mode change in case
+     * of non split screen.
+     * @param isSplitScreen Whether the divider is used by split screen or tiling.
+     * @param isDarkMode Whether the mode is ui dark mode.
+     */
+    public void setup(boolean isSplitScreen, boolean isDarkMode) {
+        mIsSplitScreen = isSplitScreen;
+        if (!mIsSplitScreen) {
+            mPaint.setColor(getTilingHandleColor(isDarkMode));
+            setAlpha(.9f);
+        }
+    }
+
+    private int getTilingHandleColor(Boolean isDarkMode) {
+        return isDarkMode ? getResources().getColor(
+                R.color.tiling_handle_background_dark, null /* theme */) : getResources().getColor(
+                R.color.tiling_handle_background_light, null /* theme */);
+    }
+
     /** sets whether it's a left/right or top/bottom split */
     public void setIsLeftRightSplit(boolean isLeftRightSplit) {
         mIsLeftRightSplit = isLeftRightSplit;
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerRoundedCorner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerRoundedCorner.java
index d5aaf75..cf0ecae 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerRoundedCorner.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerRoundedCorner.java
@@ -47,15 +47,17 @@
     private InvertedRoundedCornerDrawInfo mBottomLeftCorner;
     private InvertedRoundedCornerDrawInfo mBottomRightCorner;
     private boolean mIsLeftRightSplit;
+    private boolean mIsSplitScreen;
 
     public DividerRoundedCorner(Context context, @Nullable AttributeSet attrs) {
         super(context, attrs);
         mDividerWidth = getResources().getDimensionPixelSize(R.dimen.split_divider_bar_width);
         mDividerBarBackground = new Paint();
         mDividerBarBackground.setColor(
-                getResources().getColor(R.color.split_divider_background, null));
+                getResources().getColor(R.color.split_divider_background, null /* theme */));
         mDividerBarBackground.setFlags(Paint.ANTI_ALIAS_FLAG);
         mDividerBarBackground.setStyle(Paint.Style.FILL);
+        mIsSplitScreen = false;
     }
 
     @Override
@@ -99,7 +101,41 @@
     }
 
     /**
+     * Used by tiling infrastructure to specify display light/dark mode and
+     * whether handle colors should be overridden on display mode change in case
+     * of non split screen.
+     *
+     * @param isSplitScreen Whether the divider is used by split screen or tiling.
+     * @param isDarkMode    Whether the mode is ui dark mode.
+     */
+    public void setup(boolean isSplitScreen, boolean isDarkMode) {
+        mIsSplitScreen = isSplitScreen;
+        if (!isSplitScreen) {
+            mDividerBarBackground.setColor(getTilingHandleColor(isDarkMode));
+        }
+    }
+
+    /**
+     * Notifies the divider of ui mode change.
+     *
+     * @param isDarkMode Whether the mode is ui dark mode.
+     */
+    public void onUiModeChange(boolean isDarkMode) {
+        if (!mIsSplitScreen) {
+            mDividerBarBackground.setColor(getTilingHandleColor(isDarkMode));
+            invalidate();
+        }
+    }
+
+    private int getTilingHandleColor(boolean isDarkMode) {
+        return isDarkMode ? getResources().getColor(
+                R.color.tiling_divider_background_dark, null /* theme */) : getResources().getColor(
+                R.color.tiling_divider_background_light, null /* theme */);
+    }
+
+    /**
      * Set whether the rounded corner is for a left/right split.
+     *
      * @param isLeftRightSplit whether it's a left/right split or top/bottom split.
      */
     public void setIsLeftRightSplit(boolean isLeftRightSplit) {
@@ -123,7 +159,16 @@
             mCornerPosition = cornerPosition;
 
             final RoundedCorner roundedCorner = getDisplay().getRoundedCorner(cornerPosition);
-            mRadius = roundedCorner == null ? 0 : roundedCorner.getRadius();
+            if (mIsSplitScreen) {
+                mRadius = roundedCorner == null ? 0 : roundedCorner.getRadius();
+            } else {
+                mRadius = mContext
+                        .getResources()
+                        .getDimensionPixelSize(
+                                com.android.wm.shell.shared.R.dimen
+                                        .desktop_windowing_freeform_rounded_corner_radius);
+            }
+
 
             // Starts with a filled square, and then subtracting out a circle from the appropriate
             // corner.
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
index 0d773ec..7ef1a93 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
@@ -558,6 +558,7 @@
         } else {
             decoration.relayout(taskInfo, taskInfo.isFocused, decoration.mExclusionRegion);
         }
+        mDesktopTilingDecorViewModel.onTaskInfoChange(taskInfo);
         mActivityOrientationChangeHandler.ifPresent(handler ->
                 handler.handleActivityOrientationChange(oldTaskInfo, taskInfo));
     }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModel.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModel.kt
index ee5d0e8..e9426d2 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModel.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModel.kt
@@ -137,6 +137,10 @@
         }
     }
 
+    fun onTaskInfoChange(taskInfo: RunningTaskInfo) {
+        tilingTransitionHandlerByDisplayId.get(taskInfo.displayId)?.onTaskInfoChange(taskInfo)
+    }
+
     override fun onDisplayChange(
         displayId: Int,
         fromRotation: Int,
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManager.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManager.kt
index fbbf1a5..cb45c17 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManager.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManager.kt
@@ -57,6 +57,7 @@
     private val transactionSupplier: Supplier<SurfaceControl.Transaction>,
     private var dividerBounds: Rect,
     private val displayContext: Context,
+    private val isDarkMode: Boolean,
 ) : WindowlessWindowManager(config, leash, null), DividerMoveCallback, View.OnLayoutChangeListener {
     private lateinit var viewHost: SurfaceControlViewHost
     private var tilingDividerView: TilingDividerView? = null
@@ -153,7 +154,7 @@
         surfaceControlViewHost.setView(dividerView, lp)
         val tmpDividerBounds = Rect()
         getDividerBounds(tmpDividerBounds)
-        dividerView.setup(this, tmpDividerBounds, handleRegionSize)
+        dividerView.setup(this, tmpDividerBounds, handleRegionSize, isDarkMode)
         t.setRelativeLayer(leash, relativeLeash, 1)
             .setPosition(
                 leash,
@@ -172,6 +173,11 @@
         updateTouchRegion()
     }
 
+    /** Changes divider colour if dark/light mode is toggled. */
+    fun onUiModeChange(isDarkMode: Boolean) {
+        tilingDividerView?.onUiModeChange(isDarkMode)
+    }
+
     /** Hides the divider bar. */
     fun hideDividerBar() {
         if (!dividerShown) {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt
index 9833325..a45df04 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt
@@ -103,6 +103,7 @@
     @VisibleForTesting
     var desktopTilingDividerWindowManager: DesktopTilingDividerWindowManager? = null
     private lateinit var dividerBounds: Rect
+    private var isDarkMode = false
     private var isResizing = false
     private var isTilingFocused = false
 
@@ -129,6 +130,7 @@
         val isTiled = destinationBounds != taskInfo.configuration.windowConfiguration.bounds
 
         initTilingApps(resizeMetadata, position, taskInfo)
+        isDarkMode = isTaskInDarkMode(taskInfo)
         // Observe drag resizing to break tiling if a task is drag resized.
         desktopModeWindowDecoration.addDragResizeListener(this)
 
@@ -232,6 +234,7 @@
                     transactionSupplier,
                     dividerBounds,
                     displayContext,
+                    isDarkMode,
                 )
             }
         // a leash to present the divider on top of, without re-parenting.
@@ -356,6 +359,17 @@
         transitions.startTransition(TRANSIT_CHANGE, wct, this)
     }
 
+    fun onTaskInfoChange(taskInfo: RunningTaskInfo) {
+        val isCurrentTaskInDarkMode = isTaskInDarkMode(taskInfo)
+        if (isCurrentTaskInDarkMode == isDarkMode || !isTilingManagerInitialised) return
+        isDarkMode = isCurrentTaskInDarkMode
+        desktopTilingDividerWindowManager?.onUiModeChange(isDarkMode)
+    }
+
+    fun isTaskInDarkMode(taskInfo: RunningTaskInfo): Boolean =
+        (taskInfo.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) ==
+            Configuration.UI_MODE_NIGHT_YES
+
     override fun startAnimation(
         transition: IBinder,
         info: TransitionInfo,
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt
index b8e3b0f..54dcd2d 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt
@@ -16,6 +16,7 @@
 package com.android.wm.shell.windowdecor.tiling
 
 import android.content.Context
+import android.content.res.Configuration
 import android.graphics.Canvas
 import android.graphics.Paint
 import android.graphics.Rect
@@ -85,11 +86,14 @@
         dividerMoveCallback: DividerMoveCallback,
         dividerBounds: Rect,
         handleRegionSize: Size,
+        isDarkMode: Boolean,
     ) {
         callback = dividerMoveCallback
         this.dividerBounds.set(dividerBounds)
         handle.setIsLeftRightSplit(true)
+        handle.setup(/* isSplitScreen= */ false, isDarkMode)
         corners.setIsLeftRightSplit(true)
+        corners.setup(/* isSplitScreen= */ false, isDarkMode)
         handleRegionHeight = handleRegionSize.height
         handleRegionWidth = handleRegionSize.width
         cornersRadius =
@@ -103,6 +107,18 @@
             )
     }
 
+    fun onUiModeChange(isDarkMode: Boolean) {
+        handle.onUiModeChange(isDarkMode)
+        corners.onUiModeChange(isDarkMode)
+        paint.color =
+            if (isDarkMode) {
+                resources.getColor(R.color.tiling_divider_background_dark, null /* theme */)
+            } else {
+                resources.getColor(R.color.tiling_divider_background_light, null /* theme */)
+            }
+        invalidate()
+    }
+
     override fun onFinishInflate() {
         super.onFinishInflate()
         dividerBar = requireViewById(R.id.divider_bar)
@@ -112,7 +128,15 @@
             resources.getDimensionPixelSize(R.dimen.docked_stack_divider_lift_elevation)
         setOnTouchListener(this)
         setWillNotDraw(false)
-        paint.color = resources.getColor(R.color.split_divider_background, null)
+        paint.color =
+            if (
+                context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK ==
+                    Configuration.UI_MODE_NIGHT_YES
+            ) {
+                resources.getColor(R.color.tiling_divider_background_dark, /* theme= */null)
+            } else {
+                resources.getColor(R.color.tiling_divider_background_light, /* theme= */ null)
+            }
         paint.isAntiAlias = true
         paint.style = Paint.Style.FILL
     }
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt
index 16c7935..e89a122 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt
@@ -321,6 +321,19 @@
     }
 
     @Test
+    fun testOnTaskInfoChanged_tilingNotified() {
+        val task = createTask(
+            windowingMode = WINDOWING_MODE_FREEFORM
+        )
+        setUpMockDecorationsForTasks(task)
+
+        onTaskOpening(task)
+        desktopModeWindowDecorViewModel.onTaskInfoChanged(task)
+
+        verify(mockTilingWindowDecoration).onTaskInfoChange(task)
+    }
+
+    @Test
     @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_IMMERSIVE_HANDLE_HIDING)
     fun testInsetsStateChanged_notifiesAllDecorsInDisplay() {
         val task1 = createTask(windowingMode = WINDOWING_MODE_FREEFORM, displayId = 1)
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManagerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManagerTest.kt
index 121e0e9..8442056 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManagerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManagerTest.kt
@@ -81,6 +81,7 @@
                 transactionSupplierMock,
                 BOUNDS,
                 context,
+                /* isDarkMode= */ true
             )
     }
 
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/TilingDividerViewTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/TilingDividerViewTest.kt
index 9a9d05a..9a3d5d8 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/TilingDividerViewTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/TilingDividerViewTest.kt
@@ -60,7 +60,7 @@
         tilingDividerView =
             LayoutInflater.from(mContext).inflate(R.layout.tiling_split_divider, /* root= */ null)
                 as TilingDividerView
-        tilingDividerView.setup(dividerMoveCallbackMock, DIVIDER_BOUNDS, HANDLE_SIZE)
+        tilingDividerView.setup(dividerMoveCallbackMock, DIVIDER_BOUNDS, HANDLE_SIZE, true)
         tilingDividerView.handleY = 0..1500
     }