Initial netd binder interface.

In this change:

1. AIDL files for a new, android.net.INetd service, and
   corresponding implementation using generated code. For now the
   interface is just a prototype: it only has one trivial method.
2. Permission checking code to check for CONNECTIVITY_INTERNAL.
3. Add a Big Netd Lock and provide a wrapper that makes it easy
   to ensure that it is taken by every CommandListener command.

Bug: 27239233
Change-Id: I448d0ac233edd0e351a7fe7f13901fb6871683a2
diff --git a/server/main.cpp b/server/main.cpp
index 5e189cc..2de0091 100644
--- a/server/main.cpp
+++ b/server/main.cpp
@@ -29,13 +29,27 @@
 #define LOG_TAG "Netd"
 
 #include "cutils/log.h"
+#include "utils/RWLock.h"
+
+#include <binder/IPCThreadState.h>
+#include <binder/IServiceManager.h>
+#include <binder/ProcessState.h>
 
 #include "CommandListener.h"
+#include "NetdConstants.h"
+#include "NetdNativeService.h"
 #include "NetlinkManager.h"
 #include "DnsProxyListener.h"
 #include "MDnsSdListener.h"
 #include "FwmarkServer.h"
 
+using android::status_t;
+using android::sp;
+using android::IPCThreadState;
+using android::ProcessState;
+using android::defaultServiceManager;
+using android::net::NetdNativeService;
+
 static void blockSigpipe();
 static void remove_pid_file();
 static bool write_pid_file();
@@ -44,6 +58,10 @@
 const int PID_FILE_FLAGS = O_CREAT | O_TRUNC | O_WRONLY | O_NOFOLLOW | O_CLOEXEC;
 const mode_t PID_FILE_MODE = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;  // mode 0644, rw-r--r--
 
+
+android::RWLock android::net::gBigNetdLock;
+
+
 int main() {
 
     CommandListener *cl;
@@ -99,17 +117,15 @@
         exit(1);
     }
 
-    bool wrote_pid = write_pid_file();
+    write_pid_file();
 
-    while(1) {
-        sleep(30); // 30 sec
-        if (!wrote_pid) {
-            wrote_pid = write_pid_file();
-        }
-    }
+    IPCThreadState::self()->disableBackgroundScheduling(true);
+    NetdNativeService::publishAndJoinThreadPool();
 
     ALOGI("Netd exiting");
+
     remove_pid_file();
+
     exit(0);
 }