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