From 3e8416123a22d4c556ed77678e52be55835cfa23 Mon Sep 17 00:00:00 2001 From: JP Cottin Date: Mon, 11 Oct 2021 18:41:26 +0200 Subject: [PATCH 1/2] emu_downloads, platform_tools: add ANDROID_REPOSITORY base URL override Introduces an ANDROID_REPOSITORY environment variable, defaulting to https://dl.google.com, as the base URL for all system-image catalog fetches (sys-img2-5.xml), the emulator repo catalog (repository2-1.xml), per-package system-image zip downloads, and the platform-tools download. Lets users behind corporate proxies, in air-gapped environments, or in regions where Google's CDN is slow or unreachable point at a mirror instead. Original implementation by Greger Stolt Nilsen from #359; cherry-picked onto current master with conflict resolutions to preserve current master's sys-img2-5.xml index version and the url_dir routing logic for 16KB-page sysimg URLs. --- emu/emu_downloads_menu.py | 19 +++++++++++-------- emu/platform_tools.py | 4 +++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/emu/emu_downloads_menu.py b/emu/emu_downloads_menu.py index 36232d3e..b8f549e2 100644 --- a/emu/emu_downloads_menu.py +++ b/emu/emu_downloads_menu.py @@ -27,15 +27,17 @@ from emu.utils import download from emu.docker_config import DockerConfig +ANDROID_REPOSITORY = os.environ.get("ANDROID_REPOSITORY", "https://dl.google.com/") + SYSIMG_REPOS = [ - "https://dl.google.com/android/repository/sys-img/android/sys-img2-5.xml", - "https://dl.google.com/android/repository/sys-img/google_apis/sys-img2-5.xml", - "https://dl.google.com/android/repository/sys-img/google_apis_playstore/sys-img2-5.xml", - "https://dl.google.com/android/repository/sys-img/google_atd/sys-img2-5.xml", - "https://dl.google.com/android/repository/sys-img/android-tv/sys-img2-5.xml", + "%s/android/repository/sys-img/android/sys-img2-5.xml" % ANDROID_REPOSITORY, + "%s/android/repository/sys-img/google_apis/sys-img2-5.xml" % ANDROID_REPOSITORY, + "%s/android/repository/sys-img/google_apis_playstore/sys-img2-5.xml" % ANDROID_REPOSITORY, + "%s/android/repository/sys-img/google_atd/sys-img2-5.xml" % ANDROID_REPOSITORY, + "%s/android/repository/sys-img/android-tv/sys-img2-5.xml" % ANDROID_REPOSITORY, ] -EMU_REPOS = ["https://dl.google.com/android/repository/repository2-1.xml"] +EMU_REPOS = ["%s/android/repository/repository2-1.xml" % ANDROID_REPOSITORY] CHANNEL_MAPPING = { "channel-0": "stable", @@ -193,7 +195,8 @@ def __init__(self, pkg, licenses): # the element is labelled — for 16KB variants the path # sort is e.g. google_apis_ps16k, served from .../google_apis/. url_dir = sort_base or self.tag - self.url = "https://dl.google.com/android/repository/sys-img/%s/%s" % ( + self.url = "%s/android/repository/sys-img/%s/%s" % ( + ANDROID_REPOSITORY, url_dir, self.zip, ) @@ -252,7 +255,7 @@ def __init__(self, pkg, licenses): for archive in archives: url = archive.find(".//url").text hostos = archive.find("host-os").text - self.urls[hostos] = "https://dl.google.com/android/repository/%s" % url + self.urls[hostos] = "%s/android/repository/%s" % (ANDROID_REPOSITORY, url) def download_name(self): return "emulator-{}.zip".format(self.version) diff --git a/emu/platform_tools.py b/emu/platform_tools.py index f1dafdf2..a29b65a2 100644 --- a/emu/platform_tools.py +++ b/emu/platform_tools.py @@ -11,18 +11,20 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import os import zipfile from pathlib import Path from emu.utils import download +ANDROID_REPOSITORY = os.environ.get("ANDROID_REPOSITORY", "https://dl.google.com") class PlatformTools(object): """The platform tools zip file. It will be downloaded on demand.""" # Platform tools, needed to get adb. PLATFORM_TOOLS_URL = ( - "https://dl.google.com/android/repository/platform-tools_r29.0.5-linux.zip" + '%s/android/repository/platform-tools_r29.0.5-linux.zip' % ANDROID_REPOSITORY ) PLATFORM_TOOLS_ZIP = "platform-tools-latest-linux.zip" From 3c7ae132c7e3eb73161a16dea670f37ccfe07c59 Mon Sep 17 00:00:00 2001 From: JP Cottin Date: Sat, 16 May 2026 14:38:57 -0700 Subject: [PATCH 2/2] emu_downloads_menu, platform_tools: normalize ANDROID_REPOSITORY trailing slash The two modules disagreed on whether the default base URL had a trailing slash (`https://dl.google.com/` vs `https://dl.google.com`). Combined with format strings that start with `/android/...`, the slashed default produced double-slash URLs (`https://dl.google.com//android/...`). Servers usually tolerate this, but it's ugly in logs and breaks any exact-match logic downstream. Drop the trailing slash from both defaults, and `.rstrip("/")` the env-var value so user-supplied bases with a trailing slash also produce clean URLs. --- emu/emu_downloads_menu.py | 2 +- emu/platform_tools.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/emu/emu_downloads_menu.py b/emu/emu_downloads_menu.py index b8f549e2..5ace94c6 100644 --- a/emu/emu_downloads_menu.py +++ b/emu/emu_downloads_menu.py @@ -27,7 +27,7 @@ from emu.utils import download from emu.docker_config import DockerConfig -ANDROID_REPOSITORY = os.environ.get("ANDROID_REPOSITORY", "https://dl.google.com/") +ANDROID_REPOSITORY = os.environ.get("ANDROID_REPOSITORY", "https://dl.google.com").rstrip("/") SYSIMG_REPOS = [ "%s/android/repository/sys-img/android/sys-img2-5.xml" % ANDROID_REPOSITORY, diff --git a/emu/platform_tools.py b/emu/platform_tools.py index a29b65a2..dd6e0016 100644 --- a/emu/platform_tools.py +++ b/emu/platform_tools.py @@ -17,7 +17,7 @@ from emu.utils import download -ANDROID_REPOSITORY = os.environ.get("ANDROID_REPOSITORY", "https://dl.google.com") +ANDROID_REPOSITORY = os.environ.get("ANDROID_REPOSITORY", "https://dl.google.com").rstrip("/") class PlatformTools(object): """The platform tools zip file. It will be downloaded on demand."""