1#!/bin/bash
2
3# Copyright (C) 2020 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
17# See test_run_local_avd.sh for examples
18
19echo Run a local AVD config in WORKDIR by Android Emulator engine from the SDK
20
21OS="$(uname -s)"
22echo Running on $OS
23if [[ $OS == "Linux" ]]; then
24    DEFAULT_ANDROID_SDK_ROOT="$HOME/Android/Sdk"
25elif [[ $OS == "Darwin" ]]; then
26    DEFAULT_ANDROID_SDK_ROOT="/Users/$USER/Library/Android/sdk"
27else
28    echo Sorry, this does not work on $OS
29    exit
30fi
31
32if [[ -z $ANDROID_SDK_ROOT ]]; then
33    ANDROID_SDK_ROOT="$DEFAULT_ANDROID_SDK_ROOT"
34fi
35
36if [[ -z $WORKDIR ]]; then
37    WORKDIR="$HOME/workdir"
38fi
39
40if [[ -z $ANDROID_AVD_HOME ]]; then
41    ANDROID_AVD_HOME="$WORKDIR/.android/avd"
42fi
43
44if [[ -z $ABI ]]; then
45    ABI="x86_64"
46fi
47
48if [[ -z $AVD_IMAGE_DIR ]]; then
49    AVD_IMAGE_DIR="$WORKDIR/$ABI"
50fi
51
52if [[ -z $AVD_NAME ]]; then
53    AVD_NAME="my_car_avd_$ABI"
54fi
55
56if [[ -z $DISPLAY_DENSITY ]]; then
57    DISPLAY_DENSITY=213
58fi
59
60if [[ -z $DISPLAY_WIDTH ]]; then
61    DISPLAY_WIDTH=1920
62fi
63
64if [[ -z $DISPLAY_HEIGHT ]]; then
65    DISPLAY_HEIGHT=1080
66fi
67
68if [[ -z $RAM_MB ]]; then
69    # 3.5 GB as x86 AVD is limited to 4g
70    RAM_MB=3584
71fi
72
73# Get the script dir
74MY_NAME=$0
75MY_FILENAME=${MY_NAME##*/}  # = "name.sh"
76MY_DIR=${MY_NAME%/$MY_FILENAME}  # = "/path/to"
77
78if ! [[ -f "$ANDROID_AVD_HOME/$AVD_NAME.avd/config.ini" ]]; then
79    # Create the AVD config as there is no one
80    $MY_DIR/create_avd_config.sh "$AVD_NAME" "$WORKDIR" "$AVD_IMAGE_DIR" \
81        "$DISPLAY_DENSITY" "$DISPLAY_WIDTH" "$DISPLAY_HEIGHT" "$RAM_MB" "$ABI"
82fi
83
84echo Running "$ANDROID_AVD_HOME/$AVD_NAME.avd" by $ANDROID_SDK_ROOT
85# Tell emu where to find my car AVD & SDK
86ANDROID_AVD_HOME=$ANDROID_AVD_HOME \
87    ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT \
88    $ANDROID_SDK_ROOT/emulator/emulator \
89    -avd $AVD_NAME \
90    $@ &
91
92echo
93sleep 30
94echo a. Supported features
95adb shell pm list features
96
97echo
98echo b. GAS versions
99adb shell pm list packages --show-versioncode | grep google
100adb shell pm list packages --show-versioncode | grep vending
101
102echo
103echo c. AVD Memory Info
104adb shell "cat /proc/meminfo"
105
106echo
107echo d. AVD Prop and processes
108adb shell getprop
109adb shell ps
110