Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions emu/docker_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import socket
import sys
import zipfile

import click
import docker
from jinja2 import Environment, PackageLoader
from packaging import version
from tqdm import tqdm

from consolemenu import SelectionMenu
import emu
from emu.emu_downloads_menu import AndroidReleaseZip, PlatformTools
from emu.template_writer import TemplateWriter
Expand Down Expand Up @@ -91,6 +91,28 @@ def extract_zip(fname, path):
os.chmod(filename, mode)


DEFAULT_RESOLUTION = {'width': 1080, 'height': 1920, 'density': 440}


def select_emulator_resolution():
while True:
selection = SelectionMenu.get_selection(['Default - {} x {}: {}dpi'.format(*DEFAULT_RESOLUTION.values()),
'Customize...'],
title="Select the emulator screen resolution:")
if selection == 0:
return DEFAULT_RESOLUTION
elif selection == 1:
width = click.prompt('Please enter emulator screen width', type=int)
height = click.prompt('Please enter emulator screen height', type=int)
density = click.prompt('Please enter emulator screen density', type=int)
customized_resolution = {'width': width, 'height': height, 'density': density}
if click.confirm("Please confirm your emulator screen resolution - {} x {}: {}dpi.".
format(*customized_resolution.values())):
return customized_resolution
elif selection == 2:
sys.exit(1)


class DockerDevice(object):
"""A Docker Device is capable of creating and launching docker images.

Expand Down Expand Up @@ -233,7 +255,10 @@ def bin_place_emulator_files(self, by_copying_zip_files):
extract_zip(self.sysimg.fname, os.path.join(self.dest, "sys"))
logging.info("Done unzipping")

def create_docker_file(self, extra="", metrics=False, by_copying_zip_files=False):
def create_docker_file(self, extra="", metrics=False, by_copying_zip_files=False,
screen_resolution=None):
if screen_resolution is None:
screen_resolution = DEFAULT_RESOLUTION
if type(extra) is list:
extra = " ".join(extra)
logging.info("Emulator zip: %s", self.emulator)
Expand All @@ -256,6 +281,9 @@ def create_docker_file(self, extra="", metrics=False, by_copying_zip_files=False
"abi": self.sysimg.abi(),
"cpu": self.sysimg.cpu(),
"tag": self.sysimg.tag(),
'width': screen_resolution['width'],
'height': screen_resolution['height'],
'density': screen_resolution['density']
},
)

Expand Down
5 changes: 3 additions & 2 deletions emu/emu_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import emu
import emu.emu_downloads_menu as emu_downloads_menu
from emu.docker_config import DockerConfig
from emu.docker_device import DockerDevice
from emu.docker_device import DockerDevice, select_emulator_resolution
from emu.cloud_build import cloud_build
from emu.utils import mkdir_p

Expand Down Expand Up @@ -125,7 +125,8 @@ def create_docker_image_interactive(args):
img_zip = img.download()
emu_zip = emulator.download("linux")
device = DockerDevice(emu_zip, img_zip, args.dest, args.gpu)
device.create_docker_file(args.extra, metrics)
emu_resolution = select_emulator_resolution()
device.create_docker_file(args.extra, metrics, screen_resolution=emu_resolution)
img = device.create_container()
if img and args.start:
device.launch(img)
Expand Down
6 changes: 3 additions & 3 deletions emu/templates/avd/Pixel2.avd/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ runtime.network.speed=full
vm.heapSize=512
tag.display=Google APIs
# Set some
hw.lcd.density=440
hw.lcd.height=1920
hw.lcd.width=1080
hw.lcd.density={{density}}
hw.lcd.height={{height}}
hw.lcd.width={{width}}
# Unused
# hw.sdCard=yes
# sdcard.size=512M
Expand Down