Skip to content

Commit

Permalink
android: add support for different settings at avd creation time.
Browse files Browse the repository at this point in the history
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 dbb0b57
Show file tree
Hide file tree
Showing 7 changed files with 373 additions and 196 deletions.
2 changes: 2 additions & 0 deletions .yapfignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated protobuf code.
*_pb2.py
1 change: 1 addition & 0 deletions OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 27 additions & 9 deletions build/android/pylib/local/emulator/avd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand Down Expand Up @@ -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.')
Expand All @@ -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()
Expand Down
31 changes: 31 additions & 0 deletions build/android/pylib/local/emulator/proto/avd.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Loading

0 comments on commit dbb0b57

Please sign in to comment.