Merge branch 'proxy-and-jenkins-script' into 'master'

HTTP Proxy preference for Tor, I2P, etc; add jenkins script

This adds a preference to set the HTTP Proxy so that FDroid can funnel all traffic through Tor, I2P, psiphon, or any other HTTP proxy.

Also, there is a script for jenkins to run before calling `ant clean debug` for the whole setup process.  This script sets the `versionCode` to the UNIX time in seconds, and adds the date/time to the `versionName` so that the debug builds are very clearly marked from real builds, and they will automatically update when included in a debug repo:
https://dev.guardianproject.info/issues/2601
This commit is contained in:
Peter Serwylo 2014-06-16 20:45:30 +00:00
commit d13a8c101a
7 changed files with 122 additions and 4 deletions

View File

@ -10,6 +10,8 @@
* use FDroid repos on Tor Hidden Services (.onion addresses)
* support for a HTTP Proxy in Preferences
* directly send installed apps to other devices via Bluetooth and Android Beam
(NFC+Bluetooth), also compatible with Samsung/HTC S-Beam

19
jenkins-build Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
#
# Jenkins uses this script to set up the ant build. Jenkins will then call
# ant itself once this script has completed.
set -e
set -x
# reset version code/name to current date
versionCodeDate=`date +%s`
versionNameDate=`date +%Y-%m-%d_%H.%M.%S`
sed -i \
-e "s,android:versionCode=\"[0-9][0-9]*\",android:versionCode=\"$versionCodeDate\"," \
-e "s,android:versionName=\"\([^\"][^\"]*\)\",android:versionName=\"\1.$versionNameDate\"," \
AndroidManifest.xml
. ~/.android/bashrc
./ant-prepare.sh

View File

@ -197,6 +197,14 @@
<string name="qr_wizard_download_instructions">Scan this QR Code to connect to the website for getting started.</string>
<string name="send_fdroid_via_wifi">Send FDroid via WiFi&#8230;</string>
<string name="proxy">Proxy</string>
<string name="enable_proxy_title">Enable HTTP Proxy</string>
<string name="enable_proxy_summary">Configure HTTP Proxy for all network requests</string>
<string name="proxy_host">Proxy Host</string>
<string name="proxy_host_summary">Configure your proxy\'s hostname (e.g. 127.0.0.1)</string>
<string name="proxy_port">Proxy Port</string>
<string name="proxy_port_summary">Configure your proxy\'s port number (e.g. 8118)</string>
<!--
status_download takes four parameters:
- Repository (url)

View File

