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_MANAGER_H
17#define ANR_MANAGER_H
18
19#include "nocopyable.h"
20#include "singleton.h"
21
22#include "uds_server.h"
23#include "uds_session.h"
24
25namespace OHOS {
26namespace MMI {
27class ANRManager final {
28    DECLARE_DELAYED_SINGLETON(ANRManager);
29public:
30    DISALLOW_COPY_AND_MOVE(ANRManager);
31    void Init(UDSServer& udsServer);
32    bool TriggerANR(int32_t type, int64_t time, SessionPtr sess);
33    int32_t SetANRNoticedPid(int32_t anrPid);
34    void OnSessionLost(SessionPtr session);
35    void AddTimer(int32_t type, int32_t id, int64_t currentTime, SessionPtr sess);
36    int32_t MarkProcessed(int32_t pid, int32_t eventType, int32_t eventId);
37    void RemoveTimers(SessionPtr sess);
38    void RemoveTimersByType(SessionPtr sess, int32_t type);
39private:
40    int32_t anrNoticedPid_ { -1 };
41    UDSServer *udsServer_ { nullptr };
42    int32_t anrTimerCount_ { 0 };
43    int32_t pid_ { -1 };
44};
45
46#define ANRMgr ::OHOS::DelayedSingleton<ANRManager>::GetInstance()
47} // namespace MMI
48} // namespace OHOS
49#endif // ANR_MANAGER_H