146f34cbfSopenharmony_ci/*
246f34cbfSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
346f34cbfSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
446f34cbfSopenharmony_ci * you may not use this file except in compliance with the License.
546f34cbfSopenharmony_ci * You may obtain a copy of the License at
646f34cbfSopenharmony_ci *
746f34cbfSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
846f34cbfSopenharmony_ci *
946f34cbfSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1046f34cbfSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1146f34cbfSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1246f34cbfSopenharmony_ci * See the License for the specific language governing permissions and
1346f34cbfSopenharmony_ci * limitations under the License.
1446f34cbfSopenharmony_ci */
1546f34cbfSopenharmony_ci
1646f34cbfSopenharmony_ci#ifndef OH_AUDIO_SESSION_MANAGER_H
1746f34cbfSopenharmony_ci#define OH_AUDIO_SESSION_MANAGER_H
1846f34cbfSopenharmony_ci
1946f34cbfSopenharmony_ci#include "audio_log.h"
2046f34cbfSopenharmony_ci#include "native_audio_session_manager.h"
2146f34cbfSopenharmony_ci#include "audio_session_manager.h"
2246f34cbfSopenharmony_ci
2346f34cbfSopenharmony_cinamespace OHOS {
2446f34cbfSopenharmony_cinamespace AudioStandard {
2546f34cbfSopenharmony_ci
2646f34cbfSopenharmony_ciclass OHAudioSessionCallback : public AudioSessionCallback {
2746f34cbfSopenharmony_cipublic:
2846f34cbfSopenharmony_ci    explicit OHAudioSessionCallback(OH_AudioSession_DeactivatedCallback callback)
2946f34cbfSopenharmony_ci        : callback_(callback)
3046f34cbfSopenharmony_ci    {
3146f34cbfSopenharmony_ci    }
3246f34cbfSopenharmony_ci
3346f34cbfSopenharmony_ci    void OnAudioSessionDeactive(const AudioSessionDeactiveEvent &deactiveEvent) override;
3446f34cbfSopenharmony_ci
3546f34cbfSopenharmony_ci    OH_AudioSession_DeactivatedCallback GetCallback()
3646f34cbfSopenharmony_ci    {
3746f34cbfSopenharmony_ci        return callback_;
3846f34cbfSopenharmony_ci    }
3946f34cbfSopenharmony_ci
4046f34cbfSopenharmony_ci    ~OHAudioSessionCallback()
4146f34cbfSopenharmony_ci    {
4246f34cbfSopenharmony_ci        AUDIO_INFO_LOG("~OHAudioSessionCallback called.");
4346f34cbfSopenharmony_ci        callback_ = nullptr;
4446f34cbfSopenharmony_ci    }
4546f34cbfSopenharmony_ciprivate:
4646f34cbfSopenharmony_ci    OH_AudioSession_DeactivatedCallback callback_;
4746f34cbfSopenharmony_ci};
4846f34cbfSopenharmony_ci
4946f34cbfSopenharmony_ciclass OHAudioSessionManager {
5046f34cbfSopenharmony_cipublic:
5146f34cbfSopenharmony_ci    ~OHAudioSessionManager();
5246f34cbfSopenharmony_ci
5346f34cbfSopenharmony_ci    static OHAudioSessionManager* GetInstance()
5446f34cbfSopenharmony_ci    {
5546f34cbfSopenharmony_ci        if (!ohAudioSessionManager_) {
5646f34cbfSopenharmony_ci            ohAudioSessionManager_ = new OHAudioSessionManager();
5746f34cbfSopenharmony_ci        }
5846f34cbfSopenharmony_ci        return ohAudioSessionManager_;
5946f34cbfSopenharmony_ci    }
6046f34cbfSopenharmony_ci
6146f34cbfSopenharmony_ci    OH_AudioCommon_Result ActivateAudioSession(const AudioSessionStrategy &strategy);
6246f34cbfSopenharmony_ci
6346f34cbfSopenharmony_ci    OH_AudioCommon_Result DeactivateAudioSession();
6446f34cbfSopenharmony_ci
6546f34cbfSopenharmony_ci    bool IsAudioSessionActivated();
6646f34cbfSopenharmony_ci
6746f34cbfSopenharmony_ci    OH_AudioCommon_Result SetAudioSessionCallback(OH_AudioSession_DeactivatedCallback callback);
6846f34cbfSopenharmony_ci
6946f34cbfSopenharmony_ci    OH_AudioCommon_Result UnsetAudioSessionCallback(OH_AudioSession_DeactivatedCallback callback);
7046f34cbfSopenharmony_ci
7146f34cbfSopenharmony_ciprivate:
7246f34cbfSopenharmony_ci    OHAudioSessionManager();
7346f34cbfSopenharmony_ci
7446f34cbfSopenharmony_ci    static OHAudioSessionManager *ohAudioSessionManager_;
7546f34cbfSopenharmony_ci
7646f34cbfSopenharmony_ci    AudioSessionManager *audioSessionManager_ = AudioSessionManager::GetInstance();
7746f34cbfSopenharmony_ci};
7846f34cbfSopenharmony_ci
7946f34cbfSopenharmony_ciOHAudioSessionManager* OHAudioSessionManager::ohAudioSessionManager_ = nullptr;
8046f34cbfSopenharmony_ci
8146f34cbfSopenharmony_ci} // namespace AudioStandard
8246f34cbfSopenharmony_ci} // namespace OHOS
8346f34cbfSopenharmony_ci#endif // OH_AUDIO_SESSION_MANAGER_H