1 /* 2 * Copyright (c) 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 #ifndef OHOS_ABILITY_ABILITY_APPFREEZE_LOG_CLIENT_H 16 #define OHOS_ABILITY_ABILITY_APPFREEZE_LOG_CLIENT_H 17 #include <map> 18 #include <memory> 19 #include <mutex> 20 #include <thread> 21 #include <set> 22 #include <sys/types.h> 23 24 #include "refbase.h" 25 #include "singleton.h" 26 27 #include "event_handler.h" 28 #include "app_mgr_client.h" 29 #include "app_mgr_interface.h" 30 #include "application_impl.h" 31 #include "fault_data.h" 32 33 namespace OHOS { 34 namespace AppExecFwk { 35 class AppfreezeInner { 36 public: 37 AppfreezeInner(); 38 ~AppfreezeInner(); 39 static std::shared_ptr<AppfreezeInner> GetInstance(); 40 static void DestroyInstance(); 41 static void SetMainHandler(const std::shared_ptr<EventHandler>& eventHandler); 42 void SetApplicationInfo(const std::shared_ptr<ApplicationInfo>& applicationInfo); 43 void ThreadBlock(std::atomic_bool& isSixSecondEvent); 44 void ChangeFaultDateInfo(FaultData& faultData, const std::string& msgContent); 45 void AppfreezeHandleOverReportCount(bool isSixSecondEvent); 46 void GetMainHandlerDump(std::string& msgContent); 47 int AppfreezeHandle(const FaultData& faultInfo, bool onlyMainThread); 48 int AcquireStack(const FaultData& faultInfo, bool onlyMainThread); 49 void SetAppDebug(bool isAppDebug); 50 private: 51 static std::weak_ptr<EventHandler> appMainHandler_; 52 std::weak_ptr<ApplicationInfo> applicationInfo_; 53 void AppFreezeRecovery(); 54 int NotifyANR(const FaultData& faultData); 55 bool IsExitApp(const std::string& name); 56 bool IsHandleAppfreeze(); 57 58 static std::mutex singletonMutex_; 59 static std::shared_ptr<AppfreezeInner> instance_; 60 bool isAppDebug_ = false; 61 std::mutex handlingMutex_; 62 std::list<FaultData> handlinglist_; 63 }; 64 65 class MainHandlerDumper : public Dumper { 66 public: 67 virtual void Dump(const std::string &message) override; 68 virtual std::string GetTag() override; 69 std::string GetDumpInfo(); 70 private: 71 std::string dumpInfo; 72 }; 73 } // namespace AppExecFwk 74 } // namespace OHOS 75 #endif // OHOS_ABILITY_ABILITY_APPFREEZE_LOG_CLIENT_H