1 /* 2 * Copyright (c) 2023 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 int AppfreezeHandle(const FaultData& faultInfo, bool onlyMainThread); 45 int AcquireStack(const FaultData& faultInfo, bool onlyMainThread); 46 private: 47 static std::weak_ptr<EventHandler> appMainHandler_; 48 std::weak_ptr<ApplicationInfo> applicationInfo_; 49 void AppFreezeRecovery(); 50 int NotifyANR(const FaultData& faultData); 51 bool IsExitApp(const std::string& name); 52 bool IsHandleAppfreeze(); 53 54 static std::mutex singletonMutex_; 55 static std::shared_ptr<AppfreezeInner> instance_; 56 }; 57 58 class MainHandlerDumper : public Dumper { 59 public: 60 virtual void Dump(const std::string &message) override; 61 virtual std::string GetTag() override; 62 std::string GetDumpInfo(); 63 private: 64 std::string dumpInfo; 65 }; 66 } // namespace AppExecFwk 67 } // namespace OHOS 68 #endif // OHOS_ABILITY_ABILITY_APPFREEZE_LOG_CLIENT_H