Merge branch '2504-ipfs-optional' into 'master'

Make downloads from IPFS gateways opt-in

Closes #2504

See merge request fdroid/fdroidclient!1196
This commit is contained in:
Hans-Christoph Steiner
2023-02-23 09:00:08 +00:00
4 changed files with 17 additions and 3 deletions

View File

@@ -101,6 +101,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
public static final String PREF_UNSTABLE_UPDATES = "unstableUpdates";
public static final String PREF_KEEP_INSTALL_HISTORY = "keepInstallHistory";
public static final String PREF_SEND_TO_FDROID_METRICS = "sendToFdroidMetrics";
public static final String PREF_USE_IPFS_GATEWAYS = "useIpfsGateways";
public static final String PREF_EXPERT = "expert";
public static final String PREF_FORCE_OLD_INDEX = "forceOldIndex";
public static final String PREF_PRIVILEGED_INSTALLER = "privilegedInstaller";
@@ -517,6 +518,10 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
}
}
public boolean isIpfsEnabled() {
return preferences.getBoolean(PREF_USE_IPFS_GATEWAYS, IGNORED_B);
}
public boolean preventScreenshots() {
return preferences.getBoolean(PREF_PREVENT_SCREENSHOTS, IGNORED_B);
}

View File

@@ -65,7 +65,8 @@ public class DownloaderFactory extends org.fdroid.download.DownloaderFactory {
Proxy proxy = NetCipher.getProxy();
DownloadRequest request = new DownloadRequest(indexFile, mirrors, proxy,
repo.getUsername(), repo.getPassword(), tryFirst);
boolean oldIndex = Preferences.get().isForceOldIndexEnabled();
Preferences prefs = Preferences.get();
boolean oldIndex = prefs.isForceOldIndexEnabled();
boolean v1OrUnknown = repo.getFormatVersion() == null ||
repo.getFormatVersion() == IndexFormatVersion.ONE;
if (oldIndex || v1OrUnknown) {
@@ -73,9 +74,9 @@ public class DownloaderFactory extends org.fdroid.download.DownloaderFactory {
downloader = new HttpDownloader(HTTP_MANAGER, request, destFile);
} else {
DownloadRequest r;
if (request.getIndexFile().getIpfsCidV1() == null) r = request;
if (request.getIndexFile().getIpfsCidV1() == null || !prefs.isIpfsEnabled()) r = request;
else {
// add IPFS gateways to mirrors, because have have a CIDv1
// add IPFS gateways to mirrors, because have have a CIDv1 and IPFS is enabled in preferences
List<Mirror> m = new ArrayList<>(mirrors);
m.addAll(IPFS_MIRRORS);
r = new DownloadRequest(request.getIndexFile(), m, proxy, repo.getUsername(),

View File

@@ -40,6 +40,8 @@
<string name="keep_install_history_summary">Store a log of all installs and uninstalls in a private store</string>
<string name="send_to_fdroid_metrics">Send usage data</string>
<string name="send_to_fdroid_metrics_summary">Sends anonymous data weekly to F-Droid Metrics (requires "Keep install history")</string>
<string name="use_ipfs_gateways">Use IPFS gateways</string>
<string name="use_ipfs_gateways_summary">Download files from IPFS mirrors, if supported by the repo.</string>
<!-- message shown as a "toast" when the user enables the Send to F-Droid Metrics preference -->
<string name="toast_metrics_in_install_history">The %s Metric report is viewable in the Install History viewer</string>
<string name="send_version_and_uuid">Send version and UUID to servers</string>

View File

@@ -190,6 +190,12 @@
android:summary="@string/send_to_fdroid_metrics_summary"
android:defaultValue="false"
android:dependency="expert" />
<CheckBoxPreference
android:key="useIpfsGateways"
android:title="@string/use_ipfs_gateways"
android:summary="@string/use_ipfs_gateways_summary"
android:defaultValue="false"
android:dependency="expert" />
<CheckBoxPreference
android:key="hideAllNotifications"
android:title="@string/hide_all_notifications"