Fix issue 2001204: libaudiopolicy.so and libaudiopolicygeneric.so libraries must be pre-linked.
diff --git a/libs/audioflinger/Android.mk b/libs/audioflinger/Android.mk
index 7ed6a5f..ec9e332 100644
--- a/libs/audioflinger/Android.mk
+++ b/libs/audioflinger/Android.mk
@@ -54,6 +54,12 @@
     libutils \
     libmedia
 
+ifeq ($(TARGET_SIMULATOR),true)
+ LOCAL_LDLIBS += -ldl
+else
+ LOCAL_SHARED_LIBRARIES += libdl
+endif
+
 LOCAL_MODULE:= libaudiopolicygeneric
 
 ifeq ($(BOARD_HAVE_BLUETOOTH),true)
@@ -64,8 +70,6 @@
   LOCAL_CFLAGS += -DAUDIO_POLICY_TEST
 endif
 
-LOCAL_PRELINK_MODULE := false
-
 include $(BUILD_SHARED_LIBRARY)
 
 include $(CLEAR_VARS)
@@ -83,7 +87,9 @@
     libutils \
 	libbinder \
     libmedia \
-    libhardware_legacy
+    libhardware_legacy \
+    libaudiopolicygeneric \
+    libaudiopolicy
 
 ifeq ($(strip $(BOARD_USES_GENERIC_AUDIO)),true)
   LOCAL_STATIC_LIBRARIES += libaudiointerface
diff --git a/libs/audioflinger/AudioPolicyManagerGeneric.cpp b/libs/audioflinger/AudioPolicyManagerGeneric.cpp
index cf9ab88..4b31815 100644
--- a/libs/audioflinger/AudioPolicyManagerGeneric.cpp
+++ b/libs/audioflinger/AudioPolicyManagerGeneric.cpp
@@ -460,17 +460,6 @@
 
 // ---  class factory
 
-
-extern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface)
-{
-    return new AudioPolicyManagerGeneric(clientInterface);
-}
-
-extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface)
-{
-    delete interface;
-}
-
 AudioPolicyManagerGeneric::AudioPolicyManagerGeneric(AudioPolicyClientInterface *clientInterface)
     :
 #ifdef AUDIO_POLICY_TEST
diff --git a/libs/audioflinger/AudioPolicyService.cpp b/libs/audioflinger/AudioPolicyService.cpp
index 4810a44..7f6c4ed 100644
--- a/libs/audioflinger/AudioPolicyService.cpp
+++ b/libs/audioflinger/AudioPolicyService.cpp
@@ -23,6 +23,7 @@
 #include <utils/String16.h>
 #include <utils/threads.h>
 #include "AudioPolicyService.h"
+#include "AudioPolicyManagerGeneric.h"
 #include <cutils/properties.h>
 #include <dlfcn.h>
 
@@ -35,9 +36,6 @@
 
 namespace android {
 
-const char *AudioPolicyService::sAudioPolicyLibrary = "/system/lib/libaudiopolicy.so";
-const char *AudioPolicyService::sAudioPolicyGenericLibrary = "/system/lib/libaudiopolicygeneric.so";
-
 static bool checkPermission() {
 #ifndef HAVE_ANDROID_OS
     return true;
@@ -51,47 +49,29 @@
 // ----------------------------------------------------------------------------
 
 AudioPolicyService::AudioPolicyService()
-    : BnAudioPolicyService() , mpPolicyManager(NULL), mpPolicyManagerLibHandle(NULL)
+    : BnAudioPolicyService() , mpPolicyManager(NULL)
 {
-    const char *audioPolicyLibrary;
     char value[PROPERTY_VALUE_MAX];
 
-#if (defined GENERIC_AUDIO) || (defined AUDIO_POLICY_TEST)
-    audioPolicyLibrary = sAudioPolicyGenericLibrary;
-    LOGV("build for GENERIC_AUDIO - using generic audio policy");
-#else
-    // if running in emulation - use the emulator driver
-    if (property_get("ro.kernel.qemu", value, 0)) {
-        LOGV("Running in emulation - using generic audio policy");
-        audioPolicyLibrary = sAudioPolicyGenericLibrary;
-    }
-    else {
-        LOGV("Using hardware specific audio policy");
-        audioPolicyLibrary = sAudioPolicyLibrary;
-    }
-#endif
-
-
-    mpPolicyManagerLibHandle = dlopen(audioPolicyLibrary, RTLD_NOW | RTLD_LOCAL);
-    if (mpPolicyManagerLibHandle == NULL) {
-       LOGW("Could not load libaudio policy library");
-       return;
-    }
-
-    AudioPolicyInterface *(*createManager)(AudioPolicyClientInterface *) =
-            reinterpret_cast<AudioPolicyInterface* (*)(AudioPolicyClientInterface *)>(dlsym(mpPolicyManagerLibHandle, "createAudioPolicyManager"));
-
-    if (createManager == NULL ) {
-        LOGW("Could not get createAudioPolicyManager method");
-        return;
-    }
-
     // start tone playback thread
     mTonePlaybacThread = new AudioCommandThread();
     // start audio commands thread
     mAudioCommandThread = new AudioCommandThread();
 
-    mpPolicyManager = (*createManager)(this);
+#if (defined GENERIC_AUDIO) || (defined AUDIO_POLICY_TEST)
+    mpPolicyManager = new AudioPolicyManagerGeneric(this);
+    LOGV("build for GENERIC_AUDIO - using generic audio policy");
+#else
+    // if running in emulation - use the emulator driver
+    if (property_get("ro.kernel.qemu", value, 0)) {
+        LOGV("Running in emulation - using generic audio policy");
+        mpPolicyManager = new AudioPolicyManagerGeneric(this);
+    }
+    else {
+        LOGV("Using hardware specific audio policy");
+        mpPolicyManager = createAudioPolicyManager(this);
+    }
+#endif
 
     // load properties
     property_get("ro.camera.sound.forced", value, "0");
@@ -106,14 +86,7 @@
     mAudioCommandThread.clear();
 
     if (mpPolicyManager) {
-        void(*destroyManager)(AudioPolicyInterface *) =
-                reinterpret_cast<void(*)(AudioPolicyInterface *)>(dlsym(mpPolicyManagerLibHandle, "destroyAudioPolicyManager"));
-
-        if (destroyManager == NULL ) {
-            LOGW("Could not get destroyAudioPolicyManager method");
-            return;
-        }
-        (*destroyManager)(mpPolicyManager);
+        delete mpPolicyManager;
     }
 }
 
diff --git a/libs/audioflinger/AudioPolicyService.h b/libs/audioflinger/AudioPolicyService.h
index 47173dd..1c46975 100644
--- a/libs/audioflinger/AudioPolicyService.h
+++ b/libs/audioflinger/AudioPolicyService.h
@@ -109,8 +109,6 @@
                         AudioPolicyService();
     virtual             ~AudioPolicyService();
 
-    static const char *sAudioPolicyLibrary;
-    static const char *sAudioPolicyGenericLibrary;
     // Thread used for tone playback and to send audio config commands to audio flinger
     // For tone playback, using a separate thread is necessary to avoid deadlock with mLock because startTone()
     // and stopTone() are normally called with mLock locked and requesting a tone start or stop will cause
@@ -185,7 +183,6 @@
     AudioPolicyInterface* mpPolicyManager;          // the platform specific policy manager
     sp <AudioCommandThread> mAudioCommandThread;    // audio commands thread
     sp <AudioCommandThread> mTonePlaybacThread;     // tone playback thread
-    void *mpPolicyManagerLibHandle;
 };
 
 }; // namespace android