Merge "Support VPN Proxy(2/2)" am: 2a695c4b7b
am: e2f74af063
am: aa5d185d7b
Change-Id: Ifa4ac76f78e24296a29f99f5733075651bed9072
This commit is contained in:
@@ -140,6 +140,46 @@
|
|||||||
android:labelFor="@+id/routes"/>
|
android:labelFor="@+id/routes"/>
|
||||||
<EditText style="@style/vpn_value" android:id="@+id/routes"
|
<EditText style="@style/vpn_value" android:id="@+id/routes"
|
||||||
android:hint="@string/vpn_not_used"/>
|
android:hint="@string/vpn_not_used"/>
|
||||||
|
|
||||||
|
<TextView android:id="@+id/vpn_proxy_settings_title"
|
||||||
|
style="@style/vpn_label"
|
||||||
|
android:text="@string/proxy_settings_title"
|
||||||
|
android:labelFor="@+id/vpn_proxy_settings" />
|
||||||
|
|
||||||
|
<Spinner android:id="@+id/vpn_proxy_settings"
|
||||||
|
style="@style/vpn_value"
|
||||||
|
android:prompt="@string/proxy_settings_title"
|
||||||
|
android:entries="@array/vpn_proxy_settings" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/vpn_proxy_fields"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:visibility="gone" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/vpn_label"
|
||||||
|
android:text="@string/proxy_hostname_label"
|
||||||
|
android:labelFor="@+id/vpn_proxy_host" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/vpn_proxy_host"
|
||||||
|
style="@style/vpn_value"
|
||||||
|
android:hint="@string/proxy_hostname_hint"
|
||||||
|
android:inputType="textNoSuggestions" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/vpn_label"
|
||||||
|
android:text="@string/proxy_port_label"
|
||||||
|
android:labelFor="@+id/vpn_proxy_port" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/vpn_proxy_port"
|
||||||
|
style="@style/vpn_value"
|
||||||
|
android:hint="@string/proxy_port_hint"
|
||||||
|
android:inputType="number" />
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout android:id="@+id/login"
|
<LinearLayout android:id="@+id/login"
|
||||||
|
@@ -931,6 +931,14 @@
|
|||||||
<item>IPSec VPN with certificates and hybrid authentication</item>
|
<item>IPSec VPN with certificates and hybrid authentication</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<!-- VPN proxy settings. -->
|
||||||
|
<string-array name="vpn_proxy_settings">
|
||||||
|
<!-- No HTTP proxy is used for the current VPN [CHAR LIMIT=25] -->
|
||||||
|
<item>None</item>
|
||||||
|
<!-- Manual HTTP proxy settings are used for the current VPN [CHAR LIMIT=25] -->
|
||||||
|
<item>Manual</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<!-- Match this with the constants in LegacyVpnInfo. --> <skip />
|
<!-- Match this with the constants in LegacyVpnInfo. --> <skip />
|
||||||
<!-- Status for a VPN network. [CHAR LIMIT=100] -->
|
<!-- Status for a VPN network. [CHAR LIMIT=100] -->
|
||||||
<string-array name="vpn_states">
|
<string-array name="vpn_states">
|
||||||
|
@@ -18,6 +18,8 @@ package com.android.settings.vpn2;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.net.Proxy;
|
||||||
|
import android.net.ProxyInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.security.Credentials;
|
import android.security.Credentials;
|
||||||
@@ -67,6 +69,9 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
|
|||||||
private TextView mSearchDomains;
|
private TextView mSearchDomains;
|
||||||
private TextView mDnsServers;
|
private TextView mDnsServers;
|
||||||
private TextView mRoutes;
|
private TextView mRoutes;
|
||||||
|
private Spinner mProxySettings;
|
||||||
|
private TextView mProxyHost;
|
||||||
|
private TextView mProxyPort;
|
||||||
private CheckBox mMppe;
|
private CheckBox mMppe;
|
||||||
private TextView mL2tpSecret;
|
private TextView mL2tpSecret;
|
||||||
private TextView mIpsecIdentifier;
|
private TextView mIpsecIdentifier;
|
||||||
@@ -105,6 +110,9 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
|
|||||||
mSearchDomains = (TextView) mView.findViewById(R.id.search_domains);
|
mSearchDomains = (TextView) mView.findViewById(R.id.search_domains);
|
||||||
mDnsServers = (TextView) mView.findViewById(R.id.dns_servers);
|
mDnsServers = (TextView) mView.findViewById(R.id.dns_servers);
|
||||||
mRoutes = (TextView) mView.findViewById(R.id.routes);
|
mRoutes = (TextView) mView.findViewById(R.id.routes);
|
||||||
|
mProxySettings = (Spinner) mView.findViewById(R.id.vpn_proxy_settings);
|
||||||
|
mProxyHost = (TextView) mView.findViewById(R.id.vpn_proxy_host);
|
||||||
|
mProxyPort = (TextView) mView.findViewById(R.id.vpn_proxy_port);
|
||||||
mMppe = (CheckBox) mView.findViewById(R.id.mppe);
|
mMppe = (CheckBox) mView.findViewById(R.id.mppe);
|
||||||
mL2tpSecret = (TextView) mView.findViewById(R.id.l2tp_secret);
|
mL2tpSecret = (TextView) mView.findViewById(R.id.l2tp_secret);
|
||||||
mIpsecIdentifier = (TextView) mView.findViewById(R.id.ipsec_identifier);
|
mIpsecIdentifier = (TextView) mView.findViewById(R.id.ipsec_identifier);
|
||||||
@@ -128,6 +136,11 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
|
|||||||
mSearchDomains.setText(mProfile.searchDomains);
|
mSearchDomains.setText(mProfile.searchDomains);
|
||||||
mDnsServers.setText(mProfile.dnsServers);
|
mDnsServers.setText(mProfile.dnsServers);
|
||||||
mRoutes.setText(mProfile.routes);
|
mRoutes.setText(mProfile.routes);
|
||||||
|
if (mProfile.proxy != null) {
|
||||||
|
mProxyHost.setText(mProfile.proxy.getHost());
|
||||||
|
int port = mProfile.proxy.getPort();
|
||||||
|
mProxyPort.setText(port == 0 ? "" : Integer.toString(port));
|
||||||
|
}
|
||||||
mMppe.setChecked(mProfile.mppe);
|
mMppe.setChecked(mProfile.mppe);
|
||||||
mL2tpSecret.setText(mProfile.l2tpSecret);
|
mL2tpSecret.setText(mProfile.l2tpSecret);
|
||||||
mIpsecIdentifier.setText(mProfile.ipsecIdentifier);
|
mIpsecIdentifier.setText(mProfile.ipsecIdentifier);
|
||||||
@@ -153,6 +166,9 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
|
|||||||
mPassword.addTextChangedListener(this);
|
mPassword.addTextChangedListener(this);
|
||||||
mDnsServers.addTextChangedListener(this);
|
mDnsServers.addTextChangedListener(this);
|
||||||
mRoutes.addTextChangedListener(this);
|
mRoutes.addTextChangedListener(this);
|
||||||
|
mProxySettings.setOnItemSelectedListener(this);
|
||||||
|
mProxyHost.addTextChangedListener(this);
|
||||||
|
mProxyPort.addTextChangedListener(this);
|
||||||
mIpsecSecret.addTextChangedListener(this);
|
mIpsecSecret.addTextChangedListener(this);
|
||||||
mIpsecUserCert.setOnItemSelectedListener(this);
|
mIpsecUserCert.setOnItemSelectedListener(this);
|
||||||
mShowOptions.setOnClickListener(this);
|
mShowOptions.setOnClickListener(this);
|
||||||
@@ -175,7 +191,8 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
|
|||||||
|
|
||||||
// Switch to advanced view immediately if any advanced options are on
|
// Switch to advanced view immediately if any advanced options are on
|
||||||
if (!mProfile.searchDomains.isEmpty() || !mProfile.dnsServers.isEmpty() ||
|
if (!mProfile.searchDomains.isEmpty() || !mProfile.dnsServers.isEmpty() ||
|
||||||
!mProfile.routes.isEmpty()) {
|
!mProfile.routes.isEmpty() || (mProfile.proxy != null &&
|
||||||
|
(!mProfile.proxy.getHost().isEmpty() || mProfile.proxy.getPort() != 0))) {
|
||||||
showAdvancedOptions();
|
showAdvancedOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,6 +263,8 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
|
|||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
if (parent == mType) {
|
if (parent == mType) {
|
||||||
changeType(position);
|
changeType(position);
|
||||||
|
} else if (parent == mProxySettings) {
|
||||||
|
updateProxyFieldsVisibility(position);
|
||||||
}
|
}
|
||||||
updateUiControls();
|
updateUiControls();
|
||||||
}
|
}
|
||||||
@@ -271,6 +290,7 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
|
|||||||
* These include:
|
* These include:
|
||||||
* "Always-on VPN" checkbox
|
* "Always-on VPN" checkbox
|
||||||
* Reason for "Always-on VPN" being disabled, when necessary
|
* Reason for "Always-on VPN" being disabled, when necessary
|
||||||
|
* Proxy info if manually configured
|
||||||
* "Save account information" checkbox
|
* "Save account information" checkbox
|
||||||
* "Save" and "Connect" buttons
|
* "Save" and "Connect" buttons
|
||||||
*/
|
*/
|
||||||
@@ -298,6 +318,13 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
|
|||||||
mAlwaysOnInvalidReason.setVisibility(View.VISIBLE);
|
mAlwaysOnInvalidReason.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show proxy fields if any proxy field is filled.
|
||||||
|
if (mProfile.proxy != null && (!mProfile.proxy.getHost().isEmpty() ||
|
||||||
|
mProfile.proxy.getPort() != 0)) {
|
||||||
|
mProxySettings.setSelection(VpnProfile.PROXY_MANUAL);
|
||||||
|
updateProxyFieldsVisibility(VpnProfile.PROXY_MANUAL);
|
||||||
|
}
|
||||||
|
|
||||||
// Save account information
|
// Save account information
|
||||||
if (mAlwaysOnVpn.isChecked()) {
|
if (mAlwaysOnVpn.isChecked()) {
|
||||||
mSaveLogin.setChecked(true);
|
mSaveLogin.setChecked(true);
|
||||||
@@ -311,6 +338,11 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
|
|||||||
getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(validate(mEditing));
|
getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(validate(mEditing));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateProxyFieldsVisibility(int position) {
|
||||||
|
final int visible = position == VpnProfile.PROXY_MANUAL ? View.VISIBLE : View.GONE;
|
||||||
|
mView.findViewById(R.id.vpn_proxy_fields).setVisibility(visible);
|
||||||
|
}
|
||||||
|
|
||||||
private void showAdvancedOptions() {
|
private void showAdvancedOptions() {
|
||||||
mView.findViewById(R.id.options).setVisibility(View.VISIBLE);
|
mView.findViewById(R.id.options).setVisibility(View.VISIBLE);
|
||||||
mShowOptions.setVisibility(View.GONE);
|
mShowOptions.setVisibility(View.GONE);
|
||||||
@@ -361,6 +393,11 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
|
|||||||
!validateAddresses(mRoutes.getText().toString(), true)) {
|
!validateAddresses(mRoutes.getText().toString(), true)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!validateProxy()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (mType.getSelectedItemPosition()) {
|
switch (mType.getSelectedItemPosition()) {
|
||||||
case VpnProfile.TYPE_PPTP:
|
case VpnProfile.TYPE_PPTP:
|
||||||
case VpnProfile.TYPE_IPSEC_HYBRID_RSA:
|
case VpnProfile.TYPE_IPSEC_HYBRID_RSA:
|
||||||
@@ -435,6 +472,10 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
|
|||||||
return mEditing;
|
return mEditing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean hasProxy() {
|
||||||
|
return mProxySettings.getSelectedItemPosition() == VpnProfile.PROXY_MANUAL;
|
||||||
|
}
|
||||||
|
|
||||||
VpnProfile getProfile() {
|
VpnProfile getProfile() {
|
||||||
// First, save common fields.
|
// First, save common fields.
|
||||||
VpnProfile profile = new VpnProfile(mProfile.key);
|
VpnProfile profile = new VpnProfile(mProfile.key);
|
||||||
@@ -446,7 +487,16 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
|
|||||||
profile.searchDomains = mSearchDomains.getText().toString().trim();
|
profile.searchDomains = mSearchDomains.getText().toString().trim();
|
||||||
profile.dnsServers = mDnsServers.getText().toString().trim();
|
profile.dnsServers = mDnsServers.getText().toString().trim();
|
||||||
profile.routes = mRoutes.getText().toString().trim();
|
profile.routes = mRoutes.getText().toString().trim();
|
||||||
|
if (hasProxy()) {
|
||||||
|
String proxyHost = mProxyHost.getText().toString().trim();
|
||||||
|
String proxyPort = mProxyPort.getText().toString().trim();
|
||||||
|
// 0 is a last resort default, but the interface validates that the proxy port is
|
||||||
|
// present and non-zero.
|
||||||
|
int port = proxyPort.isEmpty() ? 0 : Integer.parseInt(proxyPort);
|
||||||
|
profile.proxy = new ProxyInfo(proxyHost, port, null);
|
||||||
|
} else {
|
||||||
|
profile.proxy = null;
|
||||||
|
}
|
||||||
// Then, save type-specific fields.
|
// Then, save type-specific fields.
|
||||||
switch (profile.type) {
|
switch (profile.type) {
|
||||||
case VpnProfile.TYPE_PPTP:
|
case VpnProfile.TYPE_PPTP:
|
||||||
@@ -483,4 +533,15 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
|
|||||||
profile.saveLogin = mSaveLogin.isChecked() || (mEditing && hasLogin);
|
profile.saveLogin = mSaveLogin.isChecked() || (mEditing && hasLogin);
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean validateProxy() {
|
||||||
|
if (!hasProxy()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String host = mProxyHost.getText().toString().trim();
|
||||||
|
final String port = mProxyPort.getText().toString().trim();
|
||||||
|
return Proxy.validate(host, port, "") == Proxy.PROXY_VALID;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user