Move utilities in LPMUtils to LPUtil

I chose LaunchParamsUtil over LaunchParamsModifierUtility

1. For its simpler name;
2. For its longer code history; and
3. To keep the original authors of utility functions in git history.

Also made a few adjustments in tests to improve readability.

Bug: 340460999
Bug: 340172101
Bug: 340172030
Test: atest WmTests:DesktopModeLaunchParamsModifierTests
Test: atest WmTests:TaskLaunchParamsModifierTests
Change-Id: I918b5a82a23db8a370ffcfc8fc9b094027b00b7c
diff --git a/services/core/java/com/android/server/wm/DesktopModeLaunchParamsModifier.java b/services/core/java/com/android/server/wm/DesktopModeLaunchParamsModifier.java
index 1128328..50ac801 100644
--- a/services/core/java/com/android/server/wm/DesktopModeLaunchParamsModifier.java
+++ b/services/core/java/com/android/server/wm/DesktopModeLaunchParamsModifier.java
@@ -18,8 +18,8 @@
 
 import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
 import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
-import static com.android.server.wm.LaunchParamsModifierUtils.applyLayoutGravity;
-import static com.android.server.wm.LaunchParamsModifierUtils.calculateLayoutBounds;
+import static com.android.server.wm.LaunchParamsUtil.applyLayoutGravity;
+import static com.android.server.wm.LaunchParamsUtil.calculateLayoutBounds;
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
diff --git a/services/core/java/com/android/server/wm/LaunchParamsModifierUtils.java b/services/core/java/com/android/server/wm/LaunchParamsModifierUtils.java
deleted file mode 100644
index db54647..0000000
--- a/services/core/java/com/android/server/wm/LaunchParamsModifierUtils.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.server.wm;
-
-import android.annotation.NonNull;
-import android.annotation.Nullable;
-import android.content.pm.ActivityInfo;
-import android.graphics.Rect;
-import android.util.Size;
-import android.view.Gravity;
-
-class LaunchParamsModifierUtils {
-
-    /**
-     * Calculates bounds based on window layout size manifest values. These can include width,
-     * height, width fraction and height fraction. In the event only one dimension of values are
-     * specified in the manifest (e.g. width but no height value), the corresponding display area
-     * dimension will be used as the default value unless some desired sizes have been specified.
-     */
-    static void calculateLayoutBounds(@NonNull Rect stableBounds,
-            @NonNull ActivityInfo.WindowLayout windowLayout, @NonNull Rect inOutBounds,
-            @Nullable Size desiredSize) {
-        final int defaultWidth = stableBounds.width();
-        final int defaultHeight = stableBounds.height();
-        int width;
-        int height;
-
-        if (desiredSize == null) {
-            // If desired bounds have not been specified, use the exiting default bounds as the
-            // desired.
-            desiredSize = new Size(stableBounds.width(), stableBounds.height());
-        }
-
-        width = desiredSize.getWidth();
-        if (windowLayout.width > 0 && windowLayout.width < defaultWidth) {
-            width = windowLayout.width;
-        } else if (windowLayout.widthFraction > 0 && windowLayout.widthFraction < 1.0f) {
-            width = (int) (defaultWidth * windowLayout.widthFraction);
-        }
-
-        height = desiredSize.getHeight();
-        if (windowLayout.height > 0 && windowLayout.height < defaultHeight) {
-            height = windowLayout.height;
-        } else if (windowLayout.heightFraction > 0 && windowLayout.heightFraction < 1.0f) {
-            height = (int) (defaultHeight * windowLayout.heightFraction);
-        }
-
-        inOutBounds.set(0, 0, width, height);
-    }
-
-    /**
-     * Applies a vertical and horizontal gravity on the inOutBounds in relation to the stableBounds.
-     */
-    static void applyLayoutGravity(int verticalGravity, int horizontalGravity,
-            @NonNull Rect inOutBounds, @NonNull Rect stableBounds) {
-        final int width = inOutBounds.width();
-        final int height = inOutBounds.height();
-
-        final float fractionOfHorizontalOffset;
-        switch (horizontalGravity) {
-            case Gravity.LEFT:
-                fractionOfHorizontalOffset = 0f;
-                break;
-            case Gravity.RIGHT:
-                fractionOfHorizontalOffset = 1f;
-                break;
-            default:
-                fractionOfHorizontalOffset = 0.5f;
-        }
-
-        final float fractionOfVerticalOffset;
-        switch (verticalGravity) {
-            case Gravity.TOP:
-                fractionOfVerticalOffset = 0f;
-                break;
-            case Gravity.BOTTOM:
-                fractionOfVerticalOffset = 1f;
-                break;
-            default:
-                fractionOfVerticalOffset = 0.5f;
-        }
-
-        inOutBounds.offsetTo(stableBounds.left, stableBounds.top);
-        final int xOffset = (int) (fractionOfHorizontalOffset * (stableBounds.width() - width));
-        final int yOffset = (int) (fractionOfVerticalOffset * (stableBounds.height() - height));
-        inOutBounds.offset(xOffset, yOffset);
-    }
-}
diff --git a/services/core/java/com/android/server/wm/LaunchParamsUtil.java b/services/core/java/com/android/server/wm/LaunchParamsUtil.java
index cd071af..9416daf 100644
--- a/services/core/java/com/android/server/wm/LaunchParamsUtil.java
+++ b/services/core/java/com/android/server/wm/LaunchParamsUtil.java
@@ -23,9 +23,11 @@
 import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
 
 import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.content.pm.ActivityInfo;
 import android.graphics.Rect;
 import android.util.Size;
