summaryrefslogtreecommitdiffstats
path: root/packages/VpnServices/src/com/android/server/vpn
diff options
context:
space:
mode:
authorHung-ying Tyan <tyanh@google.com>2009-08-03 16:22:24 +0800
committerHung-ying Tyan <tyanh@google.com>2009-08-03 16:22:24 +0800
commit935406709edb9aaf6538e23e88ecfdf77cccd8ba (patch)
tree14dd901184665435a1529013b0581fdc2b0c4ddd /packages/VpnServices/src/com/android/server/vpn
parentdc1d5704a725d207b98de1b117847297958d9148 (diff)
downloadframeworks_base-935406709edb9aaf6538e23e88ecfdf77cccd8ba.zip
frameworks_base-935406709edb9aaf6538e23e88ecfdf77cccd8ba.tar.gz
frameworks_base-935406709edb9aaf6538e23e88ecfdf77cccd8ba.tar.bz2
Issue an error when VPN connection is lost.
+ Add new error code CONNECTION_LOST to VpnManager. + Make VpnService call onError() instead of onDisconnect() when connection is lost. + Make VpnService broadcast CONNECTION_LOST when that happens.
Diffstat (limited to 'packages/VpnServices/src/com/android/server/vpn')
-rw-r--r--packages/VpnServices/src/com/android/server/vpn/VpnService.java30
1 files changed, 21 insertions, 9 deletions
diff --git a/packages/VpnServices/src/com/android/server/vpn/VpnService.java b/packages/VpnServices/src/com/android/server/vpn/VpnService.java
index b85005c..f410c7b 100644
--- a/packages/VpnServices/src/com/android/server/vpn/VpnService.java
+++ b/packages/VpnServices/src/com/android/server/vpn/VpnService.java
@@ -147,8 +147,7 @@ abstract class VpnService<E extends VpnProfile> implements Serializable {
synchronized boolean onConnect(String username, String password) {
try {
- mState = VpnState.CONNECTING;
- broadcastConnectivity(VpnState.CONNECTING);
+ setState(VpnState.CONNECTING);
stopPreviouslyRunDaemons();
String serverIp = getIp(getProfile().getServerName());
@@ -166,8 +165,7 @@ abstract class VpnService<E extends VpnProfile> implements Serializable {
synchronized void onDisconnect() {
try {
Log.i(TAG, "disconnecting VPN...");
- mState = VpnState.DISCONNECTING;
- broadcastConnectivity(VpnState.DISCONNECTING);
+ setState(VpnState.DISCONNECTING);
mNotification.showDisconnect();
mDaemonHelper.stopAll();
@@ -235,14 +233,13 @@ abstract class VpnService<E extends VpnProfile> implements Serializable {
saveOriginalDns();
saveAndSetDomainSuffices();
- mState = VpnState.CONNECTED;
mStartTime = System.currentTimeMillis();
// set DNS after saving the states in case the process gets killed
// before states are saved
saveSelf();
setVpnDns();
- broadcastConnectivity(VpnState.CONNECTED);
+ setState(VpnState.CONNECTED);
enterConnectivityLoop();
}
@@ -256,16 +253,23 @@ abstract class VpnService<E extends VpnProfile> implements Serializable {
if (mState == VpnState.IDLE) return;
+ // keep the notification when error occurs
+ if (!anyError()) mNotification.disableNotification();
+
restoreOriginalDns();
restoreOriginalDomainSuffices();
- mState = VpnState.IDLE;
- broadcastConnectivity(VpnState.IDLE);
+ setState(VpnState.IDLE);
// stop the service itself
+ SystemProperties.set(VPN_STATUS, VPN_IS_DOWN);
mContext.removeStates();
mContext.stopSelf();
}
+ private boolean anyError() {
+ return (mError != null);
+ }
+
private void restoreOriginalDns() {
// restore only if they are not overridden
String vpnDns1 = SystemProperties.get(VPN_DNS1);
@@ -309,6 +313,11 @@ abstract class VpnService<E extends VpnProfile> implements Serializable {
SystemProperties.set(DNS_DOMAIN_SUFFICES, mOriginalDomainSuffices);
}
+ private void setState(VpnState newState) {
+ mState = newState;
+ broadcastConnectivity(newState);
+ }
+
private void broadcastConnectivity(VpnState s) {
VpnManager m = new VpnManager(mContext);
Throwable err = mError;
@@ -319,6 +328,9 @@ abstract class VpnService<E extends VpnProfile> implements Serializable {
} else if (err instanceof VpnConnectingError) {
m.broadcastConnectivity(mProfile.getName(), s,
((VpnConnectingError) err).getErrorCode());
+ } else if (VPN_IS_UP.equals(SystemProperties.get(VPN_STATUS))) {
+ m.broadcastConnectivity(mProfile.getName(), s,
+ VpnManager.VPN_ERROR_CONNECTION_LOST);
} else {
m.broadcastConnectivity(mProfile.getName(), s,
VpnManager.VPN_ERROR_CONNECTION_FAILED);
@@ -366,7 +378,7 @@ abstract class VpnService<E extends VpnProfile> implements Serializable {
// returns false if vpn connectivity is broken
private boolean checkConnectivity() {
if (mDaemonHelper.anyDaemonStopped() || isLocalIpChanged()) {
- onDisconnect();
+ onError(new IOException("Connectivity lost"));
return false;
} else {
return true;