• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 ANR_HANDLER_H
17 #define ANR_HANDLER_H
18 
19 #include <atomic>
20 
21 #include "singleton.h"
22 
23 #include "proto.h"
24 
25 namespace OHOS {
26 namespace MMI {
27 class ANRHandler {
28     DECLARE_DELAYED_SINGLETON(ANRHandler);
29 
30 public:
31     DISALLOW_COPY_AND_MOVE(ANRHandler);
32 
33     void SetLastProcessedEventId(int32_t eventType, int32_t eventId, int64_t actionTime);
34     void MarkProcessed(int32_t eventType, int32_t eventId);
35     void ResetAnrArray();
36     std::mutex anrMtx_;
37 
38 private:
39     struct ANREvent {
40         bool sendStatus{ false };
41         int32_t lastEventId{ -1 };
42         int32_t lastReportId{ -1 };
43     };
44     ANREvent event_[ANR_EVENT_TYPE_NUM];
45 
46     void SendEvent(int32_t eventType, int32_t eventId);
47 };
48 
49 #define ANRHDL ::OHOS::DelayedSingleton<ANRHandler>::GetInstance()
50 } // namespace MMI
51 } // namespace OHOS
52 #endif // ANR_HANDLER_H