vm_shell: fix connect when multiple VMs are present
It always defaulted to the first CID available and then, once fixed, the
menu only displayed the first option.
Flag: n/a
Bug: b/a
Test: packages/modules/Virtualization/android/vm/vm_shell.sh start-microdroid --auto-connect
Change-Id: I73307ec408b62b49c53b87e3d4d27cb2edb5066f
diff --git a/android/vm/vm_shell.sh b/android/vm/vm_shell.sh
index 60d9329..cac5781 100755
--- a/android/vm/vm_shell.sh
+++ b/android/vm/vm_shell.sh
@@ -50,15 +50,13 @@
}
function list_cids() {
- local selected_cid=$1
- local available_cids=$(adb shell /apex/com.android.virt/bin/vm list | awk 'BEGIN { FS="[:,]" } /cid/ { print $2; }')
- echo "${available_cids}"
+ adb shell /apex/com.android.virt/bin/vm list | awk 'BEGIN { FS="[:,]" } /cid/ { print $2; }'
}
function handle_connect_cmd() {
selected_cid=$1
- available_cids=$(list_cids)
+ available_cids=($(list_cids))
if [ -z "${available_cids}" ]; then
echo No VM is available
@@ -66,11 +64,11 @@
fi
if [ ! -n "${selected_cid}" ]; then
- if [ ${#selected_cid[@]} -eq 1 ]; then
+ if [ ${#available_cids[@]} -eq 1 ]; then
selected_cid=${available_cids[0]}
else
PS3="Select CID of VM to adb-shell into: "
- select cid in ${available_cids}
+ select cid in ${available_cids[@]}
do
selected_cid=${cid}
break