Replacing custom parcelables with platform types for test APIs

Bug: 377772352
Flag: EXEMPT test only
Test: Presubmit
Change-Id: Ie464c67adf6502aee1fe65ef643e1a67260b820f
diff --git a/shared/Android.bp b/shared/Android.bp
new file mode 100644
index 0000000..6d2f407
--- /dev/null
+++ b/shared/Android.bp
@@ -0,0 +1,31 @@
+// 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 {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+// Shared between tests and launcher
+android_library {
+    name: "launcher-testing-shared",
+    srcs: [
+        "src/**/*.java",
+        "src/**/*.kt",
+    ],
+    resource_dirs: [],
+    manifest: "AndroidManifest.xml",
+    sdk_version: "current",
+    min_sdk_version: min_launcher3_sdk_version,
+}
diff --git a/tests/multivalentTests/shared/AndroidManifest.xml b/shared/AndroidManifest.xml
similarity index 100%
rename from tests/multivalentTests/shared/AndroidManifest.xml
rename to shared/AndroidManifest.xml
diff --git a/tests/shared/com/android/launcher3/testing/OWNERS b/shared/OWNERS
similarity index 100%
rename from tests/shared/com/android/launcher3/testing/OWNERS
rename to shared/OWNERS
diff --git a/tests/multivalentTests/shared/com/android/launcher3/testing/shared/ResourceUtils.java b/shared/src/com/android/launcher3/testing/shared/ResourceUtils.java
similarity index 100%
rename from tests/multivalentTests/shared/com/android/launcher3/testing/shared/ResourceUtils.java
rename to shared/src/com/android/launcher3/testing/shared/ResourceUtils.java
diff --git a/tests/multivalentTests/shared/com/android/launcher3/testing/shared/TestProtocol.java b/shared/src/com/android/launcher3/testing/shared/TestProtocol.java
similarity index 98%
rename from tests/multivalentTests/shared/com/android/launcher3/testing/shared/TestProtocol.java
rename to shared/src/com/android/launcher3/testing/shared/TestProtocol.java
index 825b52b..4a7471a 100644
--- a/tests/multivalentTests/shared/com/android/launcher3/testing/shared/TestProtocol.java
+++ b/shared/src/com/android/launcher3/testing/shared/TestProtocol.java
@@ -76,8 +76,9 @@
         }
     }
 
-    public static final String TEST_INFO_REQUEST_FIELD = "request";
     public static final String TEST_INFO_RESPONSE_FIELD = "response";
+    public static final String TEST_INFO_PARAM_INDEX = "index";
+    public static final String TEST_INFO_PARAM_CELL_SPAN = "cell-span";
 
     public static final String REQUEST_HOME_TO_OVERVIEW_SWIPE_HEIGHT =
             "home-to-overview-swipe-height";
diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java
index aa3f2f2..fb5c8c7 100644
--- a/src/com/android/launcher3/testing/TestInformationHandler.java
+++ b/src/com/android/launcher3/testing/TestInformationHandler.java
@@ -55,9 +55,7 @@
 import com.android.launcher3.Workspace;
 import com.android.launcher3.dragndrop.DragLayer;
 import com.android.launcher3.icons.ClockDrawableWrapper;
-import com.android.launcher3.testing.shared.HotseatCellCenterRequest;
 import com.android.launcher3.testing.shared.TestProtocol;
-import com.android.launcher3.testing.shared.WorkspaceCellCenterRequest;
 import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter;
 import com.android.launcher3.util.DisplayController;
 import com.android.launcher3.util.ResourceBasedOverride;
@@ -265,15 +263,15 @@
                 });
 
             case TestProtocol.REQUEST_WORKSPACE_CELL_CENTER: {
-                final WorkspaceCellCenterRequest request = extra.getParcelable(
-                        TestProtocol.TEST_INFO_REQUEST_FIELD);
+                Rect cellPos = extra.getParcelable(TestProtocol.TEST_INFO_PARAM_CELL_SPAN);
                 return getLauncherUIProperty(Bundle::putParcelable, launcher -> {
                     final Workspace<?> workspace = launcher.getWorkspace();
                     // TODO(b/216387249): allow caller selecting different pages.
                     CellLayout cellLayout = (CellLayout) workspace.getPageAt(
                             workspace.getCurrentPage());
                     final Rect cellRect = getDescendantRectRelativeToDragLayerForCell(launcher,
-                            cellLayout, request.cellX, request.cellY, request.spanX, request.spanY);
+                            cellLayout, cellPos.left, cellPos.top, cellPos.width(),
+                            cellPos.height());
                     return new Point(cellRect.centerX(), cellRect.centerY());
                 });
             }
