From fd34b94b33e926d91beb5d386e96e346fc428b08 Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Tue, 21 Aug 2018 16:30:09 -0700 Subject: [PATCH] Passing instrumentation to LauncherInstrumentation UiDevice, the old param, belongs to a support lib; as TAPL switched to AndroidX, it became impossible to pass it from platform tests that still use the old support lib. Bug: 110103162 Test: TaplTests Change-Id: I1f82099b432912fa40da96df0d6179579aab66a3 --- .../launcher3/ui/AbstractLauncherUiTest.java | 7 +++--- .../tapl/LauncherInstrumentation.java | 23 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index 7e8890ad2a..f81463a76b 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -29,6 +29,9 @@ import android.graphics.Point; import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; +import android.util.Log; +import android.view.MotionEvent; + import androidx.test.InstrumentationRegistry; import androidx.test.uiautomator.By; import androidx.test.uiautomator.BySelector; @@ -36,8 +39,6 @@ import androidx.test.uiautomator.Direction; import androidx.test.uiautomator.UiDevice; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; -import android.util.Log; -import android.view.MotionEvent; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; @@ -90,7 +91,7 @@ public abstract class AbstractLauncherUiTest { @Before public void setUp() throws Exception { mDevice = UiDevice.getInstance(getInstrumentation()); - mLauncher = new LauncherInstrumentation(mDevice); + mLauncher = new LauncherInstrumentation(getInstrumentation()); mTargetContext = InstrumentationRegistry.getTargetContext(); mTargetPackage = mTargetContext.getPackageName(); } diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 74a91a4678..09bf403aa1 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -23,16 +23,19 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import android.app.ActivityManager; +import android.app.Instrumentation; import android.app.UiAutomation; import android.os.Bundle; import android.provider.Settings; -import androidx.test.InstrumentationRegistry; +import android.view.accessibility.AccessibilityEvent; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.test.uiautomator.By; import androidx.test.uiautomator.BySelector; import androidx.test.uiautomator.UiDevice; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; -import android.view.accessibility.AccessibilityEvent; import com.android.launcher3.TestProtocol; import com.android.quickstep.SwipeUpSetting; @@ -40,9 +43,6 @@ import com.android.quickstep.SwipeUpSetting; import java.lang.ref.WeakReference; import java.util.concurrent.TimeoutException; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - /** * The main tapl object. The only object that can be explicitly constructed by the using code. It * produces all other objects. @@ -90,17 +90,19 @@ public final class LauncherInstrumentation { private final UiDevice mDevice; private final boolean mSwipeUpEnabled; private Boolean mSwipeUpEnabledOverride = null; + private final Instrumentation mInstrumentation; /** * Constructs the root of TAPL hierarchy. You get all other objects from it. */ - public LauncherInstrumentation(UiDevice device) { - mDevice = device; + public LauncherInstrumentation(Instrumentation instrumentation) { + mInstrumentation = instrumentation; + mDevice = UiDevice.getInstance(instrumentation); final boolean swipeUpEnabledDefault = !SwipeUpSetting.isSwipeUpSettingAvailable() || SwipeUpSetting.isSwipeUpEnabledDefaultValue(); mSwipeUpEnabled = Settings.Secure.getInt( - InstrumentationRegistry.getTargetContext().getContentResolver(), + instrumentation.getTargetContext().getContentResolver(), SWIPE_UP_SETTING_NAME, swipeUpEnabledDefault ? 1 : 0) == 1; assertTrue("Device must run in a test harness", ActivityManager.isRunningInTestHarness()); @@ -162,9 +164,8 @@ public final class LauncherInstrumentation { UiAutomation.AccessibilityEventFilter eventFilter, String message) { try { final AccessibilityEvent event = - InstrumentationRegistry.getInstrumentation().getUiAutomation() - .executeAndWaitForEvent( - command, eventFilter, WAIT_TIME_MS); + mInstrumentation.getUiAutomation().executeAndWaitForEvent( + command, eventFilter, WAIT_TIME_MS); assertNotNull("executeAndWaitForEvent returned null (this can't happen)", event); return (Bundle) event.getParcelableData(); } catch (TimeoutException e) {