diff options
author | Robert Greenwalt <rgreenwalt@google.com> | 2010-09-23 08:41:21 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-09-23 08:41:21 -0700 |
commit | e87ebb08fba88628a65eae88fc5bc7911cfa7d97 (patch) | |
tree | d4a26347541897b6c0477afebadcbe7649549c71 | |
parent | 0b7d6de1559a4a78af76ab501e0a15afc396c2b9 (diff) | |
parent | e5c3afb29241fd3faae309f973645d7f6a7ed111 (diff) | |
download | frameworks_base-e87ebb08fba88628a65eae88fc5bc7911cfa7d97.zip frameworks_base-e87ebb08fba88628a65eae88fc5bc7911cfa7d97.tar.gz frameworks_base-e87ebb08fba88628a65eae88fc5bc7911cfa7d97.tar.bz2 |
Merge "Cleanup Netd to prevent getting hung." into gingerbread
3 files changed, 34 insertions, 8 deletions
diff --git a/services/java/com/android/server/NativeDaemonConnector.java b/services/java/com/android/server/NativeDaemonConnector.java index f3cb9b7..7b68d68 100644 --- a/services/java/com/android/server/NativeDaemonConnector.java +++ b/services/java/com/android/server/NativeDaemonConnector.java @@ -180,7 +180,8 @@ final class NativeDaemonConnector implements Runnable { } } - private void sendCommand(String command) { + private void sendCommand(String command) + throws NativeDaemonConnectorException { sendCommand(command, null); } @@ -190,11 +191,13 @@ final class NativeDaemonConnector implements Runnable { * @param command The command to send to the daemon * @param argument The argument to send with the command (or null) */ - private void sendCommand(String command, String argument) { + private void sendCommand(String command, String argument) + throws NativeDaemonConnectorException { synchronized (this) { if (LOCAL_LOGD) Slog.d(TAG, String.format("SND -> {%s} {%s}", command, argument)); if (mOutputStream == null) { Slog.e(TAG, "No connection to daemon", new IllegalStateException()); + throw new NativeDaemonConnectorException("No output stream!"); } else { StringBuilder builder = new StringBuilder(command); if (argument != null) { @@ -224,6 +227,7 @@ final class NativeDaemonConnector implements Runnable { while (!complete) { try { + // TODO - this should not block forever String line = mResponseQueue.take(); if (LOCAL_LOGD) Slog.d(TAG, String.format("RSP <- {%s}", line)); String[] tokens = line.split(" "); diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java index 4a69f20..33b19d6 100644 --- a/services/java/com/android/server/NetworkManagementService.java +++ b/services/java/com/android/server/NetworkManagementService.java @@ -47,6 +47,7 @@ import java.lang.IllegalStateException; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.concurrent.CountDownLatch; /** * @hide @@ -54,7 +55,7 @@ import java.net.UnknownHostException; class NetworkManagementService extends INetworkManagementService.Stub { private static final String TAG = "NetworkManagmentService"; - + private static final boolean DBG = true; private static final String NETD_TAG = "NetdConnector"; class NetdResponseCode { @@ -86,6 +87,9 @@ class NetworkManagementService extends INetworkManagementService.Stub { */ private NativeDaemonConnector mConnector; + private Thread mThread; + private final CountDownLatch mConnectedSignal = new CountDownLatch(1); + private ArrayList<INetworkManagementEventObserver> mObservers; /** @@ -93,9 +97,8 @@ class NetworkManagementService extends INetworkManagementService.Stub { * * @param context Binder context for this service */ - public NetworkManagementService(Context context) { + private NetworkManagementService(Context context) { mContext = context; - mObservers = new ArrayList<INetworkManagementEventObserver>(); if ("simulator".equals(SystemProperties.get("ro.product.device"))) { @@ -104,8 +107,17 @@ class NetworkManagementService extends INetworkManagementService.Stub { mConnector = new NativeDaemonConnector( new NetdCallbackReceiver(), "netd", 10, NETD_TAG); - Thread thread = new Thread(mConnector, NETD_TAG); - thread.start(); + mThread = new Thread(mConnector, NETD_TAG); + } + + public static NetworkManagementService create(Context context) throws InterruptedException { + NetworkManagementService service = new NetworkManagementService(context); + if (DBG) Slog.d(TAG, "Creating NetworkManagementService"); + service.mThread.start(); + if (DBG) Slog.d(TAG, "Awaiting socket connection"); + service.mConnectedSignal.await(); + if (DBG) Slog.d(TAG, "Connected"); + return service; } public void registerObserver(INetworkManagementEventObserver obs) { @@ -157,6 +169,14 @@ class NetworkManagementService extends INetworkManagementService.Stub { } } + /** + * Let us know the daemon is connected + */ + protected void onConnected() { + if (DBG) Slog.d(TAG, "onConnected"); + mConnectedSignal.countDown(); + } + // // Netd Callback handling @@ -164,6 +184,7 @@ class NetworkManagementService extends INetworkManagementService.Stub { class NetdCallbackReceiver implements INativeDaemonConnectorCallbacks { public void onDaemonConnected() { + NetworkManagementService.this.onConnected(); new Thread() { public void run() { } diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 859de46..9475005 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -254,7 +254,8 @@ class ServerThread extends Thread { try { Slog.i(TAG, "NetworkManagement Service"); ServiceManager.addService( - Context.NETWORKMANAGEMENT_SERVICE, new NetworkManagementService(context)); + Context.NETWORKMANAGEMENT_SERVICE, + NetworkManagementService.create(context)); } catch (Throwable e) { Slog.e(TAG, "Failure starting NetworkManagement Service", e); } |