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 16 #ifndef OHOS_ABILITY_RUNTIME_APPFREEZE_MAMAGER_H 17 #define OHOS_ABILITY_RUNTIME_APPFREEZE_MAMAGER_H 18 19 #include <sys/types.h> 20 21 #include <fstream> 22 #include <map> 23 #include <memory> 24 #include <set> 25 #include <string> 26 #include <vector> 27 28 #include "cpp/mutex.h" 29 #include "cpp/condition_variable.h" 30 #include "fault_data.h" 31 32 namespace OHOS { 33 namespace AppExecFwk { 34 class AppfreezeManager : public std::enable_shared_from_this<AppfreezeManager> { 35 public: 36 struct AppInfo { 37 int pid; 38 int uid; 39 std::string bundleName; 40 std::string processName; 41 }; 42 43 enum TypeAttribute { 44 NORMAL_TIMEOUT = 0, 45 CRITICAL_TIMEOUT = 1, 46 }; 47 48 AppfreezeManager(); 49 ~AppfreezeManager(); 50 51 static std::shared_ptr<AppfreezeManager> GetInstance(); 52 static void DestroyInstance(); 53 int AppfreezeHandle(const FaultData& faultData, const AppfreezeManager::AppInfo& appInfo); 54 int AppfreezeHandleWithStack(const FaultData& faultData, const AppfreezeManager::AppInfo& appInfo); 55 int LifecycleTimeoutHandle(int typeId, int32_t pid, const std::string& eventName, 56 const std::string& bundleName, const std::string& msg); 57 bool IsHandleAppfreeze(const std::string& bundleName); 58 59 private: 60 AppfreezeManager& operator=(const AppfreezeManager&) = delete; 61 AppfreezeManager(const AppfreezeManager&) = delete; 62 uint64_t GetMilliseconds(); 63 std::map<int, std::set<int>> BinderParser(std::ifstream& fin, std::string& stack) const; 64 void ParseBinderPids(const std::map<int, std::set<int>>& binderInfo, std::set<int>& pids, int pid, int layer) const; 65 std::set<int> GetBinderPeerPids(std::string& stack, int pid) const; 66 std::string CatcherStacktrace(int pid) const; 67 int AcquireStack(const FaultData& faultData, const AppInfo& appInfo); 68 int NotifyANR(const FaultData& faultData, const AppfreezeManager::AppInfo& appInfo); 69 70 static const inline std::string LOGGER_DEBUG_PROC_PATH = "/proc/transaction_proc"; 71 ffrt::mutex lifecycleMutex_; 72 ffrt::condition_variable lifecycleCv_; 73 std::set<std::string> lifecycleTimeOutMarks_; 74 std::string name_; 75 static ffrt::mutex singletonMutex_; 76 static std::shared_ptr<AppfreezeManager> instance_; 77 }; 78 } // namespace AppExecFwk 79 } // namespace OHOS 80 #endif // OHOS_ABILITY_RUNTIME_APPFREEZE_MAMAGER_H