From 5c2c75eec6a64d5b3ba608b8300a9633dfd28c81 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 11 Dec 2020 21:21:06 +0800 Subject: [PATCH] Remove unnecessary lib from WmTests Only one simple method of the lib is used, that doesn't need to include the medium size lib. Bug: 159102753 Test: TaskStackChangedListenerTest Change-Id: I312c75a366bdfc5a9017c32443732b1ac96797ab --- services/tests/wmtests/Android.bp | 1 - .../wm/TaskStackChangedListenerTest.java | 17 ++------- .../android/server/wm/utils/CommonUtils.java | 37 +++++++++++++++++++ 3 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 services/tests/wmtests/src/com/android/server/wm/utils/CommonUtils.java diff --git a/services/tests/wmtests/Android.bp b/services/tests/wmtests/Android.bp index 4ca5b9e4b14f2..1ecf850adb1fc 100644 --- a/services/tests/wmtests/Android.bp +++ b/services/tests/wmtests/Android.bp @@ -47,7 +47,6 @@ android_test { "testables", "ub-uiautomator", "hamcrest-library", - "compatibility-device-util-axt", ], libs: [ diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java b/services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java index 788ef5ad2ec41..6046c9b2c2b1f 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java @@ -20,20 +20,19 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; +import static com.android.server.wm.utils.CommonUtils.runWithShellPermissionIdentity; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import android.app.Activity; -import android.app.ActivityManager; import android.app.ActivityManager.TaskDescription; import android.app.ActivityOptions; import android.app.ActivityTaskManager; import android.app.ActivityView; -import android.app.IActivityManager; import android.app.ITaskStackListener; -import android.app.Instrumentation; import android.app.Instrumentation.ActivityMonitor; import android.app.TaskStackListener; import android.content.ComponentName; @@ -44,7 +43,6 @@ import android.os.Bundle; import android.os.RemoteException; import android.os.SystemClock; import android.platform.test.annotations.Presubmit; -import android.support.test.uiautomator.UiDevice; import android.text.TextUtils; import android.view.Display; import android.view.ViewGroup; @@ -52,10 +50,7 @@ import android.view.ViewGroup; import androidx.test.filters.FlakyTest; import androidx.test.filters.MediumTest; -import com.android.compatibility.common.util.SystemUtil; - import org.junit.After; -import org.junit.Before; import org.junit.Test; import java.util.concurrent.ArrayBlockingQueue; @@ -70,17 +65,11 @@ import java.util.function.Predicate; @MediumTest public class TaskStackChangedListenerTest { - private IActivityManager mService; private ITaskStackListener mTaskStackListener; private static final int WAIT_TIMEOUT_MS = 5000; private static final Object sLock = new Object(); - @Before - public void setUp() throws Exception { - mService = ActivityManager.getService(); - } - @After public void tearDown() throws Exception { ActivityTaskManager.getService().unregisterTaskStackListener(mTaskStackListener); @@ -374,7 +363,7 @@ public class TaskStackChangedListenerTest { final ActivityMonitor monitor = new ActivityMonitor(activityClass.getName(), null, false); getInstrumentation().addMonitor(monitor); final Context context = getInstrumentation().getContext(); - SystemUtil.runWithShellPermissionIdentity(() -> context.startActivity( + runWithShellPermissionIdentity(() -> context.startActivity( new Intent(context, activityClass).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), options.toBundle())); final TestActivity activity = diff --git a/services/tests/wmtests/src/com/android/server/wm/utils/CommonUtils.java b/services/tests/wmtests/src/com/android/server/wm/utils/CommonUtils.java new file mode 100644 index 0000000000000..99d73cf5f7d35 --- /dev/null +++ b/services/tests/wmtests/src/com/android/server/wm/utils/CommonUtils.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2020 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.utils; + +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + +import android.app.UiAutomation; + +/** Provides common utility functions. */ +public class CommonUtils { + public static UiAutomation getUiAutomation() { + return getInstrumentation().getUiAutomation(); + } + + public static void runWithShellPermissionIdentity(Runnable runnable) { + getUiAutomation().adoptShellPermissionIdentity(); + try { + runnable.run(); + } finally { + getUiAutomation().dropShellPermissionIdentity(); + } + } +}