@@ -292,12 +290,11 @@
             }
 
             case TestProtocol.REQUEST_HOTSEAT_CELL_CENTER: {
-                final HotseatCellCenterRequest request = extra.getParcelable(
-                        TestProtocol.TEST_INFO_REQUEST_FIELD);
+                int cellIndex = extra.getInt(TestProtocol.TEST_INFO_PARAM_INDEX);
                 return getLauncherUIProperty(Bundle::putParcelable, launcher -> {
                     final Hotseat hotseat = launcher.getHotseat();
                     final Rect cellRect = getDescendantRectRelativeToDragLayerForCell(launcher,
-                            hotseat, request.cellInd, /* cellY= */ 0,
+                            hotseat, cellIndex, /* cellY= */ 0,
                             /* spanX= */ 1, /* spanY= */ 1);
                     // TODO(b/234322284): return the real center point.
                     return new Point(cellRect.left + (cellRect.right - cellRect.left) / 3,
diff --git a/tests/Android.bp b/tests/Android.bp
index e4fecc5..f666bba 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -151,19 +151,6 @@
     test_suites: ["general-tests"],
 }
 
-// Shared between tests and launcher
-android_library {
-    name: "launcher-testing-shared",
-    srcs: [
-        "multivalentTests/shared/com/android/launcher3/testing/shared/**/*.java",
-        "multivalentTests/shared/com/android/launcher3/testing/shared/**/*.kt",
-    ],
-    resource_dirs: [],
-    manifest: "multivalentTests/shared/AndroidManifest.xml",
-    sdk_version: "current",
-    min_sdk_version: min_launcher3_sdk_version,
-}
-
 filegroup {
     name: "launcher-testing-helpers-robo",
     srcs: [
diff --git a/tests/multivalentTests/shared/com/android/launcher3/testing/OWNERS b/tests/multivalentTests/shared/com/android/launcher3/testing/OWNERS
deleted file mode 100644
index a818d5e..0000000
--- a/tests/multivalentTests/shared/com/android/launcher3/testing/OWNERS
+++ /dev/null
@@ -1,5 +0,0 @@
-vadimt@google.com
-sunnygoyal@google.com
-winsonc@google.com
-hyunyoungs@google.com
-mateuszc@google.com
\ No newline at end of file
diff --git a/tests/multivalentTests/shared/com/android/launcher3/testing/shared/HotseatCellCenterRequest.java b/tests/multivalentTests/shared/com/android/launcher3/testing/shared/HotseatCellCenterRequest.java
deleted file mode 100644
index 7eb035a..0000000
--- a/tests/multivalentTests/shared/com/android/launcher3/testing/shared/HotseatCellCenterRequest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.launcher3.testing.shared;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-/**
- * Request object for querying a hotseat cell region in Rect.
- */
-public class HotseatCellCenterRequest implements TestInformationRequest {
-    public final int cellInd;
-
-    @Override
-    public int describeContents() {
-        return 0;
-    }
-
-    @Override
-    public void writeToParcel(Parcel dest, int flags) {
-        dest.writeInt(cellInd);
-    }
-
-    @Override
-    public String getRequestName() {
-        return TestProtocol.REQUEST_HOTSEAT_CELL_CENTER;
-    }
-
-    public static final Parcelable.Creator<HotseatCellCenterRequest> CREATOR =
-            new Parcelable.Creator<HotseatCellCenterRequest>() {
-
-                @Override
-                public HotseatCellCenterRequest createFromParcel(Parcel source) {
-                    return new HotseatCellCenterRequest(source);
-                }
-
-                @Override
-                public HotseatCellCenterRequest[] newArray(int size) {
-                    return new HotseatCellCenterRequest[size];
-                }
-            };
-
-    private HotseatCellCenterRequest(int cellInd) {
-        this.cellInd = cellInd;
-    }
-
-    private HotseatCellCenterRequest(Parcel in) {
-        this(in.readInt());
-    }
-
-    /**
-     * Create a builder for HotseatCellCenterRequest.
-     *
-     * @return HotseatCellCenterRequest builder.
-     */
-    public static HotseatCellCenterRequest.Builder builder() {
-        return new HotseatCellCenterRequest.Builder();
-    }
-
-    /**
-     * HotseatCellCenterRequest Builder.
-     */
-    public static final class Builder {
-        private int mCellInd;
-
-        private Builder() {
-            mCellInd = 0;
-        }
-
-        /**
-         * Set the index of hotseat cells.
-         */
-        public HotseatCellCenterRequest.Builder setCellInd(int i) {
-            this.mCellInd = i;
-            return this;
-        }
-
-        /**
-         * build the HotseatCellCenterRequest.
-         */
-        public HotseatCellCenterRequest build() {
-            return new HotseatCellCenterRequest(mCellInd);
-        }
-    }
-}
diff --git a/tests/multivalentTests/shared/com/android/launcher3/testing/shared/TestInformationRequest.java b/tests/multivalentTests/shared/com/android/launcher3/testing/shared/TestInformationRequest.java
deleted file mode 100644
index 38282032..0000000
--- a/tests/multivalentTests/shared/com/android/launcher3/testing/shared/TestInformationRequest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2021 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.launcher3.testing.shared;
-
-import android.os.Parcelable;
-
-/**
- * A Request sent to TestInformationHandler can implement this interface to carry more information.
- */
-public interface TestInformationRequest extends Parcelable {
-    /**
-     * The name for handler to dispatch request.
-     */
-    String getRequestName();
-}
diff --git a/tests/multivalentTests/shared/com/android/launcher3/testing/shared/WorkspaceCellCenterRequest.java b/tests/multivalentTests/shared/com/android/launcher3/testing/shared/WorkspaceCellCenterRequest.java
deleted file mode 100644
index e2cd8ea..0000000
--- a/tests/multivalentTests/shared/com/android/launcher3/testing/shared/WorkspaceCellCenterRequest.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * 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.launcher3.testing.shared;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-/**
- * Request object for querying a workspace cell region in Rect.
- */
-public class WorkspaceCellCenterRequest implements TestInformationRequest {
-    public final int cellX;
-    public final int cellY;
-    public final int spanX;
-    public final int spanY;
-
-    @Override
-    public int describeContents() {
-        return 0;
-    }
-
-    @Override
-    public void writeToParcel(Parcel dest, int flags) {
-        dest.writeInt(cellX);
-        dest.writeInt(cellY);
-        dest.writeInt(spanX);
-        dest.writeInt(spanY);
-    }
-
-    public static final Parcelable.Creator<WorkspaceCellCenterRequest> CREATOR =
-            new Parcelable.Creator<WorkspaceCellCenterRequest>() {
-
-                @Override
-                public WorkspaceCellCenterRequest createFromParcel(Parcel source) {
-                    return new WorkspaceCellCenterRequest(source);
-                }
-
-                @Override
-                public WorkspaceCellCenterRequest[] newArray(int size) {
-                    return new WorkspaceCellCenterRequest[size];
-                }
-            };
-
-    private WorkspaceCellCenterRequest(int cellX, int cellY, int spanX, int spanY) {
-        this.cellX = cellX;
-        this.cellY = cellY;
-        this.spanX = spanX;
-        this.spanY = spanY;
-    }
-
-    private WorkspaceCellCenterRequest(Parcel in) {
-        this(in.readInt(), in.readInt(), in.readInt(), in.readInt());
-    }
-
-    /**
-     * Create a builder for WorkspaceCellRectRequest.
-     *
-     * @return WorkspaceCellRectRequest builder.
-     */
-    public static WorkspaceCellCenterRequest.Builder builder() {
-        return new WorkspaceCellCenterRequest.Builder();
-    }
-
-    @Override
-    public String getRequestName() {
-        return TestProtocol.REQUEST_WORKSPACE_CELL_CENTER;
-    }
-
-    /**
-     * WorkspaceCellRectRequest Builder.
-     */
-    public static final class Builder {
-        private int mCellX;
-        private int mCellY;
-        private int mSpanX;
-        private int mSpanY;
-
-        private Builder() {
-            this.mCellX = 0;
-            this.mCellY = 0;
-            this.mSpanX = 1;
-            this.mSpanY = 1;
-        }
-
-        /**
-         * Set X coordinate of upper left corner expressed as a cell position
-         */
-        public WorkspaceCellCenterRequest.Builder setCellX(int x) {
-            this.mCellX = x;
-            return this;
-        }
-
-        /**
-         * Set Y coordinate of upper left corner expressed as a cell position
-         */
-        public WorkspaceCellCenterRequest.Builder setCellY(int y) {
-            this.mCellY = y;
-            return this;
-        }
-
-        /**
-         * Set span Width in cells
-         */
-        public WorkspaceCellCenterRequest.Builder setSpanX(int x) {
-            this.mSpanX = x;
-            return this;
-        }
-
-        /**
-         * Set span Height in cells
-         */
-        public WorkspaceCellCenterRequest.Builder setSpanY(int y) {
-            this.mSpanY = y;
-            return this;
-        }
-
-        /**
-         * build the WorkspaceCellRectRequest.
-         */
-        public WorkspaceCellCenterRequest build() {
-            return new WorkspaceCellCenterRequest(mCellX, mCellY, mSpanX, mSpanY);
-        }
-    }
-}
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index fac73d3..bdfe2ab 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -41,6 +41,7 @@
 import android.content.ContentProviderClient;
 import android.content.ContentResolver;
 import android.content.Context;
+import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ProviderInfo;
 import android.content.res.Configuration;
@@ -79,7 +80,6 @@
 import androidx.test.uiautomator.Until;
 
 import com.android.launcher3.testing.shared.ResourceUtils;
-import com.android.launcher3.testing.shared.TestInformationRequest;
 import com.android.launcher3.testing.shared.TestProtocol;
 import com.android.systemui.shared.system.QuickStepContract;
 
@@ -377,10 +377,8 @@
         }
     }
 
-    Bundle getTestInfo(TestInformationRequest request) {
-        Bundle extra = new Bundle();
-        extra.putParcelable(TestProtocol.TEST_INFO_REQUEST_FIELD, request);
-        return getTestInfo(request.getRequestName(), null, extra);
+    Bundle getTestInfo(Intent request) {
+        return getTestInfo(request.getAction(), null, request.getExtras());
     }
 
     Insets getTargetInsets() {
diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java
index a29362f..d615879 100644
--- a/tests/tapl/com/android/launcher3/tapl/Workspace.java
+++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java
@@ -29,6 +29,7 @@
 import static junit.framework.TestCase.assertNotNull;
 import static junit.framework.TestCase.assertTrue;
 
+import android.content.Intent;
 import android.graphics.Point;
 import android.graphics.Rect;
 import android.os.SystemClock;
@@ -44,9 +45,7 @@
 import androidx.test.uiautomator.UiObject2;
 import androidx.test.uiautomator.Until;
 
-import com.android.launcher3.testing.shared.HotseatCellCenterRequest;
 import com.android.launcher3.testing.shared.TestProtocol;
-import com.android.launcher3.testing.shared.WorkspaceCellCenterRequest;
 
 import java.util.List;
 import java.util.Map;
@@ -499,20 +498,23 @@
     }
 
     static Point getCellCenter(LauncherInstrumentation launcher, int cellX, int cellY) {
-        return launcher.getTestInfo(WorkspaceCellCenterRequest.builder().setCellX(cellX).setCellY(
-                cellY).build()).getParcelable(TestProtocol.TEST_INFO_RESPONSE_FIELD);
+        return getCellCenter(launcher, cellX, cellY, 1, 1);
     }
 
     static Point getCellCenter(LauncherInstrumentation launcher, int cellX, int cellY, int spanX,
             int spanY) {
-        return launcher.getTestInfo(WorkspaceCellCenterRequest.builder().setCellX(cellX)
-                .setCellY(cellY).setSpanX(spanX).setSpanY(spanY).build())
+        return launcher.getTestInfo(
+                new Intent(TestProtocol.REQUEST_WORKSPACE_CELL_CENTER)
+                        .putExtra(TestProtocol.TEST_INFO_PARAM_CELL_SPAN,
+                                new Rect(cellX, cellY, cellX + spanX, cellY + spanY)))
                 .getParcelable(TestProtocol.TEST_INFO_RESPONSE_FIELD);
     }
 
-    static Point getHotseatCellCenter(LauncherInstrumentation launcher, int cellInd) {
-        return launcher.getTestInfo(HotseatCellCenterRequest.builder()
-                .setCellInd(cellInd).build()).getParcelable(TestProtocol.TEST_INFO_RESPONSE_FIELD);
+    static Point getHotseatCellCenter(LauncherInstrumentation launcher, int cellIndex) {
+        return launcher.getTestInfo(
+                new Intent(TestProtocol.REQUEST_HOTSEAT_CELL_CENTER)
+                        .putExtra(TestProtocol.TEST_INFO_PARAM_INDEX, cellIndex))
+                .getParcelable(TestProtocol.TEST_INFO_RESPONSE_FIELD);
     }
 
     /** Returns the number of rows and columns in the workspace */