1 /* 2 * Copyright (c) 2023-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 "content_sensor_manager.h" 17 18 #include <list> 19 #include <vector> 20 #include <memory> 21 #include <thread> 22 #include "collaboration_info_collector.h" 23 #include "collector.h" 24 #include "content_sensor_manager_utils.h" 25 #include "device_profile.h" 26 #include "device_profile_manager.h" 27 #include "distributed_device_profile_errors.h" 28 #include "distributed_device_profile_log.h" 29 #include "dms_info_collector.h" 30 #include "pasteboard_info_collector.h" 31 #include "switch_status_collector.h" 32 #include "syscap_info_collector.h" 33 #include "system_info_collector.h" 34 35 namespace OHOS { 36 namespace DistributedDeviceProfile { 37 namespace { 38 const std::string TAG = "ContentSensorManager"; 39 } 40 41 IMPLEMENT_SINGLE_INSTANCE(ContentSensorManager); 42 Init()43int32_t ContentSensorManager::Init() 44 { 45 HILOGI("call!"); 46 return Collect(); 47 } 48 UnInit()49int32_t ContentSensorManager::UnInit() 50 { 51 HILOGI("ContentSensorManager UnInit"); 52 return DP_SUCCESS; 53 } 54 Collect()55int32_t ContentSensorManager::Collect() 56 { 57 auto csTask = []() { 58 HILOGI("ContentSensorManager Collect"); 59 std::list<std::shared_ptr<Collector>> taskList; 60 taskList.push_back(std::make_shared<SystemInfoCollector>()); 61 taskList.push_back(std::make_shared<SyscapInfoCollector>()); 62 taskList.push_back(std::make_shared<DmsInfoCollector>()); 63 taskList.push_back(std::make_shared<CollaborationInfoCollector>()); 64 taskList.push_back(std::make_shared<PasteboardInfoCollector>()); 65 taskList.push_back(std::make_shared<SwitchStatusCollector>()); 66 DeviceProfile deviceProfile; 67 std::vector<ServiceProfile> svrProfileList; 68 std::vector<CharacteristicProfile> charProfileList; 69 for (const auto& task : taskList) { 70 task->ConvertToProfile(deviceProfile); 71 task->ConvertToProfile(svrProfileList); 72 task->ConvertToProfile(charProfileList); 73 } 74 deviceProfile.SetDeviceId(ContentSensorManagerUtils::GetInstance().ObtainLocalUdid()); 75 DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile); 76 if (!svrProfileList.empty()) { 77 DeviceProfileManager::GetInstance().PutServiceProfileBatch(svrProfileList); 78 } else { 79 HILOGI("svrProfileList is empty"); 80 } 81 if (!charProfileList.empty()) { 82 DeviceProfileManager::GetInstance().PutCharacteristicProfileBatch(charProfileList); 83 } else { 84 HILOGI("charProfileList is empty"); 85 } 86 }; 87 std::thread(csTask).join(); 88 return DP_SUCCESS; 89 } 90 } // namespace DeviceProfile 91 } // namespace OHOS 92