summaryrefslogtreecommitdiffstats
path: root/packages/VpnServices/src/com/android/server/vpn/AndroidServiceProxy.java
diff options
context:
space:
mode:
authorHung-ying Tyan <tyanh@google.com>2009-07-11 22:23:30 +0800
committerHung-ying Tyan <tyanh@google.com>2009-07-13 13:11:36 +0800
commitdf1aa3359ccfe81a3f79ed457c7bfc75942a9d91 (patch)
tree8d915f8762b7ce3271a0a0d2b4f84287b9cda059 /packages/VpnServices/src/com/android/server/vpn/AndroidServiceProxy.java
parentcf29e116129f38309c18ba14b9893b079a712289 (diff)
downloadframeworks_base-df1aa3359ccfe81a3f79ed457c7bfc75942a9d91.zip
frameworks_base-df1aa3359ccfe81a3f79ed457c7bfc75942a9d91.tar.gz
frameworks_base-df1aa3359ccfe81a3f79ed457c7bfc75942a9d91.tar.bz2
Add error code in vpn connectivity broadcast.
* Changes + Add VpnConnectingError.java. + Broadcast the error returned by daemons. + Add error codes to VpnManager.java. + Add error code to VpnManager.broadcastConnectivity(). Patch Set 4: + Replace VPN_UP with VPN_STATUS in response to ip-up-vpn changes. + Make VpnServiceBinder a foreground service so that it won't be interrupted by the system. Patch Set 5: + Remove the support of returning 0 from daemon and restart socket in AndroidServiceProxy.
Diffstat (limited to 'packages/VpnServices/src/com/android/server/vpn/AndroidServiceProxy.java')
-rw-r--r--packages/VpnServices/src/com/android/server/vpn/AndroidServiceProxy.java54
1 files changed, 32 insertions, 22 deletions
diff --git a/packages/VpnServices/src/com/android/server/vpn/AndroidServiceProxy.java b/packages/VpnServices/src/com/android/server/vpn/AndroidServiceProxy.java
index 7dd9d9e..7e8185e 100644
--- a/packages/VpnServices/src/com/android/server/vpn/AndroidServiceProxy.java
+++ b/packages/VpnServices/src/com/android/server/vpn/AndroidServiceProxy.java
@@ -18,6 +18,7 @@ package com.android.server.vpn;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
+import android.net.vpn.VpnManager;
import android.os.SystemProperties;
import android.util.Log;
@@ -48,6 +49,9 @@ public class AndroidServiceProxy extends ProcessProxy {
private static final int END_OF_ARGUMENTS = 255;
+ private static final int STOP_SERVICE = -1;
+ private static final int AUTH_ERROR_CODE = 51;
+
private String mServiceName;
private String mSocketName;
private LocalSocket mKeepaliveSocket;
@@ -72,14 +76,21 @@ public class AndroidServiceProxy extends ProcessProxy {
@Override
public synchronized void stop() {
- if (isRunning()) setResultAndCloseControlSocket(-1);
+ if (isRunning()) {
+ try {
+ setResultAndCloseControlSocket(STOP_SERVICE);
+ } catch (IOException e) {
+ // should not occur
+ throw new RuntimeException(e);
+ }
+ }
SystemProperties.set(SVC_STOP_CMD, mServiceName);
}
/**
* Sends a command with arguments to the service through the control socket.
*/
- public void sendCommand(String ...args) throws IOException {
+ public synchronized void sendCommand(String ...args) throws IOException {
OutputStream out = getControlSocketOutput();
for (String arg : args) outputString(out, arg);
out.write(END_OF_ARGUMENTS);
@@ -114,30 +125,22 @@ public class AndroidServiceProxy extends ProcessProxy {
InputStream in = s.getInputStream();
int data = in.read();
if (data >= 0) {
- Log.d(mTag, "got data from keepalive socket: " + data);
-
- if (data == 0) {
- // re-establish the connection:
- // synchronized here so that checkSocketResult()
- // returns when new mKeepaliveSocket is available for
- // next cmd
- synchronized (this) {
- setResultAndCloseControlSocket((byte) data);
- s = mKeepaliveSocket = createServiceSocket();
- }
- } else {
- // keep the socket
- setSocketResult(data);
- }
+ Log.d(mTag, "got data from control socket: " + data);
+
+ setSocketResult(data);
} else {
// service is gone
if (mControlSocketInUse) setSocketResult(-1);
break;
}
}
- Log.d(mTag, "keepalive connection closed");
+ Log.d(mTag, "control connection closed");
} catch (IOException e) {
- Log.d(mTag, "keepalive socket broken: " + e.getMessage());
+ if (e instanceof VpnConnectingError) {
+ throw e;
+ } else {
+ Log.d(mTag, "control socket broken: " + e.getMessage());
+ }
}
// Wait 5 seconds for the service to exit
@@ -179,7 +182,7 @@ public class AndroidServiceProxy extends ProcessProxy {
}
}
- private synchronized void checkSocketResult() throws IOException {
+ private void checkSocketResult() throws IOException {
try {
// will be notified when the result comes back from service
if (mSocketResult == null) wait();
@@ -194,14 +197,21 @@ public class AndroidServiceProxy extends ProcessProxy {
}
}
- private synchronized void setSocketResult(int result) {
+ private synchronized void setSocketResult(int result)
+ throws VpnConnectingError {
if (mControlSocketInUse) {
mSocketResult = result;
notifyAll();
+ } else if (result > 0) {
+ // error from daemon
+ throw new VpnConnectingError((result == AUTH_ERROR_CODE)
+ ? VpnManager.VPN_ERROR_AUTH
+ : VpnManager.VPN_ERROR_CONNECTION_FAILED);
}
}
- private void setResultAndCloseControlSocket(int result) {
+ private void setResultAndCloseControlSocket(int result)
+ throws VpnConnectingError {
setSocketResult(result);
try {
mKeepaliveSocket.shutdownInput();