| Index: build/android/emulator.py
|
| diff --git a/build/android/emulator.py b/build/android/emulator.py
|
| index bf5dc083ea24bb2a0e5132d8e20c89be2beee5dd..d4f3caa409272f35f97022e1bf099f20ea08cc77 100755
|
| --- a/build/android/emulator.py
|
| +++ b/build/android/emulator.py
|
| @@ -113,10 +113,11 @@ class Emulator(object):
|
| # Time to wait for a "wait for boot complete" (property set on device).
|
| _WAITFORBOOT_TIMEOUT = 300
|
|
|
| - def __init__(self, fast_and_loose=False):
|
| + def __init__(self, new_avd_name, fast_and_loose):
|
| """Init an Emulator.
|
|
|
| Args:
|
| + nwe_avd_name: If set, will create a new temporary AVD.
|
| fast_and_loose: Loosen up the rules for reliable running for speed.
|
| Intended for quick testing or re-testing.
|
|
|
| @@ -128,15 +129,59 @@ class Emulator(object):
|
| 'emulator.')
|
| raise
|
| self.emulator = os.path.join(android_sdk_root, 'tools', 'emulator')
|
| + self.android = os.path.join(android_sdk_root, 'tools', 'android')
|
| self.popen = None
|
| self.device = None
|
| + self.default_avd = True
|
| self.fast_and_loose = fast_and_loose
|
| + self.abi = 'armeabi-v7a'
|
| + self.avd = 'avd_armeabi'
|
| + if 'x86' in os.environ.get('TARGET_PRODUCT', ''):
|
| + self.abi = 'x86'
|
| + self.avd = 'avd_x86'
|
| + if new_avd_name:
|
| + self.default_avd = False
|
| + self.avd = self._CreateAVD(new_avd_name)
|
|
|
| def _DeviceName(self):
|
| """Return our device name."""
|
| port = _GetAvailablePort()
|
| return ('emulator-%d' % port, port)
|
|
|
| + def _CreateAVD(self, avd_name):
|
| + avd_command = [
|
| + self.android,
|
| + '--silent',
|
| + 'create', 'avd',
|
| + '--name', avd_name,
|
| + '--abi', self.abi,
|
| + '--target', 'android-15',
|
| + '-c', '64M',
|
| + '--force',
|
| + ]
|
| + avd_process = subprocess.Popen(args=avd_command,
|
| + stdin=subprocess.PIPE,
|
| + stdout=subprocess.PIPE,
|
| + stderr=subprocess.STDOUT)
|
| + avd_process.stdin.write('no\n')
|
| + avd_process.wait()
|
| + logging.info('Create AVD command: %s', ' '.join(avd_command))
|
| + return self.avd
|
| +
|
| + def _DeleteAVD(self):
|
| + avd_command = [
|
| + self.android,
|
| + '--silent',
|
| + 'delete',
|
| + 'avd',
|
| + '--name', self.avd,
|
| + ]
|
| + avd_process = subprocess.Popen(args=avd_command,
|
| + stdout=subprocess.PIPE,
|
| + stderr=subprocess.STDOUT)
|
| + logging.info('Delete AVD command: %s', ' '.join(avd_command))
|
| + avd_process.wait()
|
| +
|
| def Launch(self, kill_all_emulators):
|
| """Launches the emulator asynchronously. Call ConfirmLaunch() to ensure the
|
| emulator is ready for use.
|
| @@ -148,9 +193,6 @@ class Emulator(object):
|
| if not self.fast_and_loose:
|
| self._AggressiveImageCleanup()
|
| (self.device, port) = self._DeviceName()
|
| - abi = 'armeabi'
|
| - if 'x86' in os.environ.get('TARGET_PRODUCT', ''):
|
| - abi = 'x86'
|
| emulator_command = [
|
| self.emulator,
|
| # Speed up emulator launch by 40%. Really.
|
| @@ -159,7 +201,7 @@ class Emulator(object):
|
| # That's not enough for 8 unit test bundles and their data.
|
| '-partition-size', '512',
|
| # Use a familiar name and port.
|
| - '-avd', 'avd_' + abi,
|
| + '-avd', self.avd,
|
| '-port', str(port)]
|
| if not self.fast_and_loose:
|
| emulator_command.extend([
|
| @@ -228,6 +270,8 @@ class Emulator(object):
|
|
|
| def Shutdown(self):
|
| """Shuts down the process started by launch."""
|
| + if not self.default_avd:
|
| + self._DeleteAVD()
|
| if self.popen:
|
| self.popen.poll()
|
| if self.popen.returncode == None:
|
| @@ -247,7 +291,7 @@ class Emulator(object):
|
| signal.signal(sig, self._ShutdownOnSignal)
|
|
|
| def main(argv):
|
| - Emulator(True).Launch(True)
|
| + Emulator(None, True).Launch(True)
|
|
|
|
|
| if __name__ == '__main__':
|
|
|