@ -70,4 +70,19 @@
android:defaultValue="false"
android:key="systemInstaller" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/proxy" >
<CheckBoxPreference
android:defaultValue="false"
android:key="enableProxy"
android:title="@string/enable_proxy_title"
android:summary="@string/enable_proxy_summary" />
<EditTextPreference
android:key="proxyHost"
android:title="@string/proxy_host"
android:summary="@string/proxy_host_summary" />
<EditTextPreference
android:key="proxyPort"
android:title="@string/proxy_port"
android:summary="@string/proxy_port_summary" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -53,6 +53,9 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
public static final String PREF_LOCAL_REPO_BONJOUR = "localRepoBonjour";
public static final String PREF_LOCAL_REPO_NAME = "localRepoName";
public static final String PREF_LOCAL_REPO_HTTPS = "localRepoHttps";
public static final String PREF_ENABLE_PROXY = "enableProxy";
public static final String PREF_PROXY_HOST = "proxyHost";
public static final String PREF_PROXY_PORT = "proxyPort";
private static final boolean DEFAULT_COMPACT_LAYOUT = false;
private static final boolean DEFAULT_ROOTED = true;
@ -64,6 +67,9 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
private static final boolean DEFAULT_INCOMP_VER = false;
private static final boolean DEFAULT_EXPERT = false;
private static final boolean DEFAULT_PERMISSIONS = false;
private static final boolean DEFAULT_ENABLE_PROXY = false;
public static final String DEFAULT_PROXY_HOST = "127.0.0.1";
public static final int DEFAULT_PROXY_PORT = 8118;
private boolean compactLayout = DEFAULT_COMPACT_LAYOUT;
private boolean filterAppsRequiringRoot = DEFAULT_ROOTED;
@ -126,6 +132,28 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
return preferences.getString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName());
}
public boolean isProxyEnabled() {
return preferences.getBoolean(PREF_ENABLE_PROXY, DEFAULT_ENABLE_PROXY);
}
public String getProxyHost() {
return preferences.getString(PREF_PROXY_HOST, DEFAULT_PROXY_HOST);
}
public int getProxyPort() {
String port = preferences.getString(PREF_PROXY_PORT, String.valueOf(DEFAULT_PROXY_PORT));
try {
return Integer.parseInt(port);
} catch (NumberFormatException e) {
// hack until this can be a number-only preference
try {
return Integer.parseInt(port.replaceAll("[^0-9]", ""));
} catch (Exception e1) {
return DEFAULT_PROXY_PORT;
}
}
}
public boolean hasCompactLayout() {
if (!isInitialized(PREF_COMPACT_LAYOUT)) {
initialize(PREF_COMPACT_LAYOUT);

View File

@ -3,12 +3,17 @@ package org.fdroid.fdroid.net;
import android.content.Context;
import android.util.Log;
import org.fdroid.fdroid.Preferences;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.SocketAddress;
import java.net.URL;
import javax.net.ssl.SSLHandshakeException;
@ -70,7 +75,14 @@ public class HttpDownloader extends Downloader {
protected void setupConnection() throws IOException {
if (connection != null)
return;
connection = (HttpURLConnection) sourceUrl.openConnection();
Preferences prefs = Preferences.get();
if (prefs.isProxyEnabled()) {
SocketAddress sa = new InetSocketAddress(prefs.getProxyHost(), prefs.getProxyPort());
Proxy proxy = new Proxy(Proxy.Type.HTTP, sa);
connection = (HttpURLConnection) sourceUrl.openConnection(proxy);
} else {
connection = (HttpURLConnection) sourceUrl.openConnection();
}
}
protected void doDownload() throws IOException, InterruptedException {

View File

@ -7,6 +7,8 @@ import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.text.TextUtils;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.PreferencesActivity;
import org.fdroid.fdroid.R;
@ -34,7 +36,10 @@ public class PreferenceFragment
Preferences.PREF_CACHE_APK,
Preferences.PREF_EXPERT,
Preferences.PREF_ROOT_INSTALLER,
Preferences.PREF_SYSTEM_INSTALLER
Preferences.PREF_SYSTEM_INSTALLER,
Preferences.PREF_ENABLE_PROXY,
Preferences.PREF_PROXY_HOST,
Preferences.PREF_PROXY_PORT,
};
@Override
@ -144,6 +149,35 @@ public class PreferenceFragment
onoffSummary(key, R.string.system_installer_on,
R.string.system_installer_off);
} else if (key.equals(Preferences.PREF_ENABLE_PROXY)) {
CheckBoxPreference pref = (CheckBoxPreference) findPreference(key);
pref.setSummary(R.string.enable_proxy_summary);
Preference h = findPreference(Preferences.PREF_PROXY_HOST);
Preference p = findPreference(Preferences.PREF_PROXY_PORT);
if (pref.isChecked()) {
h.setEnabled(true);
p.setEnabled(true);
} else {
h.setEnabled(false);
p.setEnabled(false);
}
} else if (key.equals(Preferences.PREF_PROXY_HOST)) {
EditTextPreference textPref = (EditTextPreference) findPreference(key);
String text = Preferences.get().getProxyHost();
if (TextUtils.isEmpty(text) || text.equals(Preferences.DEFAULT_PROXY_HOST))
textPref.setSummary(R.string.proxy_host_summary);
else
textPref.setSummary(text);
} else if (key.equals(Preferences.PREF_PROXY_PORT)) {
EditTextPreference textPref = (EditTextPreference) findPreference(key);
int port = Preferences.get().getProxyPort();
if (port == Preferences.DEFAULT_PROXY_PORT)
textPref.setSummary(R.string.proxy_port_summary);
else
textPref.setSummary(String.valueOf(port));
}
}