• 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 #include "anr_handler.h"
17 
18 #include <cinttypes>
19 
20 #include "define_multimodal.h"
21 
22 #include "input_manager_impl.h"
23 #include "multimodal_input_connect_manager.h"
24 #include "ffrt.h"
25 
26 namespace OHOS {
27 namespace MMI {
28 namespace {
29 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "ANRHandler" };
30 constexpr int64_t MAX_MARK_PROCESS_DELAY_TIME = 3500000;
31 constexpr int64_t MIN_MARK_PROCESS_DELAY_TIME = 50000;
32 constexpr int32_t INVALID_OR_PROCESSED_ID = -1;
33 constexpr int32_t TIME_TRANSITION = 1000;
34 } // namespace
35 
ANRHandler()36 ANRHandler::ANRHandler() {}
37 
~ANRHandler()38 ANRHandler::~ANRHandler() {}
39 
SetLastProcessedEventId(int32_t eventType,int32_t eventId,int64_t actionTime)40 void ANRHandler::SetLastProcessedEventId(int32_t eventType, int32_t eventId, int64_t actionTime)
41 {
42     CALL_DEBUG_ENTER;
43     MMI_HILOGD("Processed event type:%{public}d, id:%{public}d, actionTime:%{public}" PRId64, eventType, eventId,
44         actionTime);
45     SendEvent(eventType, eventId);
46 }
47 
MarkProcessed(int32_t eventType,int32_t eventId)48 void ANRHandler::MarkProcessed(int32_t eventType, int32_t eventId)
49 {
50     CALL_DEBUG_ENTER;
51     MMI_HILOGD("Processed event type:%{public}d, id:%{public}d", eventType, eventId);
52     int32_t ret = MultimodalInputConnMgr->MarkProcessed(eventType, eventId);
53     if (ret != 0) {
54         MMI_HILOGE("Send to server failed, ret:%{public}d", ret);
55     }
56 }
57 
SendEvent(int32_t eventType,int32_t eventId)58 void ANRHandler::SendEvent(int32_t eventType, int32_t eventId)
59 {
60     CALL_DEBUG_ENTER;
61     auto task = [this, eventType, eventId] {
62         MarkProcessed(eventType, eventId);
63     };
64     ffrt::submit(task, {}, {});
65 }
66 
ResetAnrArray()67 void ANRHandler::ResetAnrArray()
68 {
69     for (int i = 0; i < ANR_EVENT_TYPE_NUM; i++) {
70         event_[i].sendStatus = false;
71         event_[i].lastEventId = -1;
72         event_[i].lastReportId = -1;
73     }
74 }
75 } // namespace MMI
76 } // namespace OHOS