Audio V4: Split system and vendor Audio.h

audio.h and its dependencies (audio-effect.h, sound_trigger.h...)
used to be shared between system and vendor code.

This led to multiple problems:

1) Such sharing contradicts the Treble policy of
strict independence of framework and vendor code.

2) When audio.h was changed, every vendor needed to update
its code in the next release. This meant that audio*.h
headers were mostly changed in backward compatible manner.
Nevertheless, for P the HIDL interface and thus the audio.h
interface are changed in backward incompatible way.
(Some enum are becoming 64 bit long).

3) As the headers were common, some API used only by the framework
needed to be visible to the vendors (mostly enum values).

4) Treble policy is to support at least one previous HAL version

As a result the audio*.h headers are now duplicated,
one set for the framework, and one for the vendor.

Each set will evolve independently. After this split,
the framework-only APIs will be removed from the vendor headers
and vice versa.

The split is implements as such:

 + for system code

    - NOT moving the libaudio_system_headers
      Eg: system/audio.h and system/audio_effects/effect_equalizer.h
          are still in system/media/audio

    - the legacy audio HAL API that were in libhardware headers
          are now in libaudiohal_legacy_headers
      Eg: hardware/audio.h and hardware/audio_effect.h
          are now in frameworks/av/media/libaudiohal/legacy/

 + for vendor code

    - moving libaudio_system_headers and the legacy audio HAL API
          that were in libhardware_headers in
          android.hardware.audio.common.legacy@2.0
      Note that those headers are now versioned, so migrating to a @4.0
          HIDL HAL will mean changing the legacy dependency too.
      Eg: system/audio.h, system/audio-effect.h, hardware/audio.h
          are now in hardware/interfaces/audio/common/2.0/legacy

    - the legacy audio effect HAL API that was in libaudioeffects
          is now moved in android.hardware.audio.effect.legacy@2.0
      Eg: audio_effects/effect*.h are now in
          hardware/interfaces/audio/effect/2.0/legacy

    - the legacy sound trigger HAL API that were in libhardware_headers
          is now moved in android.hardware.soundtrigger.legacy@2.0
      Eg: hardware/sound_trigger.h is now in
          hardware/interfaces/audio/effect/2.0/legacy

libaudioutil being used by both system and vendor, had
to be renamed for system to libaudioutil_system.

Vendor libs that now depend on the audio.h of a specific
version and are not extensively referenced in non google code,
append @2.0 to their name.

Note that headers that are not expected to change in the 4.0 HAL are
left in all-versions folder to avoid duplication.
This is an implementation detail as the versioned libraries export
the all-versions headers.

Note that strict vendor-system separation is enforced by the
build-system. The system headers are not available for vendor
libs and vice-versa.

Note that this patch is split between numerous git repository (>10),
all the commits having the same Change-id for searchability.

Note that audio_policy.h is no longer exposed to vendors
as the legacy audio policy HAL API was never officially supported.
As a result the audiopolicy stub implementation has been removed.

Test: compile taimen-userdebug walleye-userdebug
              sailfish-userdebug marlin-userdebug
              gce_x86_phone-userdebug gce_x86_phone
              full-eng aosp_arm aosp_x86-eng
Test: check that the emulator booted and played audio
Test: full QA on sailfish-userdebug and taimen-userdebug
Bug: 38184704
Change-Id: I950f4e0a55613d72e32eba31bd563cb5bafe2d1a
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/media/libeffects/config/Android.bp b/media/libeffects/config/Android.bp
index 3e88c7c..4a1653a 100644
--- a/media/libeffects/config/Android.bp
+++ b/media/libeffects/config/Android.bp
@@ -1,7 +1,6 @@
 // Effect configuration
 cc_library_shared {
     name: "libeffectsconfig",
-    vendor_available: true,
 
     srcs: ["src/EffectsConfig.cpp"],
 
@@ -20,3 +19,29 @@
 
     export_include_dirs: ["include"],
 }
+
+cc_library_shared {
+    name: "libeffectsconfig@2.0",
+    vendor: true,
+
+    srcs: ["src/EffectsConfig.cpp"],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+
+    shared_libs: [
+        "liblog",
+        "libtinyxml2",
+    ],
+
+    export_include_dirs: ["include"],
+
+    header_libs: [
+        "android.hardware.audio.common.legacy@2.0",
+    ],
+    export_header_lib_headers: [
+        "android.hardware.audio.common.legacy@2.0",
+    ],
+}
diff --git a/media/libeffects/downmix/Android.mk b/media/libeffects/downmix/Android.mk
index a5fbf14..f32b7e7 100644
--- a/media/libeffects/downmix/Android.mk
+++ b/media/libeffects/downmix/Android.mk
@@ -17,12 +17,14 @@
 LOCAL_MODULE_RELATIVE_PATH := soundfx
 
 LOCAL_C_INCLUDES := \
