def Configure()

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


  def Configure(self,
                system_image_dir,
                skin,
                memory,
                density,
                vm_heap,
                net_type='fastnet',
                source_properties=None,
                default_properties=None,
                kvm_present=False,
                system_image_path=None,
                data_image_path=None,
                vendor_img_path=None,
                encryptionkey_img_path=None,
                advanced_features_ini=None,
                build_prop_path=None,
                data_files=None):
    """Performs pre-start configuration of the emulator."""
    assert os.path.exists(system_image_dir), ('Sysdir doesnt exist: %s' %
                                              system_image_dir)
    system_image_path = (system_image_path or
                         self._GetImagePath(system_image_dir, 'system.img'))
    data_image_path = (data_image_path or
                       self._GetImagePath(system_image_dir, 'userdata.img',
                                          ignore_non_existent_file=True))
    build_prop_path = (
        build_prop_path or self._GetImagePath(system_image_dir, 'build.prop'))

    images_dict = self.BuildImagesDict(system_image_path, data_image_path,
                                       vendor_img_path, encryptionkey_img_path,
                                       advanced_features_ini, build_prop_path,
                                       data_files)

    self._metadata_pb = emulator_meta_data_pb2.EmulatorMetaDataPb(
        system_image_dir=system_image_dir,
        skin=skin,
        memory_mb=int(memory),
        density=int(density),
        net_type=net_type,
        vm_heap=int(vm_heap),
        net_delay=NET_TYPE_TO_DELAY[net_type],
        net_speed=NET_TYPE_TO_SPEED[net_type],
        sdcard_size_mb=int(256),
        api_name=source_properties[API_LEVEL_KEY],
        emulator_architecture=self._DetermineArchitecture(source_properties),
        with_kvm=self._WithKvm(source_properties, kvm_present),
        with_adbd_pipe=False,
        with_patched_adbd=False,
        supports_gpu=self._SupportsGPU(source_properties),
        supported_open_gl_drivers=self._DetermineSupportedDrivers(
            source_properties),
        sensitive_system_image=self._DetermineSensitiveImage(source_properties),
        system_image_path=json.dumps(images_dict)
    )

    if self._metadata_pb.with_kvm:
      self._connect_poll_interval /= 4.0
      self._connect_max_attempts *= 4

    if default_properties:  # allow any user specified readonly props to take
      # precedence over our set of ro.test_harness
      # Ignores avd_config_ini. properties. They are used
      # to store device specific config.ini values.
      for prop_name, prop_value in default_properties.items():
        if not prop_name.startswith('avd_config_ini.'):
          self._metadata_pb.boot_property.add(name=prop_name, value=prop_value)
        if prop_name == DIRECT_BOOT_PROP and prop_value == '1':
          self._direct_boot = True

      # need to allow users to specify device specific sd card sizes in
      # default.properties.
      self._metadata_pb.sdcard_size_mb = int(default_properties.get(
          SDCARD_SIZE_KEY, 256))

      self._metadata_pb.emulator_type = (
          emulator_meta_data_pb2.EmulatorMetaDataPb.EmulatorType.Value(
              default_properties.get(EMULATOR_TYPE_KEY, 'QEMU').upper()))

    self._metadata_pb.qemu_arg.extend(
        self._DetermineQemuArgs(source_properties, kvm_present))
    self._metadata_pb.boot_property.add(
        name='debug.sf.nobootanimation',  # disable boot animation by default
        value='1')

    self._metadata_pb.boot_property.add(
        name='ro.monkey',  # allows for bypassing permission screens pre ICS
        value='1')

    self._metadata_pb.boot_property.add(
        name='ro.setupwizard.mode',  # skip past the intro screens.
        value='DISABLED')

    if not self._direct_boot:
      self._metadata_pb.boot_property.add(
          name='ro.lockscreen.disable.default',  # disable lockscreen (jb & up)
          value='1')

    # Add a UUID for this particular device
    self._metadata_pb.boot_property.add(
        name='ro.ninjas.device_fingerprint',
        value=str(uuid.uuid4()))

    # emulator supports bucketed densities. Map the provided density into
    # the correct bucket.
    self._metadata_pb.density = self._MapToSupportedDensity(
        self._metadata_pb.density)

    # QEMU is supposed to set qemu.sf.lcd_density - however in setting this
    # variable it races with SurfaceFlinger to read it. If SF checks it first
    # before QEMU sets it, we'll get whonky density values. We set
    # ro.sf.lcd_density to the same value QEMU will set qemu.sf.lcd_density -
    # this eliminates the race.
    self._metadata_pb.boot_property.add(
        name='ro.sf.lcd_density',
        value=str(self._metadata_pb.density))
    self._metadata_pb.boot_property.add(
        name='qemu.sf.lcd_density',
        value=str(self._metadata_pb.density))

    self._metadata_pb.boot_property.add(
        name='service.adb.root', value='1')

    # If the user has not specified heapgrowth limit in default properties,
    # default it to either 64 of vm_heap, whichever is lower.
    if not [kv for kv in self._metadata_pb.boot_property
            if kv.name == HEAP_GROWTH_LIMIT_KEY]:
      vm_heap = self._metadata_pb.vm_heap
      self._metadata_pb.boot_property.add(
          name=HEAP_GROWTH_LIMIT_KEY,
          value='%sm' % min(64, vm_heap)
      )

    # We set this value in AVD's also, however in certain cases (for example:
    # gingerbread) it is not set early enough to have an impact. By writing
    # it into the boot_property file we ensure it'll be there as soon as the
    # system starts.

    self._metadata_pb.boot_property.add(
        name='dalvik.vm.heapsize',
        value='%sm' % self._metadata_pb.vm_heap)

    # disable dex pre-verification. Verification is still done, but at runtime
    # instead of installation time.
    #
    # We do this to allow for the case where the production and test apks both
    # contain the same class. With preverification turned on, this situation
    # will result in a dalvik failure (because verification was done at
    # installation time and the verified expected the app apk to be completely
    # self contained). Since bazel will ensure that app and test apk are using
    # the same dependencies this check is superflous in our case.
    if self.GetApiVersion() <= 20:
      # no longer applicable in ART world.
      self._metadata_pb.boot_property.add(
          name='dalvik.vm.dexopt-flags',
          value='v=n,o=v')

    # Yes double specify the timezone. The emulator commandline setting works
    # for older versions of Android - and newer versions of android respect
    # this property setting.
    self._metadata_pb.boot_property.add(
        name='persist.sys.timezone',
        value='America/Los_Angeles')

    default_cores = self._GetProperty(_CORES_PROP, default_properties,
                                      source_properties, None)
    if default_cores:
      self._metadata_pb.avd_config_property.add(
          name=_CORES_PROP, value=default_cores)

    prop = self._metadata_pb.avd_config_property.add(name='hw.mainKeys')
    prop.value = self._GetProperty(prop.name, default_properties,
                                   source_properties, 'yes')

    prop = self._metadata_pb.avd_config_property.add(name='hw.camera.back')
    prop.value = self._GetProperty(prop.name, default_properties,
                                   source_properties, 'emulated')
    back_cam_config = prop.value

    prop = self._metadata_pb.avd_config_property.add(name='hw.camera.front')
    prop.value = self._GetProperty(prop.name, default_properties,
                                   source_properties, 'none')
    front_cam_config = prop.value
    # Also eliminates the race that we lost camera sometimes.
    # 'back' is the current default value for emulator.
    if front_cam_config != 'emulated' and back_cam_config == 'emulated':
      self._metadata_pb.boot_property.add(name='qemu.sf.fake_camera',
                                          value='back')
    elif front_cam_config == 'emulated' and back_cam_config != 'emulated':
      self._metadata_pb.boot_property.add(name='qemu.sf.fake_camera',
                                          value='front')
    elif front_cam_config == 'emulated' and back_cam_config == 'emulated':
      self._metadata_pb.boot_property.add(name='qemu.sf.fake_camera',
                                          value='both')
    else:
      self._metadata_pb.boot_property.add(name='qemu.sf.fake_camera',
                                          value='none')

    # Keyboard support for real keyboard.
    # emulator bug - documentation says default value is "yes".

    prop = self._metadata_pb.avd_config_property.add(name='hw.keyboard')
    prop.value = self._GetProperty(prop.name, default_properties,
                                   source_properties, 'yes')

    if self.GetApiVersion() != 15:
      # Allow user to switch back to softkeyboard.
      # in ICS this is broken - emulator will appear in landscape mode if this
      # is set.
      prop = self._metadata_pb.avd_config_property.add(name='hw.keyboard.lid')
      prop.value = self._GetProperty(prop.name, default_properties,
                                     source_properties, 'yes')

    # This forces a virtual sound card to be presented to android.
    # whether or not we do anything with this sound card is controlled by
    # the -audio commandline flag.
    self._metadata_pb.avd_config_property.add(
        name='hw.audioOutput',
        value='yes')
    self._metadata_pb.avd_config_property.add(
        name='hw.audioInput',
        value='yes')

    # emulator bug - dpi-device is ignored from the commandline
    self._metadata_pb.avd_config_property.add(
        name='hw.lcd.density',
        value=str(self._metadata_pb.density))

    # people always think the backlight simulation is some sort of indication
    # that the device is going to sleep or some low power mode and thats why
    # their tests are flaky, it's not the reason, disable it.
    self._metadata_pb.avd_config_property.add(
        name='hw.lcd.backlight',
        value='no')

    # since this ini file is parsed after our --boot_property flags are parsed
    # we must set this here (otherwise it applies our boot_prop flag and then
    # the default value of this flag (overwriting us!)
    self._metadata_pb.avd_config_property.add(
        name='vm.heapSize',
        value=str(self._metadata_pb.vm_heap))