1 /*
2 * Copyright (C) 2021 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_stub.h"
17
18 #include <string_ex.h>
19
20 #include "cellular_data_controller.h"
21 #include "cellular_data_service.h"
22 #include "ipc_skeleton.h"
23 #include "sim_account_callback_proxy.h"
24 #include "telephony_errors.h"
25 #include "telephony_log_wrapper.h"
26
27 #ifdef HICOLLIE_ENABLE
28 #include "xcollie/xcollie.h"
29 #include "xcollie/xcollie_define.h"
30 #define XCOLLIE_TIMEOUT_SECONDS 30
31 #endif
32
33 namespace OHOS {
34 namespace Telephony {
35 CellularDataServiceStub::CellularDataServiceStub() = default;
36
37 CellularDataServiceStub::~CellularDataServiceStub() = default;
38
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int32_t CellularDataServiceStub::OnRemoteRequest(
40 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
41 {
42 std::u16string myDescriptor = CellularDataServiceStub::GetDescriptor();
43 std::u16string remoteDescriptor = data.ReadInterfaceToken();
44 // NetManager has no transport description
45 if (myDescriptor != remoteDescriptor) {
46 TELEPHONY_LOGE("descriptor check fail!");
47 return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
48 }
49 std::map<uint32_t, Fun>::iterator it = eventIdFunMap_.find(code);
50 if (it != eventIdFunMap_.end()) {
51 if (it->second != nullptr) {
52 int32_t idTimer = SetTimer(code);
53 int32_t result = it->second(data, reply);
54 CancelTimer(idTimer);
55 return result;
56 }
57 } else {
58 TELEPHONY_LOGE("event code is not exist");
59 }
60 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
61 }
62
SetTimer(uint32_t code)63 int32_t CellularDataServiceStub::SetTimer(uint32_t code)
64 {
65 #ifdef HICOLLIE_ENABLE
66 int32_t idTimer = HiviewDFX::INVALID_ID;
67 std::map<uint32_t, std::string>::iterator itCollieId = collieCodeStringMap_.find(code);
68 if (itCollieId != collieCodeStringMap_.end()) {
69 std::string collieStr = itCollieId->second;
70 std::string collieName = "CellularDataServiceStub: " + collieStr;
71 unsigned int flag = HiviewDFX::XCOLLIE_FLAG_NOOP;
72 auto TimerCallback = [collieStr](void *) {
73 TELEPHONY_LOGE("OnRemoteRequest timeout func: %{public}s", collieStr.c_str());
74 };
75 idTimer = HiviewDFX::XCollie::GetInstance().SetTimer(
76 collieName, XCOLLIE_TIMEOUT_SECONDS, TimerCallback, nullptr, flag);
77 TELEPHONY_LOGD("SetTimer id: %{public}d, name: %{public}s.", idTimer, collieStr.c_str());
78 }
79 return idTimer;
80 #else
81 TELEPHONY_LOGD("No HICOLLIE_ENABLE");
82 return -1;
83 #endif
84 }
85
CancelTimer(int32_t id)86 void CellularDataServiceStub::CancelTimer(int32_t id)
87 {
88 #ifdef HICOLLIE_ENABLE
89 if (id == HiviewDFX::INVALID_ID) {
90 return;
91 }
92 TELEPHONY_LOGD("CancelTimer id: %{public}d.", id);
93 HiviewDFX::XCollie::GetInstance().CancelTimer(id);
94 #else
95 return;
96 #endif
97 }
98
OnIsCellularDataEnabled(MessageParcel & data,MessageParcel & reply)99 int32_t CellularDataServiceStub::OnIsCellularDataEnabled(MessageParcel &data, MessageParcel &reply)
100 {
101 bool dataEnabled = false;
102 int32_t result = IsCellularDataEnabled(dataEnabled);
103 if (!reply.WriteInt32(result)) {
104 TELEPHONY_LOGE("write int32 reply failed.");
105 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
106 }
107 if (result != TELEPHONY_ERR_SUCCESS) {
108 return result;
109 }
110 if (!reply.WriteBool(dataEnabled)) {
111 TELEPHONY_LOGE("write bool reply failed.");
112 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
113 }
114 return TELEPHONY_SUCCESS;
115 }
116
OnEnableCellularData(MessageParcel & data,MessageParcel & reply)117 int32_t CellularDataServiceStub::OnEnableCellularData(MessageParcel &data, MessageParcel &reply)
118 {
119 bool enable = data.ReadBool();
120 int32_t result = EnableCellularData(enable);
121 if (!reply.WriteInt32(result)) {
122 TELEPHONY_LOGE("fail to write parcel");
123 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
124 }
125 return result;
126 }
127
OnEnableIntelligenceSwitch(MessageParcel & data,MessageParcel & reply)128 int32_t CellularDataServiceStub::OnEnableIntelligenceSwitch(MessageParcel &data, MessageParcel &reply)
129 {
130 bool enable = data.ReadBool();
131 int32_t result = EnableIntelligenceSwitch(enable);
132 if (!reply.WriteInt32(result)) {
133 TELEPHONY_LOGE("fail to write parcel");
134 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
135 }
136 return result;
137 }
138
OnGetCellularDataState(MessageParcel & data,MessageParcel & reply)139 int32_t CellularDataServiceStub::OnGetCellularDataState(MessageParcel &data, MessageParcel &reply)
140 {
141 int32_t result = GetCellularDataState();
142 if (!reply.WriteInt32(result)) {
143 TELEPHONY_LOGE("fail to write parcel");
144 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
145 }
146 return result;
147 }
148
OnIsCellularDataRoamingEnabled(MessageParcel & data,MessageParcel & reply)149 int32_t CellularDataServiceStub::OnIsCellularDataRoamingEnabled(MessageParcel &data, MessageParcel &reply)
150 {
151 int32_t slotId = data.ReadInt32();
152 bool dataRoamingEnabled = false;
153 int32_t result = IsCellularDataRoamingEnabled(slotId, dataRoamingEnabled);
154 if (!reply.WriteInt32(result)) {
155 TELEPHONY_LOGE("write int32 reply failed.");
156 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
157 }
158 if (result != TELEPHONY_ERR_SUCCESS) {
159 return result;
160 }
161 if (!reply.WriteBool(dataRoamingEnabled)) {
162 TELEPHONY_LOGE("write bool reply failed.");
163 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
164 }
165
166 return TELEPHONY_SUCCESS;
167 }
168
OnEnableCellularDataRoaming(MessageParcel & data,MessageParcel & reply)169 int32_t CellularDataServiceStub::OnEnableCellularDataRoaming(MessageParcel &data, MessageParcel &reply)
170 {
171 int32_t slotId = data.ReadInt32();
172 bool enable = data.ReadBool();
173 int32_t result = EnableCellularDataRoaming(slotId, enable);
174 if (!reply.WriteInt32(result)) {
175 TELEPHONY_LOGE("fail to write parcel");
176 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
177 }
178 return result;
179 }
180
OnGetIntelligenceSwitchState(MessageParcel & data,MessageParcel & reply)181 int32_t CellularDataServiceStub::OnGetIntelligenceSwitchState(MessageParcel &data, MessageParcel &reply)
182 {
183 bool switchState = false;
184 int32_t result = GetIntelligenceSwitchState(switchState);
185 if (!reply.WriteInt32(result)) {
186 TELEPHONY_LOGE("write int32 reply failed.");
187 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
188 }
189 if (result != TELEPHONY_ERR_SUCCESS) {
190 return result;
191 }
192 if (!reply.WriteBool(switchState)) {
193 TELEPHONY_LOGE("write bool reply failed.");
194 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
195 }
196 return TELEPHONY_SUCCESS;
197 }
198
OnHandleApnChanged(MessageParcel & data,MessageParcel & reply)199 int32_t CellularDataServiceStub::OnHandleApnChanged(MessageParcel &data, MessageParcel &reply)
200 {
201 int32_t slotId = data.ReadInt32();
202 int32_t result = HandleApnChanged(slotId);
203 if (!reply.WriteInt32(result)) {
204 TELEPHONY_LOGE("fail to write parcel");
205 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
206 }
207 return result;
208 }
209
OnGetDefaultCellularDataSlotId(MessageParcel & data,MessageParcel & reply)210 int32_t CellularDataServiceStub::OnGetDefaultCellularDataSlotId(MessageParcel &data, MessageParcel &reply)
211 {
212 int32_t result = GetDefaultCellularDataSlotId();
213 if (!reply.WriteInt32(result)) {
214 TELEPHONY_LOGE("fail to write parcel");
215 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
216 }
217 return result;
218 }
219
OnGetDefaultCellularDataSimId(MessageParcel & data,MessageParcel & reply)220 int32_t CellularDataServiceStub::OnGetDefaultCellularDataSimId(MessageParcel &data, MessageParcel &reply)
221 {
222 int32_t simId = 0;
223 int32_t result = GetDefaultCellularDataSimId(simId);
224 if (!reply.WriteInt32(result)) {
225 TELEPHONY_LOGE("write int32 reply failed.");
226 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
227 }
228 if (result != TELEPHONY_ERR_SUCCESS) {
229 return result;
230 }
231 if (!reply.WriteInt32(simId)) {
232 TELEPHONY_LOGE("write int32 reply failed.");
233 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
234 }
235 return TELEPHONY_SUCCESS;
236 }
237
OnSetDefaultCellularDataSlotId(MessageParcel & data,MessageParcel & reply)238 int32_t CellularDataServiceStub::OnSetDefaultCellularDataSlotId(MessageParcel &data, MessageParcel &reply)
239 {
240 int32_t slotId = data.ReadInt32();
241 int32_t result = SetDefaultCellularDataSlotId(slotId);
242 if (!reply.WriteInt32(result)) {
243 TELEPHONY_LOGE("fail to write parcel");
244 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
245 }
246 return result;
247 }
248
OnGetCellularDataFlowType(MessageParcel & data,MessageParcel & reply)249 int32_t CellularDataServiceStub::OnGetCellularDataFlowType(MessageParcel &data, MessageParcel &reply)
250 {
251 int32_t result = GetCellularDataFlowType();
252 if (!reply.WriteInt32(result)) {
253 TELEPHONY_LOGE("fail to write parcel");
254 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
255 }
256 return result;
257 }
258
OnHasInternetCapability(MessageParcel & data,MessageParcel & reply)259 int32_t CellularDataServiceStub::OnHasInternetCapability(MessageParcel &data, MessageParcel &reply)
260 {
261 int32_t slotId = data.ReadInt32();
262 int32_t cid = data.ReadInt32();
263 int32_t result = HasInternetCapability(slotId, cid);
264 if (!reply.WriteInt32(result)) {
265 TELEPHONY_LOGE("fail to write parcel");
266 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
267 }
268 return result;
269 }
270
OnClearCellularDataConnections(MessageParcel & data,MessageParcel & reply)271 int32_t CellularDataServiceStub::OnClearCellularDataConnections(MessageParcel &data, MessageParcel &reply)
272 {
273 int32_t slotId = data.ReadInt32();
274 int32_t result = ClearCellularDataConnections(slotId);
275 if (!reply.WriteInt32(result)) {
276 TELEPHONY_LOGE("fail to write parcel");
277 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
278 }
279 return result;
280 }
281
OnClearAllConnections(MessageParcel & data,MessageParcel & reply)282 int32_t CellularDataServiceStub::OnClearAllConnections(MessageParcel &data, MessageParcel &reply)
283 {
284 int32_t slotId = data.ReadInt32();
285 DisConnectionReason reason = static_cast<DisConnectionReason>(data.ReadInt32());
286 int32_t result = ClearAllConnections(slotId, reason);
287 if (!reply.WriteInt32(result)) {
288 TELEPHONY_LOGE("fail to write parcel");
289 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
290 }
291 return result;
292 }
293
OnRegisterSimAccountCallback(MessageParcel & data,MessageParcel & reply)294 int32_t CellularDataServiceStub::OnRegisterSimAccountCallback(MessageParcel &data, MessageParcel &reply)
295 {
296 sptr<SimAccountCallback> callback = iface_cast<SimAccountCallback>(data.ReadRemoteObject());
297 int32_t result;
298 if (callback == nullptr) {
299 TELEPHONY_LOGE("callback is nullptr!");
300 result = TELEPHONY_ERR_ARGUMENT_NULL;
301 } else {
302 result = RegisterSimAccountCallback(callback);
303 }
304 reply.WriteInt32(result);
305 return result;
306 }
307
OnUnregisterSimAccountCallback(MessageParcel & data,MessageParcel & reply)308 int32_t CellularDataServiceStub::OnUnregisterSimAccountCallback(MessageParcel &data, MessageParcel &reply)
309 {
310 sptr<SimAccountCallback> callback = iface_cast<SimAccountCallback>(data.ReadRemoteObject());
311 int32_t result;
312 if (callback == nullptr) {
313 TELEPHONY_LOGE("callback is nullptr!");
314 result = TELEPHONY_ERR_ARGUMENT_NULL;
315 } else {
316 result = UnregisterSimAccountCallback(callback);
317 }
318 reply.WriteInt32(result);
319 return result;
320 }
321
OnGetDataConnApnAttr(MessageParcel & data,MessageParcel & reply)322 int32_t CellularDataServiceStub::OnGetDataConnApnAttr(MessageParcel &data, MessageParcel &reply)
323 {
324 int32_t slotId = data.ReadInt32();
325 ApnItem::Attribute apnAttr;
326 int32_t result = GetDataConnApnAttr(slotId, apnAttr);
327 if (!reply.WriteInt32(result)) {
328 TELEPHONY_LOGE("write int32 reply failed.");
329 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
330 }
331 if (!reply.WriteRawData(&apnAttr, sizeof(ApnItem::Attribute))) {
332 TELEPHONY_LOGE("write apnAttr reply failed.");
333 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
334 }
335 return TELEPHONY_SUCCESS;
336 }
337
OnGetDataConnIpType(MessageParcel & data,MessageParcel & reply)338 int32_t CellularDataServiceStub::OnGetDataConnIpType(MessageParcel &data, MessageParcel &reply)
339 {
340 int32_t slotId = data.ReadInt32();
341 std::string ipType;
342 int32_t result = GetDataConnIpType(slotId, ipType);
343 if (!reply.WriteInt32(result)) {
344 TELEPHONY_LOGE("write int32 reply failed.");
345 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
346 }
347 if (!reply.WriteString(ipType)) {
348 TELEPHONY_LOGE("write int32 reply failed.");
349 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
350 }
351 return TELEPHONY_SUCCESS;
352 }
353
OnGetApnState(MessageParcel & data,MessageParcel & reply)354 int32_t CellularDataServiceStub::OnGetApnState(MessageParcel &data, MessageParcel &reply)
355 {
356 int32_t slotId = data.ReadInt32();
357 std::string apnType = data.ReadString();
358 int32_t result = GetApnState(slotId, apnType);
359 if (!reply.WriteInt32(result)) {
360 TELEPHONY_LOGE("fail to write parcel");
361 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
362 }
363 return result;
364 }
365
OnGetRecoveryState(MessageParcel & data,MessageParcel & reply)366 int32_t CellularDataServiceStub::OnGetRecoveryState(MessageParcel &data, MessageParcel &reply)
367 {
368 int32_t result = GetDataRecoveryState();
369 if (!reply.WriteInt32(result)) {
370 TELEPHONY_LOGE("fail to write parcel");
371 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
372 }
373 return result;
374 }
375
OnIsNeedDoRecovery(MessageParcel & data,MessageParcel & reply)376 int32_t CellularDataServiceStub::OnIsNeedDoRecovery(MessageParcel &data, MessageParcel &reply)
377 {
378 int32_t slotId = data.ReadInt32();
379 int32_t needDoRecovery = data.ReadBool();
380 int32_t result = IsNeedDoRecovery(slotId, needDoRecovery);
381 if (!reply.WriteInt32(result)) {
382 TELEPHONY_LOGE("write int32 reply failed.");
383 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
384 }
385 return result;
386 }
387
OnInitCellularDataController(MessageParcel & data,MessageParcel & reply)388 int32_t CellularDataServiceStub::OnInitCellularDataController(MessageParcel &data, MessageParcel &reply)
389 {
390 int32_t slotId = data.ReadInt32();
391 int32_t result = InitCellularDataController(slotId);
392 if (!reply.WriteInt32(result)) {
393 TELEPHONY_LOGE("write int32 reply failed.");
394 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
395 }
396 return result;
397 }
398
OnEstablishAllApnsIfConnectable(MessageParcel & data,MessageParcel & reply)399 int32_t CellularDataServiceStub::OnEstablishAllApnsIfConnectable(MessageParcel &data, MessageParcel &reply)
400 {
401 int32_t slotId = data.ReadInt32();
402 int32_t result = EstablishAllApnsIfConnectable(slotId);
403 if (!reply.WriteInt32(result)) {
404 TELEPHONY_LOGE("fail to write parcel");
405 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
406 }
407 return result;
408 }
409
OnReleaseCellularDataConnection(MessageParcel & data,MessageParcel & reply)410 int32_t CellularDataServiceStub::OnReleaseCellularDataConnection(MessageParcel &data, MessageParcel &reply)
411 {
412 int32_t slotId;
413 if (!data.ReadInt32(slotId)) {
414 TELEPHONY_LOGE("write int32 slotId failed.");
415 return TELEPHONY_ERR_READ_DATA_FAIL;
416 }
417 int32_t result = ReleaseCellularDataConnection(slotId);
418 if (!reply.WriteInt32(result)) {
419 TELEPHONY_LOGE("write int32 reply failed.");
420 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
421 }
422 return result;
423 }
424
OnGetCellularDataSupplierId(MessageParcel & data,MessageParcel & reply)425 int32_t CellularDataServiceStub::OnGetCellularDataSupplierId(MessageParcel &data, MessageParcel &reply)
426 {
427 int32_t slotId = data.ReadInt32();
428 uint64_t capability = data.ReadUint64();
429 uint32_t supplierId = 0;
430 int32_t result = GetCellularDataSupplierId(slotId, capability, supplierId);
431 if (!reply.WriteInt32(result)) {
432 TELEPHONY_LOGE("write int32 reply failed.");
433 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
434 }
435 if (!reply.WriteUint32(supplierId)) {
436 TELEPHONY_LOGE("write uint32 reply failed.");
437 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
438 }
439 return result;
440 }
441
OnCorrectNetSupplierNoAvailable(MessageParcel & data,MessageParcel & reply)442 int32_t CellularDataServiceStub::OnCorrectNetSupplierNoAvailable(MessageParcel &data, MessageParcel &reply)
443 {
444 int32_t slotId = data.ReadInt32();
445 int32_t result = CorrectNetSupplierNoAvailable(slotId);
446 if (!reply.WriteInt32(result)) {
447 TELEPHONY_LOGE("write int32 reply failed.");
448 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
449 }
450 return result;
451 }
452
OnGetSupplierRegisterState(MessageParcel & data,MessageParcel & reply)453 int32_t CellularDataServiceStub::OnGetSupplierRegisterState(MessageParcel &data, MessageParcel &reply)
454 {
455 uint32_t supplierId = data.ReadUint32();
456 int32_t regState = -1;
457 int32_t result = GetSupplierRegisterState(supplierId, regState);
458 if (!reply.WriteInt32(result)) {
459 TELEPHONY_LOGE("write int32 reply failed.");
460 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
461 }
462 if (!reply.WriteInt32(regState)) {
463 TELEPHONY_LOGE("write int32 reply failed.");
464 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
465 }
466 return result;
467 }
468
OnIsSupportDunApn(MessageParcel & data,MessageParcel & reply)469 int32_t CellularDataServiceStub::OnIsSupportDunApn(MessageParcel &data, MessageParcel &reply)
470 {
471 bool isSupportDun = false;
472 int32_t result = GetIfSupportDunApn(isSupportDun);
473 if (!reply.WriteInt32(result)) {
474 TELEPHONY_LOGE("fail to write parcel");
475 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
476 }
477 if (!reply.WriteBool(isSupportDun)) {
478 TELEPHONY_LOGE("fail to write parcel");
479 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
480 }
481 return result;
482 }
483
OnGetDefaultActReportInfo(MessageParcel & data,MessageParcel & reply)484 int32_t CellularDataServiceStub::OnGetDefaultActReportInfo(MessageParcel &data, MessageParcel &reply)
485 {
486 int32_t slotId = data.ReadInt32();
487 ApnActivateReportInfo info;
488 int32_t result = GetDefaultActReportInfo(slotId, info);
489 if (!reply.WriteInt32(result)) {
490 TELEPHONY_LOGE("OnGetDefaultActReportInfo write int32 reply failed.");
491 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
492 }
493 reply.WriteInt32(info.actTimes);
494 reply.WriteInt32(info.averDuration);
495 reply.WriteInt32(info.topReason);
496 reply.WriteInt32(info.actSuccTimes);
497 return result;
498 }
499
OnGetInternalActReportInfo(MessageParcel & data,MessageParcel & reply)500 int32_t CellularDataServiceStub::OnGetInternalActReportInfo(MessageParcel &data, MessageParcel &reply)
501 {
502 int32_t slotId = data.ReadInt32();
503 ApnActivateReportInfo info;
504 int32_t result = GetInternalActReportInfo(slotId, info);
505 if (!reply.WriteInt32(result)) {
506 TELEPHONY_LOGE("OnGetInternalActReportInfo write int32 reply failed.");
507 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
508 }
509 reply.WriteInt32(info.actTimes);
510 reply.WriteInt32(info.averDuration);
511 reply.WriteInt32(info.topReason);
512 reply.WriteInt32(info.actSuccTimes);
513 return result;
514 }
515
OnQueryApnInfo(MessageParcel & data,MessageParcel & reply)516 int32_t CellularDataServiceStub::OnQueryApnInfo(MessageParcel &data, MessageParcel &reply)
517 {
518 ApnInfo info;
519 info.apnName = data.ReadString16();
520 info.apn = data.ReadString16();
521 info.mcc = data.ReadString16();
522 info.mnc = data.ReadString16();
523 info.user = data.ReadString16();
524 info.type = data.ReadString16();
525 info.proxy = data.ReadString16();
526 info.mmsproxy = data.ReadString16();
527 std::vector<uint32_t> apnIdList;
528 int32_t result = QueryApnIds(info, apnIdList);
529 int32_t size = static_cast<int32_t>(apnIdList.size());
530 bool ret = reply.WriteInt32(result);
531 ret = (ret && reply.WriteInt32(size));
532 if (!ret) {
533 TELEPHONY_LOGE("OnQueryApnInfo write reply failed.");
534 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
535 }
536 std::vector<uint32_t>::iterator it = apnIdList.begin();
537 while (it != apnIdList.end()) {
538 TELEPHONY_LOGI("OnQueryApnInfo slotIndex = %{public}d", (*it));
539 if (!reply.WriteInt32(*it)) {
540 TELEPHONY_LOGE("OnQueryApnInfo reply Marshalling is false");
541 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
542 }
543 ++it;
544 }
545 return 0;
546 }
547
OnSetPreferApn(MessageParcel & data,MessageParcel & reply)548 int32_t CellularDataServiceStub::OnSetPreferApn(MessageParcel &data, MessageParcel &reply)
549 {
550 int32_t apnId = data.ReadInt32();
551 int32_t result = SetPreferApn(apnId);
552 if (!reply.WriteInt32(result)) {
553 TELEPHONY_LOGE("fail to write parcel");
554 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
555 }
556 return result;
557 }
558
OnQueryAllApnInfo(MessageParcel & data,MessageParcel & reply)559 int32_t CellularDataServiceStub::OnQueryAllApnInfo(MessageParcel &data, MessageParcel &reply)
560 {
561 std::vector<ApnInfo> allApnInfoList;
562 int32_t result = QueryAllApnInfo(allApnInfoList);
563 int32_t size = static_cast<int32_t>(allApnInfoList.size());
564 bool ret = reply.WriteInt32(result);
565 ret = (ret && reply.WriteInt32(size));
566 if (!ret) {
567 TELEPHONY_LOGE("OnQueryAllApnInfo write reply failed.");
568 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
569 }
570 std::vector<ApnInfo>::iterator it = allApnInfoList.begin();
571 while (it != allApnInfoList.end()) {
572 TELEPHONY_LOGI("OnQueryAllApnInfo apn = %{public}s", Str16ToStr8((*it).apn).c_str());
573 if (!(*it).Marshalling(reply)) {
574 TELEPHONY_LOGE("OnQueryAllApnInfo ApnInfo reply Marshalling is false");
575 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
576 }
577 ++it;
578 }
579 return 0;
580 }
581 } // namespace Telephony
582 } // namespace OHOS