Loading services/tests/wmtests/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -47,7 +47,6 @@ android_test { "testables", "ub-uiautomator", "hamcrest-library", "compatibility-device-util-axt", ], libs: [ Loading services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java +3 −14 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -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); Loading Loading @@ -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 = Loading services/tests/wmtests/src/com/android/server/wm/utils/CommonUtils.java 0 → 100644 +37 −0 Original line number Diff line number Diff line /* * 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(); } } } Loading
services/tests/wmtests/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -47,7 +47,6 @@ android_test { "testables", "ub-uiautomator", "hamcrest-library", "compatibility-device-util-axt", ], libs: [ Loading
services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java +3 −14 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -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); Loading Loading @@ -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 = Loading
services/tests/wmtests/src/com/android/server/wm/utils/CommonUtils.java 0 → 100644 +37 −0 Original line number Diff line number Diff line /* * 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(); } } }