Skip to content

Commit

Permalink
Let's see what happens if we substitute Folger's crystals for real co…
Browse files Browse the repository at this point in the history
…ffee!

PiperOrigin-RevId: 676983588
  • Loading branch information
copybara-androidxtest committed Sep 20, 2024
1 parent 8e7b420 commit dbe1144
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
2 changes: 2 additions & 0 deletions services/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

**New Features**

* SPA FON

**Breaking Changes**

**API Changes**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ kt_android_library(
"ShellExecutorFactory.java",
"ShellExecutorFileObserverImpl.kt",
"ShellExecutorImpl.java",
"UiAutomationShellExecutor.kt",
],
idl_srcs = ["Command.aidl"],
visibility = [":export"],
deps = [
":coroutine_file_observer",
":file_observer_protocol",
"//runner/monitor",
"//services/speakeasy/java/androidx/test/services/speakeasy:protocol",
"//services/speakeasy/java/androidx/test/services/speakeasy/client",
"//services/speakeasy/java/androidx/test/services/speakeasy/client:tool_connection",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package androidx.test.services.shellexecutor;

import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;

/** Factory class for providing ShellExecutors. */
public final class ShellExecutorFactory {
Expand All @@ -32,7 +33,10 @@ public ShellExecutorFactory(Context context, String binderKey) {
public ShellExecutor create() {
// Binder keys for SpeakEasy are a string of hex digits. Binder keys for the FileObserver
// protocol are the absolute path of the directory that the server is watching.
if (binderKey.startsWith("/")) {
if (true || binderKey.equals(UiAutomationShellExecutor.BINDER_KEY)) {
return new UiAutomationShellExecutor(
InstrumentationRegistry.getInstrumentation().getUiAutomation());
} else if (binderKey.startsWith("/")) {
return new ShellExecutorFileObserverImpl(binderKey);
} else {
return new ShellExecutorImpl(context, binderKey);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package androidx.test.services.shellexecutor

import android.app.UiAutomation
import android.os.ParcelFileDescriptor
import java.io.InputStream

/** */
class UiAutomationShellExecutor(private val uiAutomation: UiAutomation) : ShellExecutor {
override fun getBinderKey(): String {
return BINDER_KEY
}

override fun executeShellCommandSync(
command: String,
parameters: List<String>,
shellEnv: Map<String, String>,
executeThroughShell: Boolean,
timeoutMs: Long,
): String {
return executeShellCommand(command, parameters, shellEnv, executeThroughShell, timeoutMs)
.readBytes()
.toString(Charsets.UTF_8)
}

override fun executeShellCommandSync(
command: String,
parameters: List<String>,
shellEnv: Map<String, String>,
executeThroughShell: Boolean,
): String {
return executeShellCommandSync(command, parameters, shellEnv, executeThroughShell, 0)
}

override fun executeShellCommand(
command: String,
parameters: List<String>,
shellEnv: Map<String, String>,
executeThroughShell: Boolean,
timeoutMs: Long,
): InputStream {
val commandLine = if (executeThroughShell) {
listOf("sh", "-c", command) + parameters
} else {
listOf(command) + parameters
}.joinToString(" ")
// How to set the environment? The command is sent via an IUiAutomationConnection binder.
// Ultimately it's calling java.lang.Runtime.exec(). Which *can* take an envp. That is, in turn,
// using ProcessBuilder.
val parcelFD = uiAutomation.executeShellCommand(commandLine)
return ParcelFileDescriptor.AutoCloseInputStream(parcelFD)
}

override fun executeShellCommand(
command: String,
parameters: List<String>,
shellEnv: Map<String, String>,
executeThroughShell: Boolean,
): InputStream {
return executeShellCommand(command, parameters, shellEnv, executeThroughShell, 0)
}

public companion object {
@JvmField val BINDER_KEY = "UiAutomationShellExecutor"
}
}

0 comments on commit dbe1144

Please sign in to comment.