+import android.view.Gravity;
 import android.view.View;
 
 /**
@@ -195,4 +197,79 @@
         }
         inOutBounds.offset(dx, dy);
     }
+
+    /**
+     * Calculates bounds based on window layout size manifest values. These can include width,
+     * height, width fraction and height fraction. In the event only one dimension of values are
+     * specified in the manifest (e.g. width but no height value), the corresponding display area
+     * dimension will be used as the default value unless some desired sizes have been specified.
+     */
+    static void calculateLayoutBounds(@NonNull Rect stableBounds,
+            @NonNull ActivityInfo.WindowLayout windowLayout, @NonNull Rect inOutBounds,
+            @Nullable Size desiredSize) {
+        final int defaultWidth = stableBounds.width();
+        final int defaultHeight = stableBounds.height();
+        int width;
+        int height;
+
+        if (desiredSize == null) {
+            // If desired bounds have not been specified, use the exiting default bounds as the
+            // desired.
+            desiredSize = new Size(stableBounds.width(), stableBounds.height());
+        }
+
+        width = desiredSize.getWidth();
+        if (windowLayout.width > 0 && windowLayout.width < defaultWidth) {
+            width = windowLayout.width;
+        } else if (windowLayout.widthFraction > 0 && windowLayout.widthFraction < 1.0f) {
+            width = (int) (defaultWidth * windowLayout.widthFraction);
+        }
+
+        height = desiredSize.getHeight();
+        if (windowLayout.height > 0 && windowLayout.height < defaultHeight) {
+            height = windowLayout.height;
+        } else if (windowLayout.heightFraction > 0 && windowLayout.heightFraction < 1.0f) {
+            height = (int) (defaultHeight * windowLayout.heightFraction);
+        }
+
+        inOutBounds.set(0, 0, width, height);
+    }
+
+    /**
+     * Applies a vertical and horizontal gravity on the inOutBounds in relation to the stableBounds.
+     */
+    static void applyLayoutGravity(int verticalGravity, int horizontalGravity,
+            @NonNull Rect inOutBounds, @NonNull Rect stableBounds) {
+        final int width = inOutBounds.width();
+        final int height = inOutBounds.height();
+
+        final float fractionOfHorizontalOffset;
+        switch (horizontalGravity) {
+            case Gravity.LEFT:
+                fractionOfHorizontalOffset = 0f;
+                break;
+            case Gravity.RIGHT:
+                fractionOfHorizontalOffset = 1f;
+                break;
+            default:
+                fractionOfHorizontalOffset = 0.5f;
+        }
+
+        final float fractionOfVerticalOffset;
+        switch (verticalGravity) {
+            case Gravity.TOP:
+                fractionOfVerticalOffset = 0f;
+                break;
+            case Gravity.BOTTOM:
+                fractionOfVerticalOffset = 1f;
+                break;
+            default:
+                fractionOfVerticalOffset = 0.5f;
+        }
+
+        inOutBounds.offsetTo(stableBounds.left, stableBounds.top);
+        final int xOffset = (int) (fractionOfHorizontalOffset * (stableBounds.width() - width));
+        final int yOffset = (int) (fractionOfVerticalOffset * (stableBounds.height() - height));
+        inOutBounds.offset(xOffset, yOffset);
+    }
 }