-	$(call include-path-for, audio-effects) \
 	$(call include-path-for, audio-utils)
 
 #-DBUILD_FLOAT
 LOCAL_CFLAGS += -fvisibility=hidden
 LOCAL_CFLAGS += -Wall -Werror
 
-LOCAL_HEADER_LIBRARIES += libhardware_headers
+LOCAL_HEADER_LIBRARIES += \
+    libhardware_headers \
+    android.hardware.audio.effect.legacy@2.0 \
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libeffects/factory/Android.bp b/media/libeffects/factory/Android.bp
index ddbfdd8..fded0b7 100644
--- a/media/libeffects/factory/Android.bp
+++ b/media/libeffects/factory/Android.bp
@@ -1,11 +1,3 @@
-cc_library_headers {
-    name: "libeffects_headers",
-    vendor_available: true,
-    export_include_dirs: ["include"],
-    header_libs: ["libhardware_headers"],
-    export_header_lib_headers: ["libhardware_headers"],
-}
-
 // Effect factory library
 cc_library_shared {
     name: "libeffects",
@@ -21,21 +13,20 @@
         "libcutils",
         "liblog",
         "libdl",
-        "libeffectsconfig",
+        "libeffectsconfig@2.0",
     ],
     cflags: ["-fvisibility=hidden"],
 
-    local_include_dirs:["include/media"],
+    export_include_dirs: ["."],
 
     header_libs: [
-        "libaudioeffects",
-        "libeffects_headers",
+        "android.hardware.audio.effect.legacy@2.0",
     ],
-    export_header_lib_headers: ["libeffects_headers"],
+    export_header_lib_headers: ["android.hardware.audio.effect.legacy@2.0"],
 }
 
 cc_binary {
-    name: "dumpEffectConfigFile",
+    name: "dumpEffectConfigFile@2.0",
     vendor: true,
     srcs: ["test/DumpConfig.cpp"],
 
@@ -47,10 +38,12 @@
         "-Werror",
     ],
 
+    header_libs: [
+        "android.hardware.audio.effect.legacy@2.0",
+    ],
 
     shared_libs: [
-        "libeffectsconfig",
+        "libeffectsconfig@2.0",
         "libeffects",
     ],
-    local_include_dirs:[".", "include"],
 }
