Skip to content

Support configurable emulator screen resolution #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand All @@ -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
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