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/modules/audio/Android.bp b/modules/audio/Android.bp
index a7467c2..7929c66 100644
--- a/modules/audio/Android.bp
+++ b/modules/audio/Android.bp
@@ -23,7 +23,10 @@
     relative_install_path: "hw",
     proprietary: true,
     srcs: ["audio_hw.c"],
-    header_libs: ["libhardware_headers"],
+    header_libs: [
+        "libhardware_headers",
+        "android.hardware.audio.common.legacy@2.0",
+    ],
     shared_libs: [
         "liblog",
     ],
@@ -41,21 +44,10 @@
     relative_install_path: "hw",
     proprietary: true,
     srcs: ["audio_hw.c"],
-    header_libs: ["libhardware_headers"],
-    shared_libs: [
-        "liblog",
+    header_libs: [
+        "libhardware_headers",
+        "android.hardware.audio.common.legacy@2.0",
     ],
-    cflags: ["-Wall", "-Werror", "-Wno-unused-parameter"],
-}
-
-// The stub audio policy HAL module that can be used as a skeleton for
-// new implementations.
-cc_library_shared {
-    name: "audio_policy.stub",
-    relative_install_path: "hw",
-    proprietary: true,
-    srcs: ["audio_policy.c"],
-    header_libs: ["libhardware_headers"],
     shared_libs: [
         "liblog",
     ],
diff --git a/modules/audio/audio_policy.c b/modules/audio/audio_policy.c
deleted file mode 100644
index 4f9cd5a..0000000
--- a/modules/audio/audio_policy.c
+++ /dev/null
@@ -1,350 +0,0 @@
-/*
- * Copyright (C) 2011 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.
- */
-
-#define LOG_TAG "audio_policy_default"
-//#define LOG_NDEBUG 0
-
-#include <errno.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <hardware/hardware.h>
-#include <system/audio.h>
-#include <system/audio_policy.h>
-#include <hardware/audio_policy.h>
-
-struct default_ap_module {
-    struct audio_policy_module module;
-};
-
-struct default_ap_device {
-    struct audio_policy_device device;
-};
-
-struct default_audio_policy {
-    struct audio_policy policy;
-
-    struct audio_policy_service_ops *aps_ops;
-    void *service;
-};
-
-static int ap_set_device_connection_state(struct audio_policy *pol,
-                                          audio_devices_t device,
-                                          audio_policy_dev_state_t state,
-                                          const char *device_address)
-{
-    return -ENOSYS;
-}
-
-static audio_policy_dev_state_t ap_get_device_connection_state(
-                                            const struct audio_policy *pol,
-                                            audio_devices_t device,
-                                            const char *device_address)
-{
-    return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
-}
-
-static void ap_set_phone_state(struct audio_policy *pol, audio_mode_t state)
-{
-}
-
-// deprecated, never called
-static void ap_set_ringer_mode(struct audio_policy *pol, uint32_t mode,
-                               uint32_t mask)
-{
-}
-
-static void ap_set_force_use(struct audio_policy *pol,
-                          audio_policy_force_use_t usage,
-                          audio_policy_forced_cfg_t config)
-{
-}
-
-    /* retreive current device category forced for a given usage */
-static audio_policy_forced_cfg_t ap_get_force_use(
-                                               const struct audio_policy *pol,
-                                               audio_policy_force_use_t usage)
-{
-    return AUDIO_POLICY_FORCE_NONE;
-}
-
-/* if can_mute is true, then audio streams that are marked ENFORCED_AUDIBLE
- * can still be muted. */
-static void ap_set_can_mute_enforced_audible(struct audio_policy *pol,
-                                             bool can_mute)
-{
-}
-
-static int ap_init_check(const struct audio_policy *pol)
-{
-    return 0;
-}
-
-static audio_io_handle_t ap_get_output(struct audio_policy *pol,
-                                       audio_stream_type_t stream,
-                                       uint32_t sampling_rate,
-                                       audio_format_t format,
-                                       audio_channel_mask_t channelMask,
-                                       audio_output_flags_t flags,
-                                       const audio_offload_info_t *info)
-{
-    return 0;
-}
-
-static int ap_start_output(struct audio_policy *pol, audio_io_handle_t output,
-                           audio_stream_type_t stream, int session)
-{
-    return -ENOSYS;
-}
-
-static int ap_stop_output(struct audio_policy *pol, audio_io_handle_t output,
-                          audio_stream_type_t stream, int session)
-{
-    return -ENOSYS;
-}
-
-static void ap_release_output(struct audio_policy *pol,
-                              audio_io_handle_t output)
-{
-}
-
-static audio_io_handle_t ap_get_input(struct audio_policy *pol, audio_source_t inputSource,
-                                      uint32_t sampling_rate,
-                                      audio_format_t format,
-                                      audio_channel_mask_t channelMask,
-                                      audio_in_acoustics_t acoustics)
-{
-    return 0;
-}
-
-static int ap_start_input(struct audio_policy *pol, audio_io_handle_t input)
-{
-    return -ENOSYS;
-}
-
-static int ap_stop_input(struct audio_policy *pol, audio_io_handle_t input)
-{
-    return -ENOSYS;
-}
-
-static void ap_release_input(struct audio_policy *pol, audio_io_handle_t input)
-{
-}
-
-static void ap_init_stream_volume(struct audio_policy *pol,
-                                  audio_stream_type_t stream, int index_min,
-                                  int index_max)
-{
-}
-
-static int ap_set_stream_volume_index(struct audio_policy *pol,
-                                      audio_stream_type_t stream,
-                                      int index)
-{
-    return -ENOSYS;
-}
-
-static int ap_get_stream_volume_index(const struct audio_policy *pol,
-                                      audio_stream_type_t stream,
-                                      int *index)
-{
-    return -ENOSYS;
-}
-
-static int ap_set_stream_volume_index_for_device(struct audio_policy *pol,
-                                      audio_stream_type_t stream,
-                                      int index,
-                                      audio_devices_t device)
-{
-    return -ENOSYS;
-}
-
-static int ap_get_stream_volume_index_for_device(const struct audio_policy *pol,
-                                      audio_stream_type_t stream,
-                                      int *index,
-                                      audio_devices_t device)
-{
-    return -ENOSYS;
-}
-
-static uint32_t ap_get_strategy_for_stream(const struct audio_policy *pol,
-                                           audio_stream_type_t stream)
-{
-    return 0;
-}
-
-static audio_devices_t ap_get_devices_for_stream(const struct audio_policy *pol,
-                                          audio_stream_type_t stream)
-{
-    return 0;
-}
-
-static audio_io_handle_t ap_get_output_for_effect(struct audio_policy *pol,
-                                            const struct effect_descriptor_s *desc)
-{
-    return 0;
-}
-
-static int ap_register_effect(struct audio_policy *pol,
-                              const struct effect_descriptor_s *desc,
-                              audio_io_handle_t output,
-                              uint32_t strategy,
-                              int session,
-                              int id)
-{
-    return -ENOSYS;
-}
-
-static int ap_unregister_effect(struct audio_policy *pol, int id)
-{
-    return -ENOSYS;
-}
-
-static int ap_set_effect_enabled(struct audio_policy *pol, int id, bool enabled)
-{
-    return -ENOSYS;
-}
-
-static bool ap_is_stream_active(const struct audio_policy *pol, audio_stream_type_t stream,
-                                uint32_t in_past_ms)
-{
-    return false;
-}
-
-static int ap_dump(const struct audio_policy *pol, int fd)
-{
-    return -ENOSYS;
-}
-
-static bool ap_is_offload_supported(const struct audio_policy *pol,
-                                   const audio_offload_info_t *info)
-{
-    return false;
-}
-
-static int create_default_ap(const struct audio_policy_device *device,
-                             struct audio_policy_service_ops *aps_ops,
-                             void *service,
-                             struct audio_policy **ap)
-{
-    struct default_audio_policy *dap;
-
-    *ap = NULL;
-
-    if (!service || !aps_ops)
-        return -EINVAL;
-
-    dap = (struct default_audio_policy *)calloc(1, sizeof(*dap));
-    if (!dap)
-        return -ENOMEM;
-
-    dap->policy.set_device_connection_state = ap_set_device_connection_state;
-    dap->policy.get_device_connection_state = ap_get_device_connection_state;
-    dap->policy.set_phone_state = ap_set_phone_state;
-    dap->policy.set_ringer_mode = ap_set_ringer_mode;
-    dap->policy.set_force_use = ap_set_force_use;
-    dap->policy.get_force_use = ap_get_force_use;
-    dap->policy.set_can_mute_enforced_audible =
-        ap_set_can_mute_enforced_audible;
-    dap->policy.init_check = ap_init_check;
-    dap->policy.get_output = ap_get_output;
-    dap->policy.start_output = ap_start_output;
-    dap->policy.stop_output = ap_stop_output;
-    dap->policy.release_output = ap_release_output;
-    dap->policy.get_input = ap_get_input;
-    dap->policy.start_input = ap_start_input;
-    dap->policy.stop_input = ap_stop_input;
-    dap->policy.release_input = ap_release_input;
-    dap->policy.init_stream_volume = ap_init_stream_volume;
-    dap->policy.set_stream_volume_index = ap_set_stream_volume_index;
-    dap->policy.get_stream_volume_index = ap_get_stream_volume_index;
-    dap->policy.set_stream_volume_index_for_device = ap_set_stream_volume_index_for_device;
-    dap->policy.get_stream_volume_index_for_device = ap_get_stream_volume_index_for_device;
-    dap->policy.get_strategy_for_stream = ap_get_strategy_for_stream;
-    dap->policy.get_devices_for_stream = ap_get_devices_for_stream;
-    dap->policy.get_output_for_effect = ap_get_output_for_effect;
-    dap->policy.register_effect = ap_register_effect;
-    dap->policy.unregister_effect = ap_unregister_effect;
-    dap->policy.set_effect_enabled = ap_set_effect_enabled;
-    dap->policy.is_stream_active = ap_is_stream_active;
-    dap->policy.dump = ap_dump;
-
-    dap->policy.is_offload_supported = ap_is_offload_supported;
-
-    dap->service = service;
-    dap->aps_ops = aps_ops;
-
-    *ap = &dap->policy;
-    return 0;
-}
-
-static int destroy_default_ap(const struct audio_policy_device *ap_dev,
-                              struct audio_policy *ap)
-{
-    free(ap);
-    return 0;
-}
-
-static int default_ap_dev_close(hw_device_t* device)
-{
-    free(device);
-    return 0;
-}
-
-static int default_ap_dev_open(const hw_module_t* module, const char* name,
-                               hw_device_t** device)
-{
-    struct default_ap_device *dev;
-
-    *device = NULL;
-
-    if (strcmp(name, AUDIO_POLICY_INTERFACE) != 0)
-        return -EINVAL;
-
-    dev = (struct default_ap_device *)calloc(1, sizeof(*dev));
-    if (!dev)
-        return -ENOMEM;
-
-    dev->device.common.tag = HARDWARE_DEVICE_TAG;
-    dev->device.common.version = 0;
-    dev->device.common.module = (hw_module_t *)module;
-    dev->device.common.close = default_ap_dev_close;
-    dev->device.create_audio_policy = create_default_ap;
-    dev->device.destroy_audio_policy = destroy_default_ap;
-
-    *device = &dev->device.common;
-
-    return 0;
-}
-
-static struct hw_module_methods_t default_ap_module_methods = {
-    .open = default_ap_dev_open,
-};
-
-struct default_ap_module HAL_MODULE_INFO_SYM = {
-    .module = {
-        .common = {
-            .tag            = HARDWARE_MODULE_TAG,
-            .version_major  = 1,
-            .version_minor  = 0,
-            .id             = AUDIO_POLICY_HARDWARE_MODULE_ID,
-            .name           = "Default audio policy HAL",
-            .author         = "The Android Open Source Project",
-            .methods        = &default_ap_module_methods,
-        },
-    },
-};
diff --git a/modules/audio_remote_submix/Android.bp b/modules/audio_remote_submix/Android.bp
index c7d018c..578949e 100644
--- a/modules/audio_remote_submix/Android.bp
+++ b/modules/audio_remote_submix/Android.bp
@@ -17,16 +17,15 @@
     relative_install_path: "hw",
     vendor: true,
     srcs: ["audio_hw.cpp"],
-    include_dirs: [
-        "system/media/audio_utils/include",
-    ],
+
     shared_libs: [
         "liblog",
         "libcutils",
         "libutils",
-        "libnbaio_mono",
+        "libnbaio_mono@2.0",
+        "libaudioutils",
     ],
-    static_libs: ["libmedia_helper"],
+    static_libs: ["libmedia_helper@2.0"],
 
     cflags: ["-Wno-unused-parameter"],
 
diff --git a/modules/usbaudio/Android.bp b/modules/usbaudio/Android.bp
index c7d403f..ecc74fb 100644
--- a/modules/usbaudio/Android.bp
+++ b/modules/usbaudio/Android.bp
@@ -25,5 +25,7 @@
         "libalsautils",
     ],
     cflags: ["-Wno-unused-parameter"],
-    header_libs: ["libhardware_headers"],
+    header_libs: [
+        "android.hardware.audio.common.legacy@2.0",
+    ],
 }