• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     void SetAppDebug(bool isAppDebug);
47 private:
48     static std::weak_ptr<EventHandler> appMainHandler_;
49     std::weak_ptr<ApplicationInfo> applicationInfo_;
50     void AppFreezeRecovery();
51     int NotifyANR(const FaultData& faultData);
52     bool IsExitApp(const std::string& name);
53     bool IsHandleAppfreeze();
54 
55     static std::mutex singletonMutex_;
56     static std::shared_ptr<AppfreezeInner> instance_;
57     bool isAppDebug_ = false;
58     std::mutex handlingMutex_;
59     std::list<FaultData> handlinglist_;
60 };
61 
62 class MainHandlerDumper : public Dumper {
63 public:
64     virtual void Dump(const std::string &message) override;
65     virtual std::string GetTag() override;
66     std::string GetDumpInfo();
67 private:
68     std::string dumpInfo;
69 };
70 }  // namespace AppExecFwk
71 }  // namespace OHOS
72 #endif // OHOS_ABILITY_ABILITY_APPFREEZE_LOG_CLIENT_H