diff --git a/runner/android_test_orchestrator/CHANGELOG.md b/runner/android_test_orchestrator/CHANGELOG.md index 6dc2ebed3..aaa74ff61 100644 --- a/runner/android_test_orchestrator/CHANGELOG.md +++ b/runner/android_test_orchestrator/CHANGELOG.md @@ -6,6 +6,8 @@ **Bug Fixes** +* Remove use of guava. Fixes https://github.com/android/android-test/issues/2422 + **New Features** **Breaking Changes** diff --git a/runner/android_test_orchestrator/java/androidx/test/orchestrator/AndroidTestOrchestrator.java b/runner/android_test_orchestrator/java/androidx/test/orchestrator/AndroidTestOrchestrator.java index 23581da79..0158ee60c 100644 --- a/runner/android_test_orchestrator/java/androidx/test/orchestrator/AndroidTestOrchestrator.java +++ b/runner/android_test_orchestrator/java/androidx/test/orchestrator/AndroidTestOrchestrator.java @@ -16,6 +16,7 @@ package androidx.test.orchestrator; +import static androidx.test.internal.util.Checks.checkState; import static androidx.test.orchestrator.OrchestratorConstants.AJUR_CLASS_ARGUMENT; import static androidx.test.orchestrator.OrchestratorConstants.AJUR_COVERAGE; import static androidx.test.orchestrator.OrchestratorConstants.AJUR_COVERAGE_FILE; @@ -24,7 +25,6 @@ import static androidx.test.orchestrator.OrchestratorConstants.ISOLATED_ARGUMENT; import static androidx.test.orchestrator.OrchestratorConstants.ORCHESTRATOR_DEBUG_ARGUMENT; import static androidx.test.orchestrator.OrchestratorConstants.TARGET_INSTRUMENTATION_ARGUMENT; -import static com.google.common.base.Preconditions.checkState; import android.Manifest.permission; import android.app.Activity; diff --git a/runner/android_test_orchestrator/java/androidx/test/orchestrator/BUILD b/runner/android_test_orchestrator/java/androidx/test/orchestrator/BUILD index 656289efa..9ba1f81a9 100644 --- a/runner/android_test_orchestrator/java/androidx/test/orchestrator/BUILD +++ b/runner/android_test_orchestrator/java/androidx/test/orchestrator/BUILD @@ -23,7 +23,6 @@ android_library( "//runner/android_junit_runner", "//services/shellexecutor:exec_client", "@maven//:androidx_core_core", - "@maven//:com_google_guava_guava", ], ) diff --git a/runner/android_test_orchestrator/java/androidx/test/orchestrator/CallbackLogic.java b/runner/android_test_orchestrator/java/androidx/test/orchestrator/CallbackLogic.java index 0ba702f48..02e393f5a 100644 --- a/runner/android_test_orchestrator/java/androidx/test/orchestrator/CallbackLogic.java +++ b/runner/android_test_orchestrator/java/androidx/test/orchestrator/CallbackLogic.java @@ -16,18 +16,19 @@ package androidx.test.orchestrator; +import static androidx.test.internal.util.Checks.checkNotNull; +import static androidx.test.internal.util.Checks.checkState; + import android.os.Bundle; import androidx.test.orchestrator.callback.OrchestratorCallback; import androidx.test.orchestrator.listeners.OrchestrationListenerManager; -import com.google.common.base.Preconditions; -import com.google.common.base.Splitter; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** Encapsulates all the logic for receiving callbacks from the app under test. */ class CallbackLogic extends OrchestratorCallback.Stub { private static final String TAG = "CallbackLogic"; - private static final Splitter CLASS_METHOD_SPLITTER = Splitter.on('#'); private final List listOfTests = new ArrayList<>(); private final Object testLock = new Object(); @@ -38,7 +39,7 @@ class CallbackLogic extends OrchestratorCallback.Stub { @Override public void addTest(String test) { synchronized (testLock) { - List classAndMethod = CLASS_METHOD_SPLITTER.splitToList(test); + List classAndMethod = Arrays.asList(test.split("#")); if (classAndMethod.size() > 1 && (classAndMethod.get(1).isEmpty() || classAndMethod.get(1).equals("null"))) { listOfTests.add(classAndMethod.get(0)); @@ -51,8 +52,7 @@ public void addTest(String test) { @Override public void sendTestNotification(Bundle bundle) { synchronized (testLock) { - Preconditions.checkNotNull( - listenerManager, "Unable to process test notification. No ListenerManager"); + checkNotNull(listenerManager, "Unable to process test notification. No ListenerManager"); listenerManager.handleNotification(bundle); } } @@ -65,8 +65,8 @@ List provideCollectedTests() { void setListenerManager(OrchestrationListenerManager mListenerManager) { synchronized (testLock) { - Preconditions.checkState(null == this.listenerManager, "Listener manager assigned twice."); - this.listenerManager = Preconditions.checkNotNull(mListenerManager, "Listener manager null"); + checkState(null == this.listenerManager, "Listener manager assigned twice."); + this.listenerManager = checkNotNull(mListenerManager, "Listener manager null"); } } } diff --git a/runner/android_test_orchestrator/java/androidx/test/orchestrator/TestRunnable.java b/runner/android_test_orchestrator/java/androidx/test/orchestrator/TestRunnable.java index e491bafe3..6e875c1c5 100644 --- a/runner/android_test_orchestrator/java/androidx/test/orchestrator/TestRunnable.java +++ b/runner/android_test_orchestrator/java/androidx/test/orchestrator/TestRunnable.java @@ -22,13 +22,14 @@ import static androidx.test.orchestrator.OrchestratorConstants.TARGET_INSTRUMENTATION_ARGUMENT; import android.content.Context; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.os.RemoteException; import android.util.Log; import androidx.annotation.VisibleForTesting; import androidx.test.services.shellexecutor.ClientNotConnected; import androidx.test.services.shellexecutor.ShellExecutorFactory; -import com.google.common.io.ByteStreams; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -135,7 +136,7 @@ public void run() { InputStream inputStream = runShellCommand(buildShellParams(getTargetInstrumentationArguments())); try { - ByteStreams.copy(inputStream, outputStream); + transferInputToOutputStream(inputStream, outputStream); } finally { if (inputStream != null) { inputStream.close(); @@ -157,6 +158,19 @@ public void run() { listener.runFinished(); } + private static void transferInputToOutputStream(InputStream is, OutputStream os) + throws IOException { + if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) { + is.transferTo(os); + } else { + byte[] buf = new byte[8192]; + int bytesRead = -1; + while ((bytesRead = is.read(buf)) >= 0) { + os.write(buf, 0, bytesRead); + } + } + } + private String getTargetInstrumentation() { return arguments.getString(TARGET_INSTRUMENTATION_ARGUMENT); } diff --git a/runner/android_test_orchestrator/stubapp/BUILD b/runner/android_test_orchestrator/stubapp/BUILD index e1569700d..554a6abe3 100644 --- a/runner/android_test_orchestrator/stubapp/BUILD +++ b/runner/android_test_orchestrator/stubapp/BUILD @@ -30,7 +30,6 @@ android_binary( "//runner/android_junit_runner", "//runner/android_test_orchestrator", "@maven//:androidx_multidex_multidex", - "@maven//:com_google_guava_guava", "@maven//:junit_junit", ], )