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-Original-Commit-Position: refs/heads/master@{#721646}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: dbb0b5728980f3ea443aa18b64c873d6fc61cf4c
This commit is contained in:
John Budorick 2019-12-04 20:41:15 +00:00 коммит произвёл Commit Bot
Родитель 5c15241d3a
Коммит ca5023e465
3 изменённых файлов: 328 добавлений и 196 удалений

Просмотреть файл

@ -23,8 +23,21 @@ from pylib import constants
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 @@ class _AvdManagerAgent(object):
'-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 @@ class _AvdManagerAgent(object):
]
if force:
create_cmd += ['--force']
if sdcard:
create_cmd += ['--sdcard', sdcard]
create_proc = cmd_helper.Popen(
create_cmd,
@ -213,7 +228,8 @@ class AvdConfig(object):
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 @@ class AvdConfig(object):
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;
}

Просмотреть файл

@ -2,217 +2,300 @@
# source: avd.proto
import sys
_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode('latin1'))
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
from google.protobuf import descriptor_pb2
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor.FileDescriptor(
name='avd.proto',
package='tools.android.avd.proto',
syntax='proto3',
serialized_pb=_b(
'\n\tavd.proto\x12\x17tools.android.avd.proto\"G\n\x0b\x43IPDPackage\x12\x14\n\x0cpackage_name\x18\x01 \x01(\t\x12\x0f\n\x07version\x18\x02 \x01(\t\x12\x11\n\tdest_path\x18\x03 \x01(\t\"\xf1\x01\n\x03\x41vd\x12>\n\x10\x65mulator_package\x18\x01 \x01(\x0b\x32$.tools.android.avd.proto.CIPDPackage\x12\x42\n\x14system_image_package\x18\x02 \x01(\x0b\x32$.tools.android.avd.proto.CIPDPackage\x12\x19\n\x11system_image_name\x18\x03 \x01(\t\x12\x39\n\x0b\x61vd_package\x18\x04 \x01(\x0b\x32$.tools.android.avd.proto.CIPDPackage\x12\x10\n\x08\x61vd_name\x18\x05 \x01(\tb\x06proto3'
))
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
name='avd.proto',
package='tools.android.avd.proto',
syntax='proto3',
serialized_options=None,
serialized_pb=_b('\n\tavd.proto\x12\x17tools.android.avd.proto\"G\n\x0b\x43IPDPackage\x12\x14\n\x0cpackage_name\x18\x01 \x01(\t\x12\x0f\n\x07version\x18\x02 \x01(\t\x12\x11\n\tdest_path\x18\x03 \x01(\t\"@\n\x0eScreenSettings\x12\x0e\n\x06height\x18\x01 \x01(\r\x12\r\n\x05width\x18\x02 \x01(\r\x12\x0f\n\x07\x64\x65nsity\x18\x03 \x01(\r\"\x1e\n\x0eSdcardSettings\x12\x0c\n\x04size\x18\x01 \x01(\t\"\x7f\n\x0b\x41vdSettings\x12\x37\n\x06screen\x18\x01 \x01(\x0b\x32\'.tools.android.avd.proto.ScreenSettings\x12\x37\n\x06sdcard\x18\x02 \x01(\x0b\x32\'.tools.android.avd.proto.SdcardSettings\"\xad\x02\n\x03\x41vd\x12>\n\x10\x65mulator_package\x18\x01 \x01(\x0b\x32$.tools.android.avd.proto.CIPDPackage\x12\x42\n\x14system_image_package\x18\x02 \x01(\x0b\x32$.tools.android.avd.proto.CIPDPackage\x12\x19\n\x11system_image_name\x18\x03 \x01(\t\x12\x39\n\x0b\x61vd_package\x18\x04 \x01(\x0b\x32$.tools.android.avd.proto.CIPDPackage\x12\x10\n\x08\x61vd_name\x18\x05 \x01(\t\x12:\n\x0c\x61vd_settings\x18\x06 \x01(\x0b\x32$.tools.android.avd.proto.AvdSettingsb\x06proto3')
)
_CIPDPACKAGE = _descriptor.Descriptor(
name='CIPDPackage',
full_name='tools.android.avd.proto.CIPDPackage',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='package_name',
full_name='tools.android.avd.proto.CIPDPackage.package_name',
index=0,
number=1,
type=9,
cpp_type=9,
label=1,
has_default_value=False,
default_value=_b("").decode('utf-8'),
message_type=None,
enum_type=None,
containing_type=None,
is_extension=False,
extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='version',
full_name='tools.android.avd.proto.CIPDPackage.version',
index=1,
number=2,
type=9,
cpp_type=9,
label=1,
has_default_value=False,
default_value=_b("").decode('utf-8'),
message_type=None,
enum_type=None,
containing_type=None,
is_extension=False,
extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='dest_path',
full_name='tools.android.avd.proto.CIPDPackage.dest_path',
index=2,
number=3,
type=9,
cpp_type=9,
label=1,
has_default_value=False,
default_value=_b("").decode('utf-8'),
message_type=None,
enum_type=None,
containing_type=None,
is_extension=False,
extension_scope=None,
options=None),
],
extensions=[],
nested_types=[],
enum_types=[],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[],
serialized_start=38,
serialized_end=109,
name='CIPDPackage',
full_name='tools.android.avd.proto.CIPDPackage',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='package_name', full_name='tools.android.avd.proto.CIPDPackage.package_name', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='version', full_name='tools.android.avd.proto.CIPDPackage.version', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='dest_path', full_name='tools.android.avd.proto.CIPDPackage.dest_path', index=2,
number=3, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=38,
serialized_end=109,
)
_SCREENSETTINGS = _descriptor.Descriptor(
name='ScreenSettings',
full_name='tools.android.avd.proto.ScreenSettings',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='height', full_name='tools.android.avd.proto.ScreenSettings.height', index=0,
number=1, type=13, cpp_type=3, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='width', full_name='tools.android.avd.proto.ScreenSettings.width', index=1,
number=2, type=13, cpp_type=3, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='density', full_name='tools.android.avd.proto.ScreenSettings.density', index=2,
number=3, type=13, cpp_type=3, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=111,
serialized_end=175,
)
_SDCARDSETTINGS = _descriptor.Descriptor(
name='SdcardSettings',
full_name='tools.android.avd.proto.SdcardSettings',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='size', full_name='tools.android.avd.proto.SdcardSettings.size', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=177,
serialized_end=207,
)
_AVDSETTINGS = _descriptor.Descriptor(
name='AvdSettings',
full_name='tools.android.avd.proto.AvdSettings',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='screen', full_name='tools.android.avd.proto.AvdSettings.screen', index=0,
number=1, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='sdcard', full_name='tools.android.avd.proto.AvdSettings.sdcard', index=1,
number=2, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=209,
serialized_end=336,
)
_AVD = _descriptor.Descriptor(
name='Avd',
full_name='tools.android.avd.proto.Avd',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='emulator_package',
full_name='tools.android.avd.proto.Avd.emulator_package',
index=0,
number=1,
type=11,
cpp_type=10,
label=1,
has_default_value=False,
default_value=None,
message_type=None,
enum_type=None,
containing_type=None,
is_extension=False,
extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='system_image_package',
full_name='tools.android.avd.proto.Avd.system_image_package',
index=1,
number=2,
type=11,
cpp_type=10,
label=1,
has_default_value=False,
default_value=None,
message_type=None,
enum_type=None,
containing_type=None,
is_extension=False,
extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='system_image_name',
full_name='tools.android.avd.proto.Avd.system_image_name',
index=2,
number=3,
type=9,
cpp_type=9,
label=1,
has_default_value=False,
default_value=_b("").decode('utf-8'),
message_type=None,
enum_type=None,
containing_type=None,
is_extension=False,
extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='avd_package',
full_name='tools.android.avd.proto.Avd.avd_package',
index=3,
number=4,
type=11,
cpp_type=10,
label=1,
has_default_value=False,
default_value=None,
message_type=None,
enum_type=None,
containing_type=None,
is_extension=False,
extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='avd_name',
full_name='tools.android.avd.proto.Avd.avd_name',
index=4,
number=5,
type=9,
cpp_type=9,
label=1,
has_default_value=False,
default_value=_b("").decode('utf-8'),
message_type=None,
enum_type=None,
containing_type=None,
is_extension=False,
extension_scope=None,
options=None),
],
extensions=[],
nested_types=[],
enum_types=[],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[],
serialized_start=112,
serialized_end=353,
name='Avd',
full_name='tools.android.avd.proto.Avd',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='emulator_package', full_name='tools.android.avd.proto.Avd.emulator_package', index=0,
number=1, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='system_image_package', full_name='tools.android.avd.proto.Avd.system_image_package', index=1,
number=2, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='system_image_name', full_name='tools.android.avd.proto.Avd.system_image_name', index=2,
number=3, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='avd_package', full_name='tools.android.avd.proto.Avd.avd_package', index=3,
number=4, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='avd_name', full_name='tools.android.avd.proto.Avd.avd_name', index=4,
number=5, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='avd_settings', full_name='tools.android.avd.proto.Avd.avd_settings', index=5,
number=6, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=339,
serialized_end=640,
)
_AVDSETTINGS.fields_by_name['screen'].message_type = _SCREENSETTINGS
_AVDSETTINGS.fields_by_name['sdcard'].message_type = _SDCARDSETTINGS
_AVD.fields_by_name['emulator_package'].message_type = _CIPDPACKAGE
_AVD.fields_by_name['system_image_package'].message_type = _CIPDPACKAGE
_AVD.fields_by_name['avd_package'].message_type = _CIPDPACKAGE
_AVD.fields_by_name['avd_settings'].message_type = _AVDSETTINGS
DESCRIPTOR.message_types_by_name['CIPDPackage'] = _CIPDPACKAGE
DESCRIPTOR.message_types_by_name['ScreenSettings'] = _SCREENSETTINGS
DESCRIPTOR.message_types_by_name['SdcardSettings'] = _SDCARDSETTINGS
DESCRIPTOR.message_types_by_name['AvdSettings'] = _AVDSETTINGS
DESCRIPTOR.message_types_by_name['Avd'] = _AVD
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
CIPDPackage = _reflection.GeneratedProtocolMessageType(
'CIPDPackage',
(_message.Message, ),
dict(
DESCRIPTOR=_CIPDPACKAGE,
__module__='avd_pb2'
# @@protoc_insertion_point(class_scope:tools.android.avd.proto.CIPDPackage)
))
CIPDPackage = _reflection.GeneratedProtocolMessageType('CIPDPackage', (_message.Message,), dict(
DESCRIPTOR = _CIPDPACKAGE,
__module__ = 'avd_pb2'
# @@protoc_insertion_point(class_scope:tools.android.avd.proto.CIPDPackage)
))
_sym_db.RegisterMessage(CIPDPackage)
Avd = _reflection.GeneratedProtocolMessageType(
'Avd',
(_message.Message, ),
dict(
DESCRIPTOR=_AVD,
__module__='avd_pb2'
# @@protoc_insertion_point(class_scope:tools.android.avd.proto.Avd)
))
ScreenSettings = _reflection.GeneratedProtocolMessageType('ScreenSettings', (_message.Message,), dict(
DESCRIPTOR = _SCREENSETTINGS,
__module__ = 'avd_pb2'
# @@protoc_insertion_point(class_scope:tools.android.avd.proto.ScreenSettings)
))
_sym_db.RegisterMessage(ScreenSettings)
SdcardSettings = _reflection.GeneratedProtocolMessageType('SdcardSettings', (_message.Message,), dict(
DESCRIPTOR = _SDCARDSETTINGS,
__module__ = 'avd_pb2'
# @@protoc_insertion_point(class_scope:tools.android.avd.proto.SdcardSettings)
))
_sym_db.RegisterMessage(SdcardSettings)
AvdSettings = _reflection.GeneratedProtocolMessageType('AvdSettings', (_message.Message,), dict(
DESCRIPTOR = _AVDSETTINGS,
__module__ = 'avd_pb2'
# @@protoc_insertion_point(class_scope:tools.android.avd.proto.AvdSettings)
))
_sym_db.RegisterMessage(AvdSettings)
Avd = _reflection.GeneratedProtocolMessageType('Avd', (_message.Message,), dict(
DESCRIPTOR = _AVD,
__module__ = 'avd_pb2'
# @@protoc_insertion_point(class_scope:tools.android.avd.proto.Avd)
))
_sym_db.RegisterMessage(Avd)
# @@protoc_insertion_point(module_scope)