Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87818d36 authored by Atneya Nair's avatar Atneya Nair
Browse files

Add AudioPolicyServiceLocal interface

Audioflinger currently accesses AudioPolicyService through AudioSystem
which accesses the service through the binder interface.

To simplify, reduce maintenance, remove shim layers, etc., follow the
approach within SystemServer to pass a separate non-binder audiopolicy
interface, since the two run in the same process (and it is not feasible
to ever run them in different processes).

Eventually, we can remove AudioSystem as the intra-service method of
access, and remove all local-only calls from the AudioPolicyService
binder interface.

Test: Compiles
Bug: 338089555
Flag: EXEMPT safe change, adding interfaces
Change-Id: I920d8ba728347f056ce14d606248bba4466cb5eb
parent c23be504
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ cc_binary {
    ],

    header_libs: [
        "audiopolicyservicelocal_headers",
        "libaudiohal_headers",
        "libmedia_headers",
        "libmediametrics_headers",
+1 −0
Original line number Diff line number Diff line
@@ -168,6 +168,7 @@ int main(int argc __unused, char **argv)
        ALOGW_IF(AudioSystem::setLocalAudioFlinger(af) != OK,
                "%s: AudioSystem already has an AudioFlinger instance!", __func__);
        const auto aps = sp<AudioPolicyService>::make();
        af->initAudioPolicyLocal(aps);
        ALOGD("%s: AudioPolicy created", __func__);
        ALOGW_IF(AudioSystem::setLocalAudioPolicyService(aps) != OK,
                 "%s: AudioSystem already has an AudioPolicyService instance!", __func__);
+4 −0
Original line number Diff line number Diff line
@@ -218,6 +218,8 @@ cc_library {
    ],

    header_libs: [
        "audiopermissioncontroller_headers",
        "audiopolicyservicelocal_headers",
        "libaaudio_headers",
        "libaudioclient_headers",
        "libaudiohal_headers",
@@ -225,6 +227,8 @@ cc_library {
        "libmedia_headers",
    ],

    export_header_lib_headers: ["audiopolicyservicelocal_headers"],

    export_shared_lib_headers: [
        "libpermission",
    ],
+11 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include <audio_utils/FdToString.h>
#include <audio_utils/SimpleLog.h>
#include <media/IAudioFlinger.h>
#include <media/IAudioPolicyServiceLocal.h>
#include <media/MediaMetricsItem.h>
#include <media/audiohal/DevicesFactoryHalInterface.h>
#include <mediautils/ServiceUtilities.h>
@@ -420,6 +421,13 @@ public:
                            const sp<MmapStreamCallback>& callback,
                            sp<MmapStreamInterface>& interface,
            audio_port_handle_t *handle) EXCLUDES_AudioFlinger_Mutex;

    void initAudioPolicyLocal(sp<media::IAudioPolicyServiceLocal> audioPolicyLocal) {
        if (mAudioPolicyServiceLocal.load() == nullptr) {
            mAudioPolicyServiceLocal = std::move(audioPolicyLocal);
        }
    }

private:
    // FIXME The 400 is temporarily too high until a leak of writers in media.log is fixed.
    static const size_t kLogMemorySize = 400 * 1024;
@@ -774,6 +782,9 @@ private:

    // Bluetooth Variable latency control logic is enabled or disabled
    std::atomic<bool> mBluetoothLatencyModesEnabled = true;

    // Local interface to AudioPolicyService, late inited, but logically const
    mediautils::atomic_sp<media::IAudioPolicyServiceLocal> mAudioPolicyServiceLocal;
};

// ----------------------------------------------------------------------------
+6 −0
Original line number Diff line number Diff line
@@ -3,6 +3,12 @@ package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

cc_library_headers {
    name: "audiopermissioncontroller_headers",
    host_supported: true,
    export_include_dirs: ["include"],
}

cc_library {
    name: "audiopermissioncontroller",

Loading