From 18a43ac47101072e0b2fa921fa22dafe02158ac6 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 13 Apr 2021 21:58:19 +0200 Subject: [PATCH] ignore system partition repos when checking for local repos The system partition repos like shipped with CalyxOS are not really visible to the user, they are built-in. So they should not prevent the warning banner showing when the user has switched Over Data and Over WiFi to never. --- .../org/fdroid/fdroid/views/StatusBanner.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/fdroid/fdroid/views/StatusBanner.java b/app/src/main/java/org/fdroid/fdroid/views/StatusBanner.java index 3adf112ee..9659b3bef 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/StatusBanner.java +++ b/app/src/main/java/org/fdroid/fdroid/views/StatusBanner.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.net.ConnectivityManager; +import android.net.Uri; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; @@ -16,6 +17,7 @@ import org.fdroid.fdroid.UpdateService; import org.fdroid.fdroid.data.Repo; import org.fdroid.fdroid.net.ConnectivityMonitorService; +import java.util.Arrays; import java.util.List; import androidx.localbroadcastmanager.content.LocalBroadcastManager; @@ -99,6 +101,16 @@ public class StatusBanner extends androidx.appcompat.widget.AppCompatTextView { preferences.unregisterOnSharedPreferenceChangeListener(dataWifiChangeListener); } + /** + * Display banner with specific text depending on updating status, network + * connectivity, and Data/WiFi Settings. This also takes into account + * whether there are local repos/mirrors available, e.g. if there is a + * mirror on a USB OTG thumb drive. Local repos on system partitions are + * not treated as local mirrors here, they are shipped as part of the + * device, and users are generally not aware of them. + * + * @see org.fdroid.fdroid.data.DBHelper#loadAdditionalRepos(String) + */ private void setBannerTextAndVisibility() { if (updateServiceStatus == UpdateService.STATUS_INFO) { setText(R.string.banner_updating_repositories); @@ -110,7 +122,17 @@ public class StatusBanner extends androidx.appcompat.widget.AppCompatTextView { } else if (overDataState == Preferences.OVER_NETWORK_NEVER && overWiFiState == Preferences.OVER_NETWORK_NEVER) { localRepos = UpdateService.getLocalRepos(getContext()); - if (localRepos.size() == 0) { + boolean hasLocalNonSystemRepos = true; + final List systemPartitions = Arrays.asList("odm", "oem", "product", "system", "vendor"); + for (Repo repo : localRepos) { + for (String segment : Uri.parse(repo.address).getPathSegments()) { + if (systemPartitions.contains(segment)) { + hasLocalNonSystemRepos = false; + } + break; // only check the first segment NOPMD + } + } + if (localRepos.size() == 0 || !hasLocalNonSystemRepos) { setText(R.string.banner_no_data_or_wifi); setVisibility(View.VISIBLE); } else {