Merge "Cleanup Netd to prevent getting hung." into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
e87ebb08fb
@ -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(" ");
|
||||
|
@ -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() {
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user