• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024-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 #include "usage_fold_event_report.h"
16 
17 #include "display_manager.h"
18 #include "hiview_logger.h"
19 #include "logger_event.h"
20 #include "sys_event.h"
21 
22 namespace OHOS {
23 namespace HiviewDFX {
24 DEFINE_LOG_TAG("UsageFoldEventReport");
25 
Init(const std::string & workPath)26 void UsageFoldEventReport::Init(const std::string& workPath)
27 {
28     if (!OHOS::Rosen::DisplayManager::GetInstance().IsFoldable()) {
29         HIVIEW_LOGI("unfoldable device");
30         return;
31     }
32     foldEventCacher_ = std::make_unique<FoldEventCacher>(workPath);
33     foldAppUsageFactory_ = std::make_unique<FoldAppUsageEventFactory>(workPath);
34 }
35 
ProcessEvent(std::shared_ptr<Event> event)36 void UsageFoldEventReport::ProcessEvent(std::shared_ptr<Event> event)
37 {
38     if (foldEventCacher_ != nullptr) {
39         auto sysEvent = Event::DownCastTo<SysEvent>(event);
40         foldEventCacher_->ProcessEvent(sysEvent);
41     }
42 }
43 
ReportEvent()44 void UsageFoldEventReport::ReportEvent()
45 {
46     if (foldAppUsageFactory_ == nullptr) {
47         HIVIEW_LOGI("foldAppUsageFactory is nullptr");
48         return;
49     }
50     std::vector<std::unique_ptr<LoggerEvent>> foldAppUsageEvents;
51     foldAppUsageFactory_->Create(foldAppUsageEvents);
52     HIVIEW_LOGI("report fold app usage event num: %{public}zu", foldAppUsageEvents.size());
53     for (size_t i = 0; i < foldAppUsageEvents.size(); ++i) {
54         foldAppUsageEvents[i]->Report();
55     }
56 }
57 }  // namespace HiviewDFX
58 }  // namespace OHOS
59