| Index: build/android/pylib/utils/emulator.py
|
| diff --git a/build/android/pylib/utils/emulator.py b/build/android/pylib/utils/emulator.py
|
| index 4ff2f0309c18a7c0042af8145b31a853954685ea..e2bf1e05a3b008387301081051aac4c8212f32cc 100644
|
| --- a/build/android/pylib/utils/emulator.py
|
| +++ b/build/android/pylib/utils/emulator.py
|
| @@ -28,12 +28,59 @@ from pylib import pexpect
|
| import errors
|
| import run_command
|
|
|
| -# Android API level
|
| -API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION
|
| -
|
| # SD card size
|
| SDCARD_SIZE = '512M'
|
|
|
| +# Template used to generate config.ini files for the emulator
|
| +CONFIG_TEMPLATE = """avd.ini.encoding=ISO-8859-1
|
| +hw.dPad=no
|
| +hw.lcd.density=320
|
| +sdcard.size=512M
|
| +hw.cpu.arch={hw.cpu.arch}
|
| +hw.device.hash=-708107041
|
| +hw.camera.back=none
|
| +disk.dataPartition.size=800M
|
| +hw.gpu.enabled=yes
|
| +skin.path=720x1280
|
| +skin.dynamic=yes
|
| +hw.keyboard=yes
|
| +hw.ramSize=1024
|
| +hw.device.manufacturer=Google
|
| +hw.sdCard=yes
|
| +hw.mainKeys=no
|
| +hw.accelerometer=yes
|
| +skin.name=720x1280
|
| +abi.type={abi.type}
|
| +hw.trackBall=no
|
| +hw.device.name=Galaxy Nexus
|
| +hw.battery=yes
|
| +hw.sensors.proximity=yes
|
| +image.sysdir.1=system-images/android-{api.level}/{abi.type}/
|
| +hw.sensors.orientation=yes
|
| +hw.audioInput=yes
|
| +hw.camera.front=none
|
| +hw.gps=yes
|
| +vm.heapSize=128
|
| +{extras}"""
|
| +
|
| +CONFIG_REPLACEMENTS = {
|
| + 'x86': {
|
| + '{hw.cpu.arch}': 'x86',
|
| + '{abi.type}': 'x86',
|
| + '{extras}': ''
|
| + },
|
| + 'arm': {
|
| + '{hw.cpu.arch}': 'arm',
|
| + '{abi.type}': 'armeabi-v7a',
|
| + '{extras}': 'hw.cpu.model=cortex-a8\n'
|
| + },
|
| + 'mips': {
|
| + '{hw.cpu.arch}': 'mips',
|
| + '{abi.type}': 'mips',
|
| + '{extras}': ''
|
| + }
|
| +}
|
| +
|
| class EmulatorLaunchException(Exception):
|
| """Emulator failed to launch."""
|
| pass
|
| @@ -104,12 +151,13 @@ def _GetAvailablePort():
|
| return port
|
|
|
|
|
| -def LaunchEmulators(emulator_count, abi, wait_for_boot=True):
|
| +def LaunchEmulators(emulator_count, abi, api_level, wait_for_boot=True):
|
| """Launch multiple emulators and wait for them to boot.
|
|
|
| Args:
|
| emulator_count: number of emulators to launch.
|
| abi: the emulator target platform
|
| + api_level: the api level (e.g., 19 for Android v4.4 - KitKat release)
|
| wait_for_boot: whether or not to wait for emulators to boot up
|
|
|
| Returns:
|
| @@ -120,8 +168,9 @@ def LaunchEmulators(emulator_count, abi, wait_for_boot=True):
|
| t = time_profile.TimeProfile('Emulator launch %d' % n)
|
| # Creates a temporary AVD.
|
| avd_name = 'run_tests_avd_%d' % n
|
| - logging.info('Emulator launch %d with avd_name=%s', n, avd_name)
|
| - emulator = Emulator(avd_name, abi)
|
| + logging.info('Emulator launch %d with avd_name=%s and api=%d',
|
| + n, avd_name, api_level)
|
| + emulator = Emulator(avd_name, abi, api_level)
|
| emulator.Launch(kill_all_emulators=n == 0)
|
| t.Stop()
|
| emulators.append(emulator)
|
| @@ -162,12 +211,13 @@ class Emulator(object):
|
| # Time to wait for a "wait for boot complete" (property set on device).
|
| _WAITFORBOOT_TIMEOUT = 300
|
|
|
| - def __init__(self, avd_name, abi):
|
| + def __init__(self, avd_name, abi, api_level):
|
| """Init an Emulator.
|
|
|
| Args:
|
| avd_name: name of the AVD to create
|
| - abi: target platform for emulator being created
|
| + abi: target platform for emulator being created, defaults to x86
|
| + api_level: the api level of the image
|
| """
|
| android_sdk_root = os.path.join(constants.EMULATOR_SDK_ROOT, 'sdk')
|
| self.emulator = os.path.join(android_sdk_root, 'tools', 'emulator')
|
| @@ -176,6 +226,7 @@ class Emulator(object):
|
| self.device = None
|
| self.abi = abi
|
| self.avd_name = avd_name
|
| + self.api_level = api_level
|
| self._CreateAVD()
|
|
|
| def _DeviceName(self):
|
| @@ -191,16 +242,20 @@ class Emulator(object):
|
|
|
| if self.abi == 'arm':
|
| abi_option = 'armeabi-v7a'
|
| + elif self.abi == 'mips':
|
| + abi_option = 'mips'
|
| else:
|
| abi_option = 'x86'
|
|
|
| + api_target = 'android-%s' % self.api_level
|
| +
|
| avd_command = [
|
| self.android,
|
| '--silent',
|
| 'create', 'avd',
|
| '--name', self.avd_name,
|
| '--abi', abi_option,
|
| - '--target', API_TARGET,
|
| + '--target', api_target,
|
| '--sdcard', SDCARD_SIZE,
|
| '--force',
|
| ]
|
| @@ -213,13 +268,6 @@ class Emulator(object):
|
| avd_process.sendline('no\n')
|
| avd_process.expect('Created AVD \'%s\'' % self.avd_name)
|
|
|
| - # Setup test device as default Galaxy Nexus AVD
|
| - avd_config_dir = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android',
|
| - 'avd_configs')
|
| - avd_config_ini = os.path.join(avd_config_dir,
|
| - 'AVD_for_Galaxy_Nexus_by_Google_%s.avd' %
|
| - self.abi, 'config.ini')
|
| -
|
| # Replace current configuration with default Galaxy Nexus config.
|
| avds_dir = os.path.join(os.path.expanduser('~'), '.android', 'avd')
|
| ini_file = os.path.join(avds_dir, '%s.ini' % self.avd_name)
|
| @@ -233,11 +281,19 @@ class Emulator(object):
|
| # Create new configuration files with Galaxy Nexus by Google settings.
|
| with open(ini_file, 'w') as new_ini:
|
| new_ini.write('avd.ini.encoding=ISO-8859-1\n')
|
| - new_ini.write('target=%s\n' % API_TARGET)
|
| + new_ini.write('target=%s\n' % api_target)
|
| new_ini.write('path=%s/%s.avd\n' % (avds_dir, self.avd_name))
|
| new_ini.write('path.rel=avd/%s.avd\n' % self.avd_name)
|
|
|
| - shutil.copy(avd_config_ini, new_config_ini)
|
| + custom_config = CONFIG_TEMPLATE
|
| + replacements = CONFIG_REPLACEMENTS[self.abi]
|
| + for key in replacements:
|
| + custom_config = custom_config.replace(key, replacements[key])
|
| + custom_config = custom_config.replace('{api.level}', str(self.api_level))
|
| +
|
| + with open(new_config_ini, 'w') as new_config_ini:
|
| + new_config_ini.write(custom_config)
|
| +
|
| return self.avd_name
|
|
|
|
|
|
|