Use stubs generated by build system

instead of hand-crafted stub for libnetd_resolv apex.

Bug: N/A
Test: m && flash && boot
Test: adb shell ldd /system/bin/netd # shows libnetd_resolv.so from apex
Change-Id: I0eefe1fb2bfef70489c32fd075a11cef538e048b
diff --git a/server/Android.bp b/server/Android.bp
index c1705d6..1bea8a0 100644
--- a/server/Android.bp
+++ b/server/Android.bp
@@ -102,9 +102,6 @@
         "netd_aidl_interface-cpp",
         "netd_event_listener_interface-cpp",
     ],
-    header_libs: [
-        "libnetd_resolv_headers",
-    ],
     aidl: {
         export_aidl_headers: true,
         local_include_dirs: ["binder"],
@@ -131,6 +128,7 @@
         "libjsoncpp",
         "liblog",
         "libmdnssd",
+        "libnetd_resolv",
         "libnetdbpf",
         "libnetdutils",
         "libnetutils",
@@ -147,9 +145,6 @@
     static_libs: [
         "libnetd_server",
     ],
-    header_libs: [
-        "libnetd_resolv_headers",
-    ],
     srcs: [
         "DummyNetwork.cpp",
         "EventReporter.cpp",
@@ -166,7 +161,6 @@
         "PhysicalNetwork.cpp",
         "PppController.cpp",
         "Process.cpp",
-        "ResolvStub.cpp",
         "VirtualNetwork.cpp",
         "main.cpp",
         "oem_iptables_hook.cpp",
diff --git a/server/NetworkController.cpp b/server/NetworkController.cpp
index e490a9f..3e428ff 100644
--- a/server/NetworkController.cpp
+++ b/server/NetworkController.cpp
@@ -30,7 +30,6 @@
 #include <android-base/strings.h>
 #include <cutils/misc.h>  // FIRST_APPLICATION_UID
 #include <netd_resolv/resolv.h>
-#include <netd_resolv/resolv_stub.h>
 #include "log/log.h"
 
 #include "Controllers.h"
@@ -213,8 +212,7 @@
         // servers (through the default network). Otherwise, the query is guaranteed to fail.
         // http://b/29498052
         Network *network = getNetworkLocked(*netId);
-        if (network && network->getType() == Network::VIRTUAL &&
-            !RESOLV_STUB.resolv_has_nameservers(*netId)) {
+        if (network && network->getType() == Network::VIRTUAL && !resolv_has_nameservers(*netId)) {
             *netId = mDefaultNetId;
         }
     } else {
@@ -223,7 +221,7 @@
         // them). Otherwise, use the default network's DNS servers.
         // TODO: Consider if we should set the explicit bit here.
         VirtualNetwork* virtualNetwork = getVirtualNetworkForUserLocked(uid);
-        if (virtualNetwork && RESOLV_STUB.resolv_has_nameservers(virtualNetwork->getNetId())) {
+        if (virtualNetwork && resolv_has_nameservers(virtualNetwork->getNetId())) {
             *netId = virtualNetwork->getNetId();
         } else {
             // TODO: return an error instead of silently doing the DNS lookup on the wrong network.
diff --git a/server/ResolvStub.cpp b/server/ResolvStub.cpp
deleted file mode 100644
index 6eb7b9f..0000000
--- a/server/ResolvStub.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string>
-
-#include <dlfcn.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define LOG_TAG "Netd"
-#include <log/log.h>
-
-#include <netd_resolv/resolv_stub.h>
-
-struct ResolvStub RESOLV_STUB;
-
-inline constexpr char APEX_LIB64_DIR[] = "/apex/com.android.resolv/lib64";
-inline constexpr char APEX_LIB_DIR[] = "/apex/com.android.resolv/lib";
-inline constexpr char LIBNAME[] = "libnetd_resolv.so";
-
-template <typename FunctionType>
-static void resolvStubInitFunction(void* handle, const char* symbol, FunctionType** stubPtr) {
-    void* f = dlsym(handle, symbol);
-    if (f == nullptr) {
-        ALOGE("Can't find symbol %s in %s", symbol, LIBNAME);
-        abort();
-    }
-    *stubPtr = reinterpret_cast<FunctionType*>(f);
-}
-
-int resolv_stub_init() {
-    void* netdResolvHandle = nullptr;
-
-    for (const auto& dir : {APEX_LIB64_DIR, APEX_LIB_DIR}) {
-        std::string path = std::string(dir) + "/" + LIBNAME;
-        netdResolvHandle = dlopen(path.c_str(), RTLD_NOW);
-        if (netdResolvHandle != nullptr) {
-            ALOGI("Loaded resolver library from %s", path.c_str());
-            break;
-        }
-        ALOGW("dlopen(%s) failed: %s", path.c_str(), dlerror());
-    }
-
-    if (netdResolvHandle == nullptr) {
-        ALOGE("Fatal: couldn't open libnetd_resolv");
-        abort();
-    }
-
-#define STR(x) #x
-#define RESOLV_STUB_LOAD_SYMBOL(x) resolvStubInitFunction(netdResolvHandle, STR(x), &RESOLV_STUB.x)
-    RESOLV_STUB_LOAD_SYMBOL(resolv_has_nameservers);
-    RESOLV_STUB_LOAD_SYMBOL(resolv_init);
-    RESOLV_STUB_LOAD_SYMBOL(resolv_gethostbyaddr_from_cache);
-#undef RESOLV_STUB_LOAD_SYMBOL
-#undef STR
-
-    return 0;
-}
diff --git a/server/main.cpp b/server/main.cpp
index cfbadee..b3408be 100644
--- a/server/main.cpp
+++ b/server/main.cpp
@@ -48,7 +48,6 @@
 #include "Process.h"
 
 #include "netd_resolv/resolv.h"
-#include "netd_resolv/resolv_stub.h"
 
 using android::IPCThreadState;
 using android::sp;
@@ -99,7 +98,7 @@
             .tagSocket = &tagSocketCallback,
             .evaluate_domain_name = &evaluateDomainNameCallback,
     };
-    return RESOLV_STUB.resolv_init(callbacks);
+    return resolv_init(&callbacks);
 }
 
 }  // namespace
@@ -119,9 +118,6 @@
         setCloseOnExec(sock);
     }
 
-    // Before we start any threads, populate the resolver stub pointers.
-    resolv_stub_init();
-
     // Make sure BPF programs are loaded before doing anything
     while (!android::base::WaitForProperty("bpf.progs_loaded", "1",
            std::chrono::seconds(5))) {