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