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 an AVD configuration for bigger RAM, heap & data-disk sizes. So it can perform better. e.g. 20RAM=4096 HEAP=576 DATA_DISK=6000 AVD_DIR="$HOME/.android/avd/Automotive_10_landscape_API_30.avd" ./patch_avd.sh 21 22''' 23} 24 25if [[ -z $AVD_DIR ]]; then 26 readme 27 exit 28fi 29 30# set up for Linux or macOS 31OS="$(uname -s)" 32echo "Running on $OS" 33if [[ $OS == "Linux" ]]; then 34 SED_I_CMD="sed -i " 35elif [[ $OS == "Darwin" ]]; then 36 SED_I_CMD="sed -i ''" 37else 38 echo "ERROR: this does not work on $OS" 39 exit 40fi 41 42MY_NAME=$0 43SCRIPT_NAME=${MY_NAME##*/} 44SCRIPT_DIR=${MY_NAME%/$SCRIPT_NAME} 45echo Running from $SCRIPT_DIR 46 47if [[ -z $RAM ]]; then 48 RAM=4096 49fi 50echo "RAM=$RAM" 51 52if [[ -z $HEAP ]]; then 53 HEAP=576 54fi 55echo "HEAP=$HEAP" 56 57if [[ -z $DATA_DISK ]]; then 58 DATA_DISK=6000 59fi 60echo "DATA_DISK=$DATA_DISK" 61 62AVD_CONFIG="$AVD_DIR/config.ini" 63if [[ ! -e $AVD_CONFIG ]]; then 64 echo "ERROR: no AVD config file at: $AVD_CONFIG" 65 exit 66fi 67echo "AVD_CONFIG=$AVD_CONFIG" 68 69echo "CHANGE: hw.ramSize=$RAM, vm.heapSize=$HEAP & disk.dataPartition.size=${DATA_DISK}M in $AVD_CONFIG" 70$SED_I_CMD '/^hw.ramSize/d' $AVD_CONFIG 71$SED_I_CMD '/^vm.heapSize/d' $AVD_CONFIG 72$SED_I_CMD '/^disk.dataPartition.size/d' $AVD_CONFIG 73echo "hw.ramSize=$RAM" >> $AVD_CONFIG 74echo "vm.heapSize=$HEAP" >> $AVD_CONFIG 75echo "disk.dataPartition.size=${DATA_DISK}M" >> $AVD_CONFIG 76cat $AVD_CONFIG | grep "hw.ramSize" 77cat $AVD_CONFIG | grep "vm.heapSize" 78cat $AVD_CONFIG | grep "disk.dataPartition.size" 79