android / android/android-test
UiDevice.executeShellCommand doesn't support full adb shell functionality
- Lingua principale
- Java
- Stelle
- 1.2k
- Fork
- 342
- Merge medio
- 11h 29m
- PR unite (30g)
- 2
Descrizione
### 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.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia individuando UiDevice.executeShellCommand e confronta il suo comportamento con l’implementazione di ShellUtils.kt a cui si fa riferimento. Riproduci quindi l’esempio di pipeline documentato, poi determina come esporre e documentare lo script proposto e il supporto opzionale a stdin, includendo il riferimento alle utilità shell di Android. Il lavoro è completo quando gli script shell possono usare stdin, pipe e redirezioni tramite l’upstream API.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java, shell
- Ambito
- cli, testing
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100