diff --git a/media/libeffects/factory/include/media/EffectsFactoryApi.h b/media/libeffects/factory/include/media/EffectsFactoryApi.h
deleted file mode 100644
index a5a12eb..0000000
--- a/media/libeffects/factory/include/media/EffectsFactoryApi.h
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_EFFECTSFACTORYAPI_H_
-#define ANDROID_EFFECTSFACTORYAPI_H_
-
-#include <cutils/compiler.h>
-#include <errno.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <hardware/audio_effect.h>
-
-#if __cplusplus
-extern "C" {
-#endif
-
-/////////////////////////////////////////////////
-//      Effect factory interface
-/////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////////////////
-//
-//    Function:       EffectQueryNumberEffects
-//
-//    Description:    Returns the number of different effects in all loaded libraries.
-//          Each effect must have a different effect uuid (see
-//          effect_descriptor_t). This function together with EffectQueryEffect()
-//          is used to enumerate all effects present in all loaded libraries.
-//          Each time EffectQueryNumberEffects() is called, the factory must
-//          reset the index of the effect descriptor returned by next call to
-//          EffectQueryEffect() to restart enumeration from the beginning.
-//
-//    Input/Output:
-//          pNumEffects:    address where the number of effects should be returned.
-//
-//    Output:
-//        returned value:    0          successful operation.
-//                          -ENODEV     factory failed to initialize
-//                          -EINVAL     invalid pNumEffects
-//        *pNumEffects:     updated with number of effects in factory
-//
-////////////////////////////////////////////////////////////////////////////////
-ANDROID_API
-int EffectQueryNumberEffects(uint32_t *pNumEffects);
-
-////////////////////////////////////////////////////////////////////////////////
-//
-//    Function:       EffectQueryEffect
-//
-//    Description:    Returns a descriptor of the next available effect.
-//          See effect_descriptor_t for a details on effect descriptor.
-//          This function together with EffectQueryNumberEffects() is used to enumerate all
-//          effects present in all loaded libraries. The enumeration sequence is:
-//              EffectQueryNumberEffects(&num_effects);
-//              for (i = 0; i < num_effects; i++)
-//                  EffectQueryEffect(i,...);
-//
-//    Input/Output:
-//          pDescriptor:    address where to return the effect descriptor.
-//
-//    Output:
-//        returned value:    0          successful operation.
-//                          -ENOENT     no more effect available
-//                          -ENODEV     factory failed to initialize
-//                          -EINVAL     invalid pDescriptor
-//                          -ENOSYS     effect list has changed since last execution of
-//                                      EffectQueryNumberEffects()
-//        *pDescriptor:     updated with the effect descriptor.
-//
-////////////////////////////////////////////////////////////////////////////////
-ANDROID_API
-int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor);
-
-////////////////////////////////////////////////////////////////////////////////
-//
-//    Function:       EffectCreate
-//
-//    Description:    Creates an effect engine of the specified type and returns an
-//          effect control interface on this engine. The function will allocate the
-//          resources for an instance of the requested effect engine and return
-//          a handle on the effect control interface.
-//
-//    Input:
-//          pEffectUuid:    pointer to the effect uuid.
-//          sessionId:  audio session to which this effect instance will be attached. All effects
-//              created with the same session ID are connected in series and process the same signal
-//              stream.  Knowing that two effects are part of the same effect chain can help the
-//              library implement some kind of optimizations.
-//          ioId:   identifies the output or input stream this effect is directed to at audio HAL.
-//              For future use especially with tunneled HW accelerated effects
-//
-//    Input/Output:
-//          pHandle:        address where to return the effect handle.
-//
-//    Output:
-//        returned value:    0          successful operation.
-//                          -ENODEV     factory failed to initialize
-//                          -EINVAL     invalid pEffectUuid or pHandle
-//                          -ENOENT     no effect with this uuid found
-//        *pHandle:         updated with the effect handle.
-//
-////////////////////////////////////////////////////////////////////////////////
-ANDROID_API
-int EffectCreate(const effect_uuid_t *pEffectUuid, int32_t sessionId, int32_t ioId,
-        effect_handle_t *pHandle);
-
-////////////////////////////////////////////////////////////////////////////////
-//
-//    Function:       EffectRelease
-//
-//    Description:    Releases the effect engine whose handle is given as argument.
-//          All resources allocated to this particular instance of the effect are
-//          released.
-//
-//    Input:
-//          handle:    handle on the effect interface to be released.
-//
-//    Output:
-//        returned value:    0          successful operation.
-//                          -ENODEV     factory failed to initialize
-//                          -EINVAL     invalid interface handle
-//
-////////////////////////////////////////////////////////////////////////////////
-ANDROID_API
-int EffectRelease(effect_handle_t handle);
-
-////////////////////////////////////////////////////////////////////////////////
-//
-//    Function:       EffectGetDescriptor
-//
-//    Description:    Returns the descriptor of the effect which uuid is pointed
-//          to by first argument.
-//
-//    Input:
-//          pEffectUuid:    pointer to the effect uuid.
-//
-//    Input/Output:
-//          pDescriptor:    address where to return the effect descriptor.
-//
-//    Output:
-//        returned value:    0          successful operation.
-//                          -ENODEV     factory failed to initialize
-//                          -EINVAL     invalid pEffectUuid or pDescriptor
-//                          -ENOENT     no effect with this uuid found
-//        *pDescriptor:     updated with the effect descriptor.
-//
-////////////////////////////////////////////////////////////////////////////////
-ANDROID_API
-int EffectGetDescriptor(const effect_uuid_t *pEffectUuid, effect_descriptor_t *pDescriptor);
-
-////////////////////////////////////////////////////////////////////////////////
-//
-//    Function:       EffectIsNullUuid
-//
-//    Description:    Helper function to compare effect uuid to EFFECT_UUID_NULL
-//
-//    Input:
-//          pEffectUuid: pointer to effect uuid to compare to EFFECT_UUID_NULL.
-//
-//    Output:
-//        returned value:    0 if uuid is different from EFFECT_UUID_NULL.
-//                           1 if uuid is equal to EFFECT_UUID_NULL.
-//
-////////////////////////////////////////////////////////////////////////////////
-ANDROID_API
-int EffectIsNullUuid(const effect_uuid_t *pEffectUuid);
-
-ANDROID_API
-int EffectDumpEffects(int fd);
-
-#if __cplusplus
-}  // extern "C"
-#endif
-
-
-#endif /*ANDROID_EFFECTSFACTORYAPI_H_*/
diff --git a/media/libeffects/loudness/Android.mk b/media/libeffects/loudness/Android.mk
index 712cbd5..8a4b451 100644
--- a/media/libeffects/loudness/Android.mk
+++ b/media/libeffects/loudness/Android.mk
@@ -19,6 +19,6 @@
 LOCAL_MODULE:= libldnhncr
 
 LOCAL_HEADER_LIBRARIES := \
