OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Provides an interface to start and stop Android emulator. | 5 """Provides an interface to start and stop Android emulator. |
6 | 6 |
7 Emulator: The class provides the methods to launch/shutdown the emulator with | 7 Emulator: The class provides the methods to launch/shutdown the emulator with |
8 the android virtual device named 'avd_armeabi' . | 8 the android virtual device named 'avd_armeabi' . |
9 """ | 9 """ |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... | |
32 | 32 |
33 # Template used to generate config.ini files for the emulator | 33 # Template used to generate config.ini files for the emulator |
34 CONFIG_TEMPLATE = """avd.ini.encoding=ISO-8859-1 | 34 CONFIG_TEMPLATE = """avd.ini.encoding=ISO-8859-1 |
35 hw.dPad=no | 35 hw.dPad=no |
36 hw.lcd.density=320 | 36 hw.lcd.density=320 |
37 sdcard.size={sdcard.size} | 37 sdcard.size={sdcard.size} |
38 hw.cpu.arch={hw.cpu.arch} | 38 hw.cpu.arch={hw.cpu.arch} |
39 hw.device.hash=-708107041 | 39 hw.device.hash=-708107041 |
40 hw.camera.back=none | 40 hw.camera.back=none |
41 disk.dataPartition.size=800M | 41 disk.dataPartition.size=800M |
42 hw.gpu.enabled=yes | 42 hw.gpu.enabled={gpu} |
43 skin.path=720x1280 | 43 skin.path=720x1280 |
44 skin.dynamic=yes | 44 skin.dynamic=yes |
45 hw.keyboard=yes | 45 hw.keyboard=yes |
46 hw.ramSize=1024 | 46 hw.ramSize=1024 |
47 hw.device.manufacturer=Google | 47 hw.device.manufacturer=Google |
48 hw.sdCard=yes | 48 hw.sdCard=yes |
49 hw.mainKeys=no | 49 hw.mainKeys=no |
50 hw.accelerometer=yes | 50 hw.accelerometer=yes |
51 skin.name=720x1280 | 51 skin.name=720x1280 |
52 abi.type={abi.type} | 52 abi.type={abi.type} |
53 hw.trackBall=no | 53 hw.trackBall=no |
54 hw.device.name=Galaxy Nexus | 54 hw.device.name=Galaxy Nexus |
55 hw.battery=yes | 55 hw.battery=yes |
56 hw.sensors.proximity=yes | 56 hw.sensors.proximity=yes |
57 image.sysdir.1=system-images/android-{api.level}/default/{abi.type}/ | 57 image.sysdir.1=system-images/android-{api.level}/default/{abi.type}/ |
58 hw.sensors.orientation=yes | 58 hw.sensors.orientation=yes |
59 hw.audioInput=yes | 59 hw.audioInput=yes |
60 hw.camera.front=none | 60 hw.camera.front=none |
61 hw.gps=yes | 61 hw.gps=yes |
62 vm.heapSize=128 | 62 vm.heapSize=128 |
63 {extras}""" | 63 {extras}""" |
64 | 64 |
65 CONFIG_REPLACEMENTS = { | 65 CONFIG_REPLACEMENTS = { |
jbudorick
2016/01/28 01:22:07
I think this should be using string.format instead
| |
66 'x86': { | 66 'x86': { |
67 '{hw.cpu.arch}': 'x86', | 67 '{hw.cpu.arch}': 'x86', |
68 '{abi.type}': 'x86', | 68 '{abi.type}': 'x86', |
69 '{extras}': '' | 69 '{extras}': '' |
70 }, | 70 }, |
71 'arm': { | 71 'arm': { |
72 '{hw.cpu.arch}': 'arm', | 72 '{hw.cpu.arch}': 'arm', |
73 '{abi.type}': 'armeabi-v7a', | 73 '{abi.type}': 'armeabi-v7a', |
74 '{extras}': 'hw.cpu.model=cortex-a8\n' | 74 '{extras}': 'hw.cpu.model=cortex-a8\n' |
75 }, | 75 }, |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 new_ini.write('target=%s\n' % api_target) | 324 new_ini.write('target=%s\n' % api_target) |
325 new_ini.write('path=%s/%s.avd\n' % (BASE_AVD_DIR, self.avd_name)) | 325 new_ini.write('path=%s/%s.avd\n' % (BASE_AVD_DIR, self.avd_name)) |
326 new_ini.write('path.rel=avd/%s.avd\n' % self.avd_name) | 326 new_ini.write('path.rel=avd/%s.avd\n' % self.avd_name) |
327 | 327 |
328 custom_config = CONFIG_TEMPLATE | 328 custom_config = CONFIG_TEMPLATE |
329 replacements = CONFIG_REPLACEMENTS[self.abi] | 329 replacements = CONFIG_REPLACEMENTS[self.abi] |
330 for key in replacements: | 330 for key in replacements: |
331 custom_config = custom_config.replace(key, replacements[key]) | 331 custom_config = custom_config.replace(key, replacements[key]) |
332 custom_config = custom_config.replace('{api.level}', str(api_level)) | 332 custom_config = custom_config.replace('{api.level}', str(api_level)) |
333 custom_config = custom_config.replace('{sdcard.size}', self.sdcard_size) | 333 custom_config = custom_config.replace('{sdcard.size}', self.sdcard_size) |
334 custom_config.replace('{gpu}', 'no' if self.headless else 'yes') | |
334 | 335 |
335 with open(new_config_ini, 'w') as new_config_ini: | 336 with open(new_config_ini, 'w') as new_config_ini: |
336 new_config_ini.write(custom_config) | 337 new_config_ini.write(custom_config) |
337 | 338 |
338 return self.avd_name | 339 return self.avd_name |
339 | 340 |
340 | 341 |
341 def _DeleteAVD(self): | 342 def _DeleteAVD(self): |
342 """Delete the AVD of this emulator.""" | 343 """Delete the AVD of this emulator.""" |
343 avd_command = [ | 344 avd_command = [ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 self.emulator, | 382 self.emulator, |
382 # Speed up emulator launch by 40%. Really. | 383 # Speed up emulator launch by 40%. Really. |
383 '-no-boot-anim', | 384 '-no-boot-anim', |
384 ] | 385 ] |
385 if self.headless: | 386 if self.headless: |
386 emulator_command.extend([ | 387 emulator_command.extend([ |
387 '-no-skin', | 388 '-no-skin', |
388 '-no-audio', | 389 '-no-audio', |
389 '-no-window' | 390 '-no-window' |
390 ]) | 391 ]) |
392 else: | |
393 emulator_command.extend([ | |
394 '-gpu', 'on' | |
395 ]) | |
391 emulator_command.extend([ | 396 emulator_command.extend([ |
392 # Use a familiar name and port. | 397 # Use a familiar name and port. |
393 '-avd', self.avd_name, | 398 '-avd', self.avd_name, |
394 '-port', str(port), | 399 '-port', str(port), |
395 # Enable GPU by default. | |
396 '-gpu', 'on', | |
397 # all the argument after qemu are sub arguments for qemu | 400 # all the argument after qemu are sub arguments for qemu |
398 '-qemu', '-m', '1024', | 401 '-qemu', '-m', '1024', |
399 ]) | 402 ]) |
400 if self.abi == 'x86' and self.enable_kvm: | 403 if self.abi == 'x86' and self.enable_kvm: |
401 emulator_command.extend([ | 404 emulator_command.extend([ |
402 # For x86 emulator --enable-kvm will fail early, avoiding accidental | 405 # For x86 emulator --enable-kvm will fail early, avoiding accidental |
403 # runs in a slow mode (i.e. without hardware virtualization support). | 406 # runs in a slow mode (i.e. without hardware virtualization support). |
404 '--enable-kvm', | 407 '--enable-kvm', |
405 ]) | 408 ]) |
406 | 409 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 logging.critical('emulator _ShutdownOnSignal') | 479 logging.critical('emulator _ShutdownOnSignal') |
477 for sig in self._SIGNALS: | 480 for sig in self._SIGNALS: |
478 signal.signal(sig, signal.SIG_DFL) | 481 signal.signal(sig, signal.SIG_DFL) |
479 self.Shutdown() | 482 self.Shutdown() |
480 raise KeyboardInterrupt # print a stack | 483 raise KeyboardInterrupt # print a stack |
481 | 484 |
482 def _InstallKillHandler(self): | 485 def _InstallKillHandler(self): |
483 """Install a handler to kill the emulator when we exit unexpectedly.""" | 486 """Install a handler to kill the emulator when we exit unexpectedly.""" |
484 for sig in self._SIGNALS: | 487 for sig in self._SIGNALS: |
485 signal.signal(sig, self._ShutdownOnSignal) | 488 signal.signal(sig, self._ShutdownOnSignal) |
OLD | NEW |