1 /*
2 * Copyright (c) 2023 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 #ifndef LOG_TAG
16 #define LOG_TAG "PolicyProviderStub"
17 #endif
18
19 #include "policy_provider_stub.h"
20 #include "audio_service_log.h"
21 #include "audio_errors.h"
22
23 namespace OHOS {
24 namespace AudioStandard {
25
~PolicyProviderWrapper()26 PolicyProviderWrapper::~PolicyProviderWrapper()
27 {
28 policyWorker_ = nullptr;
29 }
30
PolicyProviderWrapper(IPolicyProvider * policyWorker)31 PolicyProviderWrapper::PolicyProviderWrapper(IPolicyProvider *policyWorker) : policyWorker_(policyWorker)
32 {
33 }
34
GetProcessDeviceInfo(const AudioProcessConfig & config,bool lockFlag,AudioDeviceDescriptor & deviceInfo)35 int32_t PolicyProviderWrapper::GetProcessDeviceInfo(const AudioProcessConfig &config, bool lockFlag,
36 AudioDeviceDescriptor &deviceInfo)
37 {
38 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
39 return policyWorker_->GetProcessDeviceInfo(config, lockFlag, deviceInfo);
40 }
41
InitSharedVolume(std::shared_ptr<AudioSharedMemory> & buffer)42 int32_t PolicyProviderWrapper::InitSharedVolume(std::shared_ptr<AudioSharedMemory> &buffer)
43 {
44 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
45 return policyWorker_->InitSharedVolume(buffer);
46 }
47
NotifyCapturerAdded(const AudioCapturerInfo & capturerInfo,const AudioStreamInfo & streamInfo,uint32_t sessionId)48 int32_t PolicyProviderWrapper::NotifyCapturerAdded(const AudioCapturerInfo &capturerInfo,
49 const AudioStreamInfo &streamInfo, uint32_t sessionId)
50 {
51 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
52 return policyWorker_->NotifyCapturerAdded(capturerInfo, streamInfo, sessionId);
53 }
54
NotifyWakeUpCapturerRemoved()55 int32_t PolicyProviderWrapper::NotifyWakeUpCapturerRemoved()
56 {
57 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
58 return policyWorker_->NotifyWakeUpCapturerRemoved();
59 }
60
IsAbsVolumeSupported(bool & isSupported)61 int32_t PolicyProviderWrapper::IsAbsVolumeSupported(bool &isSupported)
62 {
63 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
64 isSupported = policyWorker_->IsAbsVolumeSupported();
65 return SUCCESS;
66 }
67
OffloadGetRenderPosition(uint32_t & delayValue,uint64_t & sendDataSize,uint32_t & timeStamp)68 int32_t PolicyProviderWrapper::OffloadGetRenderPosition(uint32_t &delayValue, uint64_t &sendDataSize,
69 uint32_t &timeStamp)
70 {
71 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
72 return policyWorker_->OffloadGetRenderPosition(delayValue, sendDataSize, timeStamp);
73 }
74
NearlinkGetRenderPosition(uint32_t & delayValue)75 int32_t PolicyProviderWrapper::NearlinkGetRenderPosition(uint32_t &delayValue)
76 {
77 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
78 return policyWorker_->NearlinkGetRenderPosition(delayValue);
79 }
80
GetAndSaveClientType(uint32_t uid,const std::string & bundleName)81 int32_t PolicyProviderWrapper::GetAndSaveClientType(uint32_t uid, const std::string &bundleName)
82 {
83 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
84 return policyWorker_->GetAndSaveClientType(uid, bundleName);
85 }
86
GetMaxRendererInstances(int32_t & maxInstances)87 int32_t PolicyProviderWrapper::GetMaxRendererInstances(int32_t &maxInstances)
88 {
89 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
90 maxInstances = policyWorker_->GetMaxRendererInstances();
91 return SUCCESS;
92 }
93
NotifyCapturerRemoved(uint64_t sessionId)94 int32_t PolicyProviderWrapper::NotifyCapturerRemoved(uint64_t sessionId)
95 {
96 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
97 return policyWorker_->NotifyCapturerRemoved(sessionId);
98 }
99
LoadModernInnerCapSink(int32_t innerCapId)100 int32_t PolicyProviderWrapper::LoadModernInnerCapSink(int32_t innerCapId)
101 {
102 #ifdef HAS_FEATURE_INNERCAPTURER
103 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
104 return policyWorker_->LoadModernInnerCapSink(innerCapId);
105 #else
106 (void)innerCapId;
107 return AUDIO_ERR;
108 #endif
109 }
110
UnloadModernInnerCapSink(int32_t innerCapId)111 int32_t PolicyProviderWrapper::UnloadModernInnerCapSink(int32_t innerCapId)
112 {
113 #ifdef HAS_FEATURE_INNERCAPTURER
114 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
115 return policyWorker_->UnloadModernInnerCapSink(innerCapId);
116 #else
117 (void)innerCapId;
118 return AUDIO_ERR;
119 #endif
120 }
121
ClearAudioFocusBySessionID(int32_t sessionID)122 int32_t PolicyProviderWrapper::ClearAudioFocusBySessionID(int32_t sessionID)
123 {
124 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
125 return policyWorker_->ClearAudioFocusBySessionID(sessionID);
126 }
127
CaptureConcurrentCheck(const uint32_t sessionID)128 int32_t PolicyProviderWrapper::CaptureConcurrentCheck(const uint32_t sessionID)
129 {
130 CHECK_AND_RETURN_RET_LOG(policyWorker_ != nullptr, AUDIO_INIT_FAIL, "policyWorker_ is null");
131 return policyWorker_->CaptureConcurrentCheck(sessionID);
132 }
133 } // namespace AudioStandard
134 } // namespace OHOS
135