1 /*
2 * Copyright (C) 2023 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 "satellite_sms_callback_stub.h"
17 #include "satellite_sms_callback.h"
18 #include "tel_ril_sms_parcel.h"
19 #include "radio_event.h"
20 #include "telephony_errors.h"
21 #include "telephony_log_wrapper.h"
22
23 namespace OHOS {
24 namespace Telephony {
SatelliteSmsCallbackStub()25 SatelliteSmsCallbackStub::SatelliteSmsCallbackStub()
26 {
27 TELEPHONY_LOGD("SatelliteSmsCallbackStub");
28 InitFuncMap();
29 }
30
InitFuncMap()31 void SatelliteSmsCallbackStub::InitFuncMap()
32 {
33 requestFuncMap_[static_cast<uint32_t>(SatelliteSmsCallbackInterfaceCode::SEND_SMS_RESPONSE)] =
34 [this](MessageParcel &data, MessageParcel &reply) { return OnSendSmsResponse(data, reply); };
35 requestFuncMap_[static_cast<uint32_t>(SatelliteSmsCallbackInterfaceCode::SMS_STATUS_REPORT_NOTIFY)] =
36 [this](MessageParcel &data, MessageParcel &reply) { return OnSmsStatusReportNotify(data, reply); };
37 requestFuncMap_[static_cast<uint32_t>(SatelliteSmsCallbackInterfaceCode::NEW_SMS_NOTIFY)] =
38 [this](MessageParcel &data, MessageParcel &reply) { return OnNewSmsNotify(data, reply); };
39 }
40
~SatelliteSmsCallbackStub()41 SatelliteSmsCallbackStub::~SatelliteSmsCallbackStub()
42 {
43 requestFuncMap_.clear();
44 }
45
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)46 int32_t SatelliteSmsCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
47 MessageOption &option)
48 {
49 std::u16string myDescriptor = SatelliteSmsCallbackStub::GetDescriptor();
50 std::u16string remoteDescriptor = data.ReadInterfaceToken();
51 if (myDescriptor != remoteDescriptor) {
52 TELEPHONY_LOGE("Descriptor check failed, return");
53 return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
54 }
55 auto itFunc = requestFuncMap_.find(code);
56 if (itFunc != requestFuncMap_.end()) {
57 auto requestFunc = itFunc->second;
58 if (requestFunc != nullptr) {
59 return requestFunc(data, reply);
60 }
61 }
62 TELEPHONY_LOGD("Do not found the requestFunc of code=%{public}d, need to check", code);
63 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
64 }
65
OnSendSmsResponseResponse(MessageParcel & data,MessageParcel & reply,int32_t & eventCode)66 int32_t SatelliteSmsCallbackStub::OnSendSmsResponseResponse(MessageParcel &data, MessageParcel &reply,
67 int32_t &eventCode)
68 {
69 int32_t flag = data.ReadInt32();
70 int32_t serial = data.ReadInt32();
71 int32_t error = data.ReadInt32();
72 int32_t type = data.ReadInt32();
73 auto info = std::make_shared<RadioResponseInfo>();
74 if (info == nullptr) {
75 TELEPHONY_LOGE("info is null!");
76 return TELEPHONY_ERR_LOCAL_PTR_NULL;
77 }
78 info->flag = flag;
79 info->serial = serial;
80 info->error = static_cast<ErrType>(error);
81 info->type = static_cast<ResponseTypes>(type);
82 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventCode, info);
83 if (response == nullptr) {
84 TELEPHONY_LOGE("response is null!");
85 return TELEPHONY_ERR_LOCAL_PTR_NULL;
86 }
87 if (!reply.WriteInt32(SendSmsResponse(response))) {
88 return TELEPHONY_ERR_WRITE_DATA_FAIL;
89 }
90 return TELEPHONY_SUCCESS;
91 }
92
OnSendSmsResponseResult(MessageParcel & data,MessageParcel & reply,int32_t & eventCode)93 int32_t SatelliteSmsCallbackStub::OnSendSmsResponseResult(MessageParcel &data, MessageParcel &reply,
94 int32_t &eventCode)
95 {
96 int32_t msgRef = data.ReadInt32();
97 std::string pdu = data.ReadString();
98 int32_t errCode = data.ReadInt32();
99 int64_t flag = data.ReadInt64();
100 auto info = std::make_shared<SendSmsResultInfo>();
101 if (info == nullptr) {
102 TELEPHONY_LOGE("info is null!");
103 return TELEPHONY_ERR_LOCAL_PTR_NULL;
104 }
105 info->msgRef = msgRef;
106 info->pdu = pdu;
107 info->errCode = errCode;
108 info->flag = flag;
109 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventCode, info);
110 if (response == nullptr) {
111 TELEPHONY_LOGE("response is null!");
112 return TELEPHONY_ERR_LOCAL_PTR_NULL;
113 }
114 if (!reply.WriteInt32(SendSmsResponse(response))) {
115 return TELEPHONY_ERR_WRITE_DATA_FAIL;
116 }
117 return TELEPHONY_SUCCESS;
118 }
119
OnSendSmsResponse(MessageParcel & data,MessageParcel & reply)120 int32_t SatelliteSmsCallbackStub::OnSendSmsResponse(MessageParcel &data, MessageParcel &reply)
121 {
122 int32_t eventCode = data.ReadInt32();
123 int32_t smsCallbackType = data.ReadInt32();
124 if (smsCallbackType == static_cast<int32_t>(SatelliteSmsResultType::HRIL_RADIO_RESPONSE)) {
125 return OnSendSmsResponseResponse(data, reply, eventCode);
126 }
127
128 if (smsCallbackType == static_cast<int32_t>(SatelliteSmsResultType::SEND_SMS_RESULT)) {
129 return OnSendSmsResponseResult(data, reply, eventCode);
130 }
131
132 TELEPHONY_LOGE("SatelliteSmsCallbackStub: sms response is null!");
133 return TELEPHONY_ERR_READ_DATA_FAIL;
134 }
135
OnSmsStatusReportNotify(MessageParcel & data,MessageParcel & reply)136 int32_t SatelliteSmsCallbackStub::OnSmsStatusReportNotify(MessageParcel &data, MessageParcel &reply)
137 {
138 int32_t eventCode = data.ReadInt32();
139
140 auto info = std::make_shared<SmsMessageInfo>();
141 if (info == nullptr) {
142 TELEPHONY_LOGE("info is null!");
143 return TELEPHONY_ERR_LOCAL_PTR_NULL;
144 }
145 int32_t type = 0;
146 if (!data.ReadInt32(type)) {
147 TELEPHONY_LOGE("SmsMessageInfo is null!");
148 return TELEPHONY_ERR_READ_DATA_FAIL;
149 }
150 info->indicationType = type;
151 info->size = data.ReadInt32();
152 data.ReadUInt8Vector(&(info->pdu));
153 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventCode, info);
154 if (response == nullptr) {
155 TELEPHONY_LOGE("response is null!");
156 return TELEPHONY_ERR_LOCAL_PTR_NULL;
157 }
158 int32_t result = reply.WriteInt32(SmsStatusReportNotify(response));
159 if (result != TELEPHONY_SUCCESS) {
160 TELEPHONY_LOGE("Failed to write response!");
161 return TELEPHONY_ERR_WRITE_DATA_FAIL;
162 }
163 return TELEPHONY_SUCCESS;
164 }
165
OnNewSmsNotify(MessageParcel & data,MessageParcel & reply)166 int32_t SatelliteSmsCallbackStub::OnNewSmsNotify(MessageParcel &data, MessageParcel &reply)
167 {
168 int32_t eventCode = data.ReadInt32();
169
170 auto info = std::make_shared<SmsMessageInfo>();
171 if (info == nullptr) {
172 TELEPHONY_LOGE("info is null!");
173 return TELEPHONY_ERR_LOCAL_PTR_NULL;
174 }
175 int32_t type = 0;
176 if (!data.ReadInt32(type)) {
177 TELEPHONY_LOGE("SmsMessageInfo is null!");
178 return TELEPHONY_ERR_READ_DATA_FAIL;
179 }
180 info->indicationType = type;
181 info->size = data.ReadInt32();
182 data.ReadUInt8Vector(&(info->pdu));
183 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventCode, info);
184 if (response == nullptr) {
185 TELEPHONY_LOGE("response is null!");
186 return TELEPHONY_ERR_LOCAL_PTR_NULL;
187 }
188 reply.WriteInt32(NewSmsNotify(response));
189 return TELEPHONY_SUCCESS;
190 }
191 } // namespace Telephony
192 } // namespace OHOS
193