• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_RIL_MANAGER_TEST_H
17 #define OHOS_RIL_MANAGER_TEST_H
18 
19 #include <iservmgr_hdi.h>
20 
21 #include "event_runner.h"
22 
23 #include "hril_call_parcel.h"
24 #include "hril_data_parcel.h"
25 #include "hril_modem_parcel.h"
26 #include "hril_network_parcel.h"
27 #include "hril_sim_parcel.h"
28 #include "hril_sms_parcel.h"
29 #include "ril_data_profile_test.h"
30 
31 #define SAMPLE_WRITE_READ 123
32 namespace OHOS {
33 namespace Telephony {
34 enum CellularRadioState {
35     RADIO_OFF, /* Radio explicitly powered off (eg CFUN=0) */
36     RADIO_UNAVAILABLE, /* Radio unavailable (eg, resetting or not booted) */
37     RADIO_ON /* Radio is on */
38 };
39 
40 struct HRilRequestTest {
41     int32_t serialId_;
42     int32_t requestId_;
43     AppExecFwk::InnerEvent::Pointer pointer_ = AppExecFwk::InnerEvent::Pointer(nullptr, nullptr);
44 
HRilRequestTestHRilRequestTest45     HRilRequestTest(int32_t serialId, int32_t requestId, const AppExecFwk::InnerEvent::Pointer &pointer)
46     {
47         serialId_ = serialId;
48         requestId_ = requestId;
49         pointer_ = std::move(const_cast<AppExecFwk::InnerEvent::Pointer &>(pointer));
50     }
51 };
52 
53 class RilManagerTest {
54     typedef struct UusInfo {
55         int32_t uusDcs; /* 3GPP TS 23.038 [25] Cell Broadcast Data Coding Scheme(default 0) */
56     } UusInfo;
57 
58 public:
59     RilManagerTest(int32_t preferredNetworkType, int32_t cdmaSubscription);
60     ~RilManagerTest();
61 
62     void OnInit();
63     void SetSlotId(int32_t slotId);
64 
65     int32_t SendInt32Event(int32_t dispatchId, int32_t value);
66     int32_t SendStringEvent(int32_t dispatchId, const char *value);
67     int32_t SendBufferEvent(int32_t dispatchId, OHOS::MessageParcel &eventData);
68     int32_t SendCommonBufferEvent(int32_t dispatchId, const void *eventData, size_t dataLength);
69     void SetCellularRadioIndication();
70     void SetCellularRadioResponse();
71 
72     void RilSendAck();
73     void RilProcessResponseDone(std::shared_ptr<HRilRequestTest> request, HRilRadioResponseInfo &responseInfo);
74     DataProfileDataInfo ConvertToHalDataProfile(RilDataProfileTest dp);
75     GsmSmsMessageInfo ConstructGsmSendSmsRilRequest(std::string smscPdu, std::string pdu);
76 
77     void GetCallList(const AppExecFwk::InnerEvent::Pointer &result);
78     void RilCmDial(std::string address, int32_t clirMode, const AppExecFwk::InnerEvent::Pointer &result);
79     void Hangup(int32_t gsmIndex, const AppExecFwk::InnerEvent::Pointer &result);
80     void Answer(const AppExecFwk::InnerEvent::Pointer &result);
81     void Reject(const AppExecFwk::InnerEvent::Pointer &result);
82     void HoldCall(const AppExecFwk::InnerEvent::Pointer &result);
83     void UnHoldCall(const AppExecFwk::InnerEvent::Pointer &result);
84     void SwitchCall(const AppExecFwk::InnerEvent::Pointer &result);
85     void RilCmJoin(int32_t callType, const AppExecFwk::InnerEvent::Pointer &result);
86     void RilCmSplit(int32_t callIndex, int32_t callType, const AppExecFwk::InnerEvent::Pointer &result);
87     void CallSupplement(int32_t hangupType, const AppExecFwk::InnerEvent::Pointer &result);
88     void SendDtmf(char dtmfKey, int32_t index, const AppExecFwk::InnerEvent::Pointer &result);
89     void StartDtmf(char dtmfKey, int32_t index, const AppExecFwk::InnerEvent::Pointer &result);
90     void StopDtmf(int32_t index, const AppExecFwk::InnerEvent::Pointer &result);
91     void SetUssd(std::string str, const AppExecFwk::InnerEvent::Pointer &result);
92     void GetUssd(const AppExecFwk::InnerEvent::Pointer &result);
93     void SetMute(int32_t mute, const AppExecFwk::InnerEvent::Pointer &result);
94     void GetMute(const AppExecFwk::InnerEvent::Pointer &result);
95     void GetEmergencyList(const AppExecFwk::InnerEvent::Pointer &result);
96     void GetFailReason(const AppExecFwk::InnerEvent::Pointer &result);
97 
98     void GetImsi(std::string aid, const AppExecFwk::InnerEvent::Pointer &response);
99 
100     void GetRilCmSignalStrength(const std::shared_ptr<AppExecFwk::EventHandler> &handler, int32_t what);
101 
102     void GetCsRegStatus(const AppExecFwk::InnerEvent::Pointer &response);
103     void GetPsRegStatus(const AppExecFwk::InnerEvent::Pointer &response);
104     void GetCellInfoList(const AppExecFwk::InnerEvent::Pointer &response);
105     void GetCurrentCellInfo(const AppExecFwk::InnerEvent::Pointer &response);
106     void GetOperatorInfo(const std::shared_ptr<AppExecFwk::EventHandler> &handler, int32_t what);
107     void GetNetworkSearchInfo(const AppExecFwk::InnerEvent::Pointer &response);
108     void GetNetworkSelectionMode(const AppExecFwk::InnerEvent::Pointer &response);
109     void GetPreferredNetwork(const AppExecFwk::InnerEvent::Pointer &response);
110     void GetImsRegStatus(const AppExecFwk::InnerEvent::Pointer &response);
111     void GetPsAttachStatus(const AppExecFwk::InnerEvent::Pointer &response);
112     void SetPreferredNetwrok(int32_t preferredNetwork, const AppExecFwk::InnerEvent::Pointer &result);
113     void SetLocationUpdate(int32_t enableFlg, const AppExecFwk::InnerEvent::Pointer &result);
114     void SetPsAttachStatus(int32_t attachFlg, const AppExecFwk::InnerEvent::Pointer &result);
115     void SetNetworkSelectionMode(int32_t mode, std::string plmn, const AppExecFwk::InnerEvent::Pointer &result);
116     void GetVoiceRadio(const AppExecFwk::InnerEvent::Pointer &response);
117 
118     void SendSms(std::string smscPdu, std::string pdu, const std::shared_ptr<AppExecFwk::EventHandler> &handler,
119         const AppExecFwk::InnerEvent::Pointer &response);
120     void SendSmsMoreMode(std::string smscPdu, std::string pdu,
121         const std::shared_ptr<AppExecFwk::EventHandler> &handler, const AppExecFwk::InnerEvent::Pointer &response);
122     void SendSmsAck(bool success, int32_t cause, const AppExecFwk::InnerEvent::Pointer &response);
123     void GetSmscAddr(const AppExecFwk::InnerEvent::Pointer &response);
124     void SetSmscAddr(int32_t tosca, std::string address, const AppExecFwk::InnerEvent::Pointer &response);
125     void SetRadioState(int32_t fan, int32_t rst, const AppExecFwk::InnerEvent::Pointer &response);
126     void GetRadioState(const AppExecFwk::InnerEvent::Pointer &response);
127     void GetImei(const AppExecFwk::InnerEvent::Pointer &response);
128     void GetSimIO(int32_t command, int32_t fileId, int32_t p1, int32_t p2, int32_t p3, std::string data,
129         std::string path, const AppExecFwk::InnerEvent::Pointer &response);
130     void ActivatePdpContext(int32_t radioTechnology, RilDataProfileTest dataProfile, bool isRoaming,
131         bool allowRoaming, const AppExecFwk::InnerEvent::Pointer &response);
132     void DeactivatePdpContext(int32_t ci, int32_t reason, const AppExecFwk::InnerEvent::Pointer &response);
133     void SetInitApnInfo(RilDataProfileTest dataProfile, const AppExecFwk::InnerEvent::Pointer &response);
134     void GetPdpContext(const AppExecFwk::InnerEvent::Pointer &response);
135     void GetSimStatus(const AppExecFwk::InnerEvent::Pointer &result);
136     void SimOpenLogicalChannel(std::string appID, int32_t p2, const AppExecFwk::InnerEvent::Pointer &response);
137     void SimCloseLogicalChannel(int32_t channelId, const AppExecFwk::InnerEvent::Pointer &response);
138     void SimTransmitApduLogicalChannel(ApduSimIORequestInfo reqInfo, const AppExecFwk::InnerEvent::Pointer &response);
139     void UnlockSimLock(int32_t lockType, std::string password, const AppExecFwk::InnerEvent::Pointer &response);
140     void GetLinkBandwidthInfo(const int32_t cid, const AppExecFwk::InnerEvent::Pointer &result);
141 
142     static const int32_t INVALID_WAKELOCK = -1;
143     static const int32_t FOR_WAKELOCK = 0;
144     static const int32_t FOR_ACK_WAKELOCK = 1;
145     static const int32_t HRIL_ADAPTER_RADIO_INDICATION = 2001;
146     static const int32_t HRIL_ADAPTER_RADIO_RESPONSE = 2002;
147     static const int32_t RIL_ADAPTER_OEM_INDICATION = 2003;
148     static const int32_t RIL_ADAPTER_OEM_RESPONSE = 2004;
149     sptr<IRemoteObject> cellularRadio_;
150     int32_t cdmaSubscription_ = 0;
151 
GetNextSerialId()152     static int32_t GetNextSerialId()
153     {
154         return nextSerialId_++;
155     }
156 
157     static std::atomic_int nextSerialId_;
158     static std::unordered_map<int32_t, std::shared_ptr<HRilRequestTest>> requestMap_;
159 
160 private:
161     std::shared_ptr<HRilRequestTest> CreateRequest(int32_t request, const AppExecFwk::InnerEvent::Pointer &result);
162 
163     static constexpr const char *RIL_ADAPTER_SERVICE_NAME = "cellular_radio1";
164     static constexpr int32_t PAYLOAD_NUM = 1234;
165     int32_t slotId_;
166 };
167 } // namespace Telephony
168 } // namespace OHOS
169 #endif // OHOS_RIL_MANAGER_TEST_H
170