1/*
2 * Copyright (C) 2021 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 TELEPHONY_STATE_REGISTRY_STUB_H
17#define TELEPHONY_STATE_REGISTRY_STUB_H
18
19#include <map>
20
21#include "iremote_stub.h"
22
23#include "telephony_log_wrapper.h"
24#include "i_telephony_state_notify.h"
25#include "state_registry_ipc_interface_code.h"
26
27namespace OHOS {
28namespace Telephony {
29class TelephonyStateRegistryStub : public IRemoteStub<ITelephonyStateNotify> {
30public:
31    TelephonyStateRegistryStub();
32    ~TelephonyStateRegistryStub();
33
34    int32_t OnRemoteRequest(
35        uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
36
37    virtual int32_t RegisterStateChange(const sptr<TelephonyObserverBroker> &telephonyObserver, int32_t slotId,
38        uint32_t mask, const std::string &bundleName, bool notifyNow, pid_t pid, int32_t uid, int32_t tokenId) = 0;
39
40    virtual int32_t UnregisterStateChange(int32_t slotId, uint32_t mask, int32_t tokenId, pid_t pid) = 0;
41
42private:
43    int32_t ReadData(MessageParcel &data, MessageParcel &reply, sptr<TelephonyObserverBroker> &callback);
44    int32_t RegisterStateChange(const sptr<TelephonyObserverBroker> &telephonyObserver,
45        int32_t slotId, uint32_t mask, bool isUpdate) override;
46    int32_t UnregisterStateChange(int32_t slotId, uint32_t mask) override;
47    void parseSignalInfos(
48        MessageParcel &data, const int32_t size, std::vector<sptr<SignalInformation>> &result);
49    void ParseLteNrSignalInfos(
50        MessageParcel &data, std::vector<sptr<SignalInformation>> &result, SignalInformation::NetworkType type);
51
52private:
53    using TelephonyStateFunc = std::function<int32_t(MessageParcel &data, MessageParcel &reply)>;
54
55    int32_t OnUpdateCellInfo(MessageParcel &data, MessageParcel &reply);
56    int32_t OnUpdateCallState(MessageParcel &data, MessageParcel &reply);
57    int32_t OnUpdateCallStateForSlotId(MessageParcel &data, MessageParcel &reply);
58    int32_t OnUpdateSignalInfo(MessageParcel &data, MessageParcel &reply);
59    int32_t OnUpdateNetworkState(MessageParcel &data, MessageParcel &reply);
60    int32_t OnUpdateSimState(MessageParcel &data, MessageParcel &reply);
61    int32_t OnRegisterStateChange(MessageParcel &data, MessageParcel &reply);
62    int32_t OnUnregisterStateChange(MessageParcel &data, MessageParcel &reply);
63    int32_t OnUpdateCellularDataConnectState(MessageParcel &data, MessageParcel &reply);
64    int32_t OnUpdateCellularDataFlow(MessageParcel &data, MessageParcel &reply);
65    int32_t OnUpdateCfuIndicator(MessageParcel &data, MessageParcel &reply);
66    int32_t OnUpdateVoiceMailMsgIndicator(MessageParcel &data, MessageParcel &reply);
67    int32_t OnIccAccountUpdated(MessageParcel &data, MessageParcel &reply);
68    int32_t SetTimer(uint32_t code);
69    void CancelTimer(int32_t id);
70
71private:
72    std::map<StateNotifyInterfaceCode, TelephonyStateFunc> memberFuncMap_;
73    std::map<uint32_t, std::string> collieCodeStringMap_ = {
74        { uint32_t(StateNotifyInterfaceCode::ADD_OBSERVER), "ADD_OBSERVER" },
75    };
76};
77} // namespace Telephony
78} // namespace OHOS
79#endif // TELEPHONY_STATE_REGISTRY_STUB_H
80