1 /*
2 * Copyright (C) 2021-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 "cellular_data_service_proxy.h"
17
18 #include "iremote_object.h"
19 #include "message_option.h"
20 #include "message_parcel.h"
21 #include "telephony_errors.h"
22 #include "telephony_log_wrapper.h"
23 #include "securec.h"
24 #include "string_ex.h"
25
26 namespace OHOS {
27 namespace Telephony {
IsCellularDataEnabled(bool & dataEnabled)28 int32_t CellularDataServiceProxy::IsCellularDataEnabled(bool &dataEnabled)
29 {
30 MessageParcel data;
31 MessageParcel reply;
32 MessageOption option;
33 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
34 if (Remote() == nullptr) {
35 TELEPHONY_LOGE("remote is null");
36 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
37 }
38 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::IS_CELLULAR_DATA_ENABLED, data,
39 reply, option);
40 if (error != TELEPHONY_SUCCESS) {
41 TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
42 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
43 }
44 int32_t result = reply.ReadInt32();
45 if (result == TELEPHONY_SUCCESS) {
46 dataEnabled = reply.ReadBool();
47 }
48
49 return result;
50 }
51
EnableCellularData(bool enable)52 int32_t CellularDataServiceProxy::EnableCellularData(bool enable)
53 {
54 MessageParcel data;
55 MessageParcel reply;
56 MessageOption option;
57 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
58 data.WriteBool(enable);
59 if (Remote() == nullptr) {
60 TELEPHONY_LOGE("remote is null");
61 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
62 }
63 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::ENABLE_CELLULAR_DATA, data,
64 reply, option);
65 if (error != TELEPHONY_SUCCESS) {
66 TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
67 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
68 }
69 int32_t result = reply.ReadInt32();
70 return result;
71 }
72
GetIntelligenceSwitchState(bool & state)73 int32_t CellularDataServiceProxy::GetIntelligenceSwitchState(bool &state)
74 {
75 MessageParcel data;
76 MessageParcel reply;
77 MessageOption option;
78 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
79 if (Remote() == nullptr) {
80 TELEPHONY_LOGE("remote is null");
81 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
82 }
83 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_INTELLIGENCE_SWITCH_STATE, data,
84 reply, option);
85 if (error != TELEPHONY_SUCCESS) {
86 TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
87 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
88 }
89 int32_t result = reply.ReadInt32();
90 state = reply.ReadBool();
91 return result;
92 }
93
EnableIntelligenceSwitch(bool enable)94 int32_t CellularDataServiceProxy::EnableIntelligenceSwitch(bool enable)
95 {
96 MessageParcel data;
97 MessageParcel reply;
98 MessageOption option;
99 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
100 data.WriteBool(enable);
101 if (Remote() == nullptr) {
102 TELEPHONY_LOGE("remote is null");
103 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
104 }
105 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::ENABLE_INTELLIGENCE_SWITCH, data,
106 reply, option);
107 if (error != TELEPHONY_SUCCESS) {
108 TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
109 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
110 }
111 int32_t result = reply.ReadInt32();
112 return result;
113 }
114
GetCellularDataState()115 int32_t CellularDataServiceProxy::GetCellularDataState()
116 {
117 MessageParcel data;
118 MessageParcel reply;
119 MessageOption option;
120 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
121 if (Remote() == nullptr) {
122 TELEPHONY_LOGE("remote is null");
123 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
124 }
125 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_CELLULAR_DATA_STATE, data,
126 reply, option);
127 if (error != TELEPHONY_SUCCESS) {
128 TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
129 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
130 }
131 int32_t result = reply.ReadInt32();
132 return result;
133 }
134
GetApnState(int32_t slotId,const std::string & apnType)135 int32_t CellularDataServiceProxy::GetApnState(int32_t slotId, const std::string &apnType)
136 {
137 MessageParcel data;
138 MessageParcel reply;
139 MessageOption option;
140 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
141 data.WriteInt32(slotId);
142 data.WriteString(apnType);
143 if (Remote() == nullptr) {
144 TELEPHONY_LOGE("remote is null");
145 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
146 }
147 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_CELLULAR_DATA_APN_STATE, data,
148 reply, option);
149 if (error != TELEPHONY_SUCCESS) {
150 TELEPHONY_LOGE("function GetCellularDataState call failed! errCode:%{public}d", error);
151 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
152 }
153 int32_t result = reply.ReadInt32();
154 return result;
155 }
156
GetDataRecoveryState()157 int32_t CellularDataServiceProxy::GetDataRecoveryState()
158 {
159 MessageParcel data;
160 MessageParcel reply;
161 MessageOption option;
162 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
163 if (Remote() == nullptr) {
164 TELEPHONY_LOGE("remote is null");
165 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
166 }
167 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_RECOVERY_STATE, data,
168 reply, option);
169 if (error != TELEPHONY_SUCCESS) {
170 TELEPHONY_LOGE("function GetDefaultCellularDataSlotId call failed! errCode:%{public}d", error);
171 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
172 }
173 int32_t result = reply.ReadInt32();
174 return result;
175 }
176
IsCellularDataRoamingEnabled(int32_t slotId,bool & dataRoamingEnabled)177 int32_t CellularDataServiceProxy::IsCellularDataRoamingEnabled(int32_t slotId, bool &dataRoamingEnabled)
178 {
179 MessageParcel data;
180 MessageParcel reply;
181 MessageOption option;
182 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
183 data.WriteInt32(slotId);
184 if (Remote() == nullptr) {
185 TELEPHONY_LOGE("remote is null");
186 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
187 }
188 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::IS_DATA_ROAMING_ENABLED, data,
189 reply, option);
190 if (error != TELEPHONY_SUCCESS) {
191 TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
192 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
193 }
194 int32_t result = reply.ReadInt32();
195 if (result == TELEPHONY_SUCCESS) {
196 dataRoamingEnabled = reply.ReadBool();
197 }
198
199 return result;
200 }
201
EnableCellularDataRoaming(int32_t slotId,bool enable)202 int32_t CellularDataServiceProxy::EnableCellularDataRoaming(int32_t slotId, bool enable)
203 {
204 MessageParcel data;
205 MessageParcel reply;
206 MessageOption option;
207 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
208 data.WriteInt32(slotId);
209 data.WriteBool(enable);
210 if (Remote() == nullptr) {
211 TELEPHONY_LOGE("remote is null");
212 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
213 }
214 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::ENABLE_DATA_ROAMING, data,
215 reply, option);
216 if (error != TELEPHONY_SUCCESS) {
217 TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
218 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
219 }
220 int32_t result = reply.ReadInt32();
221 return result;
222 }
223
HandleApnChanged(int32_t slotId)224 int32_t CellularDataServiceProxy::HandleApnChanged(int32_t slotId)
225 {
226 MessageParcel data;
227 MessageParcel reply;
228 MessageOption option;
229 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
230 data.WriteInt32(slotId);
231 if (Remote() == nullptr) {
232 TELEPHONY_LOGE("remote is null");
233 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
234 }
235 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::APN_DATA_CHANGED, data, reply, option);
236 if (error != TELEPHONY_SUCCESS) {
237 TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
238 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
239 }
240 int32_t result = reply.ReadInt32();
241 return result;
242 }
243
GetDefaultCellularDataSlotId()244 int32_t CellularDataServiceProxy::GetDefaultCellularDataSlotId()
245 {
246 MessageParcel data;
247 MessageParcel reply;
248 MessageOption option;
249 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
250 if (Remote() == nullptr) {
251 TELEPHONY_LOGE("remote is null");
252 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
253 }
254 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_DEFAULT_SLOT_ID, data,
255 reply, option);
256 if (error != TELEPHONY_SUCCESS) {
257 TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
258 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
259 }
260 int32_t result = reply.ReadInt32();
261 return result;
262 }
263
GetDefaultCellularDataSimId(int32_t & simId)264 int32_t CellularDataServiceProxy::GetDefaultCellularDataSimId(int32_t &simId)
265 {
266 MessageParcel data;
267 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
268 if (Remote() == nullptr) {
269 TELEPHONY_LOGE("failed: remote is null");
270 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
271 }
272 MessageParcel reply;
273 MessageOption option;
274 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_DEFAULT_SIM_ID, data, reply, option);
275 if (error != TELEPHONY_SUCCESS) {
276 TELEPHONY_LOGE("SendRequest failed! errCode:%{public}d", error);
277 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
278 }
279 int32_t result = reply.ReadInt32();
280 TELEPHONY_LOGD("end: result=%{public}d", result);
281 if (result == TELEPHONY_ERR_SUCCESS) {
282 simId = reply.ReadInt32();
283 }
284 return result;
285 }
286
SetDefaultCellularDataSlotId(int32_t slotId)287 int32_t CellularDataServiceProxy::SetDefaultCellularDataSlotId(int32_t slotId)
288 {
289 MessageParcel data;
290 MessageParcel reply;
291 MessageOption option;
292 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
293 data.WriteInt32(slotId);
294 if (Remote() == nullptr) {
295 TELEPHONY_LOGE("remote is null");
296 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
297 }
298 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::SET_DEFAULT_SLOT_ID, data,
299 reply, option);
300 if (error != TELEPHONY_SUCCESS) {
301 TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
302 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
303 }
304 int32_t result = reply.ReadInt32();
305 return result;
306 }
307
GetCellularDataFlowType()308 int32_t CellularDataServiceProxy::GetCellularDataFlowType()
309 {
310 MessageParcel data;
311 MessageParcel reply;
312 MessageOption option;
313 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
314 if (Remote() == nullptr) {
315 TELEPHONY_LOGE("remote is null");
316 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
317 }
318 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::GET_FLOW_TYPE_ID, data, reply, option);
319 if (error != TELEPHONY_SUCCESS) {
320 TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
321 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
322 }
323 int32_t result = reply.ReadInt32();
324 return result;
325 }
326
HasInternetCapability(int32_t slotId,int32_t cid)327 int32_t CellularDataServiceProxy::HasInternetCapability(int32_t slotId, int32_t cid)
328 {
329 MessageParcel data;
330 MessageParcel reply;
331 MessageOption option;
332 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
333 data.WriteInt32(slotId);
334 data.WriteInt32(cid);
335 if (Remote() == nullptr) {
336 TELEPHONY_LOGE("remote is null");
337 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
338 }
339 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::HAS_CAPABILITY, data, reply, option);
340 if (error != TELEPHONY_SUCCESS) {
341 TELEPHONY_LOGE("Strategy switch fail! errCode:%{public}d", error);
342 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
343 }
344 int32_t result = reply.ReadInt32();
345 return result;
346 }
347
ClearCellularDataConnections(int32_t slotId)348 int32_t CellularDataServiceProxy::ClearCellularDataConnections(int32_t slotId)
349 {
350 MessageParcel data;
351 MessageParcel reply;
352 MessageOption option;
353 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
354 data.WriteInt32(slotId);
355 if (Remote() == nullptr) {
356 TELEPHONY_LOGE("remote is null");
357 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
358 }
359 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::CLEAR_ALL_CONNECTIONS, data,
360 reply, option);
361 if (error != TELEPHONY_SUCCESS) {
362 TELEPHONY_LOGE("Strategy switch fail! errCode:%{public}d", error);
363 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
364 }
365 int32_t result = reply.ReadInt32();
366 return result;
367 }
368
ClearAllConnections(int32_t slotId,DisConnectionReason reason)369 int32_t CellularDataServiceProxy::ClearAllConnections(int32_t slotId, DisConnectionReason reason)
370 {
371 MessageParcel data;
372 MessageParcel reply;
373 MessageOption option;
374 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
375 data.WriteInt32(slotId);
376 data.WriteInt32(static_cast<int32_t>(reason));
377 if (Remote() == nullptr) {
378 TELEPHONY_LOGE("remote is null");
379 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
380 }
381 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::CLEAR_ALL_CONNECTIONS_USE_REASON, data,
382 reply, option);
383 if (error != TELEPHONY_SUCCESS) {
384 TELEPHONY_LOGE("Strategy switch fail! errCode:%{public}d", error);
385 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
386 }
387 int32_t result = reply.ReadInt32();
388 return result;
389 }
390
RegisterSimAccountCallback(const sptr<SimAccountCallback> & callback)391 int32_t CellularDataServiceProxy::RegisterSimAccountCallback(const sptr<SimAccountCallback> &callback)
392 {
393 if (callback == nullptr) {
394 TELEPHONY_LOGE("callback is nullptr!");
395 return TELEPHONY_ERR_ARGUMENT_NULL;
396 }
397 MessageParcel data;
398 MessageParcel reply;
399 MessageOption option;
400 if (!data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
401 TELEPHONY_LOGE("write interface token failed!");
402 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
403 }
404 if (!data.WriteRemoteObject(callback->AsObject())) {
405 TELEPHONY_LOGE("write remote object failed!");
406 return TELEPHONY_ERR_WRITE_DATA_FAIL;
407 }
408 sptr<OHOS::IRemoteObject> remote = Remote();
409 if (remote == nullptr) {
410 TELEPHONY_LOGE("remote is nullptr!");
411 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
412 }
413 int32_t error = remote->SendRequest(static_cast<uint32_t>(CellularDataInterfaceCode::REG_SIM_ACCOUNT_CALLBACK),
414 data, reply, option);
415 if (error != TELEPHONY_SUCCESS) {
416 TELEPHONY_LOGD("error! errCode:%{public}d", error);
417 return error;
418 }
419 return reply.ReadInt32();
420 }
421
UnregisterSimAccountCallback(const sptr<SimAccountCallback> & callback)422 int32_t CellularDataServiceProxy::UnregisterSimAccountCallback(const sptr<SimAccountCallback> &callback)
423 {
424 MessageParcel data;
425 MessageParcel reply;
426 MessageOption option;
427 if (!data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
428 TELEPHONY_LOGE("write interface token failed!");
429 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
430 }
431 if (!data.WriteRemoteObject(callback->AsObject())) {
432 TELEPHONY_LOGE("write remote object failed!");
433 return TELEPHONY_ERR_WRITE_DATA_FAIL;
434 }
435 sptr<OHOS::IRemoteObject> remote = Remote();
436 if (remote == nullptr) {
437 TELEPHONY_LOGE("remote is nullptr!");
438 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
439 }
440 int32_t error = remote->SendRequest(static_cast<uint32_t>(CellularDataInterfaceCode::UN_REG_SIM_ACCOUNT_CALLBACK),
441 data, reply, option);
442 if (error != TELEPHONY_SUCCESS) {
443 TELEPHONY_LOGE("error! errCode:%{public}d", error);
444 return error;
445 }
446 return reply.ReadInt32();
447 }
448
GetDataConnApnAttr(int32_t slotId,ApnItem::Attribute & apnAttr)449 int32_t CellularDataServiceProxy::GetDataConnApnAttr(int32_t slotId, ApnItem::Attribute &apnAttr)
450 {
451 MessageParcel dataParcel;
452 MessageParcel replyParcel;
453 MessageOption option;
454 if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
455 TELEPHONY_LOGE("write interface token failed!");
456 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
457 }
458 if (!dataParcel.WriteInt32(slotId)) {
459 TELEPHONY_LOGE("write userId failed!");
460 return TELEPHONY_ERR_WRITE_DATA_FAIL;
461 }
462 sptr<OHOS::IRemoteObject> remote = Remote();
463 if (remote == nullptr) {
464 TELEPHONY_LOGE("remote is nullptr!");
465 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
466 }
467 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::GET_DATA_CONN_APN_ATTR,
468 dataParcel, replyParcel, option);
469 if (error != TELEPHONY_SUCCESS) {
470 TELEPHONY_LOGE("Strategy switch fail! errCode:%{public}d", error);
471 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
472 }
473 int32_t result = replyParcel.ReadInt32();
474 if (result == TELEPHONY_ERR_SUCCESS) {
475 auto apnAttrPtr = replyParcel.ReadRawData(sizeof(ApnItem::Attribute));
476 if (apnAttrPtr == nullptr) {
477 return TELEPHONY_ERR_READ_DATA_FAIL;
478 }
479 if (memcpy_s(&apnAttr, sizeof(ApnItem::Attribute), apnAttrPtr, sizeof(ApnItem::Attribute)) != EOK) {
480 return TELEPHONY_ERR_MEMCPY_FAIL;
481 }
482 } else {
483 TELEPHONY_LOGE("end failed: result=%{public}d", result);
484 }
485
486 return TELEPHONY_ERR_SUCCESS;
487 }
488
GetDataConnIpType(int32_t slotId,std::string & ipType)489 int32_t CellularDataServiceProxy::GetDataConnIpType(int32_t slotId, std::string &ipType)
490 {
491 MessageParcel dataParcel;
492 MessageParcel replyParcel;
493 MessageOption option;
494 if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
495 TELEPHONY_LOGE("write interface token failed!");
496 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
497 }
498 if (!dataParcel.WriteInt32(slotId)) {
499 TELEPHONY_LOGE("write userId failed!");
500 return TELEPHONY_ERR_WRITE_DATA_FAIL;
501 }
502 sptr<OHOS::IRemoteObject> remote = Remote();
503 if (remote == nullptr) {
504 TELEPHONY_LOGE("remote is nullptr!");
505 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
506 }
507 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::GET_DATA_CONN_IP_TYPE, dataParcel,
508 replyParcel, option);
509 if (error != TELEPHONY_SUCCESS) {
510 TELEPHONY_LOGE("Strategy switch fail! errCode:%{public}d", error);
511 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
512 }
513 int32_t result = replyParcel.ReadInt32();
514 TELEPHONY_LOGI("end: result=%{public}d", result);
515 if (result == TELEPHONY_ERR_SUCCESS) {
516 ipType = replyParcel.ReadString();
517 }
518
519 return TELEPHONY_ERR_SUCCESS;
520 }
521
IsNeedDoRecovery(int32_t slotId,bool needDoRecovery)522 int32_t CellularDataServiceProxy::IsNeedDoRecovery(int32_t slotId, bool needDoRecovery)
523 {
524 MessageParcel dataParcel;
525 MessageParcel replyParcel;
526 MessageOption option;
527 if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
528 TELEPHONY_LOGE("write interface token failed!");
529 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
530 }
531 dataParcel.WriteInt32(slotId);
532 dataParcel.WriteBool(needDoRecovery);
533 sptr<OHOS::IRemoteObject> remote = Remote();
534 if (remote == nullptr) {
535 TELEPHONY_LOGE("remote is nullptr!");
536 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
537 }
538 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::IS_NEED_DO_RECOVERY, dataParcel,
539 replyParcel, option);
540 if (error != TELEPHONY_SUCCESS) {
541 TELEPHONY_LOGE("function IsNeedDoRecovery call failed! errCode:%{public}d", error);
542 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
543 }
544 int32_t result = replyParcel.ReadInt32();
545 return result;
546 }
547
InitCellularDataController(int32_t slotId)548 int32_t CellularDataServiceProxy::InitCellularDataController(int32_t slotId)
549 {
550 MessageParcel dataParcel;
551 MessageParcel replyParcel;
552 MessageOption option;
553 if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
554 TELEPHONY_LOGE("write interface token failed!");
555 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
556 }
557 dataParcel.WriteInt32(slotId);
558 sptr<OHOS::IRemoteObject> remote = Remote();
559 if (remote == nullptr) {
560 TELEPHONY_LOGE("remote is nullptr!");
561 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
562 }
563 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::INIT_CELLULAR_DATA_CONTROLLER, dataParcel,
564 replyParcel, option);
565 if (error != TELEPHONY_SUCCESS) {
566 TELEPHONY_LOGE("function InitCellularDataController call failed! errCode:%{public}d", error);
567 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
568 }
569 int32_t result = replyParcel.ReadInt32();
570 return result;
571 }
572
EstablishAllApnsIfConnectable(int32_t slotId)573 int32_t CellularDataServiceProxy::EstablishAllApnsIfConnectable(int32_t slotId)
574 {
575 MessageParcel data;
576 MessageParcel reply;
577 MessageOption option;
578 data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor());
579 data.WriteInt32(slotId);
580 if (Remote() == nullptr) {
581 TELEPHONY_LOGE("remote is null");
582 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
583 }
584
585 int32_t error = Remote()->SendRequest((uint32_t)CellularDataInterfaceCode::ESTABLISH_ALL_APNS_IF_CONNECTABLE,
586 data, reply, option);
587 if (error != TELEPHONY_SUCCESS) {
588 TELEPHONY_LOGE("EstablishAllApnsIfConnectable fail! errCode: %{public}d", error);
589 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
590 }
591 int32_t result = reply.ReadInt32();
592 return result;
593 }
594
ReleaseCellularDataConnection(int32_t slotId)595 int32_t CellularDataServiceProxy::ReleaseCellularDataConnection(int32_t slotId)
596 {
597 MessageParcel dataParcel;
598 MessageParcel replyParcel;
599 MessageOption option;
600 if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
601 TELEPHONY_LOGE("write interface token failed!");
602 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
603 }
604 if (!dataParcel.WriteInt32(slotId)) {
605 TELEPHONY_LOGE("write slotId failed");
606 return TELEPHONY_ERR_WRITE_DATA_FAIL;
607 }
608 sptr<OHOS::IRemoteObject> remote = Remote();
609 if (remote == nullptr) {
610 TELEPHONY_LOGE("remote is nullptr!");
611 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
612 }
613 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::RELEASE_CELLULAR_DATA_CONNECTION,
614 dataParcel, replyParcel, option);
615 if (error != TELEPHONY_SUCCESS) {
616 TELEPHONY_LOGE("function ReleaseCellularDataConnection call failed! errCode:%{public}d", error);
617 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
618 }
619 int32_t result;
620 if (!replyParcel.ReadInt32(result)) {
621 TELEPHONY_LOGE("read reply result failed");
622 }
623 return result;
624 }
625
GetCellularDataSupplierId(int32_t slotId,uint64_t capability,uint32_t & supplierId)626 int32_t CellularDataServiceProxy::GetCellularDataSupplierId(int32_t slotId, uint64_t capability, uint32_t &supplierId)
627 {
628 MessageParcel dataParcel;
629 MessageParcel replyParcel;
630 MessageOption option;
631 if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
632 TELEPHONY_LOGE("write interface token failed!");
633 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
634 }
635 dataParcel.WriteInt32(slotId);
636 dataParcel.WriteUint64(capability);
637 sptr<OHOS::IRemoteObject> remote = Remote();
638 if (remote == nullptr) {
639 TELEPHONY_LOGE("remote is nullptr!");
640 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
641 }
642 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::GET_CELLULAR_DATA_SUPPLIERID,
643 dataParcel, replyParcel, option);
644 if (error != TELEPHONY_SUCCESS) {
645 TELEPHONY_LOGE("function GetCellularDataSupplierId call failed! errCode:%{public}d", error);
646 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
647 }
648 int32_t result = replyParcel.ReadInt32();
649 TELEPHONY_LOGD("end: result=%{public}d", result);
650 if (result == TELEPHONY_ERR_SUCCESS) {
651 supplierId = replyParcel.ReadUint32();
652 }
653 return result;
654 }
655
CorrectNetSupplierNoAvailable(int32_t slotId)656 int32_t CellularDataServiceProxy::CorrectNetSupplierNoAvailable(int32_t slotId)
657 {
658 MessageParcel dataParcel;
659 MessageParcel replyParcel;
660 MessageOption option;
661 if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
662 TELEPHONY_LOGE("write interface token failed!");
663 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
664 }
665 dataParcel.WriteInt32(slotId);
666 sptr<OHOS::IRemoteObject> remote = Remote();
667 if (remote == nullptr) {
668 TELEPHONY_LOGE("remote is nullptr!");
669 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
670 }
671 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::CORRECT_NET_SUPPLIER_NO_AVAILABLE,
672 dataParcel, replyParcel, option);
673 if (error != TELEPHONY_SUCCESS) {
674 TELEPHONY_LOGE("function CorrectNetSupplierNoAvailable call failed! errCode:%{public}d", error);
675 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
676 }
677 int32_t result = replyParcel.ReadInt32();
678 return result;
679 }
680
GetSupplierRegisterState(uint32_t supplierId,int32_t & regState)681 int32_t CellularDataServiceProxy::GetSupplierRegisterState(uint32_t supplierId, int32_t ®State)
682 {
683 MessageParcel dataParcel;
684 MessageParcel replyParcel;
685 MessageOption option;
686 if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
687 TELEPHONY_LOGE("write interface token failed!");
688 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
689 }
690 dataParcel.WriteUint32(supplierId);
691 sptr<OHOS::IRemoteObject> remote = Remote();
692 if (remote == nullptr) {
693 TELEPHONY_LOGE("remote is nullptr!");
694 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
695 }
696 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::GET_SUPPLIER_REGISTER_STATE,
697 dataParcel, replyParcel, option);
698 if (error != TELEPHONY_SUCCESS) {
699 TELEPHONY_LOGE("function GetSupplierRegisterState call failed! errCode:%{public}d", error);
700 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
701 }
702 int32_t result = replyParcel.ReadInt32();
703 TELEPHONY_LOGD("end: result=%{public}d", result);
704 if (result == TELEPHONY_ERR_SUCCESS) {
705 regState = replyParcel.ReadInt32();
706 }
707 return result;
708 }
709
GetIfSupportDunApn(bool & isSupportDun)710 int32_t CellularDataServiceProxy::GetIfSupportDunApn(bool &isSupportDun)
711 {
712 MessageParcel data;
713 MessageParcel reply;
714 MessageOption option;
715 if (!data.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
716 TELEPHONY_LOGE("write interface token failed!");
717 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
718 }
719 sptr<OHOS::IRemoteObject> remote = Remote();
720 if (remote == nullptr) {
721 TELEPHONY_LOGE("remote is nullptr!");
722 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
723 }
724 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::GET_IF_SUPPORT_DUN_APN, data,
725 reply, option);
726 if (error != TELEPHONY_SUCCESS) {
727 TELEPHONY_LOGE("call failed! errCode:%{public}d", error);
728 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
729 }
730 int32_t result = reply.ReadInt32();
731 if (result == TELEPHONY_ERR_SUCCESS) {
732 isSupportDun = reply.ReadBool();
733 }
734 return result;
735 }
736
GetDefaultActReportInfo(int32_t slotId,ApnActivateReportInfo & info)737 int32_t CellularDataServiceProxy::GetDefaultActReportInfo(int32_t slotId, ApnActivateReportInfo &info)
738 {
739 MessageParcel dataParcel;
740 MessageParcel replyParcel;
741 MessageOption option;
742 if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
743 TELEPHONY_LOGE("write interface token failed!");
744 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
745 }
746 dataParcel.WriteInt32(slotId);
747 sptr<OHOS::IRemoteObject> remote = Remote();
748 if (remote == nullptr) {
749 TELEPHONY_LOGE("remote is nullptr!");
750 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
751 }
752 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::GET_DEFAULT_ACT_REPORT_INFO,
753 dataParcel, replyParcel, option);
754 if (error != TELEPHONY_SUCCESS) {
755 TELEPHONY_LOGE("function GetDefaultActReportInfo call failed! errCode:%{public}d", error);
756 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
757 }
758 int32_t result = replyParcel.ReadInt32();
759 TELEPHONY_LOGD("end: result=%{public}d", result);
760 if (result == TELEPHONY_ERR_SUCCESS) {
761 info.actTimes = replyParcel.ReadUint32();
762 info.averDuration = replyParcel.ReadUint32();
763 info.topReason = replyParcel.ReadUint32();
764 info.actSuccTimes = replyParcel.ReadUint32();
765 }
766 return result;
767 }
768
GetInternalActReportInfo(int32_t slotId,ApnActivateReportInfo & info)769 int32_t CellularDataServiceProxy::GetInternalActReportInfo(int32_t slotId, ApnActivateReportInfo &info)
770 {
771 MessageParcel dataParcel;
772 MessageParcel replyParcel;
773 MessageOption option;
774 if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
775 TELEPHONY_LOGE("write interface token failed!");
776 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
777 }
778 dataParcel.WriteInt32(slotId);
779 sptr<OHOS::IRemoteObject> remote = Remote();
780 if (remote == nullptr) {
781 TELEPHONY_LOGE("remote is nullptr!");
782 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
783 }
784 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::GET_INTERNAL_ACT_REPORT_INFO,
785 dataParcel, replyParcel, option);
786 if (error != TELEPHONY_SUCCESS) {
787 TELEPHONY_LOGE("function GetInternalActReportInfo call failed! errCode:%{public}d", error);
788 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
789 }
790 int32_t result = replyParcel.ReadInt32();
791 TELEPHONY_LOGD("end: result=%{public}d", result);
792 if (result == TELEPHONY_ERR_SUCCESS) {
793 info.actTimes = replyParcel.ReadUint32();
794 info.averDuration = replyParcel.ReadUint32();
795 info.topReason = replyParcel.ReadUint32();
796 info.actSuccTimes = replyParcel.ReadUint32();
797 }
798 return result;
799 }
800
QueryApnIds(ApnInfo apnInfo,std::vector<uint32_t> & apnIdList)801 int32_t CellularDataServiceProxy::QueryApnIds(ApnInfo apnInfo, std::vector<uint32_t> &apnIdList)
802 {
803 MessageParcel dataParcel;
804 MessageParcel replyParcel;
805 MessageOption option;
806 if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
807 TELEPHONY_LOGE("write interface token failed!");
808 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
809 }
810 dataParcel.WriteString16(apnInfo.apnName);
811 dataParcel.WriteString16(apnInfo.apn);
812 dataParcel.WriteString16(apnInfo.mcc);
813 dataParcel.WriteString16(apnInfo.mnc);
814 dataParcel.WriteString16(apnInfo.user);
815 dataParcel.WriteString16(apnInfo.type);
816 dataParcel.WriteString16(apnInfo.proxy);
817 dataParcel.WriteString16(apnInfo.mmsproxy);
818 TELEPHONY_LOGI("QueryApnIds type: %{public}s", Str16ToStr8(apnInfo.type).c_str());
819 sptr<OHOS::IRemoteObject> remote = Remote();
820 if (remote == nullptr) {
821 TELEPHONY_LOGE("remote is nullptr!");
822 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
823 }
824 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::QUERY_APN_INFO,
825 dataParcel, replyParcel, option);
826 if (error != TELEPHONY_SUCCESS) {
827 TELEPHONY_LOGE("function QueryApnIds call failed! errCode:%{public}d", error);
828 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
829 }
830 int32_t result = replyParcel.ReadInt32();
831 TELEPHONY_LOGI("QueryApnIds end: result=%{public}d", result);
832 if (result == TELEPHONY_ERR_SUCCESS) {
833 int32_t size = replyParcel.ReadInt32();
834 if (size > MAX_REPLY_COUNT) {
835 TELEPHONY_LOGE("QueryApnIds size error = %{public}d", size);
836 return result;
837 }
838 TELEPHONY_LOGI("QueryApnIds size = %{public}d", size);
839 apnIdList.clear();
840 for (int i = 0; i < size; i++) {
841 int apnId = replyParcel.ReadInt32();
842 TELEPHONY_LOGI("QueryApnIds success apnId = %{public}d", apnId);
843 apnIdList.emplace_back(apnId);
844 }
845 }
846 return result;
847 }
848
SetPreferApn(int32_t apnId)849 int32_t CellularDataServiceProxy::SetPreferApn(int32_t apnId)
850 {
851 MessageParcel dataParcel;
852 MessageParcel replyParcel;
853 MessageOption option;
854 if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
855 TELEPHONY_LOGE("write interface token failed!");
856 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
857 }
858 dataParcel.WriteInt32(apnId);
859 sptr<OHOS::IRemoteObject> remote = Remote();
860 if (remote == nullptr) {
861 TELEPHONY_LOGE("remote is nullptr!");
862 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
863 }
864 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::SET_PREFER_APN,
865 dataParcel, replyParcel, option);
866 if (error != TELEPHONY_SUCCESS) {
867 TELEPHONY_LOGE("function SetPreferApn call failed! errCode:%{public}d", error);
868 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
869 }
870 return replyParcel.ReadInt32();
871 }
872
QueryAllApnInfo(std::vector<ApnInfo> & apnInfoList)873 int32_t CellularDataServiceProxy::QueryAllApnInfo(std::vector<ApnInfo> &apnInfoList)
874 {
875 MessageParcel dataParcel;
876 MessageParcel replyParcel;
877 MessageOption option;
878 if (!dataParcel.WriteInterfaceToken(CellularDataServiceProxy::GetDescriptor())) {
879 TELEPHONY_LOGE("write interface token failed!");
880 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
881 }
882 sptr<OHOS::IRemoteObject> remote = Remote();
883 if (remote == nullptr) {
884 TELEPHONY_LOGE("remote is nullptr!");
885 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
886 }
887 int32_t error = remote->SendRequest((uint32_t)CellularDataInterfaceCode::QUERY_ALL_APN_INFO,
888 dataParcel, replyParcel, option);
889 if (error != TELEPHONY_SUCCESS) {
890 TELEPHONY_LOGE("function QueryAllApnInfo call failed! errCode:%{public}d", error);
891 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
892 }
893 int32_t result = replyParcel.ReadInt32();
894 TELEPHONY_LOGI("QueryAllApnInfo end: result=%{public}d", result);
895 if (result == TELEPHONY_ERR_SUCCESS) {
896 int32_t size = replyParcel.ReadInt32();
897 if (size > MAX_REPLY_COUNT) {
898 TELEPHONY_LOGE("QueryAllApnInfo size error = %{public}d", size);
899 return result;
900 }
901 TELEPHONY_LOGI("QueryAllApnInfo size = %{public}d", size);
902 apnInfoList.clear();
903 for (int i = 0; i < size; i++) {
904 ApnInfo apnInfo;
905 apnInfo.ReadFromParcel(replyParcel);
906 apnInfoList.emplace_back(apnInfo);
907 }
908 }
909 return result;
910 }
911 } // namespace Telephony
912 } // namespace OHOS
913