def _MakeAndroidPlatform()

in tools/android/emulator/unified_launcher.py [0:0]


def _MakeAndroidPlatform():
  """Pulls together all the binary tools / libs we'll be using today."""
  platform = emulated_device.AndroidPlatform()
  runfiles_base = os.environ.get(
      'TEST_SRCDIR') or os.environ.get('DEVICE_RUNFILES')
  if not runfiles_base:
    logging.warning('Cannot find runfiles (via env vars). Defaulting to $CWD.')
    runfiles_base = os.getcwd()
  else:
    runfiles_base = os.path.abspath(runfiles_base)

  if FLAGS.emulator_extra_lib_dir:
    for lib_dir in FLAGS.emulator_extra_lib_dir:
      assert os.path.exists(lib_dir), '%s: does not exist' % lib_dir
    platform.prepended_library_path = ':'.join(
        FLAGS.emulator_extra_lib_dir)

  root_dir = os.path.join(runfiles_base, 'android_test_support')
  # Sometimes we are running from android_test_support, fix root_dir here.
  if not os.path.exists(root_dir):
    root_dir = runfiles_base

  if FLAGS.custom_emulator:
    base_emulator_path = os.path.dirname(
        os.path.join(root_dir, FLAGS.custom_emulator))
  elif FLAGS.emulator_x86:
    base_emulator_path = os.path.dirname(os.path.join(root_dir,
                                                      FLAGS.emulator_x86))
  else:
    base_emulator_path = os.path.join(root_dir, (
        'third_party/java/android/android_sdk_linux/tools'))

  if not os.path.exists(base_emulator_path):
    logging.error('emulator tools dir %s does not exist.', base_emulator_path)
    sys.exit(1)
  if FLAGS.android_sdk_path:
    platform.android_sdk = FLAGS.android_sdk_path

  platform.base_emulator_path = base_emulator_path

  adb_path = None
  if FLAGS.use_h2o or FLAGS.use_waterfall:
    if FLAGS.adb_bin or FLAGS.waterfall_bin:
      adb_path = FLAGS.adb_bin or FLAGS.waterfall_bin
    else:
      adb_path = (''
                  'tools/android/emulator/support/waterfall/waterfall_bin')
  else:
    if FLAGS.adb_turbo:
      adb_path = FLAGS.adb_turbo
    else:
      adb_path = (''
                  'tools/android/emulator/support/adb.turbo')

  g3_relative = os.path.join('android_test_support', adb_path)
  if os.path.exists(adb_path):
    platform.adb = os.path.abspath(adb_path)
  elif os.path.exists(g3_relative):
    platform.adb = os.path.abspath(g3_relative)
  else:
    platform.adb = resources.GetResourceFilename(g3_relative)

  assert os.path.exists(platform.adb), ('%s: does not exist. please pass '
                                        '--adb_turbo' % platform.adb)
  platform.real_adb = FLAGS.adb

  if FLAGS.flag_configured_android_tools:
    platform.launcher_tool = FLAGS.android_launcher_tool
    platform.emulator_x86 = FLAGS.emulator_x86
    platform.emulator_arm = FLAGS.emulator_arm
    if FLAGS.kvm_device:
      platform.kvm_device = FLAGS.kvm_device
    platform.empty_snapshot_fs = FLAGS.empty_snapshot_fs
    platform.mksdcard = FLAGS.mksdcard
    platform.bios_files = filter(lambda e: e, FLAGS.bios_files)

  if FLAGS.custom_emulator:
    platform.emulator_wrapper_launcher = FLAGS.custom_emulator
  else:
    platform.emulator_wrapper_launcher = _ExtractSuffixFile(
        FLAGS.system_images, '/emulator')

  return platform