• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# Copyright (C) 2021 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
17readme() {
18  echo '''
19Change all AVD configuration for bigger RAM, heap & data-disk sizes. So it can perform better.
20If TAG_ID of AVD is empty, it will change all AVDs. e.g.
21
22RAM=4096 HEAP=576 DATA_DISK=6000 AVD_ROOT_DIR="$HOME/.android/avd" TAG_ID="android-automotive" ./patch_all_avds.sh
23'''
24}
25
26# set up for Linux or macOS
27OS="$(uname -s)"
28echo "Running on $OS"
29if [[ $OS == "Linux" ]]; then
30  SED_I_CMD="sed -i "
31elif [[ $OS == "Darwin" ]]; then
32  SED_I_CMD="sed -i ''"
33else
34  echo "ERROR: this does not work on $OS"
35  exit
36fi
37
38MY_NAME=$0
39SCRIPT_NAME=${MY_NAME##*/}
40SCRIPT_DIR=${MY_NAME%/$SCRIPT_NAME}
41echo Running from $SCRIPT_DIR
42
43# Export VAR with the value of the key in a file as:
44# getValue "VAR" "KEY" "config.ini FILE"
45# e.g. getValue "MY_AVD_ID" "AvdId" "$avd_dir/config.ini"
46getValue() {
47    VAR=$1
48    KEY=$2
49    FILE=$3
50    LINE=$(cat $FILE | grep $KEY)
51    VALUE=${LINE##*=}
52    export "${VAR}=$VALUE"
53    echo "${VAR}=$VALUE"
54}
55
56if [[ -z $AVD_ROOT_DIR ]]; then
57  AVD_ROOT_DIR="$HOME/.android/avd"
58fi
59echo "AVD_ROOT_DIR=$AVD_ROOT_DIR"
60
61if [[ -z $RAM ]]; then
62    RAM=4096
63fi
64echo "RAM=$RAM"
65
66if [[ -z $HEAP ]]; then
67    HEAP=576
68fi
69echo "HEAP=$HEAP"
70
71if [[ -z $DATA_DISK ]]; then
72    DATA_DISK=6000
73fi
74echo "DATA_DISK=$DATA_DISK"
75
76for file in $(ls "$AVD_ROOT_DIR"); do
77  avd_dir="$AVD_ROOT_DIR/$file"
78  if [[ $file == *.avd ]]; then
79    # Filter AVD type by TAG_ID
80    config_file="$avd_dir/config.ini"
81    getValue "MY_AVD_ID"  "AvdId" $config_file
82    if [[ -n $TAG_ID  ]]; then
83      getValue "MY_TAG_ID" "tag.id" $config_file
84      if [[ $TAG_ID != $MY_TAG_ID ]]; then
85        echo "SKIP: $MY_AVD_ID is $MY_TAG_ID rather $TAG_ID "
86        echo
87        continue
88      fi
89    fi
90    RAM=$RAM HEAP=$HEAP DATA_DISK=$DATA_DISK AVD_DIR=$avd_dir $SCRIPT_DIR/patch_avd.sh
91    echo
92  fi
93done