Merge "Binding tests to TouchInteractionService to preventing it from getting destroyed" into tm-qpr-dev
This commit is contained in:
commit
2e1524ec2f
|
@ -44,6 +44,7 @@ filegroup {
|
||||||
srcs: [
|
srcs: [
|
||||||
"src/com/android/launcher3/ui/AbstractLauncherUiTest.java",
|
"src/com/android/launcher3/ui/AbstractLauncherUiTest.java",
|
||||||
"src/com/android/launcher3/ui/PortraitLandscapeRunner.java",
|
"src/com/android/launcher3/ui/PortraitLandscapeRunner.java",
|
||||||
|
"src/com/android/launcher3/ui/TaplTestsLauncher3.java",
|
||||||
"src/com/android/launcher3/util/TestUtil.java",
|
"src/com/android/launcher3/util/TestUtil.java",
|
||||||
"src/com/android/launcher3/util/Wait.java",
|
"src/com/android/launcher3/util/Wait.java",
|
||||||
"src/com/android/launcher3/util/WidgetUtils.java",
|
"src/com/android/launcher3/util/WidgetUtils.java",
|
||||||
|
@ -54,7 +55,7 @@ filegroup {
|
||||||
"src/com/android/launcher3/util/rule/ShellCommandRule.java",
|
"src/com/android/launcher3/util/rule/ShellCommandRule.java",
|
||||||
"src/com/android/launcher3/util/rule/SimpleActivityRule.java",
|
"src/com/android/launcher3/util/rule/SimpleActivityRule.java",
|
||||||
"src/com/android/launcher3/util/rule/TestStabilityRule.java",
|
"src/com/android/launcher3/util/rule/TestStabilityRule.java",
|
||||||
"src/com/android/launcher3/ui/TaplTestsLauncher3.java",
|
"src/com/android/launcher3/util/rule/TISBindRule.java",
|
||||||
"src/com/android/launcher3/testcomponent/BaseTestingActivity.java",
|
"src/com/android/launcher3/testcomponent/BaseTestingActivity.java",
|
||||||
"src/com/android/launcher3/testcomponent/OtherBaseTestingActivity.java",
|
"src/com/android/launcher3/testcomponent/OtherBaseTestingActivity.java",
|
||||||
"src/com/android/launcher3/testcomponent/CustomShortcutConfigActivity.java",
|
"src/com/android/launcher3/testcomponent/CustomShortcutConfigActivity.java",
|
||||||
|
|
|
@ -51,11 +51,13 @@ import com.android.launcher3.tapl.Widgets;
|
||||||
import com.android.launcher3.tapl.Workspace;
|
import com.android.launcher3.tapl.Workspace;
|
||||||
import com.android.launcher3.util.TestUtil;
|
import com.android.launcher3.util.TestUtil;
|
||||||
import com.android.launcher3.util.rule.ScreenRecordRule.ScreenRecord;
|
import com.android.launcher3.util.rule.ScreenRecordRule.ScreenRecord;
|
||||||
|
import com.android.launcher3.util.rule.TISBindRule;
|
||||||
import com.android.launcher3.widget.picker.WidgetsFullSheet;
|
import com.android.launcher3.widget.picker.WidgetsFullSheet;
|
||||||
import com.android.launcher3.widget.picker.WidgetsRecyclerView;
|
import com.android.launcher3.widget.picker.WidgetsRecyclerView;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@ -71,6 +73,9 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
|
||||||
private static final String STORE_APP_NAME = "Play Store";
|
private static final String STORE_APP_NAME = "Play Store";
|
||||||
private static final String GMAIL_APP_NAME = "Gmail";
|
private static final String GMAIL_APP_NAME = "Gmail";
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TISBindRule mTISBindRule = new TISBindRule();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
@ -214,7 +219,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
|
||||||
false /* tapRight */);
|
false /* tapRight */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@IwTest(focusArea="launcher")
|
@IwTest(focusArea = "launcher")
|
||||||
@Test
|
@Test
|
||||||
@ScreenRecord // b/202433017
|
@ScreenRecord // b/202433017
|
||||||
public void testWorkspace() throws Exception {
|
public void testWorkspace() throws Exception {
|
||||||
|
@ -341,7 +346,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@IwTest(focusArea="launcher")
|
@IwTest(focusArea = "launcher")
|
||||||
@Test
|
@Test
|
||||||
@PortraitLandscape
|
@PortraitLandscape
|
||||||
@ScreenRecord // b/256898879
|
@ScreenRecord // b/256898879
|
||||||
|
@ -610,16 +615,16 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return List of workspace grid coordinates. Those are not pixels. See {@link
|
* @return List of workspace grid coordinates. Those are not pixels. See {@link
|
||||||
* Workspace#getIconGridDimensions()}
|
* Workspace#getIconGridDimensions()}
|
||||||
*/
|
*/
|
||||||
private Point[] getCornersAndCenterPositions() {
|
private Point[] getCornersAndCenterPositions() {
|
||||||
final Point dimensions = mLauncher.getWorkspace().getIconGridDimensions();
|
final Point dimensions = mLauncher.getWorkspace().getIconGridDimensions();
|
||||||
return new Point[] {
|
return new Point[]{
|
||||||
new Point(0, 1),
|
new Point(0, 1),
|
||||||
new Point(0, dimensions.y - 2),
|
new Point(0, dimensions.y - 2),
|
||||||
new Point(dimensions.x - 1, 1),
|
new Point(dimensions.x - 1, 1),
|
||||||
new Point(dimensions.x - 1, dimensions.y - 2),
|
new Point(dimensions.x - 1, dimensions.y - 2),
|
||||||
new Point(dimensions.x / 2, dimensions.y / 2)
|
new Point(dimensions.x / 2, dimensions.y / 2)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023 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.util.rule;
|
||||||
|
|
||||||
|
import android.app.UiAutomation;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.ServiceConnection;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
|
||||||
|
import org.junit.rules.TestRule;
|
||||||
|
import org.junit.runner.Description;
|
||||||
|
import org.junit.runners.model.Statement;
|
||||||
|
|
||||||
|
public class TISBindRule implements TestRule {
|
||||||
|
public static String TAG = "TISBindRule";
|
||||||
|
public static String INTENT_FILTER = "android.intent.action.QUICKSTEP_SERVICE";
|
||||||
|
public static String TIS_PERMISSIONS = "android.permission.STATUS_BAR_SERVICE";
|
||||||
|
|
||||||
|
private String getLauncherPackageName(Context context) {
|
||||||
|
return ComponentName.unflattenFromString(context.getString(
|
||||||
|
com.android.internal.R.string.config_recentsComponentName)).getPackageName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ServiceConnection createConnection() {
|
||||||
|
return new ServiceConnection() {
|
||||||
|
@Override
|
||||||
|
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||||
|
Log.d(TAG, "Connected to TouchInteractionService");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceDisconnected(ComponentName componentName) {
|
||||||
|
Log.d(TAG, "Disconnected from TouchInteractionService");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Statement apply(@NonNull Statement base, @NonNull Description description) {
|
||||||
|
return new Statement() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void evaluate() throws Throwable {
|
||||||
|
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||||
|
final ServiceConnection connection = createConnection();
|
||||||
|
UiAutomation uiAutomation =
|
||||||
|
InstrumentationRegistry.getInstrumentation().getUiAutomation();
|
||||||
|
uiAutomation.adoptShellPermissionIdentity(TIS_PERMISSIONS);
|
||||||
|
Intent launchIntent = new Intent(INTENT_FILTER);
|
||||||
|
launchIntent.setPackage(getLauncherPackageName(context));
|
||||||
|
context.bindService(launchIntent, connection, Context.BIND_AUTO_CREATE);
|
||||||
|
uiAutomation.dropShellPermissionIdentity();
|
||||||
|
try {
|
||||||
|
base.evaluate();
|
||||||
|
} finally {
|
||||||
|
context.unbindService(connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue