• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/bash
2#
3# Copyright 2019 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17usage() {
18  cat >&2 <<EOF
19Determine and print the 32- or 64-bit architecture of a device.
20
21Usage:
22  $0 --32    Select the 32-bit architecture
23  $0 --64    Select the 64-bit architecture
24EOF
25  exit 1
26}
27
28check_32bit() {
29  if ! adb shell test -e /system/bin/linker; then
30    echo >&2 "Device does not have 32-bit support"
31    exit 1
32  fi
33}
34
35if [[ $# -ne 1 ]]; then
36  usage
37fi
38
39uname_m="$(adb shell uname -m)"
40
41case "$1" in
42  (--32)
43    case $uname_m in
44      (armv*)
45        echo arm
46        ;;
47      (i?86)
48        echo x86
49        ;;
50      (aarch64)
51        check_32bit
52        echo arm
53        ;;
54      (x86_64)
55        check_32bit
56        echo x86
57        ;;
58      (*)
59        echo >&2 "Unknown ISA: $uname_m"
60        exit 1
61    esac
62    ;;
63  (--64)
64    case $uname_m in
65      (aarch64)
66        echo arm64
67        ;;
68      (x86_64)
69        echo x86_64
70        ;;
71      (*)
72        echo >&2 "Unknown ISA: $uname_m"
73        exit 1
74    esac
75    ;;
76  (*) usage;;
77esac
78