From 84635ee73556f8f1689c005c80823820dc1efd04 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Mon, 6 May 2024 11:32:33 -0300 Subject: [PATCH] [app] construct proper URI for non-HTTP repos so the DownloaderFactory has a chance to instantiate a different non-HTTP Downloader. --- .../main/java/org/fdroid/fdroid/Utils.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/Utils.java b/app/src/main/java/org/fdroid/fdroid/Utils.java index 7fef8bc62..730754490 100644 --- a/app/src/main/java/org/fdroid/fdroid/Utils.java +++ b/app/src/main/java/org/fdroid/fdroid/Utils.java @@ -21,6 +21,7 @@ package org.fdroid.fdroid; import android.content.ClipData; import android.content.ClipboardManager; +import android.content.ContentResolver; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; @@ -161,16 +162,29 @@ public final class Utils { /** * Returns the repository address. Usually this is {@link Repository#getAddress()}, - * but in case of a content:// repo, we need to take its local Uri instead. + * but in case of a content:// repo, we need to take its local Uri instead, + * so we can know that we need to use different downloaders for non-HTTP locations. */ public static String getRepoAddress(Repository repository) { - List mirrors = repository.getAllMirrors(); - if (mirrors.size() == 2 && mirrors.get(1).getBaseUrl().startsWith("content://")) { - return mirrors.get(1).getBaseUrl(); - } else { + List mirrors = repository.getMirrors(); + // check if we need to account for non-HTTP mirrors + String nonHttpUri = null; + for (Mirror m : mirrors) { + if (ContentResolver.SCHEME_CONTENT.equals(m.getUrl().getProtocol().getName())) { + nonHttpUri = m.getBaseUrl(); + break; + } else if (ContentResolver.SCHEME_FILE.equals(m.getUrl().getProtocol().getName())) { + nonHttpUri = m.getBaseUrl(); + break; + } + } + // return normal canonical URL, if this is a pure HTTP repo + if (nonHttpUri == null) { String address = repository.getAddress(); if (address.endsWith("/")) return address.substring(0, address.length() - 1); return address; + } else { + return nonHttpUri; } }