diff --git a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
index f37638f..5c9a84d 100644
--- a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
+++ b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
@@ -40,8 +40,6 @@
 import static com.android.server.wm.ActivityStarter.Request;
 import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
 import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
-import static com.android.server.wm.LaunchParamsModifierUtils.applyLayoutGravity;
-import static com.android.server.wm.LaunchParamsModifierUtils.calculateLayoutBounds;
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -644,13 +642,13 @@
         displayArea.getStableRect(stableBounds);
 
         if (windowLayout.hasSpecifiedSize()) {
-            calculateLayoutBounds(stableBounds, windowLayout, inOutBounds,
+            LaunchParamsUtil.calculateLayoutBounds(stableBounds, windowLayout, inOutBounds,
                     /* desiredBounds */ null);
         } else if (inOutBounds.isEmpty()) {
             getTaskBounds(root, displayArea, windowLayout, WINDOWING_MODE_FREEFORM,
                     /* hasInitialBounds */ false, inOutBounds);
         }
-        applyLayoutGravity(verticalGravity, horizontalGravity, inOutBounds,
+        LaunchParamsUtil.applyLayoutGravity(verticalGravity, horizontalGravity, inOutBounds,
                 stableBounds);
     }
 
diff --git a/services/tests/wmtests/src/com/android/server/wm/DesktopModeLaunchParamsModifierTests.java b/services/tests/wmtests/src/com/android/server/wm/DesktopModeLaunchParamsModifierTests.java
index 12c1377..a4bec64 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DesktopModeLaunchParamsModifierTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DesktopModeLaunchParamsModifierTests.java
@@ -57,7 +57,8 @@
 @SmallTest
 @Presubmit
 @RunWith(WindowTestRunner.class)
-public class DesktopModeLaunchParamsModifierTests extends LaunchParamsModifierTestsBase {
+public class DesktopModeLaunchParamsModifierTests extends
+        LaunchParamsModifierTestsBase<DesktopModeLaunchParamsModifier> {
     @Before
     public void setUp() throws Exception {
         mActivity = new ActivityBuilder(mAtm).build();
diff --git a/services/tests/wmtests/src/com/android/server/wm/LaunchParamsModifierTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/LaunchParamsModifierTestsBase.java
index 55f5df1..87671f2 100644
--- a/services/tests/wmtests/src/com/android/server/wm/LaunchParamsModifierTestsBase.java
+++ b/services/tests/wmtests/src/com/android/server/wm/LaunchParamsModifierTestsBase.java
@@ -33,7 +33,7 @@
 import com.android.server.wm.LaunchParamsController.LaunchParamsModifier;
 
 /** Common base class for launch param modifier unit test classes. */
-public class LaunchParamsModifierTestsBase extends WindowTestsBase{
+public class LaunchParamsModifierTestsBase<T extends LaunchParamsModifier> extends WindowTestsBase {
 
     static final Rect DISPLAY_BOUNDS = new Rect(/* left */ 0, /* top */ 0,
             /* right */ 1920, /* bottom */ 1080);
@@ -42,7 +42,7 @@
 
     ActivityRecord mActivity;
 
-    LaunchParamsModifier mTarget;
+    T mTarget;
 
     LaunchParams mCurrent;
     LaunchParams mResult;
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java
index 2ce21ba..3c921c6 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java
@@ -70,7 +70,8 @@
 @SmallTest
 @Presubmit
 @RunWith(WindowTestRunner.class)
-public class TaskLaunchParamsModifierTests extends LaunchParamsModifierTestsBase {
+public class TaskLaunchParamsModifierTests extends
+        LaunchParamsModifierTestsBase<TaskLaunchParamsModifier> {
     private static final Rect SMALL_DISPLAY_BOUNDS = new Rect(/* left */ 0, /* top */ 0,
             /* right */ 1000, /* bottom */ 500);
     private static final Rect SMALL_DISPLAY_STABLE_BOUNDS = new Rect(/* left */ 100,
@@ -1898,8 +1899,7 @@
         }
         Rect startingBounds = new Rect(0, 0, 20, 20);
         Rect adjustedBounds = new Rect(startingBounds);
-        ((TaskLaunchParamsModifier) mTarget).adjustBoundsToAvoidConflict(displayBounds,
-                existingTaskBounds, adjustedBounds);
+        mTarget.adjustBoundsToAvoidConflict(displayBounds, existingTaskBounds, adjustedBounds);
         assertEquals(startingBounds, adjustedBounds);
     }