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 void SendProcessKillEvent(const std::string& killReason); 55 int NotifyANR(const FaultData& faultData); 56 bool IsExitApp(const std::string& name); 57 bool IsHandleAppfreeze(); 58 59 static std::mutex singletonMutex_; 60 static std::shared_ptr<AppfreezeInner> instance_; 61 bool isAppDebug_ = false; 62 std::mutex handlingMutex_; 63 std::list<FaultData> handlinglist_; 64 }; 65 66 class MainHandlerDumper : public Dumper { 67 public: 68 virtual void Dump(const std::string &message) override; 69 virtual std::string GetTag() override; 70 std::string GetDumpInfo(); 71 private: 72 std::string dumpInfo; 73 }; 74 } // namespace AppExecFwk 75 } // namespace OHOS 76 #endif // OHOS_ABILITY_ABILITY_APPFREEZE_LOG_CLIENT_H