audio policy: implement routing control

Add implementation of audio routing control via AudioSystem APIs.

The following APIs are implemented:
- listAudioPorts(): return a list of devices and output/input mixers ports
that can be used as sources or sinks for audio patches.
- createAudioPatch()/releaseAudioPatch(): create/release a connection patch between
two audio ports (e.g. to connect input from an HDMI device to a speaker output device).
Only one client application can own a patch from a given source.
When an audio port (device or mix) is part of an application created patch, its routing cannot
not be changed by a policy decision.
- listAudioPatches(): return a list of existing patches.

Each audio port addition/removal and each audio patch creation/release increments a generation count.
This generation count is used to ensure consistency betwen calls to
listAudioPorts() and listAudioPatches().

Bug: 14815883.

Change-Id: I022b638c2f5f0bb41543c7cfca7488fb45cfdd80
diff --git a/services/audiopolicy/AudioPolicyInterfaceImpl.cpp b/services/audiopolicy/AudioPolicyInterfaceImpl.cpp
index 7cd253b..2b33703 100644
--- a/services/audiopolicy/AudioPolicyInterfaceImpl.cpp
+++ b/services/audiopolicy/AudioPolicyInterfaceImpl.cpp
@@ -463,43 +463,72 @@
     return mAudioPolicyManager->isOffloadSupported(info);
 }
 
-status_t AudioPolicyService::listAudioPorts(audio_port_role_t role __unused,
-                                            audio_port_type_t type __unused,
+status_t AudioPolicyService::listAudioPorts(audio_port_role_t role,
+                                            audio_port_type_t type,
                                             unsigned int *num_ports,
-                                            struct audio_port *ports __unused,
-                                            unsigned int *generation __unused)
+                                            struct audio_port *ports,
+                                            unsigned int *generation)
 {
-    *num_ports = 0;
-    return INVALID_OPERATION;
+    Mutex::Autolock _l(mLock);
+    if (mAudioPolicyManager == NULL) {
+        return NO_INIT;
+    }
+
+    return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation);
 }
 
-status_t AudioPolicyService::getAudioPort(struct audio_port *port __unused)
+status_t AudioPolicyService::getAudioPort(struct audio_port *port)
 {
-    return INVALID_OPERATION;
+    Mutex::Autolock _l(mLock);
+    if (mAudioPolicyManager == NULL) {
+        return NO_INIT;
+    }
+
+    return mAudioPolicyManager->getAudioPort(port);
 }
 
-status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch __unused,
-        audio_patch_handle_t *handle __unused)
+status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch,
+        audio_patch_handle_t *handle)
 {
-    return INVALID_OPERATION;
+    Mutex::Autolock _l(mLock);
+    if (mAudioPolicyManager == NULL) {
+        return NO_INIT;
+    }
+    return mAudioPolicyManager->createAudioPatch(patch, handle,
+                                                  IPCThreadState::self()->getCallingUid());
 }
 
-status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle __unused)
+status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle)
 {
-    return INVALID_OPERATION;
+    Mutex::Autolock _l(mLock);
+    if (mAudioPolicyManager == NULL) {
+        return NO_INIT;
+    }
+
+    return mAudioPolicyManager->releaseAudioPatch(handle,
+                                                     IPCThreadState::self()->getCallingUid());
 }
 
 status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches,
-        struct audio_patch *patches __unused,
-        unsigned int *generation __unused)
+        struct audio_patch *patches,
+        unsigned int *generation)
 {
-    *num_patches = 0;
-    return INVALID_OPERATION;
+    Mutex::Autolock _l(mLock);
+    if (mAudioPolicyManager == NULL) {
+        return NO_INIT;
+    }
+
+    return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation);
 }
 
-status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config __unused)
+status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config)
 {
-    return INVALID_OPERATION;
+    Mutex::Autolock _l(mLock);
+    if (mAudioPolicyManager == NULL) {
+        return NO_INIT;
+    }
+
+    return mAudioPolicyManager->setAudioPortConfig(config);
 }
 
 }; // namespace android