Use uname -m to get the device ISA.

On minimal targets the /data/dalvik-cache subdirectories may not exist.
Querying the uname from the kernel is more robust and avoids the need
for root.

Change-Id: I764f12f514a1c644ffe433b1adf4137e43be1031
diff --git a/test/utils/get-device-isa b/test/utils/get-device-isa
index c9b342d..5f9c2a4 100755
--- a/test/utils/get-device-isa
+++ b/test/utils/get-device-isa
@@ -25,48 +25,53 @@
   exit 1
 }
 
+check_32bit() {
+  if ! adb shell test -e /system/bin/linker; then
+    echo >&2 "Device does not have 32-bit support"
+    exit 1
+  fi
+}
+
 if [[ $# -ne 1 ]]; then
   usage
 fi
 
-ARCHITECTURES_32="(arm|x86|none)"
-ARCHITECTURES_64="(arm64|x86_64|none)"
+uname_m="$(adb shell uname -m)"
 
 case "$1" in
   (--32)
-    ARCHITECTURES_PATTERN="${ARCHITECTURES_32}"
+    case $uname_m in
+      (armv*)
+        echo arm
+        ;;
+      (i?86)
+        echo x86
+        ;;
+      (aarch64)
+        check_32bit
+        echo arm
+        ;;
+      (x86_64)
+        check_32bit
+        echo x86
+        ;;
+      (*)
+        echo >&2 "Unknown ISA: $uname_m"
+        exit 1
+    esac
     ;;
   (--64)
-    ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
+    case $uname_m in
+      (aarch64)
+        echo arm64
+        ;;
+      (x86_64)
+        echo x86_64
+        ;;
+      (*)
+        echo >&2 "Unknown ISA: $uname_m"
+        exit 1
+    esac
     ;;
   (*) usage;;
 esac
-
-# Need to be root to query /data/dalvik-cache
-adb root > /dev/null
-adb wait-for-device
-ISA=
-ISA_adb_invocation=
-ISA_outcome=
-# We iterate a few times to workaround an adb issue. b/32655576
-for i in {1..10}; do
-  ISA_adb_invocation=$(adb shell ls /data/dalvik-cache)
-  ISA_outcome=$?
-  ISA=$(echo $ISA_adb_invocation | grep -Ewo "${ARCHITECTURES_PATTERN}")
-  if [[ -n "$ISA" ]]; then
-    break;
-  fi
-done
-if [[ -z "$ISA" ]]; then
-  echo >&2 "Unable to determine architecture"
-  # Print a few things for helping diagnosing the problem.
-  echo >&2 "adb invocation output: $ISA_adb_invocation"
-  echo >&2 "adb invocation outcome: $ISA_outcome"
-  echo >&2 $(adb shell ls -F /data/dalvik-cache)
-  echo >&2 $(adb shell ls /data/dalvik-cache)
-  echo >&2 ${ARCHITECTURES_PATTERN}
-  echo >&2 $(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
-  exit 1
-fi
-
-echo "$ISA"