1 /* 2 * Copyright (c) 2021 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 FREEZE_DETECTOR_PLUGIN_H 17 #define FREEZE_DETECTOR_PLUGIN_H 18 19 #include <memory> 20 21 #include "event.h" 22 #include "event_loop.h" 23 #include "freeze_common.h" 24 #include "plugin.h" 25 #include "watch_point.h" 26 #include "resolver.h" 27 28 namespace OHOS { 29 namespace HiviewDFX { 30 class FreezeDetectorPlugin : public Plugin { 31 public: 32 FreezeDetectorPlugin(); 33 ~FreezeDetectorPlugin(); 34 bool ReadyToLoad() override; 35 bool OnEvent(std::shared_ptr<Event> &event) override; 36 void OnLoad() override; 37 void OnUnload() override; 38 bool CanProcessEvent(std::shared_ptr<Event> event) override; 39 void OnEventListeningCallback(const Event& msg) override; 40 41 private: 42 const static uint64_t toNanoSecondMultple = 1000000; 43 const static int minAppUid = 10000; 44 45 std::string RemoveRedundantNewline(const std::string& content) const; 46 WatchPoint MakeWatchPoint(const Event& event); 47 void CheckForeGround(long uid, long pid, unsigned long long eventTime, std::string& foreGround); 48 void ProcessEvent(WatchPoint watchPoint); 49 std::shared_ptr<FreezeCommon> freezeCommon_ = nullptr; 50 std::unique_ptr<FreezeResolver> freezeResolver_ = nullptr; 51 }; 52 } // namespace HiviewDFX 53 } // namespace OHOS 54 #endif // HIVIEW_PLUGIN_FREEZE_DETECTOR_H 55