in tools/android/emulator/unified_launcher.py [0:0]
def _Run(adb_server_port,
emulator_port,
adb_port,
enable_display,
start_vnc_on_port,
logcat_path,
logcat_filter,
system_images,
input_image_file,
emulator_metadata_path,
apks,
system_apks,
net_type,
export_launch_metadata_path=None,
preverify_apks=False,
new_process_group=False,
window_scale=None,
broadcast_message=None,
initial_locale=None,
initial_ime=None,
with_audio=False,
qemu_gdb_port=0,
enable_single_step=False,
with_boot_anim=False,
extra_certs=None,
emulator_tmp_dir=None,
lockdown_level=None,
open_gl_driver=None,
experimental_open_gl=False,
add_insecure_cert=False,
grant_runtime_permissions=True,
accounts=None,
reporter=None,
mini_boot=False,
sim_access_rules_file=None,
phone_number=None):
"""Starts a device for use or testing.
Args:
adb_server_port: the adb server port to connect to
emulator_port: the port the emulator will use for its telnet interface
adb_port: the port the emulator will accept adb connections on
enable_display: true the emulator starts with display, false otherwise.
start_vnc_on_port: if a port is specified, starts vnc server at that port.
logcat_path: the directory to store logcat data to (None implies no logcat)
logcat_filter: the filter to apply to logcat (None implies no logcat)
system_images: system images to restart with (only valid for bazel created
start scripts).
input_image_file: a compressed file containing userdata files. (only valid
for bazel start scripts)
emulator_metadata_path: the path to the emulator_metadata_pb. (Only valid
for bazel start scripts)
apks: extra apks to install on the started device.
system_apks: apks to install onto the /system partition.
net_type: The type of network to use.
export_launch_metadata_path: optional path to write the emulator metadata
to.
preverify_apks: install apks onto the emulator with verification turned on
defaults to false.
new_process_group: emulator will be in a seperate process group (default
false)
window_scale: Scale factor of emulator window in percent.
broadcast_message: A dict of key value extras to broadcast at launch.
initial_locale: A locale, that would be send through broadcasting message
and set as a locale on an android device if possible.
initial_ime: The ime, that would be send through broadcasting message
and set as an ime on an android device if possible.
with_audio: Indicates the emulator should output audio to the local sound
card.
qemu_gdb_port: Start the gdb stub in qemu listening on this port
enable_single_step: Start qemu in single step mode.
with_boot_anim: Enables boot animation.
extra_certs: additional CA certs to install.
emulator_tmp_dir: Temporary directory where files are placed when the
emulator is launched
lockdown_level: Lockdown level, higher level includes all lower levels.
open_gl_driver: [optional] specifies the driver to use for OpenGL.
experimental_open_gl: [optional] disables sanity checks for OpenGL.
add_insecure_cert: [optional] bool: adds the cyber villians cert.
grant_runtime_permissions: [optional] bool: Grant runtime permissions while
installing apk on api level > 23.
accounts: A list of accounts to be added to emulator at launch.
reporter: a reporting.Reporter to track the emulator state.
mini_boot: should the device be booted up in a minimalistic mode.
sim_access_rules_file: sim access rules textproto filepath.
phone_number: custom phone number to on the sim.
"""
device = emulated_device.EmulatedDevice(
android_platform=_MakeAndroidPlatform(),
adb_server_port=adb_server_port,
emulator_telnet_port=emulator_port,
emulator_adb_port=adb_port,
qemu_gdb_port=qemu_gdb_port,
enable_single_step=enable_single_step,
logcat_path=logcat_path,
logcat_filter=logcat_filter,
enable_console_auth=FLAGS.enable_console_auth,
enable_g3_monitor=FLAGS.enable_g3_monitor,
enable_gps=FLAGS.enable_gps,
add_insecure_cert=add_insecure_cert,
reporter=reporter,
mini_boot=mini_boot,
sim_access_rules_file=sim_access_rules_file,
phone_number=phone_number,
source_properties=_ReadSourceProperties(FLAGS.source_properties_file),
use_waterfall=FLAGS.use_h2o or FLAGS.use_waterfall,
forward_bin=FLAGS.forward_bin,
ports_bin=FLAGS.forward_bin)
_RestartDevice(
device,
enable_display=enable_display,
start_vnc_on_port=start_vnc_on_port,
net_type=net_type,
system_image_files=system_images,
input_image_file=input_image_file,
proto_filepath=emulator_metadata_path,
new_process_group=new_process_group,
window_scale=window_scale,
with_audio=with_audio,
with_boot_anim=with_boot_anim,
emulator_tmp_dir=emulator_tmp_dir,
open_gl_driver=open_gl_driver,
experimental_open_gl=experimental_open_gl,
snapshot_file=FLAGS.snapshot_file)
device.SyncTime()
if mini_boot:
return
if preverify_apks:
device.PreverifyApks()
if system_apks:
device.InstallSystemApks(system_apks)
gmscore_apks = None
if apks:
gmscore_apks = [apk for apk in apks if 'gmscore' in apk.lower()]
other_apks = [apk for apk in apks if apk not in gmscore_apks]
_TryInstallApks(device, other_apks, grant_runtime_permissions)
if export_launch_metadata_path:
proto = device.GetEmulatorMetadataProto()
with open(export_launch_metadata_path, 'wb') as proto_file:
proto_file.write(proto.SerializeToString())
if add_insecure_cert:
device.InstallCyberVillainsCert()
if extra_certs:
for cert in extra_certs:
device.AddCert(cert)
if initial_locale is not None:
broadcast_message['initial_locale'] = initial_locale
if initial_ime is not None:
broadcast_message['initial_ime'] = initial_ime
# send broadcast ACTION_MOBILE_NINJAS_START to the device
device.BroadcastDeviceReady(broadcast_message)
if adb_server_port:
device.ConnectDevice()
if lockdown_level:
device.Lockdown(lockdown_level)
if accounts:
for account in accounts:
account_name, password = account.split(':', 1)
account_extras = collections.OrderedDict()
account_extras['account_name'] = account_name
account_extras['password'] = password
account_extras.update(_ADD_ACCOUNT_BOOLEAN_EXTRAS)
device.BroadcastDeviceReady(account_extras,
_ADD_ACCOUNT_BROADCAST_ACTION)
if gmscore_apks:
_TryInstallApks(device, gmscore_apks, grant_runtime_permissions)