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_call_callback_proxy.h"
17
18 #include "message_option.h"
19 #include "message_parcel.h"
20
21 namespace OHOS {
22 namespace Telephony {
SatelliteCallCallbackProxy(const sptr<IRemoteObject> & impl)23 SatelliteCallCallbackProxy::SatelliteCallCallbackProxy(const sptr<IRemoteObject> &impl)
24 : IRemoteProxy<SatelliteCallCallbackInterface>(impl)
25 {}
26
DialSatelliteResponse(int32_t slotId,const RadioResponseInfo & info)27 int32_t SatelliteCallCallbackProxy::DialSatelliteResponse(int32_t slotId, const RadioResponseInfo &info)
28 {
29 MessageParcel in;
30 int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in, info);
31 if (ret != TELEPHONY_SUCCESS) {
32 return ret;
33 }
34 return SendResponseInfo(static_cast<int32_t>(SatelliteCallCallbackInterfaceCode::SATELLITE_DIAL), in);
35 }
36
HangUpSatelliteResponse(int32_t slotId,const RadioResponseInfo & info)37 int32_t SatelliteCallCallbackProxy::HangUpSatelliteResponse(int32_t slotId, const RadioResponseInfo &info)
38 {
39 MessageParcel in;
40 int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in, info);
41 if (ret != TELEPHONY_SUCCESS) {
42 return ret;
43 }
44 return SendResponseInfo(static_cast<int32_t>(SatelliteCallCallbackInterfaceCode::SATELLITE_HANG_UP), in);
45 }
46
RejectSatelliteResponse(int32_t slotId,const RadioResponseInfo & info)47 int32_t SatelliteCallCallbackProxy::RejectSatelliteResponse(int32_t slotId, const RadioResponseInfo &info)
48 {
49 MessageParcel in;
50 int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in, info);
51 if (ret != TELEPHONY_SUCCESS) {
52 return ret;
53 }
54 return SendResponseInfo(static_cast<int32_t>(SatelliteCallCallbackInterfaceCode::SATELLITE_REJECT), in);
55 }
56
AnswerSatelliteResponse(int32_t slotId,const RadioResponseInfo & info)57 int32_t SatelliteCallCallbackProxy::AnswerSatelliteResponse(int32_t slotId, const RadioResponseInfo &info)
58 {
59 MessageParcel in;
60 int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in, info);
61 if (ret != TELEPHONY_SUCCESS) {
62 return ret;
63 }
64 return SendResponseInfo(static_cast<int32_t>(SatelliteCallCallbackInterfaceCode::SATELLITE_ANSWER), in);
65 }
66
CallStateChangeReport(int32_t slotId)67 int32_t SatelliteCallCallbackProxy::CallStateChangeReport(int32_t slotId)
68 {
69 MessageParcel in;
70 int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
71 if (ret != TELEPHONY_SUCCESS) {
72 return ret;
73 }
74 return SendResponseInfo(static_cast<int32_t>(SatelliteCallCallbackInterfaceCode::SATELLITE_CALL_STATE_CHANGE), in);
75 }
76
GetSatelliteCallsDataResponse(int32_t slotId,const RadioResponseInfo & info)77 int32_t SatelliteCallCallbackProxy::GetSatelliteCallsDataResponse(int32_t slotId, const RadioResponseInfo &info)
78 {
79 MessageParcel in;
80 int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in, info);
81 if (ret != TELEPHONY_SUCCESS) {
82 return ret;
83 }
84 return SendResponseInfo(static_cast<int32_t>(SatelliteCallCallbackInterfaceCode::SATELLITE_GET_CALLS_DATA), in);
85 }
86
GetSatelliteCallsDataResponse(int32_t slotId,const SatelliteCurrentCallList & callList)87 int32_t SatelliteCallCallbackProxy::GetSatelliteCallsDataResponse(
88 int32_t slotId, const SatelliteCurrentCallList &callList)
89 {
90 MessageParcel in;
91 int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
92 if (ret != TELEPHONY_SUCCESS) {
93 return ret;
94 }
95 if (!in.WriteInt32(slotId)) {
96 return TELEPHONY_ERR_WRITE_DATA_FAIL;
97 }
98 if (!in.WriteInt32(callList.callSize)) {
99 return TELEPHONY_ERR_WRITE_DATA_FAIL;
100 }
101 if (!in.WriteInt32(callList.flag)) {
102 return TELEPHONY_ERR_WRITE_DATA_FAIL;
103 }
104 if (!in.WriteInt32(static_cast<int32_t>(callList.calls.size()))) {
105 return TELEPHONY_ERR_WRITE_DATA_FAIL;
106 }
107 for (auto call : callList.calls) {
108 if (!in.WriteInt32(call.index) || !in.WriteInt32(call.dir) || !in.WriteInt32(call.state) ||
109 !in.WriteInt32(call.mode) || !in.WriteInt32(call.mpty) || !in.WriteInt32(call.voiceDomain) ||
110 !in.WriteInt32(call.callType) || !in.WriteString(call.number) || !in.WriteInt32(call.type) ||
111 !in.WriteString(call.alpha) || !in.WriteInt32(call.toa)) {
112 return TELEPHONY_ERR_WRITE_DATA_FAIL;
113 }
114 }
115 return SendResponseInfo(static_cast<int32_t>(SatelliteCallCallbackInterfaceCode::SATELLITE_GET_CALLS_DATA), in);
116 }
117
SendResponseInfo(int32_t eventId,MessageParcel & in)118 int32_t SatelliteCallCallbackProxy::SendResponseInfo(int32_t eventId, MessageParcel &in)
119 {
120 MessageOption option;
121 MessageParcel out;
122 sptr<IRemoteObject> remote = Remote();
123 if (remote == nullptr) {
124 return TELEPHONY_ERR_LOCAL_PTR_NULL;
125 }
126 int32_t error = remote->SendRequest(eventId, in, out, option);
127 if (error == ERR_NONE) {
128 return out.ReadInt32();
129 }
130 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
131 }
132
WriteCommonInfo(int32_t slotId,const std::string & funcName,MessageParcel & in)133 int32_t SatelliteCallCallbackProxy::WriteCommonInfo(int32_t slotId, const std::string &funcName, MessageParcel &in)
134 {
135 if (!in.WriteInterfaceToken(SatelliteCallCallbackProxy::GetDescriptor())) {
136 TELEPHONY_LOGE("[slot%{public}d]%{public}s:Write descriptor token fail!", slotId, funcName.c_str());
137 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
138 }
139 if (!in.WriteInt32(slotId)) {
140 TELEPHONY_LOGE("[slot%{public}d]%{public}s:Write slotId fail!", slotId, funcName.c_str());
141 return TELEPHONY_ERR_WRITE_DATA_FAIL;
142 }
143 return TELEPHONY_SUCCESS;
144 }
145
WriteCommonInfo(int32_t slotId,const std::string & funcName,MessageParcel & in,const RadioResponseInfo & info)146 int32_t SatelliteCallCallbackProxy::WriteCommonInfo(
147 int32_t slotId, const std::string &funcName, MessageParcel &in, const RadioResponseInfo &info)
148 {
149 int32_t ret = WriteCommonInfo(slotId, funcName, in);
150 if (ret != TELEPHONY_SUCCESS) {
151 return ret;
152 }
153 if (!in.WriteRawData((const void *)&info, sizeof(RadioResponseInfo))) {
154 TELEPHONY_LOGE("[slot%{public}d]%{public}s:Write info fail!", slotId, funcName.c_str());
155 return TELEPHONY_ERR_WRITE_DATA_FAIL;
156 }
157 return TELEPHONY_SUCCESS;
158 }
159
WriteSsBaseResultCommonInfo(int32_t slotId,const std::string & funcName,MessageParcel & in,const SsBaseResult & ssResult)160 int32_t SatelliteCallCallbackProxy::WriteSsBaseResultCommonInfo(
161 int32_t slotId, const std::string &funcName, MessageParcel &in, const SsBaseResult &ssResult)
162 {
163 int32_t ret = WriteCommonInfo(slotId, funcName, in);
164 if (ret != TELEPHONY_SUCCESS) {
165 return ret;
166 }
167 if (!in.WriteInt32(ssResult.index)) {
168 return TELEPHONY_ERR_WRITE_DATA_FAIL;
169 }
170 if (!in.WriteInt32(ssResult.result)) {
171 return TELEPHONY_ERR_WRITE_DATA_FAIL;
172 }
173 if (!in.WriteInt32(ssResult.reason)) {
174 return TELEPHONY_ERR_WRITE_DATA_FAIL;
175 }
176 if (!in.WriteString(ssResult.message)) {
177 return TELEPHONY_ERR_WRITE_DATA_FAIL;
178 }
179 return TELEPHONY_SUCCESS;
180 }
181 } // namespace Telephony
182 } // namespace OHOS