• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #ifndef LOG_TAG
16 #define LOG_TAG "AudioConnectedDevice"
17 #endif
18 
19 #include "audio_connected_device.h"
20 #include <ability_manager_client.h>
21 #include "iservice_registry.h"
22 #include "parameter.h"
23 #include "parameters.h"
24 #include "audio_policy_log.h"
25 #include "audio_inner_call.h"
26 #include "media_monitor_manager.h"
27 #include "audio_spatialization_service.h"
28 
29 
30 #include "audio_policy_utils.h"
31 
32 namespace OHOS {
33 namespace AudioStandard {
34 
35 static const char *SETTINGS_DATA_BASE_URI =
36     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true";
37 static const char *PREDICATES_STRING = "settings.general.device_name";
38 
39 class DataShareObserverCallBack : public AAFwk::DataAbilityObserverStub {
40 public:
OnChange()41     void OnChange() override
42     {
43         std::string deviceName = "";
44         int32_t ret = AudioPolicyUtils::GetInstance().GetDeviceNameFromDataShareHelper(deviceName);
45         CHECK_AND_RETURN_LOG(ret == SUCCESS, "Local UpdateDisplayName init device failed");
46         AudioConnectedDevice::GetInstance().SetDisplayName(deviceName, true);
47     }
48 };
49 
IsConnectedOutputDevice(const std::shared_ptr<AudioDeviceDescriptor> & desc)50 bool AudioConnectedDevice::IsConnectedOutputDevice(const std::shared_ptr<AudioDeviceDescriptor> &desc)
51 {
52     std::shared_lock<std::shared_mutex> lock(mutex_);
53     DeviceType deviceType = desc->deviceType_;
54 
55     CHECK_AND_RETURN_RET_LOG(desc->deviceRole_ == DeviceRole::OUTPUT_DEVICE, false,
56         "Not output device!");
57 
58     auto isPresent = [&deviceType] (const std::shared_ptr<AudioDeviceDescriptor> &desc) {
59         CHECK_AND_RETURN_RET_LOG(desc != nullptr, false, "Invalid device descriptor");
60         if (deviceType == DEVICE_TYPE_FILE_SINK) {
61             return false;
62         }
63         return ((deviceType == desc->deviceType_) && (desc->deviceRole_ == DeviceRole::OUTPUT_DEVICE));
64     };
65 
66     auto itr = std::find_if(connectedDevices_.begin(), connectedDevices_.end(), isPresent);
67     CHECK_AND_RETURN_RET_LOG(itr != connectedDevices_.end(), false, "Device not available");
68 
69     return true;
70 }
71 
CheckExistOutputDevice(DeviceType activeDevice,std::string macAddress)72 std::shared_ptr<AudioDeviceDescriptor> AudioConnectedDevice::CheckExistOutputDevice(DeviceType activeDevice,
73     std::string macAddress)
74 {
75     std::shared_lock<std::shared_mutex> lock(mutex_);
76     auto isOutputDevicePresent = [&activeDevice, &macAddress] (const std::shared_ptr<AudioDeviceDescriptor> &desc) {
77         CHECK_AND_RETURN_RET_LOG(desc != nullptr, false, "Invalid device descriptor");
78         if ((activeDevice == desc->deviceType_) && (OUTPUT_DEVICE == desc->deviceRole_)) {
79             if (activeDevice == DEVICE_TYPE_BLUETOOTH_A2DP) {
80                 // If the device type is A2DP, need to compare mac address in addition.
81                 return desc->macAddress_ == macAddress;
82             }
83             return true;
84         }
85         return false;
86     };
87 
88     auto itr = std::find_if(connectedDevices_.begin(), connectedDevices_.end(), isOutputDevicePresent);
89     if (itr != connectedDevices_.end()) {
90         return *itr;
91     }
92     return nullptr;
93 }
94 
CheckExistInputDevice(DeviceType activeDevice)95 std::shared_ptr<AudioDeviceDescriptor> AudioConnectedDevice::CheckExistInputDevice(DeviceType activeDevice)
96 {
97     std::shared_lock<std::shared_mutex> lock(mutex_);
98     auto isInputDevicePresent = [&activeDevice] (const std::shared_ptr<AudioDeviceDescriptor> &desc) {
99         CHECK_AND_RETURN_RET_LOG(desc != nullptr, false, "Invalid device descriptor");
100         return ((activeDevice == desc->deviceType_) && (INPUT_DEVICE == desc->deviceRole_));
101     };
102 
103     auto itr = std::find_if(connectedDevices_.begin(), connectedDevices_.end(), isInputDevicePresent);
104     if (itr != connectedDevices_.end()) {
105         return *itr;
106     }
107     return nullptr;
108 }
109 
GetConnectedDeviceByType(int32_t deviceType)110 std::shared_ptr<AudioDeviceDescriptor> AudioConnectedDevice::GetConnectedDeviceByType(int32_t deviceType)
111 {
112     std::shared_lock<std::shared_mutex> lock(mutex_);
113     auto isPresent = [&deviceType] (const std::shared_ptr<AudioDeviceDescriptor> &desc) {
114         if (deviceType == desc->deviceType_) {
115             return true;
116         }
117         return false;
118     };
119     auto it = std::find_if(connectedDevices_.begin(), connectedDevices_.end(), isPresent);
120     if (it != connectedDevices_.end()) {
121         return *it;
122     }
123     return nullptr;
124 }
125 
GetConnectedDeviceByType(std::string networkId,DeviceType deviceType)126 std::shared_ptr<AudioDeviceDescriptor> AudioConnectedDevice::GetConnectedDeviceByType(
127     std::string networkId, DeviceType deviceType)
128 {
129     std::shared_lock<std::shared_mutex> lock(mutex_);
130     auto isPresent = [&networkId, &deviceType] (const std::shared_ptr<AudioDeviceDescriptor> &desc) {
131         if (deviceType == desc->deviceType_ && networkId == desc->networkId_) {
132             return true;
133         }
134         return false;
135     };
136     auto it = std::find_if(connectedDevices_.begin(), connectedDevices_.end(), isPresent);
137     if (it != connectedDevices_.end()) {
138         return *it;
139     }
140     return nullptr;
141 }
142 
GetConnectedDeviceByType(std::string networkId,DeviceType deviceType,std::string macAddress)143 std::shared_ptr<AudioDeviceDescriptor> AudioConnectedDevice::GetConnectedDeviceByType(
144     std::string networkId, DeviceType deviceType, std::string macAddress)
145 {
146     std::shared_lock<std::shared_mutex> lock(mutex_);
147     auto isPresent = [&networkId, &deviceType, &macAddress] (const std::shared_ptr<AudioDeviceDescriptor> &desc) {
148         if (deviceType == desc->deviceType_ && networkId == desc->networkId_ && macAddress == desc->macAddress_) {
149             return true;
150         }
151         return false;
152     };
153     auto it = std::find_if(connectedDevices_.begin(), connectedDevices_.end(), isPresent);
154     if (it != connectedDevices_.end()) {
155         return *it;
156     }
157     return nullptr;
158 }
159 
GetAllConnectedDeviceByType(std::string networkId,DeviceType deviceType,std::string macAddress,DeviceRole deviceRole,std::vector<std::shared_ptr<AudioDeviceDescriptor>> & descForCb)160 void AudioConnectedDevice::GetAllConnectedDeviceByType(std::string networkId, DeviceType deviceType,
161     std::string macAddress, DeviceRole deviceRole, std::vector<std::shared_ptr<AudioDeviceDescriptor>> &descForCb)
162 {
163     std::shared_lock<std::shared_mutex> lock(mutex_);
164     auto isPresent =
165         [&networkId, &deviceType, &macAddress, &deviceRole] (const std::shared_ptr<AudioDeviceDescriptor> &desc) {
166         if (deviceType == desc->deviceType_ && networkId == desc->networkId_ && macAddress == desc->macAddress_
167             && (!IsUsb(desc->deviceType_) || deviceRole == desc->deviceRole_)) {
168             return true;
169         }
170         return false;
171     };
172     auto it = std::find_if(connectedDevices_.begin(), connectedDevices_.end(), isPresent);
173     while (it != connectedDevices_.end()) {
174         descForCb.push_back(*it);
175         it = std::find_if(std::next(it), connectedDevices_.end(), isPresent);
176     }
177     return;
178 }
179 
DelConnectedDevice(std::string networkId,DeviceType deviceType,std::string macAddress,DeviceRole deviceRole)180 void AudioConnectedDevice::DelConnectedDevice(std::string networkId, DeviceType deviceType, std::string macAddress,
181     DeviceRole deviceRole)
182 {
183     std::unique_lock<std::shared_mutex> lock(mutex_);
184     auto isPresent = [&deviceType, &networkId, &macAddress,
185         &deviceRole] (const std::shared_ptr<AudioDeviceDescriptor> &descriptor) {
186         return descriptor->deviceType_ == deviceType && descriptor->networkId_ == networkId
187             && descriptor->macAddress_ == macAddress &&
188             (!IsUsb(descriptor->deviceType_) || descriptor->deviceRole_ == deviceRole);
189     };
190 
191     connectedDevices_.erase(std::remove_if(connectedDevices_.begin(), connectedDevices_.end(), isPresent),
192         connectedDevices_.end());
193     return;
194 }
195 
DelConnectedDevice(std::string networkId,DeviceType deviceType,std::string macAddress)196 void AudioConnectedDevice::DelConnectedDevice(std::string networkId, DeviceType deviceType, std::string macAddress)
197 {
198     std::unique_lock<std::shared_mutex> lock(mutex_);
199     auto isPresent =
200         [&deviceType, &networkId, &macAddress] (const std::shared_ptr<AudioDeviceDescriptor> &descriptor) {
201         return descriptor->deviceType_ == deviceType && descriptor->networkId_ == networkId
202             && descriptor->macAddress_ == macAddress;
203     };
204 
205     connectedDevices_.erase(std::remove_if(connectedDevices_.begin(), connectedDevices_.end(), isPresent),
206         connectedDevices_.end());
207     return;
208 }
209 
DelConnectedDevice(std::string networkId,DeviceType deviceType)210 void AudioConnectedDevice::DelConnectedDevice(std::string networkId, DeviceType deviceType)
211 {
212     std::unique_lock<std::shared_mutex> lock(mutex_);
213     auto isPresent = [&deviceType, &networkId] (const std::shared_ptr<AudioDeviceDescriptor> &descriptor) {
214         return descriptor->deviceType_ == deviceType && descriptor->networkId_ == networkId;
215     };
216 
217     connectedDevices_.erase(std::remove_if(connectedDevices_.begin(), connectedDevices_.end(), isPresent),
218         connectedDevices_.end());
219     return;
220 }
221 
AddConnectedDevice(std::shared_ptr<AudioDeviceDescriptor> remoteDeviceDescriptor)222 void AudioConnectedDevice::AddConnectedDevice(std::shared_ptr<AudioDeviceDescriptor> remoteDeviceDescriptor)
223 {
224     std::unique_lock<std::shared_mutex> lock(mutex_);
225     UpdateDeviceDesc4DmDevice(*remoteDeviceDescriptor);
226     connectedDevices_.insert(connectedDevices_.begin(), remoteDeviceDescriptor);
227     return;
228 }
229 
CheckDeviceConnected(std::string selectedDevice)230 bool AudioConnectedDevice::CheckDeviceConnected(std::string selectedDevice)
231 {
232     std::shared_lock<std::shared_mutex> lock(mutex_);
233     for (auto device : connectedDevices_) {
234         if (AudioPolicyUtils::GetInstance().GetRemoteModuleName(device->networkId_, device->deviceRole_)
235             == selectedDevice) {
236             return true;
237         }
238     }
239     return false;
240 }
241 
SetDisplayName(const std::string & deviceName,bool isLocalDevice)242 void AudioConnectedDevice::SetDisplayName(const std::string &deviceName, bool isLocalDevice)
243 {
244     std::shared_lock<std::shared_mutex> lock(mutex_);
245     for (const auto& deviceInfo : connectedDevices_) {
246         if ((isLocalDevice && deviceInfo->networkId_ == LOCAL_NETWORK_ID) ||
247             (!isLocalDevice && deviceInfo->networkId_ != LOCAL_NETWORK_ID)) {
248             deviceInfo->displayName_ = deviceName;
249         }
250     }
251 }
252 
UpdateDmDeviceMap(DmDevice && dmDevice,bool isConnect)253 void AudioConnectedDevice::UpdateDmDeviceMap(DmDevice &&dmDevice, bool isConnect)
254 {
255     std::shared_lock<std::shared_mutex> lock(mutex_);
256     AUDIO_INFO_LOG("Entry. deviceName_=%{public}s, dmDeviceType_=%{public}d",
257         dmDevice.deviceName_.c_str(), dmDevice.dmDeviceType_);
258     lock_guard<mutex> lg(dmDeviceMtx_);
259     if (isConnect) {
260         dmDeviceMap_[dmDevice.networkId_] = dmDevice;
261         auto it = find_if(connectedDevices_.begin(), connectedDevices_.end(), [&dmDevice](auto &item) {
262             return item->networkId_ == dmDevice.networkId_;
263         });
264         if (it != connectedDevices_.end()) {
265             (*it)->displayName_ = dmDevice.deviceName_;
266             (*it)->deviceName_ = dmDevice.deviceName_;
267             (*it)->dmDeviceType_ = dmDevice.dmDeviceType_;
268         }
269     } else {
270         dmDeviceMap_.erase(dmDevice.networkId_);
271     }
272 }
273 
UpdateDeviceDesc4DmDevice(AudioDeviceDescriptor & deviceDesc)274 void AudioConnectedDevice::UpdateDeviceDesc4DmDevice(AudioDeviceDescriptor &deviceDesc)
275 {
276     if (deviceDesc.deviceType_ == DEVICE_TYPE_SPEAKER && deviceDesc.networkId_ != LOCAL_NETWORK_ID) {
277         lock_guard<mutex> lg(dmDeviceMtx_);
278         auto it = dmDeviceMap_.find(deviceDesc.networkId_);
279         if (it != dmDeviceMap_.end()) {
280             deviceDesc.dmDeviceType_ = it->second.dmDeviceType_;
281             deviceDesc.deviceName_ = it->second.deviceName_;
282             deviceDesc.displayName_ = it->second.deviceName_;
283         }
284     }
285 }
286 
SetDisplayName(const std::string macAddress,const std::string deviceName)287 void AudioConnectedDevice::SetDisplayName(const std::string macAddress, const std::string deviceName)
288 {
289     std::shared_lock<std::shared_mutex> lock(mutex_);
290     for (auto device : connectedDevices_) {
291         if (device->macAddress_ == macAddress) {
292             device->deviceName_ = deviceName;
293             int32_t bluetoothId_ = device->deviceId_;
294             std::string name_ = device->deviceName_;
295         }
296     }
297 }
298 
UpdateConnectDevice(DeviceType deviceType,const std::string & macAddress,const std::string & deviceName,const AudioStreamInfo & streamInfo)299 void AudioConnectedDevice::UpdateConnectDevice(DeviceType deviceType, const std::string &macAddress,
300     const std::string &deviceName, const AudioStreamInfo &streamInfo)
301 {
302     std::shared_lock<std::shared_mutex> lock(mutex_);
303     auto isPresent = [&deviceType, &macAddress] (const std::shared_ptr<AudioDeviceDescriptor> &descriptor) {
304         return descriptor->macAddress_ == macAddress && descriptor->deviceType_ == deviceType;
305     };
306 
307     auto it = std::find_if(connectedDevices_.begin(), connectedDevices_.end(), isPresent);
308     if (it != connectedDevices_.end()) {
309         (*it)->deviceName_ = deviceName;
310         (*it)->audioStreamInfo_ = { streamInfo };
311     }
312 }
313 
GetDevicesInner(DeviceFlag deviceFlag)314 std::vector<std::shared_ptr<AudioDeviceDescriptor>> AudioConnectedDevice::GetDevicesInner(DeviceFlag deviceFlag)
315 {
316     std::shared_lock<std::shared_mutex> lock(mutex_);
317     std::vector<std::shared_ptr<AudioDeviceDescriptor>> deviceList = {};
318 
319     CHECK_AND_RETURN_RET_LOG(deviceFlag >= DeviceFlag::OUTPUT_DEVICES_FLAG &&
320         deviceFlag <= DeviceFlag::ALL_L_D_DEVICES_FLAG,
321         deviceList, "Invalid flag provided %{public}d", deviceFlag);
322 
323     CHECK_AND_RETURN_RET(deviceFlag != DeviceFlag::ALL_L_D_DEVICES_FLAG, connectedDevices_);
324 
325     for (auto device : connectedDevices_) {
326         if (device == nullptr) {
327             continue;
328         }
329         bool filterAllLocal = deviceFlag == DeviceFlag::ALL_DEVICES_FLAG && device->networkId_ == LOCAL_NETWORK_ID;
330         bool filterLocalOutput = deviceFlag == DeviceFlag::OUTPUT_DEVICES_FLAG
331             && device->networkId_ == LOCAL_NETWORK_ID
332             && device->deviceRole_ == DeviceRole::OUTPUT_DEVICE;
333         bool filterLocalInput = deviceFlag == DeviceFlag::INPUT_DEVICES_FLAG
334             && device->networkId_ == LOCAL_NETWORK_ID
335             && device->deviceRole_ == DeviceRole::INPUT_DEVICE;
336 
337         bool filterAllRemote = deviceFlag == DeviceFlag::ALL_DISTRIBUTED_DEVICES_FLAG
338             && device->networkId_ != LOCAL_NETWORK_ID;
339         bool filterRemoteOutput = deviceFlag == DeviceFlag::DISTRIBUTED_OUTPUT_DEVICES_FLAG
340             && (device->networkId_ != LOCAL_NETWORK_ID || device->deviceType_ == DEVICE_TYPE_REMOTE_CAST)
341             && device->deviceRole_ == DeviceRole::OUTPUT_DEVICE;
342         bool filterRemoteInput = deviceFlag == DeviceFlag::DISTRIBUTED_INPUT_DEVICES_FLAG
343             && device->networkId_ != LOCAL_NETWORK_ID
344             && device->deviceRole_ == DeviceRole::INPUT_DEVICE;
345 
346         if (filterAllLocal || filterLocalOutput || filterLocalInput || filterAllRemote || filterRemoteOutput
347             || filterRemoteInput) {
348             std::shared_ptr<AudioDeviceDescriptor> devDesc = std::make_shared<AudioDeviceDescriptor>(*device);
349             deviceList.push_back(devDesc);
350         }
351     }
352 
353     AUDIO_DEBUG_LOG("GetDevices list size = [%{public}zu]", deviceList.size());
354     return deviceList;
355 }
356 
FindConnectedHeadset()357 DeviceType AudioConnectedDevice::FindConnectedHeadset()
358 {
359     std::shared_lock<std::shared_mutex> lock(mutex_);
360     const auto& itr = std::find_if(connectedDevices_.begin(), connectedDevices_.end(),
361         [](const std::shared_ptr<AudioDeviceDescriptor> &devDesc) {
362         CHECK_AND_RETURN_RET_LOG(devDesc != nullptr, false, "Invalid device descriptor");
363         return ((devDesc->deviceType_ == DEVICE_TYPE_WIRED_HEADSET) ||
364             (devDesc->deviceType_ == DEVICE_TYPE_WIRED_HEADPHONES) ||
365             (devDesc->deviceType_ == DEVICE_TYPE_USB_HEADSET) ||
366             (devDesc->deviceType_ == DEVICE_TYPE_DP) ||
367             (devDesc->deviceType_ == DEVICE_TYPE_ACCESSORY) ||
368             (devDesc->deviceType_ == DEVICE_TYPE_USB_ARM_HEADSET) ||
369             (devDesc->deviceType_ == DEVICE_TYPE_HDMI) ||
370             (devDesc->deviceType_ == DEVICE_TYPE_LINE_DIGITAL));
371     });
372 
373     DeviceType retType = DEVICE_TYPE_NONE;
374     if (itr != connectedDevices_.end()) {
375         retType = (*itr)->deviceType_;
376     }
377     return retType;
378 }
379 
GetCopy()380 std::vector<std::shared_ptr<AudioDeviceDescriptor>> AudioConnectedDevice::GetCopy()
381 {
382     std::shared_lock<std::shared_mutex> lock(mutex_);
383     return connectedDevices_;
384 }
385 
GetDevicesForGroup(GroupType type,int32_t groupId)386 std::vector<std::shared_ptr<AudioDeviceDescriptor>> AudioConnectedDevice::GetDevicesForGroup(GroupType type,
387     int32_t groupId)
388 {
389     std::shared_lock<std::shared_mutex> lock(mutex_);
390     std::vector<std::shared_ptr<AudioDeviceDescriptor>> devices = {};
391     for (auto devDes : connectedDevices_) {
392         if (devDes == nullptr) {
393             continue;
394         }
395         bool inVolumeGroup = type == VOLUME_TYPE && devDes->volumeGroupId_ == groupId;
396         bool inInterruptGroup = type == INTERRUPT_TYPE && devDes->interruptGroupId_ == groupId;
397 
398         if (inVolumeGroup || inInterruptGroup) {
399             std::shared_ptr<AudioDeviceDescriptor> device = std::make_shared<AudioDeviceDescriptor>(*devDes);
400             devices.push_back(device);
401         }
402     }
403     return devices;
404 }
405 
IsArmDevice(const std::string & address,const DeviceRole role)406 bool AudioConnectedDevice::IsArmDevice(const std::string& address, const DeviceRole role)
407 {
408     std::shared_lock<std::shared_mutex> lock(mutex_);
409     return std::any_of(connectedDevices_.begin(), connectedDevices_.end(),
410         [&address, &role](const auto& item) {
411             return (item->deviceType_ == DEVICE_TYPE_USB_ARM_HEADSET &&
412                 item->macAddress_ == address && item->deviceRole_ == role);
413         });
414 }
415 
HasArm(const DeviceRole role)416 bool AudioConnectedDevice::HasArm(const DeviceRole role)
417 {
418     std::shared_lock<std::shared_mutex> lock(mutex_);
419     return std::find_if(connectedDevices_.cbegin(), connectedDevices_.cend(), [role](const auto& item) {
420         return item->deviceType_ == DEVICE_TYPE_USB_ARM_HEADSET && item->deviceRole_ == role;
421     }) != connectedDevices_.cend();
422 }
423 
HasHifi(const DeviceRole role)424 bool AudioConnectedDevice::HasHifi(const DeviceRole role)
425 {
426     std::shared_lock<std::shared_mutex> lock(mutex_);
427     return std::find_if(connectedDevices_.cbegin(), connectedDevices_.cend(), [role](const auto& item) {
428         return item->deviceType_ == DEVICE_TYPE_USB_HEADSET && item->deviceRole_ == role;
429     }) != connectedDevices_.cend();
430 }
431 
GetUsbDeviceDescriptor(const std::string & address,const DeviceRole role)432 std::shared_ptr<AudioDeviceDescriptor> AudioConnectedDevice::GetUsbDeviceDescriptor(const std::string &address,
433     const DeviceRole role)
434 {
435     std::shared_lock<std::shared_mutex> lock(mutex_);
436     auto it = std::find_if(connectedDevices_.cbegin(), connectedDevices_.cend(), [&address, role](const auto &item) {
437         return IsUsb(item->deviceType_) && item->macAddress_ == address && item->deviceRole_ == role;
438     });
439     if (it != connectedDevices_.cend()) {
440         return *it;
441     }
442     return nullptr;
443 }
444 
GetSha256EncryptAddress(const std::string & address)445 static std::string GetSha256EncryptAddress(const std::string& address)
446 {
447     const int32_t HexWidth = 2;
448     unsigned char hash[SHA256_DIGEST_LENGTH];
449     SHA256(reinterpret_cast<const unsigned char *>(address.c_str()), address.size(), hash);
450     std::stringstream ss;
451     for (int32_t i = 0; i < SHA256_DIGEST_LENGTH; ++i) {
452         ss << std::hex << std::setw(HexWidth) << std::setfill('0') << (int32_t)hash[i];
453     }
454     return ss.str();
455 }
456 
UpdateSpatializationSupported(const std::string macAddress,const bool support)457 void AudioConnectedDevice::UpdateSpatializationSupported(const std::string macAddress, const bool support)
458 {
459     std::shared_lock<std::shared_mutex> lock(mutex_);
460     for (auto device : connectedDevices_) {
461         std::string encryAddress = GetSha256EncryptAddress(device->macAddress_);
462         if (encryAddress == macAddress && device->deviceType_ ==  DEVICE_TYPE_BLUETOOTH_A2DP &&
463             device->spatializationSupported_ != support) {
464             device->spatializationSupported_ = support;
465             AUDIO_INFO_LOG("spatializationSupported is set to %{public}d", support);
466         }
467     }
468 }
469 
RegisterNameMonitorHelper()470 void AudioConnectedDevice::RegisterNameMonitorHelper()
471 {
472     std::shared_ptr<DataShare::DataShareHelper> dataShareHelper
473         = AudioPolicyUtils::GetInstance().CreateDataShareHelperInstance();
474     CHECK_AND_RETURN_LOG(dataShareHelper != nullptr, "dataShareHelper is NULL");
475 
476     auto uri = std::make_shared<Uri>(std::string(SETTINGS_DATA_BASE_URI) + "&key=" + PREDICATES_STRING);
477     sptr<AAFwk::DataAbilityObserverStub> settingDataObserver = std::make_unique<DataShareObserverCallBack>().release();
478     dataShareHelper->RegisterObserver(*uri, settingDataObserver);
479 
480     dataShareHelper->Release();
481 }
482 
483 }
484 }