Fix issue 1795088       Improve audio routing code

Initial commit for review.
Integrated comments after patch set 1 review.
Fixed lockup in AudioFlinger::ThreadBase::exit()
Fixed lockup when playing tone with AudioPlocyService startTone()
diff --git a/cmds/servicemanager/service_manager.c b/cmds/servicemanager/service_manager.c
index e4aa8b5..f3a4713 100644
--- a/cmds/servicemanager/service_manager.c
+++ b/cmds/servicemanager/service_manager.c
@@ -30,6 +30,7 @@
     { AID_MEDIA, "media.audio_flinger" },
     { AID_MEDIA, "media.player" },
     { AID_MEDIA, "media.camera" },
+    { AID_MEDIA, "media.audio_policy" },
     { AID_RADIO, "radio.phone" },
     { AID_RADIO, "radio.sms" },
     { AID_RADIO, "radio.phonesubinfo" },
diff --git a/cmds/system_server/library/system_init.cpp b/cmds/system_server/library/system_init.cpp
index ea78461..1d57fdc 100644
--- a/cmds/system_server/library/system_init.cpp
+++ b/cmds/system_server/library/system_init.cpp
@@ -17,6 +17,7 @@
 #include <SurfaceFlinger.h>
 #include <AudioFlinger.h>
 #include <CameraService.h>
+#include <AudioPolicyService.h>
 #include <MediaPlayerService.h>
 
 #include <android_runtime/AndroidRuntime.h>
@@ -80,6 +81,9 @@
 
         // Start the camera service
         CameraService::instantiate();
+
+        // Start the audio policy service
+        AudioPolicyService::instantiate();
     }
 
     // And now start the Android runtime.  We have to do this bit