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);
|
sendCommand(command, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,11 +191,13 @@ final class NativeDaemonConnector implements Runnable {
|
|||||||
* @param command The command to send to the daemon
|
* @param command The command to send to the daemon
|
||||||
* @param argument The argument to send with the command (or null)
|
* @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) {
|
synchronized (this) {
|
||||||
if (LOCAL_LOGD) Slog.d(TAG, String.format("SND -> {%s} {%s}", command, argument));
|
if (LOCAL_LOGD) Slog.d(TAG, String.format("SND -> {%s} {%s}", command, argument));
|
||||||
if (mOutputStream == null) {
|
if (mOutputStream == null) {
|
||||||
Slog.e(TAG, "No connection to daemon", new IllegalStateException());
|
Slog.e(TAG, "No connection to daemon", new IllegalStateException());
|
||||||
|
throw new NativeDaemonConnectorException("No output stream!");
|
||||||
} else {
|
} else {
|
||||||
StringBuilder builder = new StringBuilder(command);
|
StringBuilder builder = new StringBuilder(command);
|
||||||
if (argument != null) {
|
if (argument != null) {
|
||||||
@ -224,6 +227,7 @@ final class NativeDaemonConnector implements Runnable {
|
|||||||
|
|
||||||
while (!complete) {
|
while (!complete) {
|
||||||
try {
|
try {
|
||||||
|
// TODO - this should not block forever
|
||||||
String line = mResponseQueue.take();
|
String line = mResponseQueue.take();
|
||||||
if (LOCAL_LOGD) Slog.d(TAG, String.format("RSP <- {%s}", line));
|
if (LOCAL_LOGD) Slog.d(TAG, String.format("RSP <- {%s}", line));
|
||||||
String[] tokens = line.split(" ");
|
String[] tokens = line.split(" ");
|
||||||
|
@ -47,6 +47,7 @@ import java.lang.IllegalStateException;
|
|||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
@ -54,7 +55,7 @@ import java.net.UnknownHostException;
|
|||||||
class NetworkManagementService extends INetworkManagementService.Stub {
|
class NetworkManagementService extends INetworkManagementService.Stub {
|
||||||
|
|
||||||
private static final String TAG = "NetworkManagmentService";
|
private static final String TAG = "NetworkManagmentService";
|
||||||
|
private static final boolean DBG = true;
|
||||||
private static final String NETD_TAG = "NetdConnector";
|
private static final String NETD_TAG = "NetdConnector";
|
||||||
|
|
||||||
class NetdResponseCode {
|
class NetdResponseCode {
|
||||||
@ -86,6 +87,9 @@ class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
*/
|
*/
|
||||||
private NativeDaemonConnector mConnector;
|
private NativeDaemonConnector mConnector;
|
||||||
|
|
||||||
|
private Thread mThread;
|
||||||
|
private final CountDownLatch mConnectedSignal = new CountDownLatch(1);
|
||||||
|
|
||||||
private ArrayList<INetworkManagementEventObserver> mObservers;
|
private ArrayList<INetworkManagementEventObserver> mObservers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,9 +97,8 @@ class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
*
|
*
|
||||||
* @param context Binder context for this service
|
* @param context Binder context for this service
|
||||||
*/
|
*/
|
||||||
public NetworkManagementService(Context context) {
|
private NetworkManagementService(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
|
||||||
mObservers = new ArrayList<INetworkManagementEventObserver>();
|
mObservers = new ArrayList<INetworkManagementEventObserver>();
|
||||||
|
|
||||||
if ("simulator".equals(SystemProperties.get("ro.product.device"))) {
|
if ("simulator".equals(SystemProperties.get("ro.product.device"))) {
|
||||||
@ -104,8 +107,17 @@ class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
mConnector = new NativeDaemonConnector(
|
mConnector = new NativeDaemonConnector(
|
||||||
new NetdCallbackReceiver(), "netd", 10, NETD_TAG);
|
new NetdCallbackReceiver(), "netd", 10, NETD_TAG);
|
||||||
Thread thread = new Thread(mConnector, NETD_TAG);
|
mThread = new Thread(mConnector, NETD_TAG);
|
||||||
thread.start();
|
}
|
||||||
|
|
||||||
|
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) {
|
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
|
// Netd Callback handling
|
||||||
@ -164,6 +184,7 @@ class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
class NetdCallbackReceiver implements INativeDaemonConnectorCallbacks {
|
class NetdCallbackReceiver implements INativeDaemonConnectorCallbacks {
|
||||||
public void onDaemonConnected() {
|
public void onDaemonConnected() {
|
||||||
|
NetworkManagementService.this.onConnected();
|
||||||
new Thread() {
|
new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,8 @@ class ServerThread extends Thread {
|
|||||||
try {
|
try {
|
||||||
Slog.i(TAG, "NetworkManagement Service");
|
Slog.i(TAG, "NetworkManagement Service");
|
||||||
ServiceManager.addService(
|
ServiceManager.addService(
|
||||||
Context.NETWORKMANAGEMENT_SERVICE, new NetworkManagementService(context));
|
Context.NETWORKMANAGEMENT_SERVICE,
|
||||||
|
NetworkManagementService.create(context));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Slog.e(TAG, "Failure starting NetworkManagement Service", e);
|
Slog.e(TAG, "Failure starting NetworkManagement Service", e);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user