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 #include "collaboration_info_collector.h"
17 #include "content_sensor_manager_utils.h"
18 #include "device_profile_manager.h"
19 #include "distributed_device_profile_errors.h"
20 #include "distributed_device_profile_log.h"
21 #include "profile_utils.h"
22
23 namespace OHOS {
24 namespace DistributedDeviceProfile {
25 namespace {
26 const std::string TAG = "CollaborationInfoCollector";
27 const std::vector<std::string> COLLABORATION_SERVICE_ID_VECTOR = { "distributeCameraControllerService",
28 "padCarCollaborate" };
29 const std::string COLLABORATION_CHARACTERISTIC_KEY = "status";
30 const std::string COLLABORATION_CHARACTERISTIC_VALUE = "false";
31 }
32
ConvertToProfile(std::vector<ServiceProfile> & svrProfileList)33 bool CollaborationInfoCollector::ConvertToProfile(std::vector<ServiceProfile> &svrProfileList)
34 {
35 HILOGI("called!");
36 auto deviceId = GetDeviceUdid();
37 for (auto it = COLLABORATION_SERVICE_ID_VECTOR.begin(); it != COLLABORATION_SERVICE_ID_VECTOR.end(); it++) {
38 ServiceProfile svrProfile;
39 if (DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, *it, svrProfile) == DP_SUCCESS) {
40 continue;
41 }
42 svrProfile.SetDeviceId(deviceId);
43 svrProfile.SetServiceName(*it);
44 svrProfile.SetServiceType(*it);
45 svrProfileList.push_back(svrProfile);
46 }
47 return true;
48 }
49
ConvertToProfile(std::vector<CharacteristicProfile> & charProfileList)50 bool CollaborationInfoCollector::ConvertToProfile(std::vector<CharacteristicProfile> &charProfileList)
51 {
52 HILOGI("called!");
53 auto deviceId = GetDeviceUdid();
54 for (auto it = COLLABORATION_SERVICE_ID_VECTOR.begin(); it != COLLABORATION_SERVICE_ID_VECTOR.end(); it++) {
55 CharacteristicProfile charProfile;
56 if (DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, *it,
57 COLLABORATION_CHARACTERISTIC_KEY, charProfile) == DP_SUCCESS) {
58 continue;
59 }
60 charProfile.SetDeviceId(deviceId);
61 charProfile.SetServiceName(*it);
62 charProfile.SetCharacteristicKey(COLLABORATION_CHARACTERISTIC_KEY);
63 charProfile.SetCharacteristicValue(COLLABORATION_CHARACTERISTIC_VALUE);
64 charProfileList.push_back(charProfile);
65 }
66 return true;
67 }
68
GetDeviceUdid()69 std::string CollaborationInfoCollector::GetDeviceUdid()
70 {
71 HILOGI("called!");
72 return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
73 }
74 } // namespace DeviceProfile
75 } // namespace OHOS