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_core_callback_stub.h"
17
18 #include "tel_ril_base_parcel.h"
19 #include "radio_event.h"
20 #include "telephony_errors.h"
21 #include "telephony_log_wrapper.h"
22
23
24 namespace OHOS {
25 namespace Telephony {
SatelliteCoreCallbackStub()26 SatelliteCoreCallbackStub::SatelliteCoreCallbackStub()
27 {
28 TELEPHONY_LOGD("SatelliteCoreCallbackStub");
29 InitFuncMap();
30 }
31
InitFuncMap()32 void SatelliteCoreCallbackStub::InitFuncMap()
33 {
34 requestFuncMap_[static_cast<uint32_t>(SatelliteCoreCallbackInterfaceCode::SET_RADIO_STATE_RESPONSE)] =
35 [this](MessageParcel &data, MessageParcel &reply) { return OnSetRadioStateResponse(data, reply); };
36 requestFuncMap_[static_cast<uint32_t>(SatelliteCoreCallbackInterfaceCode::RADIO_STATE_CHANGED)] =
37 [this](MessageParcel &data, MessageParcel &reply) { return OnRadioStateChanged(data, reply); };
38 requestFuncMap_[static_cast<uint32_t>(SatelliteCoreCallbackInterfaceCode::SATELLITE_STATUS_CHANGED)] =
39 [this](MessageParcel &data, MessageParcel &reply) { return OnSatelliteStatusChanged(data, reply); };
40 requestFuncMap_[static_cast<uint32_t>(SatelliteCoreCallbackInterfaceCode::SIM_STATE_CHANGED)] =
41 [this](MessageParcel &data, MessageParcel &reply) { return OnSimStateChanged(data, reply); };
42 }
43
~SatelliteCoreCallbackStub()44 SatelliteCoreCallbackStub::~SatelliteCoreCallbackStub()
45 {
46 requestFuncMap_.clear();
47 }
48
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)49 int32_t SatelliteCoreCallbackStub::OnRemoteRequest(
50 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
51 {
52 std::u16string myDescriptor = SatelliteCoreCallbackStub::GetDescriptor();
53 std::u16string remoteDescriptor = data.ReadInterfaceToken();
54 if (myDescriptor != remoteDescriptor) {
55 TELEPHONY_LOGE("Descriptor check failed, return");
56 return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
57 }
58 auto itFunc = requestFuncMap_.find(code);
59 if (itFunc != requestFuncMap_.end()) {
60 auto requestFunc = itFunc->second;
61 if (requestFunc != nullptr) {
62 return requestFunc(data, reply);
63 }
64 }
65 TELEPHONY_LOGD("Do not found the requestFunc of code=%{public}d, need to check", code);
66 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
67 }
68
OnSetRadioStateResponse(MessageParcel & data,MessageParcel & reply)69 int32_t SatelliteCoreCallbackStub::OnSetRadioStateResponse(MessageParcel &data, MessageParcel &reply)
70 {
71 int32_t eventCode = data.ReadInt32();
72 int32_t dataType = data.ReadInt32();
73 if (dataType == SatelliteRadioResponseType::DEFAULT_RADIO_RESPONSE) {
74 int32_t flag = data.ReadInt32();
75 int32_t serial = data.ReadInt32();
76 int32_t error = data.ReadInt32();
77 int32_t type = data.ReadInt32();
78 auto info = std::make_shared<RadioResponseInfo>();
79 if (info == nullptr) {
80 return TELEPHONY_ERR_LOCAL_PTR_NULL;
81 }
82 info->flag = flag;
83 info->serial = serial;
84 info->error = static_cast<ErrType>(error);
85 info->type = static_cast<ResponseTypes>(type);
86 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventCode, info);
87 if (response == nullptr) {
88 TELEPHONY_LOGE("hril response is null!");
89 return TELEPHONY_ERR_LOCAL_PTR_NULL;
90 }
91 reply.WriteInt32(SetRadioStateResponse(response));
92 return TELEPHONY_SUCCESS;
93 }
94
95 if (dataType == SatelliteRadioResponseType::RADIO_STATE_INFO) {
96 int64_t flag = data.ReadInt64();
97 int32_t state = data.ReadInt32();
98 auto info = std::make_unique<RadioStateInfo>();
99 if (info == nullptr) {
100 return TELEPHONY_ERR_LOCAL_PTR_NULL;
101 }
102 info->flag = flag;
103 info->state = state;
104 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventCode, info);
105 if (response == nullptr) {
106 TELEPHONY_LOGE("radio info response is null!");
107 return TELEPHONY_ERR_LOCAL_PTR_NULL;
108 }
109 reply.WriteInt32(SetRadioStateResponse(response));
110 return TELEPHONY_SUCCESS;
111 }
112
113 TELEPHONY_LOGE("SatelliteCoreCallbackStub: radio response is null!");
114 return TELEPHONY_ERR_READ_DATA_FAIL;
115 }
116
OnRadioStateChanged(MessageParcel & data,MessageParcel & reply)117 int32_t SatelliteCoreCallbackStub::OnRadioStateChanged(MessageParcel &data, MessageParcel &reply)
118 {
119 int32_t eventCode = data.ReadInt32();
120
121 auto info = std::make_shared<Int32Parcel>();
122 if (!data.ReadInt32(info->data)) {
123 TELEPHONY_LOGE("Int32Parcel is null!");
124 return TELEPHONY_ERR_READ_DATA_FAIL;
125 }
126
127 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventCode, info);
128 if (response == nullptr) {
129 TELEPHONY_LOGE("response is null!");
130 return TELEPHONY_ERR_LOCAL_PTR_NULL;
131 }
132 reply.WriteInt32(RadioStateChanged(response));
133 return TELEPHONY_SUCCESS;
134 }
135
OnSatelliteStatusChanged(MessageParcel & data,MessageParcel & reply)136 int32_t SatelliteCoreCallbackStub::OnSatelliteStatusChanged(MessageParcel &data, MessageParcel &reply)
137 {
138 int32_t eventCode = data.ReadInt32();
139 std::shared_ptr<SatelliteStatus> satelliteStatus = std::make_shared<SatelliteStatus>();
140 satelliteStatus->slotId = data.ReadInt32();
141 satelliteStatus->mode = data.ReadInt32();
142 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventCode, satelliteStatus);
143 if (response == nullptr) {
144 TELEPHONY_LOGE("response is null!");
145 return TELEPHONY_ERR_LOCAL_PTR_NULL;
146 }
147 reply.WriteInt32(SatelliteStatusChanged(response));
148 return TELEPHONY_SUCCESS;
149 }
150
OnSimStateChanged(MessageParcel & data,MessageParcel & reply)151 int32_t SatelliteCoreCallbackStub::OnSimStateChanged(MessageParcel &data, MessageParcel &reply)
152 {
153 int32_t eventCode = data.ReadInt32();
154
155 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventCode);
156 if (response == nullptr) {
157 TELEPHONY_LOGE("response is null!");
158 return TELEPHONY_ERR_LOCAL_PTR_NULL;
159 }
160 reply.WriteInt32(SimStateChanged(response));
161 return TELEPHONY_SUCCESS;
162 }
163 } // namespace Telephony
164 } // namespace OHOS
165