Replacing custom parcelables with platform types for test APIs
Bug: 377772352 Flag: EXEMPT test only Test: Presubmit Change-Id: Ie464c67adf6502aee1fe65ef643e1a67260b820f
This commit is contained in:
1 parent
eda3c8ec60
commit
a39a09ba6a
13 files changed
+52
-307
No files matched your search
@@ -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,
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
-1
@@ -76,8 +76,9 @@ public final class TestProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
@@ -55,9 +55,7 @@ import com.android.launcher3.ShortcutAndWidgetContainer;
|
||||
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 @@ public class TestInformationHandler implements ResourceBasedOverride {
|
||||
});
|
||||
|
||||
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 @@ public class TestInformationHandler implements ResourceBasedOverride {
|
||||
}
|
||||
|
||||
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,
|
||||
|
||||
@@ -151,19 +151,6 @@ android_test {
|
||||
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: [
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
vadimt@google.com
|
||||
sunnygoyal@google.com
|
||||
winsonc@google.com
|
||||
hyunyoungs@google.com
|
||||
mateuszc@google.com
|
||||
-99
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
-29
@@ -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();
|
||||
}
|
||||
-138
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ import android.content.ComponentName;
|
||||
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.UiObject2;
|
||||
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 @@ public final class LauncherInstrumentation {
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
@@ -29,6 +29,7 @@ import static com.android.launcher3.testing.shared.TestProtocol.OVERVIEW_STATE_O
|
||||
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.UiDevice;
|
||||
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 @@ public final class Workspace extends Home {
|
||||
}
|
||||
|
||||
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 */
|
||||
|
||||
Reference in new issue
Block a user