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

Commit 09c60172 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "AudioSystem : Add method to disable creation of thread pool" into main...

Merge "AudioSystem : Add method to disable creation of thread pool" into main am: 1f603834 am: 066bec5d

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/3031323



Change-Id: Ib541833d83189ac5ccc25e74c48cfa71c7f01aa6
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 2f8620dc 066bec5d
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ template <typename ServiceInterface, typename Client, typename AidlInterface,
        typename ServiceTraits>
class ServiceHandler {
public:
    sp<ServiceInterface> getService(bool canStartThreadPool = true)
    sp<ServiceInterface> getService()
            EXCLUDES(mMutex) NO_THREAD_SAFETY_ANALYSIS {  // std::unique_ptr
        sp<ServiceInterface> service;
        sp<Client> client;
@@ -143,7 +143,7 @@ public:
        client = mClient;
        service = mService;
        // Make sure callbacks can be received by the client
        if (canStartThreadPool) {
        if (mCanStartThreadPool) {
            ProcessState::self()->startThreadPool();
        }
        ul.unlock();
@@ -186,6 +186,10 @@ public:
        if (mClient) ServiceTraits::onClearService(mClient);
    }

    void disableThreadPool() {
        mCanStartThreadPool = false;
    }

private:
    std::mutex mSingleGetter;
    std::mutex mMutex;
@@ -194,6 +198,7 @@ private:
    sp<ServiceInterface> mLocalService GUARDED_BY(mMutex);
    sp<ServiceInterface> mService GUARDED_BY(mMutex);
    sp<Client> mClient GUARDED_BY(mMutex);
    std::atomic<bool> mCanStartThreadPool = true;
};

struct AudioFlingerTraits {
@@ -224,10 +229,6 @@ sp<IAudioFlinger> AudioSystem::get_audio_flinger() {
    return gAudioFlingerServiceHandler.getService();
}

sp<IAudioFlinger> AudioSystem::get_audio_flinger_for_fuzzer() {
    return gAudioFlingerServiceHandler.getService(false /* canStartThreadPool */);
}

sp<AudioSystem::AudioFlingerClient> AudioSystem::getAudioFlingerClient() {
    return gAudioFlingerServiceHandler.getClient();
}
@@ -957,6 +958,11 @@ void AudioSystem::clearAudioPolicyService() {
    gAudioPolicyServiceHandler.clearService();
}

void AudioSystem::disableThreadPool() {
    gAudioFlingerServiceHandler.disableThreadPool();
    gAudioPolicyServiceHandler.disableThreadPool();
}

// ---------------------------------------------------------------------------

void AudioSystem::onNewAudioModulesAvailable() {
+3 −1
Original line number Diff line number Diff line
@@ -77,6 +77,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
    CHECK_EQ(NO_ERROR, AServiceManager_addService(moduleService.get()->asBinder().get(),
                                                  "android.hardware.audio.core.IModule/default"));

    // Disable creating thread pool for fuzzer instance of audio flinger and audio policy services
    AudioSystem::disableThreadPool();

    const auto audioFlinger = sp<AudioFlinger>::make();
    const auto afAdapter = sp<AudioFlingerServerAdapter>::make(audioFlinger);

@@ -85,7 +88,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
                     String16(IAudioFlinger::DEFAULT_SERVICE_NAME), IInterface::asBinder(afAdapter),
                     false /* allowIsolated */, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT));

    AudioSystem::get_audio_flinger_for_fuzzer();
    const auto audioPolicyService = sp<AudioPolicyService>::make();

    CHECK_EQ(NO_ERROR,
+4 −1
Original line number Diff line number Diff line
@@ -187,7 +187,10 @@ public:

    // helper function to obtain AudioFlinger service handle
    static sp<IAudioFlinger> get_audio_flinger();
    static sp<IAudioFlinger> get_audio_flinger_for_fuzzer();

    // function to disable creation of thread pool (Used for testing).
    // This should be called before get_audio_flinger() or get_audio_policy_service().
    static void disableThreadPool();

    static float linearToLog(int volume);
    static int logToLinear(float volume);
+3 −1
Original line number Diff line number Diff line
@@ -79,6 +79,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
    CHECK_EQ(NO_ERROR, AServiceManager_addService(moduleService.get()->asBinder().get(),
                                                  "android.hardware.audio.core.IModule/default"));

    // Disable creating thread pool for fuzzer instance of audio flinger and audio policy services
    AudioSystem::disableThreadPool();

    const auto audioFlinger = sp<AudioFlinger>::make();
    const auto afAdapter = sp<AudioFlingerServerAdapter>::make(audioFlinger);

@@ -87,7 +90,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
                     String16(IAudioFlinger::DEFAULT_SERVICE_NAME), IInterface::asBinder(afAdapter),
                     false /* allowIsolated */, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT));

    AudioSystem::get_audio_flinger_for_fuzzer();
    const auto audioPolicyService = sp<AudioPolicyService>::make();

    CHECK_EQ(NO_ERROR,