From f9a140977ffa113aadf768dfd48670be9c25d630 Mon Sep 17 00:00:00 2001 From: "Johnny.H" Date: Fri, 18 Dec 2020 14:57:07 +0800 Subject: [PATCH 1/3] Support configurable emulator screen resolution --- emu/docker_device.py | 34 ++++++++++++++++++++++--- emu/emu_docker.py | 5 ++-- emu/templates/avd/Pixel2.avd/config.ini | 6 ++--- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/emu/docker_device.py b/emu/docker_device.py index 46febcad..c4d19da7 100644 --- a/emu/docker_device.py +++ b/emu/docker_device.py @@ -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 @@ -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. @@ -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) @@ -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'] }, ) diff --git a/emu/emu_docker.py b/emu/emu_docker.py index fd212b04..5d316126 100644 --- a/emu/emu_docker.py +++ b/emu/emu_docker.py @@ -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 @@ -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) diff --git a/emu/templates/avd/Pixel2.avd/config.ini b/emu/templates/avd/Pixel2.avd/config.ini index 39825e89..fd75183d 100644 --- a/emu/templates/avd/Pixel2.avd/config.ini +++ b/emu/templates/avd/Pixel2.avd/config.ini @@ -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 From 7df3ed58a0e1c096a8ff488a72b58cb97a6ec06f Mon Sep 17 00:00:00 2001 From: "Johnny.H" Date: Mon, 1 Mar 2021 18:21:01 +0800 Subject: [PATCH 2/3] add iputils-ping --- emu/templates/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emu/templates/Dockerfile b/emu/templates/Dockerfile index 22f0b10f..ed99153a 100644 --- a/emu/templates/Dockerfile +++ b/emu/templates/Dockerfile @@ -23,7 +23,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libnss3 libxcomposite1 libxcursor1 libxi6 \ libxext6 libxfixes3 zlib1g libgl1 pulseaudio socat \ # Enable turncfg through usage of curl - curl ca-certificates && \ + curl ca-certificates iputils-ping && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* From 1f8de23d448f8efc7834db9c03b56dc94a69917a Mon Sep 17 00:00:00 2001 From: "Johnny.H" Date: Tue, 2 Mar 2021 13:48:56 +0800 Subject: [PATCH 3/3] disable ports 8554 and 5554 --- emu/templates/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/emu/templates/Dockerfile b/emu/templates/Dockerfile index ed99153a..f1413d00 100644 --- a/emu/templates/Dockerfile +++ b/emu/templates/Dockerfile @@ -50,13 +50,13 @@ COPY sys/ /android/sdk/system-images/android/ # RUN --security=insecure cd /android/sdk && ./launch-emulator.sh -quit-after-boot 120 # This is the console port, you usually want to keep this closed. -EXPOSE 5554 +# EXPOSE 5554 # This is the ADB port, useful. EXPOSE 5555 # This is the gRPC port, also useful, we don't want ADB to incorrectly identify this. -EXPOSE 8554 +# EXPOSE 8554 ENV ANDROID_SDK_ROOT /android/sdk ENV ANDROID_AVD_HOME /android-home