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
18 #include "hril_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 &SatelliteSmsCallbackStub::OnSendSmsResponse;
35 requestFuncMap_[static_cast<uint32_t>(SatelliteSmsCallbackInterfaceCode::SMS_STATUS_REPORT_NOTIFY)] =
36 &SatelliteSmsCallbackStub::OnSmsStatusReportNotify;
37 requestFuncMap_[static_cast<uint32_t>(SatelliteSmsCallbackInterfaceCode::NEW_SMS_NOTIFY)] =
38 &SatelliteSmsCallbackStub::OnNewSmsNotify;
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(
47 uint32_t code, MessageParcel &data, MessageParcel &reply, 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 (this->*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
OnSendSmsResponse(MessageParcel & data,MessageParcel & reply)66 int32_t SatelliteSmsCallbackStub::OnSendSmsResponse(MessageParcel &data, MessageParcel &reply)
67 {
68 int32_t eventCode = data.ReadInt32();
69 int32_t smsCallbackType = data.ReadInt32();
70 if (smsCallbackType == static_cast<int32_t>(SatelliteSmsResultType::HRIL_RADIO_RESPONSE)) {
71 int32_t flag = data.ReadInt32();
72 int32_t serial = data.ReadInt32();
73 int32_t error = data.ReadInt32();
74 int32_t type = data.ReadInt32();
75 auto info = std::make_shared<HRilRadioResponseInfo>();
76 if (info == nullptr) {
77 TELEPHONY_LOGE("info is null!");
78 return TELEPHONY_ERR_LOCAL_PTR_NULL;
79 }
80 info->flag = flag;
81 info->serial = serial;
82 info->error = static_cast<HRilErrType>(error);
83 info->type = static_cast<HRilResponseTypes>(type);
84 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventCode, info);
85 if (response == nullptr) {
86 TELEPHONY_LOGE("response is null!");
87 return TELEPHONY_ERR_LOCAL_PTR_NULL;
88 }
89 reply.WriteInt32(SendSmsResponse(response));
90 return TELEPHONY_SUCCESS;
91 }
92
93 if (smsCallbackType == static_cast<int32_t>(SatelliteSmsResultType::SEND_SMS_RESULT)) {
94 int32_t msgRef = data.ReadInt32();
95 std::string pdu = data.ReadString();
96 int32_t errCode = data.ReadInt32();
97 int64_t flag = data.ReadInt64();
98 auto info = std::make_shared<SendSmsResultInfo>();
99 if (info == nullptr) {
100 TELEPHONY_LOGE("info is null!");
101 return TELEPHONY_ERR_LOCAL_PTR_NULL;
102 }
103 info->msgRef = msgRef;
104 info->pdu = pdu;
105 info->errCode = errCode;
106 info->flag = flag;
107 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventCode, info);
108 if (response == nullptr) {
109 TELEPHONY_LOGE("response is null!");
110 return TELEPHONY_ERR_LOCAL_PTR_NULL;
111 }
112 reply.WriteInt32(SendSmsResponse(response));
113 return TELEPHONY_SUCCESS;
114 }
115
116 TELEPHONY_LOGE("SatelliteSmsCallbackStub: sms response is null!");
117 return TELEPHONY_ERR_READ_DATA_FAIL;
118 }
119
OnSmsStatusReportNotify(MessageParcel & data,MessageParcel & reply)120 int32_t SatelliteSmsCallbackStub::OnSmsStatusReportNotify(MessageParcel &data, MessageParcel &reply)
121 {
122 int32_t eventCode = data.ReadInt32();
123
124 auto info = std::make_shared<SmsMessageInfo>();
125 if (info == nullptr) {
126 TELEPHONY_LOGE("info is null!");
127 return TELEPHONY_ERR_LOCAL_PTR_NULL;
128 }
129 int32_t type = 0;
130 if (!data.ReadInt32(type)) {
131 TELEPHONY_LOGE("SmsMessageInfo is null!");
132 return TELEPHONY_ERR_READ_DATA_FAIL;
133 }
134 info->indicationType = type;
135 info->size = data.ReadInt32();
136 data.ReadUInt8Vector(&(info->pdu));
137 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventCode, info);
138 if (response == nullptr) {
139 TELEPHONY_LOGE("response is null!");
140 return TELEPHONY_ERR_LOCAL_PTR_NULL;
141 }
142 reply.WriteInt32(SmsStatusReportNotify(response));
143 return TELEPHONY_SUCCESS;
144 }
145
OnNewSmsNotify(MessageParcel & data,MessageParcel & reply)146 int32_t SatelliteSmsCallbackStub::OnNewSmsNotify(MessageParcel &data, MessageParcel &reply)
147 {
148 int32_t eventCode = data.ReadInt32();
149
150 auto info = std::make_shared<SmsMessageInfo>();
151 if (info == nullptr) {
152 TELEPHONY_LOGE("info is null!");
153 return TELEPHONY_ERR_LOCAL_PTR_NULL;
154 }
155 int32_t type = 0;
156 if (!data.ReadInt32(type)) {
157 TELEPHONY_LOGE("SmsMessageInfo is null!");
158 return TELEPHONY_ERR_READ_DATA_FAIL;
159 }
160 info->indicationType = type;
161 info->size = data.ReadInt32();
162 data.ReadUInt8Vector(&(info->pdu));
163 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventCode, info);
164 if (response == nullptr) {
165 TELEPHONY_LOGE("response is null!");
166 return TELEPHONY_ERR_LOCAL_PTR_NULL;
167 }
168 reply.WriteInt32(NewSmsNotify(response));
169 return TELEPHONY_SUCCESS;
170 }
171 } // namespace Telephony
172 } // namespace OHOS
173