summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/vpn2
diff options
context:
space:
mode:
authorChia-chi Yeh <chiachi@android.com>2011-07-04 03:17:33 -0700
committerChia-chi Yeh <chiachi@android.com>2011-07-04 03:35:39 -0700
commit97fd85fd9776f3fb5c35217e82bcbcb5aea8416d (patch)
treedf4b02efc82caf9c2aa231b06b5b54a60a1ba213 /src/com/android/settings/vpn2
parent5c9e37c295a0219731882eca7a8805a08a439c34 (diff)
downloadpackages_apps_settings-97fd85fd9776f3fb5c35217e82bcbcb5aea8416d.zip
packages_apps_settings-97fd85fd9776f3fb5c35217e82bcbcb5aea8416d.tar.gz
packages_apps_settings-97fd85fd9776f3fb5c35217e82bcbcb5aea8416d.tar.bz2
VpnSettings: add status report.
Change-Id: Ia050d997524b39868e6acce82d12b0415909ab77
Diffstat (limited to 'src/com/android/settings/vpn2')
-rw-r--r--src/com/android/settings/vpn2/VpnSettings.java84
1 files changed, 56 insertions, 28 deletions
diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java
index 0153f9b..7f6c9f4 100644
--- a/src/com/android/settings/vpn2/VpnSettings.java
+++ b/src/com/android/settings/vpn2/VpnSettings.java
@@ -37,6 +37,7 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.AdapterContextMenuInfo;
+import com.android.internal.net.LegacyVpnInfo;
import com.android.internal.net.VpnConfig;
import com.android.settings.SettingsPreferenceFragment;
@@ -49,13 +50,8 @@ public class VpnSettings extends SettingsPreferenceFragment implements
private static final String TAG = "VpnSettings";
- // Match these constants with R.array.vpn_states.
- private static final int STATE_NONE = -1;
- private static final int STATE_CONNECTING = 0;
- private static final int STATE_CONNECTED = 1;
- private static final int STATE_DISCONNECTED = 2;
- private static final int STATE_FAILED = 3;
-
+ private final IConnectivityManager mService = IConnectivityManager.Stub
+ .asInterface(ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
private final KeyStore mKeyStore = KeyStore.getInstance();
private boolean mUnlocking = false;
@@ -63,6 +59,7 @@ public class VpnSettings extends SettingsPreferenceFragment implements
private VpnDialog mDialog;
private Handler mUpdater;
+ private LegacyVpnInfo mInfo;
// The key of the profile for the current ContextMenu.
private String mSelectedKey;
@@ -263,8 +260,17 @@ public class VpnSettings extends SettingsPreferenceFragment implements
}
if (preference instanceof VpnPreference) {
- mDialog = new VpnDialog(getActivity(), this,
- ((VpnPreference) preference).getProfile(), false);
+ VpnProfile profile = ((VpnPreference) preference).getProfile();
+ if (mInfo != null && profile.key.equals(mInfo.key) &&
+ mInfo.state == LegacyVpnInfo.STATE_CONNECTED) {
+ try {
+ mInfo.intent.send();
+ return true;
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ mDialog = new VpnDialog(getActivity(), this, profile, false);
} else {
// Generate a new key. Here we just use the current time.
long millis = System.currentTimeMillis();
@@ -284,20 +290,30 @@ public class VpnSettings extends SettingsPreferenceFragment implements
mUpdater.removeMessages(0);
if (isResumed()) {
-
-
-
-
+ try {
+ LegacyVpnInfo info = mService.getLegacyVpnInfo();
+ if (mInfo != null) {
+ VpnPreference preference = mPreferences.get(mInfo.key);
+ if (preference != null) {
+ preference.update(-1);
+ }
+ mInfo = null;
+ }
+ if (info != null) {
+ VpnPreference preference = mPreferences.get(info.key);
+ if (preference != null) {
+ preference.update(info.state);
+ mInfo = info;
+ }
+ }
+ } catch (Exception e) {
+ // ignore
+ }
mUpdater.sendEmptyMessageDelayed(0, 1000);
}
return true;
}
- private static IConnectivityManager getService() {
- return IConnectivityManager.Stub.asInterface(
- ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
- }
-
private void connect(VpnProfile profile) {
String[] racoon = null;
switch (profile.type) {
@@ -346,6 +362,7 @@ public class VpnSettings extends SettingsPreferenceFragment implements
}
VpnConfig config = new VpnConfig();
+ config.packagz = profile.key;
config.session = profile.name;
config.routes = profile.routes;
if (!profile.searchDomains.isEmpty()) {
@@ -353,23 +370,30 @@ public class VpnSettings extends SettingsPreferenceFragment implements
}
try {
- getService().doLegacyVpn(config, racoon, mtpd);
+ mService.startLegacyVpn(config, racoon, mtpd);
} catch (Exception e) {
Log.e(TAG, "connect", e);
}
}
private void disconnect(String key) {
+ if (mInfo != null && key.equals(mInfo.key)) {
+ try {
+ mService.prepareVpn(VpnConfig.LEGACY_VPN, VpnConfig.LEGACY_VPN);
+ } catch (Exception e) {
+ // ignore
+ }
+ }
}
-
private class VpnPreference extends Preference {
private VpnProfile mProfile;
- private int mState = STATE_NONE;
+ private int mState = -1;
VpnPreference(Context context, VpnProfile profile) {
super(context);
setPersistent(false);
+ setOrder(0);
setOnPreferenceClickListener(VpnSettings.this);
mProfile = profile;
@@ -385,18 +409,23 @@ public class VpnSettings extends SettingsPreferenceFragment implements
update();
}
+ void update(int state) {
+ mState = state;
+ update();
+ }
+
void update() {
- if (mState != STATE_NONE) {
- String[] states = getContext().getResources()
- .getStringArray(R.array.vpn_states);
- setSummary(states[mState]);
- } else {
+ if (mState < 0) {
String[] types = getContext().getResources()
.getStringArray(R.array.vpn_types_long);
setSummary(types[mProfile.type]);
+ } else {
+ String[] states = getContext().getResources()
+ .getStringArray(R.array.vpn_states);
+ setSummary(states[mState]);
}
setTitle(mProfile.name);
- notifyChanged();
+ notifyHierarchyChanged();
}
@Override
@@ -404,7 +433,6 @@ public class VpnSettings extends SettingsPreferenceFragment implements
int result = -1;
if (preference instanceof VpnPreference) {
VpnPreference another = (VpnPreference) preference;
-
if ((result = another.mState - mState) == 0 &&
(result = mProfile.name.compareTo(another.mProfile.name)) == 0 &&
(result = mProfile.type - another.mProfile.type) == 0) {