android / android/android-test
UiDevice.executeShellCommand doesn't support full adb shell functionality
- Vorherrschende Sprache
- Java
- Sterne
- 1.2k
- Forks
- 342
- Ø Merge
- 11 Std. 29 Min.
- Gemergte PRs (30 T.)
- 2
Beschreibung
### Description
`UiDevice.executeShellCommand` doesn't have an affordance for stdin, and doesn't allow piping between multiple commands, or redirects.
### Steps to Reproduce
```
// The following line will fail:
assertEquals("foo\n", mUiDevice.executeShellCommand("echo foo | xargs echo $1"))
```
### AndroidX Test and Android OS Versions
uiautomator 2.2.0, any supported (example above requires API 26, due to `xargs` usage)
### Proposal
I worked around this (in the Jetpack repo) by adding an extension - [`UiDevice.executeShellScript(script: String, stdin: String? = null)`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:benchmark/perfetto/src/main/java/androidx/benchmark/perfetto/ShellUtils.kt;l=37;drc=2193701d13f8c18dc3540a3c5e6f34cb93fae6cc)
Would you be interested in accepting this functionality upstream?
It works by writing the 'script' param to a shell-readable location, copying it to a shell-runnable location (needed in Q+), and executing it there. As this adds additional binder calls, I think it makes sense to add it as a separate method. Can also as part of this link to [Android's shell and utilities](https://android.googlesource.com/platform/system/core/+/master/shell_and_utilities/README.md#) from the docs of both methods, as that's a *very* necessary reference for running shell commands on Android.
Beitragsleitfaden
Rechercherichtung
Beginnen Sie damit, UiDevice.executeShellCommand zu finden und sein Verhalten mit der referenzierten Implementierung in ShellUtils.kt zu vergleichen. Reproduzieren Sie anschließend das dokumentierte Pipeline-Beispiel und bestimmen Sie dann, wie das vorgeschlagene Skript und die optionale stdin-Unterstützung bereitgestellt und dokumentiert werden sollten, einschließlich der Referenz für Android-Shell-Dienstprogramme. Als abgeschlossen gilt die Aufgabe, wenn Shell-Skripte über die upstream API stdin, Pipes und Umleitungen verwenden können.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java, shell
- Bereich
- cli, testing
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100