1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ST_AUDIO_SESSION_MANAGER_H
17 #define ST_AUDIO_SESSION_MANAGER_H
18 
19 #include "audio_system_manager.h"
20 
21 namespace OHOS {
22 namespace AudioStandard {
23 class AudioSessionCallback {
24 public:
25     virtual ~AudioSessionCallback() = default;
26     /**
27      * @brief OnAudioSessionDeactive will be executed when the audio session is deactivated be others.
28      *
29      * @param deactiveEvent the audio session deactive event info.
30      * @since 12
31      */
32     virtual void OnAudioSessionDeactive(const AudioSessionDeactiveEvent &deactiveEvent) = 0;
33 };
34 
35 class AudioSessionManager {
36 public:
37     AudioSessionManager() = default;
38     virtual ~AudioSessionManager() = default;
39 
40     static AudioSessionManager *GetInstance();
41 
42     /**
43      * @brief Activate audio session.
44      *
45      * @param strategy Target audio session strategy.
46      * @return Returns {@link SUCCESS} if the operation is successful; returns an error code
47      * defined in {@link audio_errors.h} otherwise.
48      * @since 12
49      */
50     int32_t ActivateAudioSession(const AudioSessionStrategy &strategy);
51 
52     /**
53      * @brief Deactivate audio session.
54      *
55      * @return Returns {@link SUCCESS} if the operation is successful; returns an error code
56      * defined in {@link audio_errors.h} otherwise.
57      * @since 12
58      */
59     int32_t DeactivateAudioSession();
60 
61     /**
62      * @brief Query whether the audio session is active.
63      *
64      * @return Returns <b>true</b> if the audio session is active; returns <b>false</b> otherwise.
65      * @since 12
66      */
67     bool IsAudioSessionActivated();
68 
69     /**
70      * @brief Set audio session callback.
71      *
72      * @param audioSessionCallback The audio session callback.
73      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
74      * defined in {@link audio_errors.h} otherwise.
75      * @since 12
76      */
77     int32_t SetAudioSessionCallback(const std::shared_ptr<AudioSessionCallback> &audioSessionCallback);
78 
79     /**
80      * @brief Unset all audio session callbacks.
81      *
82      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
83      * defined in {@link audio_errors.h} otherwise.
84      * @since 12
85      */
86     int32_t UnsetAudioSessionCallback();
87 
88     /**
89      * @brief Unset audio session callback.
90      *
91      * @param audioSessionCallback The audio session callback.
92      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
93      * defined in {@link audio_errors.h} otherwise.
94      * @since 12
95      */
96     int32_t UnsetAudioSessionCallback(const std::shared_ptr<AudioSessionCallback> &audioSessionCallback);
97 };
98 } // namespace AudioStandard
99 } // namespace OHOS
100 #endif // ST_AUDIO_SESSION_MANAGER_H
101