/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_ABILITY_RUNTIME_APPFREEZE_MAMAGER_H #define OHOS_ABILITY_RUNTIME_APPFREEZE_MAMAGER_H #include #include #include #include #include #include #include #include "cpp/mutex.h" #include "cpp/condition_variable.h" #include "fault_data.h" #include "freeze_util.h" namespace OHOS { using AbilityRuntime::FreezeUtil; namespace AppExecFwk { class AppfreezeManager : public std::enable_shared_from_this { public: struct AppInfo { int pid; int uid; std::string bundleName; std::string processName; }; enum TypeAttribute { NORMAL_TIMEOUT = 0, CRITICAL_TIMEOUT = 1, }; struct ParamInfo { int typeId = TypeAttribute::NORMAL_TIMEOUT; int32_t pid = 0; std::string eventName; std::string bundleName; std::string msg; }; AppfreezeManager(); ~AppfreezeManager(); static std::shared_ptr GetInstance(); static void DestroyInstance(); int AppfreezeHandle(const FaultData& faultData, const AppfreezeManager::AppInfo& appInfo); int AppfreezeHandleWithStack(const FaultData& faultData, const AppfreezeManager::AppInfo& appInfo); int LifecycleTimeoutHandle(const ParamInfo& info, std::unique_ptr flow = nullptr); bool IsHandleAppfreeze(const std::string& bundleName); bool IsProcessDebug(int32_t pid, std::string processName); private: AppfreezeManager& operator=(const AppfreezeManager&) = delete; AppfreezeManager(const AppfreezeManager&) = delete; uint64_t GetMilliseconds(); std::map> BinderParser(std::ifstream& fin, std::string& stack) const; void ParseBinderPids(const std::map>& binderInfo, std::set& pids, int pid, int layer) const; std::set GetBinderPeerPids(std::string& stack, int pid) const; std::string CatchJsonStacktrace(int pid) const; std::string CatcherStacktrace(int pid) const; int AcquireStack(const FaultData& faultData, const AppInfo& appInfo); int NotifyANR(const FaultData& faultData, const AppfreezeManager::AppInfo& appInfo, const std::string& binderInfo); static const inline std::string LOGGER_DEBUG_PROC_PATH = "/proc/transaction_proc"; std::string name_; static ffrt::mutex singletonMutex_; static std::shared_ptr instance_; }; } // namespace AppExecFwk } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_APPFREEZE_MAMAGER_H