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

Commit ac830ff8 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 8554681 from 70142153 to tm-release

Change-Id: I1dc8e6c26d0739afab42e8f54a255472b4653465
parents 1f6c8a2b 70142153
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -832,6 +832,11 @@ const sp<IAudioPolicyService> AudioSystem::get_audio_policy_service() {
    return ap;
}

void AudioSystem::clearAudioPolicyService() {
    Mutex::Autolock _l(gLockAPS);
    gAudioPolicyService.clear();
}

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

void AudioSystem::onNewAudioModulesAvailable() {
@@ -1150,8 +1155,15 @@ status_t AudioSystem::initStreamVolume(audio_stream_type_t stream,
            legacy2aidl_audio_stream_type_t_AudioStreamType(stream));
    int32_t indexMinAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(indexMin));
    int32_t indexMaxAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(indexMax));
    return statusTFromBinderStatus(
    status_t status = statusTFromBinderStatus(
            aps->initStreamVolume(streamAidl, indexMinAidl, indexMaxAidl));
    if (status == DEAD_OBJECT) {
        // This is a critical operation since w/o proper stream volumes no audio
        // will be heard. Make sure we recover from a failure in any case.
        ALOGE("Received DEAD_OBJECT from APS, clearing the client");
        clearAudioPolicyService();
    }
    return status;
}

status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream,
@@ -1412,10 +1424,7 @@ void AudioSystem::clearAudioConfigCache() {
        }
        gAudioFlinger.clear();
    }
    {
        Mutex::Autolock _l(gLockAPS);
        gAudioPolicyService.clear();
    }
    clearAudioPolicyService();
}

status_t AudioSystem::setSupportedSystemUsages(const std::vector<audio_usage_t>& systemUsages) {
@@ -2603,10 +2612,7 @@ void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who __
            mAudioVolumeGroupCallback[i]->onServiceDied();
        }
    }
    {
        Mutex::Autolock _l(gLockAPS);
        AudioSystem::gAudioPolicyService.clear();
    }
    AudioSystem::clearAudioPolicyService();

    ALOGW("AudioPolicyService server died!");
}
+1 −0
Original line number Diff line number Diff line
@@ -350,6 +350,7 @@ public:
    static void clearAudioConfigCache();

    static const sp<media::IAudioPolicyService> get_audio_policy_service();
    static void clearAudioPolicyService();

    // helpers for android.media.AudioManager.getProperty(), see description there for meaning
    static uint32_t getPrimaryOutputSamplingRate();
+7 −0
Original line number Diff line number Diff line
@@ -70,6 +70,13 @@ const DeviceTypeSet& getAudioDeviceOutAllBleSet() {
    return audioDeviceOutAllBleSet;
}

const DeviceTypeSet& getAudioDeviceOutLeAudioUnicastSet() {
    static const DeviceTypeSet audioDeviceOutLeAudioUnicastSet = DeviceTypeSet(
            std::begin(AUDIO_DEVICE_OUT_BLE_UNICAST_ARRAY),
            std::end(AUDIO_DEVICE_OUT_BLE_UNICAST_ARRAY));
    return audioDeviceOutLeAudioUnicastSet;
}

std::string deviceTypesToString(const DeviceTypeSet &deviceTypes) {
    if (deviceTypes.empty()) {
        return "Empty device types";
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ const DeviceTypeSet& getAudioDeviceOutAllUsbSet();
const DeviceTypeSet& getAudioDeviceInAllSet();
const DeviceTypeSet& getAudioDeviceInAllUsbSet();
const DeviceTypeSet& getAudioDeviceOutAllBleSet();
const DeviceTypeSet& getAudioDeviceOutLeAudioUnicastSet();

template<typename T>
static std::vector<T> Intersection(const std::set<T>& a, const std::set<T>& b) {
+81 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.
 */

#pragma once

#include "MethodStatistics.h"
#include <chrono>
#include <memory>
#include <string>
#include <utility>

namespace android::mediautils {

class ScopedStatistics {
  public:
    /**
     * ScopedStatistics is a RAII way of obtaining
     * execution time statistics for a scoped C++ block.
     *
     * It updates the MethodStatistics shared pointer parameter
     * with the methodName parameter and the duration/lifetime of the
     * ScopedStatistics object.
     *
     * Not thread-safe, but expected to run in a single execution
     * thread, and there are no user serviceable parts exposed.
     *
     * Example:
     *
     * std::shared_ptr<mediautils::MethodStatistics<std::string>> stats =
     *     std::make_shared<mediautils::MethodStatistics<std::string>>();
     *
     * // ...
     * {
     *    mediautils::ScopedStatistics scopedStatistics("MyClass:myMethod", stats);
     *
     *    // some work to be timed here - up to the end of the block.
     * }
     *
     * \param methodName the methodname to use "ClassName::methodName"
     * \param statistics a shared ptr to the MethodStatistics object to use.
     */
    ScopedStatistics(std::string methodName,
               std::shared_ptr<mediautils::MethodStatistics<std::string>> statistics)
        : mMethodName{std::move(methodName)}
        , mStatistics{std::move(statistics)}
        , mBegin{std::chrono::steady_clock::now()} {}

    // No copy constructor.
    ScopedStatistics(const ScopedStatistics& scopedStatistics) = delete;
    ScopedStatistics& operator=(const ScopedStatistics& scopedStatistics) = delete;

    ~ScopedStatistics() {
        if (mStatistics) {
            const float elapsedMs = std::chrono::duration_cast<std::chrono::nanoseconds>(
                                            std::chrono::steady_clock::now() - mBegin)
                                            .count() *
                                    1e-6; // ns to ms.
            mStatistics->event(mMethodName, elapsedMs);
        }
    }

  private:
    const std::string mMethodName;
    const std::shared_ptr<mediautils::MethodStatistics<std::string>> mStatistics;
    const std::chrono::steady_clock::time_point mBegin;
};

} // namespace android::mediautils
Loading