Skip to content
Permalink
Browse files

android: add support for different settings at avd creation time.

Starting with sdcard size as well as screen dimensions and density.
Also adds a marshmallow tablet AVD configuration.

Bug: 922145
Change-Id: I72d083599e920307f5db1eeb7e6fd708105878bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1918275
Commit-Queue: John Budorick <jbudorick@chromium.org>
Reviewed-by: Ted Choc <tedchoc@chromium.org>
Reviewed-by: Yun Liu <yliuyliu@google.com>
Cr-Commit-Position: refs/heads/master@{#721646}
  • Loading branch information
jbudorick authored and Commit Bot committed Dec 4, 2019
1 parent 48b0240 commit dbb0b5728980f3ea443aa18b64c873d6fc61cf4c
@@ -0,0 +1,2 @@
# Generated protobuf code.
*_pb2.py
1 OWNERS
@@ -14,6 +14,7 @@ per-file .gn=file://build/OWNERS
per-file .vpython*=dpranke@chromium.org
per-file .vpython*=iannucci@chromium.org
per-file .vpython*=jbudorick@chromium.org
per-file .yapfignore=*
per-file AUTHORS=*
per-file BUILD.gn=file://build/OWNERS
per-file codereview.settings=agable@chromium.org
@@ -23,8 +23,21 @@
from pylib.local.emulator.proto import avd_pb2

_ALL_PACKAGES = object()
_CONFIG_INI_CONTENTS = textwrap.dedent("""\
disk.dataPartition.size=4G
hw.lcd.density={density}
hw.lcd.height={height}
hw.lcd.width={width}
""")
_DEFAULT_AVDMANAGER_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'tools',
'bin', 'avdmanager')
# Default to a 480dp mdpi screen (a relatively large phone).
# See https://developer.android.com/training/multiscreen/screensizes
# and https://developer.android.com/training/multiscreen/screendensities
# for more information.
_DEFAULT_SCREEN_DENSITY = 160
_DEFAULT_SCREEN_HEIGHT = 960
_DEFAULT_SCREEN_WIDTH = 480


class AvdException(Exception):
@@ -85,7 +98,7 @@ def __init__(self, avd_home, sdk_root):
'-Dcom.android.sdkmanager.toolsdir=%s' % fake_tools_dir,
})

def Create(self, avd_name, system_image, force=False):
def Create(self, avd_name, system_image, force=False, sdcard=None):
"""Call `avdmanager create`.
Args:
@@ -106,6 +119,8 @@ def Create(self, avd_name, system_image, force=False):
]
if force:
create_cmd += ['--force']
if sdcard:
create_cmd += ['--sdcard', sdcard]

create_proc = cmd_helper.Popen(
create_cmd,
@@ -213,7 +228,8 @@ def Create(self,
avd_manager.Create(
avd_name=self._config.avd_name,
system_image=self._config.system_image_name,
force=force)
force=force,
sdcard=self._config.avd_settings.sdcard.size)

try:
logging.info('Modifying AVD configuration.')
@@ -227,14 +243,16 @@ def Create(self,
with open(root_ini, 'a') as root_ini_file:
root_ini_file.write('path.rel=avd/%s.avd\n' % self._config.avd_name)

height = (self._config.avd_settings.screen.height
or _DEFAULT_SCREEN_HEIGHT)
width = (self._config.avd_settings.screen.width or _DEFAULT_SCREEN_WIDTH)
density = (self._config.avd_settings.screen.density
or _DEFAULT_SCREEN_DENSITY)

with open(config_ini, 'a') as config_ini_file:
config_ini_file.write(
textwrap.dedent("""\
disk.dataPartition.size=4G
hw.lcd.density=160
hw.lcd.height=960
hw.lcd.width=480
"""))
config_ini_contents = _CONFIG_INI_CONTENTS.format(
density=density, height=height, width=width)
config_ini_file.write(config_ini_contents)

# Start & stop the AVD.
self._Initialize()
@@ -18,6 +18,34 @@ message CIPDPackage {
string dest_path = 3;
}

message ScreenSettings {
// Screen height in pixels.
uint32 height = 1;

// Screen width in pixels.
uint32 width = 2;

// Scren density in dpi.
uint32 density = 3;
}

message SdcardSettings {
// Size of the sdcard that should be created for this AVD.
// Can be anything that `mksdcard` or `avdmanager -c` would accept:
// - a number of bytes
// - a number followed by K, M, or G, indicating that many
// KiB, MiB, or GiB, respectively.
string size = 1;
}

message AvdSettings {
// Settings pertaining to the AVD's screen.
ScreenSettings screen = 1;

// Settings pertaining to the AVD's sdcard.
SdcardSettings sdcard = 2;
}

message Avd {
// The emulator to use in running the AVD.
CIPDPackage emulator_package = 1;
@@ -32,4 +60,7 @@ message Avd {
CIPDPackage avd_package = 4;
// The name of the AVD to create or use.
string avd_name = 5;

// How to configure the AVD at creation.
AvdSettings avd_settings = 6;
}

0 comments on commit dbb0b57

Please sign in to comment.
You can’t perform that action at this time.