1 /* 2 * Copyright (c) 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 #ifndef HIVIEW_PLUGINS_USAGE_EVENT_REPORT_INCLUDE_USAGE_EVENT_REPORT_H 17 #define HIVIEW_PLUGINS_USAGE_EVENT_REPORT_INCLUDE_USAGE_EVENT_REPORT_H 18 19 #include <memory> 20 #include <string> 21 22 #include "event_loop.h" 23 #include "shutdown/iasync_shutdown_callback.h" 24 #include "plugin.h" 25 26 namespace OHOS { 27 namespace HiviewDFX { 28 class UsageEventReport : public Plugin { 29 public: 30 UsageEventReport(); ~UsageEventReport()31 ~UsageEventReport() {} 32 void OnLoad() override; 33 void OnUnload() override; 34 void TimeOut(); 35 static void SaveEventToDb(); 36 37 private: 38 void Init(); 39 void InitCallback(); 40 void Start(); 41 void ReportDailyEvent(); 42 void ReportTimeOutEvent(); 43 void ReportSysUsageEvent(); 44 void DeletePluginStatsEvents(); 45 static void StartServiceByOption(const std::string& opt); 46 static void SavePluginStatsEvents(); 47 static void SaveSysUsageEvent(); 48 49 private: 50 sptr<PowerMgr::IAsyncShutdownCallback> callback_; 51 uint64_t timeOutCnt_; 52 static uint64_t lastSysReportTime_; 53 static uint64_t lastReportTime_; 54 static uint64_t nextReportTime_; 55 static std::string workPath_; 56 }; // UsageEventReport 57 } // namespace HiviewDFX 58 } // namespace OHOS 59 #endif // HIVIEW_PLUGINS_USAGE_EVENT_REPORT_INCLUDE_USAGE_EVENT_REPORT_H 60