Skip to content

Commit a2e69c5

Browse files
brettchabotcopybara-androidxtest
authored andcommitted
Remove guava from orchestrator.
Use of guava is unnecessary and currently results in ClassNotFoundExceptions on APIs <= 23. Fixes #2422 PiperOrigin-RevId: 789467366
1 parent ef851d9 commit a2e69c5

File tree

6 files changed

+27
-13
lines changed

6 files changed

+27
-13
lines changed

runner/android_test_orchestrator/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
**Bug Fixes**
88

9+
* Remove use of guava. Fixes https://github.com/android/android-test/issues/2422
10+
911
**New Features**
1012

1113
**Breaking Changes**

runner/android_test_orchestrator/java/androidx/test/orchestrator/AndroidTestOrchestrator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package androidx.test.orchestrator;
1818

19+
import static androidx.test.internal.util.Checks.checkState;
1920
import static androidx.test.orchestrator.OrchestratorConstants.AJUR_CLASS_ARGUMENT;
2021
import static androidx.test.orchestrator.OrchestratorConstants.AJUR_COVERAGE;
2122
import static androidx.test.orchestrator.OrchestratorConstants.AJUR_COVERAGE_FILE;
@@ -24,7 +25,6 @@
2425
import static androidx.test.orchestrator.OrchestratorConstants.ISOLATED_ARGUMENT;
2526
import static androidx.test.orchestrator.OrchestratorConstants.ORCHESTRATOR_DEBUG_ARGUMENT;
2627
import static androidx.test.orchestrator.OrchestratorConstants.TARGET_INSTRUMENTATION_ARGUMENT;
27-
import static com.google.common.base.Preconditions.checkState;
2828

2929
import android.Manifest.permission;
3030
import android.app.Activity;

runner/android_test_orchestrator/java/androidx/test/orchestrator/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ android_library(
2323
"//runner/android_junit_runner",
2424
"//services/shellexecutor:exec_client",
2525
"@maven//:androidx_core_core",
26-
"@maven//:com_google_guava_guava",
2726
],
2827
)
2928

runner/android_test_orchestrator/java/androidx/test/orchestrator/CallbackLogic.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616

1717
package androidx.test.orchestrator;
1818

19+
import static androidx.test.internal.util.Checks.checkNotNull;
20+
import static androidx.test.internal.util.Checks.checkState;
21+
1922
import android.os.Bundle;
2023
import androidx.test.orchestrator.callback.OrchestratorCallback;
2124
import androidx.test.orchestrator.listeners.OrchestrationListenerManager;
22-
import com.google.common.base.Preconditions;
23-
import com.google.common.base.Splitter;
2425
import java.util.ArrayList;
26+
import java.util.Arrays;
2527
import java.util.List;
2628

2729
/** Encapsulates all the logic for receiving callbacks from the app under test. */
2830
class CallbackLogic extends OrchestratorCallback.Stub {
2931
private static final String TAG = "CallbackLogic";
30-
private static final Splitter CLASS_METHOD_SPLITTER = Splitter.on('#');
3132

3233
private final List<String> listOfTests = new ArrayList<>();
3334
private final Object testLock = new Object();
@@ -38,7 +39,7 @@ class CallbackLogic extends OrchestratorCallback.Stub {
3839
@Override
3940
public void addTest(String test) {
4041
synchronized (testLock) {
41-
List<String> classAndMethod = CLASS_METHOD_SPLITTER.splitToList(test);
42+
List<String> classAndMethod = Arrays.asList(test.split("#"));
4243
if (classAndMethod.size() > 1
4344
&& (classAndMethod.get(1).isEmpty() || classAndMethod.get(1).equals("null"))) {
4445
listOfTests.add(classAndMethod.get(0));
@@ -51,8 +52,7 @@ public void addTest(String test) {
5152
@Override
5253
public void sendTestNotification(Bundle bundle) {
5354
synchronized (testLock) {
54-
Preconditions.checkNotNull(
55-
listenerManager, "Unable to process test notification. No ListenerManager");
55+
checkNotNull(listenerManager, "Unable to process test notification. No ListenerManager");
5656
listenerManager.handleNotification(bundle);
5757
}
5858
}
@@ -65,8 +65,8 @@ List<String> provideCollectedTests() {
6565

6666
void setListenerManager(OrchestrationListenerManager mListenerManager) {
6767
synchronized (testLock) {
68-
Preconditions.checkState(null == this.listenerManager, "Listener manager assigned twice.");
69-
this.listenerManager = Preconditions.checkNotNull(mListenerManager, "Listener manager null");
68+
checkState(null == this.listenerManager, "Listener manager assigned twice.");
69+
this.listenerManager = checkNotNull(mListenerManager, "Listener manager null");
7070
}
7171
}
7272
}

runner/android_test_orchestrator/java/androidx/test/orchestrator/TestRunnable.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
import static androidx.test.orchestrator.OrchestratorConstants.TARGET_INSTRUMENTATION_ARGUMENT;
2323

2424
import android.content.Context;
25+
import android.os.Build.VERSION;
26+
import android.os.Build.VERSION_CODES;
2527
import android.os.Bundle;
2628
import android.os.RemoteException;
2729
import android.util.Log;
2830
import androidx.annotation.VisibleForTesting;
2931
import androidx.test.services.shellexecutor.ClientNotConnected;
3032
import androidx.test.services.shellexecutor.ShellExecutorFactory;
31-
import com.google.common.io.ByteStreams;
3233
import java.io.IOException;
3334
import java.io.InputStream;
3435
import java.io.OutputStream;
@@ -135,7 +136,7 @@ public void run() {
135136
InputStream inputStream =
136137
runShellCommand(buildShellParams(getTargetInstrumentationArguments()));
137138
try {
138-
ByteStreams.copy(inputStream, outputStream);
139+
transferInputToOutputStream(inputStream, outputStream);
139140
} finally {
140141
if (inputStream != null) {
141142
inputStream.close();
@@ -157,6 +158,19 @@ public void run() {
157158
listener.runFinished();
158159
}
159160

161+
private static void transferInputToOutputStream(InputStream is, OutputStream os)
162+
throws IOException {
163+
if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) {
164+
is.transferTo(os);
165+
} else {
166+
byte[] buf = new byte[8192];
167+
int bytesRead = -1;
168+
while ((bytesRead = is.read(buf)) >= 0) {
169+
os.write(buf, 0, bytesRead);
170+
}
171+
}
172+
}
173+
160174
private String getTargetInstrumentation() {
161175
return arguments.getString(TARGET_INSTRUMENTATION_ARGUMENT);
162176
}

runner/android_test_orchestrator/stubapp/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ android_binary(
3030
"//runner/android_junit_runner",
3131
"//runner/android_test_orchestrator",
3232
"@maven//:androidx_multidex_multidex",
33-
"@maven//:com_google_guava_guava",
3433
"@maven//:junit_junit",
3534
],
3635
)

0 commit comments

Comments
 (0)