Ensure Netd Service is alive
At least on android TV emulator system image, the Netd
service could be null when the setDnsConfigurationForNetwork
is invoked.
bug: 28553503
Change-Id: If059495c8573ede287c4e9d8f343318d519fca7f
diff --git a/services/core/java/com/android/server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java
index 2418160..e5b301e 100644
--- a/services/core/java/com/android/server/NetworkManagementService.java
+++ b/services/core/java/com/android/server/NetworkManagementService.java
@@ -330,6 +330,7 @@
if (DBG) Slog.d(TAG, "Awaiting socket connection");
connectedSignal.await();
if (DBG) Slog.d(TAG, "Connected");
+ service.connectNativeNetdService();
return service;
}
@@ -560,11 +561,7 @@
}
}
- /**
- * Prepare native daemon once connected, enabling modules and pushing any
- * existing in-memory rules.
- */
- private void prepareNativeDaemon() {
+ private void connectNativeNetdService() {
boolean nativeServiceAvailable = false;
try {
mNetdService = INetd.Stub.asInterface(ServiceManager.getService(NETD_SERVICE_NAME));
@@ -573,6 +570,13 @@
if (!nativeServiceAvailable) {
Slog.wtf(TAG, "Can't connect to NativeNetdService " + NETD_SERVICE_NAME);
}
+ }
+
+ /**
+ * Prepare native daemon once connected, enabling modules and pushing any
+ * existing in-memory rules.
+ */
+ private void prepareNativeDaemon() {
mBandwidthControlEnabled = false;
@@ -767,12 +771,16 @@
// event is dispatched from internal NDC thread, so we prepare the
// daemon back on main thread.
if (mConnectedSignal != null) {
+ // The system is booting and we're connecting to netd for the first time.
mConnectedSignal.countDown();
mConnectedSignal = null;
} else {
+ // We're reconnecting to netd after the socket connection
+ // was interrupted (e.g., if it crashed).
mFgHandler.post(new Runnable() {
@Override
public void run() {
+ connectNativeNetdService();
prepareNativeDaemon();
}
});