-    libaudioeffects
+    android.hardware.audio.effect.legacy@2.0 \
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libeffects/lvm/wrapper/Android.mk b/media/libeffects/lvm/wrapper/Android.mk
index 341dbc2..4673f6c 100644
--- a/media/libeffects/lvm/wrapper/Android.mk
+++ b/media/libeffects/lvm/wrapper/Android.mk
@@ -35,7 +35,10 @@
 	$(call include-path-for, audio-effects) \
 	$(call include-path-for, audio-utils) \
 
-LOCAL_HEADER_LIBRARIES += libhardware_headers
+LOCAL_HEADER_LIBRARIES += \
+    libhardware_headers \
+    android.hardware.audio.effect.legacy@2.0 \
+
 include $(BUILD_SHARED_LIBRARY)
 
 
@@ -67,10 +70,11 @@
     $(LOCAL_PATH)/Reverb \
     $(LOCAL_PATH)/../lib/Common/lib/ \
     $(LOCAL_PATH)/../lib/Reverb/lib/ \
-    $(call include-path-for, audio-effects) \
     $(call include-path-for, audio-utils) \
 
-LOCAL_HEADER_LIBRARIES += libhardware_headers
+LOCAL_HEADER_LIBRARIES += \
+    libhardware_headers \
+    android.hardware.audio.effect.legacy@2.0 \
 
 LOCAL_SANITIZE := integer_overflow
 
diff --git a/media/libeffects/preprocessing/Android.mk b/media/libeffects/preprocessing/Android.mk
index 358da8b..3f81047 100644
--- a/media/libeffects/preprocessing/Android.mk
+++ b/media/libeffects/preprocessing/Android.mk
@@ -32,5 +32,8 @@
 LOCAL_CFLAGS += -fvisibility=hidden
 LOCAL_CFLAGS += -Wall -Werror
 
-LOCAL_HEADER_LIBRARIES += libhardware_headers
+LOCAL_HEADER_LIBRARIES += \
+    libhardware_headers \
+    android.hardware.audio.effect.legacy@2.0
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libeffects/proxy/Android.bp b/media/libeffects/proxy/Android.bp
new file mode 100644
index 0000000..1cf1b69
--- /dev/null
+++ b/media/libeffects/proxy/Android.bp
@@ -0,0 +1,26 @@
+cc_library_shared {
+    name: "libeffectproxy",
+    relative_install_path: "soundfx",
+
+    vendor: true,
+    srcs: ["EffectProxy.cpp"],
+
+    include_dirs: ["."],
+
+    cflags: [
+        "-fvisibility=hidden",
+        "-Wall",
+        "-Werror",
+    ],
+
+    shared_libs: [
+        "liblog",
+        "libcutils",
+        "libutils",
+        "libdl",
+        "libeffects",
+    ],
+    header_libs: [
+        "android.hardware.audio.effect.legacy@2.0",
+    ],
+}
diff --git a/media/libeffects/proxy/Android.mk b/media/libeffects/proxy/Android.mk
deleted file mode 100644
index c4de30d..0000000
--- a/media/libeffects/proxy/Android.mk
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright 2013 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-LOCAL_MODULE:= libeffectproxy
-LOCAL_MODULE_RELATIVE_PATH := soundfx
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_VENDOR_MODULE := true
-LOCAL_SRC_FILES := \
-        EffectProxy.cpp
-
-LOCAL_CFLAGS+= -fvisibility=hidden
-LOCAL_CFLAGS += -Wall -Werror
-
-LOCAL_SHARED_LIBRARIES := liblog libcutils libutils libdl libeffects
-
-LOCAL_C_INCLUDES := \
-        system/media/audio_effects/include \
-        frameworks/av/media/libeffects/factory
-
-include $(BUILD_SHARED_LIBRARY)
-
diff --git a/media/libeffects/visualizer/Android.mk b/media/libeffects/visualizer/Android.mk
index 70409de..ba23fba 100644
--- a/media/libeffects/visualizer/Android.mk
+++ b/media/libeffects/visualizer/Android.mk
@@ -22,5 +22,8 @@
 	$(call include-path-for, audio-effects)
 
 
-LOCAL_HEADER_LIBRARIES += libhardware_headers
+LOCAL_HEADER_LIBRARIES += \
+    libhardware_headers \
+    android.hardware.audio.effect.legacy@2.0 \
+
 include $(BUILD_SHARED_LIBRARY)