1 /* 2 * Copyright (c) 2021-2022 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 "app_info_collector.h" 19 #include "device_info_collector.h" 20 #include "device_profile_log.h" 21 #include "hitrace_meter.h" 22 #include "storage_info_collector.h" 23 #include "syscap_info_collector.h" 24 #include "system_info_collector.h" 25 26 namespace OHOS { 27 namespace DeviceProfile { 28 namespace { 29 const std::string TAG = "ContentSensorManager"; 30 const std::string DP_CONTENT_SENSOR_TRACE = "DP_CONTENT_SENSOR"; 31 } 32 33 IMPLEMENT_SINGLE_INSTANCE(ContentSensorManager); 34 Init()35bool ContentSensorManager::Init() 36 { 37 auto runner = AppExecFwk::EventRunner::Create("csCollector"); 38 csCollectorHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner); 39 if (csCollectorHandler_ == nullptr) { 40 return false; 41 } 42 return Collect(); 43 } 44 Collect()45bool ContentSensorManager::Collect() 46 { 47 auto csTask = []() { 48 HILOGI("ContentSensorManager Collect"); 49 std::list<std::shared_ptr<ContentCollector>> taskList; 50 taskList.push_back(std::make_shared<DeviceInfoCollector>()); 51 taskList.push_back(std::make_shared<SystemInfoCollector>()); 52 taskList.push_back(std::make_shared<SyscapInfoCollector>()); 53 taskList.push_back(std::make_shared<StorageInfoCollector>()); 54 taskList.push_back(std::make_shared<AppInfoCollector>()); 55 HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_CONTENT_SENSOR_TRACE); 56 for (auto& task : taskList) { 57 ServiceCharacteristicProfile profileData; 58 if (!task->ConvertToProfileData(profileData)) { 59 continue; 60 } 61 task->DoCollect(profileData); 62 } 63 }; 64 if (!csCollectorHandler_->PostTask(csTask)) { 65 HILOGE("post task failed"); 66 return false; 67 } 68 return true; 69 } 70 } // namespace DeviceProfile 71 } // namespace OHOS