• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 POLICY_HANDLER_H
17 #define POLICY_HANDLER_H
18 
19 #include <sstream>
20 #include <map>
21 #include <mutex>
22 #include <vector>
23 
24 #include "ipolicy_provider_ipc.h"
25 #include "i_policy_provider.h"
26 
27 namespace OHOS {
28 namespace AudioStandard {
29 class PolicyHandler {
30 public:
31     static PolicyHandler& GetInstance();
32 
33     ~PolicyHandler();
34 
35     void Dump(std::string &dumpString);
36 
37     // would be called only once
38     bool ConfigPolicyProvider(const sptr<IPolicyProviderIpc> policyProvider);
39 
40     bool GetProcessDeviceInfo(const AudioProcessConfig &config, bool lockFlag, AudioDeviceDescriptor &deviceInfo);
41 
42     bool InitVolumeMap();
43 
44     bool GetSharedVolume(AudioVolumeType streamType, DeviceType deviceType, Volume &vol);
45 
46     void SetActiveOutputDevice(DeviceType deviceType);
47 
48     uint32_t GenerateSessionId(int32_t uid);
49 
50     DeviceType GetActiveOutPutDevice();
51 
52     int32_t NotifyCapturerAdded(AudioCapturerInfo capturerInfo, AudioStreamInfo streamInfo, uint32_t sessionId);
53 
54     int32_t NotifyWakeUpCapturerRemoved();
55 
56     bool IsAbsVolumeSupported();
57 
58     int32_t OffloadGetRenderPosition(uint32_t &delayValue, uint64_t &sendDataSize, uint32_t &timeStamp);
59 
60     int32_t NearlinkGetRenderPosition(uint32_t &delayValue);
61 
62     bool GetHighResolutionExist();
63 
64     void SetHighResolutionExist(bool isHighResExist);
65 
66     int32_t GetAndSaveClientType(uint32_t uid, const std::string &bundleName);
67 
68     int32_t GetMaxRendererInstances();
69 
70     int32_t NotifyCapturerRemoved(uint64_t sessionId);
71 
72 #ifdef HAS_FEATURE_INNERCAPTURER
73     int32_t LoadModernInnerCapSink(int32_t innerCapId);
74 
75     int32_t UnloadModernInnerCapSink(int32_t innerCapId);
76 #endif
77     int32_t ClearAudioFocusBySessionID(const int32_t &sessionID);
78 
79     int32_t CaptureConcurrentCheck(const uint32_t &sessionID);
80 private:
81     PolicyHandler();
82     sptr<IPolicyProviderIpc> iPolicyProvider_ = nullptr;
83 
84 private:
85     std::shared_ptr<AudioSharedMemory> policyVolumeMap_ = nullptr;
86     volatile Volume *volumeVector_ = nullptr;
87     volatile bool *sharedAbsVolumeScene_ = nullptr;
88     DeviceType deviceType_ = DEVICE_TYPE_SPEAKER;
89     bool isHighResolutionExist_ = false;
90 };
91 } // namespace AudioStandard
92 } // namespace OHOS
93 #endif // POLICY_HANDLER_H
94