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 "gsm_sms_sender_test.h"
17
18 #include <iostream>
19
20 #include "ability_context.h"
21 #include "ability_info.h"
22 #include "access_mms_token.h"
23 #include "context_deal.h"
24 #include "iservice_registry.h"
25 #include "sms_delivery_callback_test.h"
26 #include "sms_send_callback_test.h"
27 #include "string_utils.h"
28 #include "telephony_errors.h"
29
30 namespace OHOS {
31 namespace Telephony {
32 namespace {
33 const std::string CU_MMSC = "http://mmsc.myuni.com.cn";
34 const std::string SEND_MMS_FILE_URL = "/data/app/deSrc/SendReq.mms";
35 } // namespace
36
TestGsmSendShortData(const sptr<ISmsServiceInterface> &smsService) const37 void GsmSmsSenderTest::TestGsmSendShortData(const sptr<ISmsServiceInterface> &smsService) const
38 {
39 AccessMmsToken token;
40 if (smsService == nullptr) {
41 std::cout << "smsService is nullptr." << std::endl;
42 return;
43 }
44 std::string dest;
45 std::cout << "Please enter the card id" << std::endl;
46 int32_t slotIdTesta;
47 std::cin >> dest;
48 slotIdTesta = atoi(dest.c_str());
49 std::cout << "Please enter the receiver's telephone number" << std::endl;
50 dest.clear();
51 std::cin >> dest;
52 std::string sca("");
53 OHOS::sptr<SmsSendCallbackTest> sendCallBackPtr(new SmsSendCallbackTest());
54 OHOS::sptr<SmsDeliveryCallbackTest> deliveryCallBackPtr(new SmsDeliveryCallbackTest());
55 uint16_t port = 100;
56 uint8_t data[] = "hello world";
57 bool isMmsApp = false;
58 smsService->SendMessage(slotIdTesta, StringUtils::ToUtf16(dest), StringUtils::ToUtf16(sca), port, data,
59 (sizeof(data) / sizeof(data[0]) - 1), sendCallBackPtr, deliveryCallBackPtr, false);
60 smsService->SendMessage(slotIdTesta, StringUtils::ToUtf16(dest), StringUtils::ToUtf16(sca), port, data,
61 (sizeof(data) / sizeof(data[0]) - 1), sendCallBackPtr, deliveryCallBackPtr, true);
62 std::cout << "TestGsmSendShortData" << std::endl;
63 }
64
TestGsmSendLongData(const sptr<ISmsServiceInterface> &smsService) const65 void GsmSmsSenderTest::TestGsmSendLongData(const sptr<ISmsServiceInterface> &smsService) const
66 {
67 AccessMmsToken token;
68 if (smsService == nullptr) {
69 std::cout << "smsService is nullptr." << std::endl;
70 return;
71 }
72 int32_t slotIdTestb;
73 std::string dest;
74 std::cout << "Please enter the card id" << std::endl;
75 std::cin >> dest;
76 slotIdTestb = atoi(dest.c_str());
77 dest.clear();
78 std::cout << "Please enter the receiver's telephone number" << std::endl;
79 std::cin >> dest;
80 std::string sca("");
81 OHOS::sptr<SmsSendCallbackTest> sendCallBackPtr(new SmsSendCallbackTest());
82 OHOS::sptr<SmsDeliveryCallbackTest> deliveryCallBackPtr(new SmsDeliveryCallbackTest());
83 uint8_t data[] =
84 R"(This is the test data!This is the test data!This is the test data!
85 This is the test data!This is the test data!This is the test data!
86 This is the test data!This is the test data!This is the test data!
87 This is the test data!This is the test data!This is the test data!
88 This is the test data!This is the test data!This is the test data!
89 This is the test data!This is the test data!This is the test data!)";
90 uint16_t port = 100;
91
92 smsService->SendMessage(slotIdTestb, StringUtils::ToUtf16(dest), StringUtils::ToUtf16(sca), port, data,
93 sizeof(data) / sizeof(data[0]), sendCallBackPtr, deliveryCallBackPtr, true);
94 smsService->SendMessage(slotIdTestb, StringUtils::ToUtf16(dest), StringUtils::ToUtf16(sca), port, data,
95 sizeof(data) / sizeof(data[0]), sendCallBackPtr, deliveryCallBackPtr, false);
96 std::cout << "TestGsmSendLongData" << std::endl;
97 }
98
TestSendShortText(const sptr<ISmsServiceInterface> &smsService) const99 void GsmSmsSenderTest::TestSendShortText(const sptr<ISmsServiceInterface> &smsService) const
100 {
101 AccessMmsToken token;
102 if (smsService == nullptr) {
103 std::cout << "smsService is nullptr." << std::endl;
104 return;
105 }
106 std::string dest;
107 std::cout << "Please enter the card id" << std::endl;
108 int32_t slotIdTestc;
109 std::cin >> dest;
110 slotIdTestc = atoi(dest.c_str());
111 dest.clear();
112 std::string text;
113 std::cin.ignore();
114 std::cout << "Please enter the receiver's telephone number" << std::endl;
115 getline(std::cin, dest);
116 std::cout << "Please enter text" << std::endl;
117 getline(std::cin, text);
118 std::string sca("");
119 OHOS::sptr<SmsSendCallbackTest> sendCallBackPtr(new SmsSendCallbackTest());
120 OHOS::sptr<SmsDeliveryCallbackTest> deliveryCallBackPtr(new SmsDeliveryCallbackTest());
121 smsService->SendMessage(slotIdTestc, StringUtils::ToUtf16(dest), StringUtils::ToUtf16(sca),
122 StringUtils::ToUtf16(text), sendCallBackPtr, deliveryCallBackPtr, true);
123 smsService->SendMessage(slotIdTestc, StringUtils::ToUtf16(dest), StringUtils::ToUtf16(sca),
124 StringUtils::ToUtf16(text), sendCallBackPtr, deliveryCallBackPtr, false);
125 std::cout << "TestGsmSendShortText" << std::endl;
126 }
127
TestSendMms(const sptr<ISmsServiceInterface> &smsService) const128 void GsmSmsSenderTest::TestSendMms(const sptr<ISmsServiceInterface> &smsService) const
129 {
130 AccessMmsToken token;
131 if (smsService == nullptr) {
132 std::cout << "smsService is nullptr." << std::endl;
133 return;
134 }
135 std::string dest;
136 std::cout << "Please enter the card id" << std::endl;
137 int32_t slotId;
138 std::cin >> dest;
139 slotId = atoi(dest.c_str());
140 dest.clear();
141 std::u16string mmsc(StringUtils::ToUtf16(CU_MMSC));
142 std::u16string data(StringUtils::ToUtf16(SEND_MMS_FILE_URL));
143 std::u16string ua(u"");
144 std::u16string uaprof(u"");
145 int64_t time = 0;
146 int32_t result = smsService->SendMms(slotId, mmsc, data, ua, uaprof, time);
147 if (result == 0) {
148 std::cout << "send mms success" << std::endl;
149 } else {
150 std::cout << "send mms fail" << std::endl;
151 }
152 result = smsService->SendMms(slotId, mmsc, data, ua, uaprof, time, true);
153 if (result == 0) {
154 std::cout << "send mms success" << std::endl;
155 } else {
156 std::cout << "send mms fail" << std::endl;
157 }
158 }
159
TestSendLongText(const sptr<ISmsServiceInterface> &smsService) const160 void GsmSmsSenderTest::TestSendLongText(const sptr<ISmsServiceInterface> &smsService) const
161 {
162 AccessMmsToken token;
163 if (smsService == nullptr) {
164 std::cout << "smsService is nullptr." << std::endl;
165 return;
166 }
167 int32_t slotIdTestd;
168 std::string dest;
169 std::cout << "Please enter the card id" << std::endl;
170 std::cin >> dest;
171 slotIdTestd = atoi(dest.c_str());
172 dest.clear();
173 std::cout << "Please enter the receiver's telephone number" << std::endl;
174 std::cin >> dest;
175 std::string sca("");
176 std::string text(
177 R"(This is the test data!This is the test data!This is the test data!
178 This is the test data!This is the test data!This is the test data!
179 This is the test data!This is the test data!This is the test data!
180 This is the test data!This is the test data!This is the test data!
181 This is the test data!This is the test data!This is the test data!
182 This is the test data!This is the test data!This is the test data!)");
183 OHOS::sptr<SmsSendCallbackTest> sendCallBackPtr(new SmsSendCallbackTest());
184 OHOS::sptr<SmsDeliveryCallbackTest> deliveryCallBackPtr(new SmsDeliveryCallbackTest());
185 smsService->SendMessage(slotIdTestd, StringUtils::ToUtf16(dest), StringUtils::ToUtf16(sca),
186 StringUtils::ToUtf16(text), sendCallBackPtr, deliveryCallBackPtr, true);
187 smsService->SendMessage(slotIdTestd, StringUtils::ToUtf16(dest), StringUtils::ToUtf16(sca),
188 StringUtils::ToUtf16(text), sendCallBackPtr, deliveryCallBackPtr, false);
189 std::cout << "TestGsmSendLongText" << std::endl;
190 }
191
TestSetSmscAddr(const sptr<ISmsServiceInterface> &smsService) const192 void GsmSmsSenderTest::TestSetSmscAddr(const sptr<ISmsServiceInterface> &smsService) const
193 {
194 AccessMmsToken token;
195 bool result = false;
196 if (smsService == nullptr) {
197 std::cout << "smsService is nullptr." << std::endl;
198 return;
199 }
200 std::string dest;
201 std::cout << "Please enter the card id" << std::endl;
202 int32_t slotIdTeste;
203 std::cin >> dest;
204 slotIdTeste = atoi(dest.c_str());
205 dest.clear();
206 std::string sca;
207 std::cout << "Please enter smsc" << std::endl;
208 std::cin >> sca;
209 result = smsService->SetSmscAddr(slotIdTeste, StringUtils::ToUtf16(sca));
210 if (result) {
211 std::cout << "TestSetSmscAddr OK!" << std::endl;
212 } else {
213 std::cout << "TestSetSmscAddr failed!" << std::endl;
214 }
215 }
216
TestGetSmscAddr(const sptr<ISmsServiceInterface> &smsService) const217 void GsmSmsSenderTest::TestGetSmscAddr(const sptr<ISmsServiceInterface> &smsService) const
218 {
219 AccessMmsToken token;
220 std::u16string result;
221 if (smsService == nullptr) {
222 std::cout << "smsService is nullptr." << std::endl;
223 return;
224 }
225 std::string dest;
226 std::cout << "Please enter the card id" << std::endl;
227 int32_t slotIdTestf;
228 std::cin >> dest;
229 slotIdTestf = atoi(dest.c_str());
230 dest.clear();
231 smsService->GetSmscAddr(slotIdTestf, result);
232 std::cout << "TestGetSmscAddr:" << StringUtils::ToUtf8(result) << std::endl;
233 }
234
TestAddSimMessage(const sptr<ISmsServiceInterface> &smsService) const235 void GsmSmsSenderTest::TestAddSimMessage(const sptr<ISmsServiceInterface> &smsService) const
236 {
237 AccessMmsToken token;
238 bool result = false;
239 if (smsService == nullptr) {
240 std::cout << "smsService is nullptr." << std::endl;
241 return;
242 }
243 std::string dest;
244 std::cout << "Please enter the card id" << std::endl;
245 int32_t slotIdTestg;
246 std::cin >> dest;
247 slotIdTestg = atoi(dest.c_str());
248 std::string smsc;
249 std::cout << "Please enter smsc" << std::endl;
250 std::cin >> smsc;
251 std::string pdu;
252 std::cout << "Please enter pdu" << std::endl;
253 std::cin >> pdu;
254 std::string input;
255 std::cout << "Please enter status" << std::endl;
256 std::cin >> input;
257 uint32_t status = std::atoi(input.c_str());
258 result = smsService->AddSimMessage(slotIdTestg, StringUtils::ToUtf16(smsc), StringUtils::ToUtf16(pdu),
259 static_cast<ISmsServiceInterface::SimMessageStatus>(status));
260 if (result == 0) {
261 std::cout << "TestAddSimMessage OK!" << std::endl;
262 } else {
263 std::cout << "TestAddSimMessage failed!" << std::endl;
264 }
265 }
266
TestDelSimMessage(const sptr<ISmsServiceInterface> &smsService) const267 void GsmSmsSenderTest::TestDelSimMessage(const sptr<ISmsServiceInterface> &smsService) const
268 {
269 AccessMmsToken token;
270 if (smsService == nullptr) {
271 std::cout << "smsService is nullptr." << std::endl;
272 return;
273 }
274 bool result = false;
275 int32_t slotIdTesth;
276 std::string dest;
277 std::cout << "Please enter the card id" << std::endl;
278 std::cin >> dest;
279 slotIdTesth = atoi(dest.c_str());
280 dest.clear();
281 std::string input;
282 std::cout << "Please enter msgIndex" << std::endl;
283 std::cin >> input;
284 uint32_t msgIndex = std::atoi(input.c_str());
285 result = smsService->DelSimMessage(slotIdTesth, msgIndex);
286 if (result == 0) {
287 std::cout << "TestDelSimMessage OK!" << std::endl;
288 } else {
289 std::cout << "TestDelSimMessage failed!" << std::endl;
290 }
291 }
292
TestUpdateSimMessage(const sptr<ISmsServiceInterface> &smsService) const293 void GsmSmsSenderTest::TestUpdateSimMessage(const sptr<ISmsServiceInterface> &smsService) const
294 {
295 AccessMmsToken token;
296 if (smsService == nullptr) {
297 std::cout << "smsService is nullptr." << std::endl;
298 return;
299 }
300 bool result = false;
301 std::string dest;
302 std::cout << "Please enter the card id" << std::endl;
303 int32_t slotIdTesti;
304 std::cin >> dest;
305 slotIdTesti = atoi(dest.c_str());
306 dest.clear();
307 std::string input;
308 std::cout << "Please enter msgIndex" << std::endl;
309 std::cin >> input;
310 uint32_t msgIndex = std::atoi(input.c_str());
311 std::string pdu;
312 std::cout << "Please enter pdu" << std::endl;
313 std::cin >> pdu;
314 std::string smsc;
315 std::cout << "Please enter smsc" << std::endl;
316 std::cin >> smsc;
317 int32_t status;
318 std::cout << "Please enter status" << std::endl;
319 std::cin >> status;
320 std::u16string pduData = StringUtils::ToUtf16(pdu);
321 std::u16string smscData = StringUtils::ToUtf16(smsc);
322 result = smsService->UpdateSimMessage(
323 slotIdTesti, msgIndex, static_cast<ISmsServiceInterface::SimMessageStatus>(status), pduData, smscData);
324 if (result) {
325 std::cout << "TestUpdateSimMessage OK!" << std::endl;
326 } else {
327 std::cout << "TestUpdateSimMessage failed!" << std::endl;
328 }
329 }
330
TestGetAllSimMessages(const sptr<ISmsServiceInterface> &smsService) const331 void GsmSmsSenderTest::TestGetAllSimMessages(const sptr<ISmsServiceInterface> &smsService) const
332 {
333 AccessMmsToken token;
334 std::vector<ShortMessage> result;
335 if (smsService == nullptr) {
336 std::cout << "smsService is nullptr." << std::endl;
337 return;
338 }
339 std::string dest;
340 std::cout << "Please enter the card id" << std::endl;
341 int32_t slotIdTestj;
342 std::cin >> dest;
343 slotIdTestj = atoi(dest.c_str());
344 dest.clear();
345 smsService->GetAllSimMessages(slotIdTestj, result);
346 std::cout << "TestGetAllSimMessages Begin:" << std::endl;
347 for (auto &item : result) {
348 std::cout << "[" << item.GetIndexOnSim() << "] " << StringUtils::StringToHex(item.GetPdu()) << std::endl;
349 std::cout << "status:" << item.GetIccMessageStatus()
350 << " message:" << StringUtils::ToUtf8(item.GetVisibleMessageBody()) << std::endl;
351 }
352 std::cout << "TestGetAllSimMessages End!" << std::endl;
353 }
354
TestEnableCBRangeConfig(const sptr<ISmsServiceInterface> &smsService) const355 void GsmSmsSenderTest::TestEnableCBRangeConfig(const sptr<ISmsServiceInterface> &smsService) const
356 {
357 AccessMmsToken token;
358 if (smsService == nullptr) {
359 std::cout << "smsService is nullptr." << std::endl;
360 return;
361 }
362 std::string dest;
363 std::cout << "Please enter the card id" << std::endl;
364 int32_t slotIdTestk;
365 std::cin >> dest;
366 bool enable = true;
367 slotIdTestk = atoi(dest.c_str());
368 dest.clear();
369 uint8_t ranType = 1;
370 uint32_t startMessageId = 0;
371 uint32_t endMessageId = 0;
372 std::cout << "Please enter startMessageId" << std::endl;
373 std::string input;
374 std::cin >> input;
375 startMessageId = std::atoi(input.c_str());
376 std::cout << "Please enter endMessageId" << std::endl;
377 std::cin >> input;
378 endMessageId = std::atoi(input.c_str());
379 int32_t result = smsService->SetCBConfig(slotIdTestk, enable, startMessageId, endMessageId, ranType);
380 std::cout << "TestEnableCBRangeConfig:" << result << std::endl;
381 }
382
TestDisableCBRangeConfig(const sptr<ISmsServiceInterface> &smsService) const383 void GsmSmsSenderTest::TestDisableCBRangeConfig(const sptr<ISmsServiceInterface> &smsService) const
384 {
385 AccessMmsToken token;
386 if (smsService == nullptr) {
387 std::cout << "smsService is nullptr." << std::endl;
388 return;
389 }
390 std::string dest;
391 std::cout << "Please enter the card id" << std::endl;
392 std::cin >> dest;
393 int32_t slotIdTestl = atoi(dest.c_str());
394 bool enable = false;
395 uint32_t startMessageId = 0;
396 uint32_t endMessageId = 0;
397 uint8_t ranType = 1;
398 std::string input;
399 std::cout << "Please enter startMessageId" << std::endl;
400 std::cin >> input;
401 startMessageId = std::atoi(input.c_str());
402 std::cout << "Please enter endMessageId" << std::endl;
403 std::cin >> input;
404 endMessageId = std::atoi(input.c_str());
405 int32_t result = smsService->SetCBConfig(slotIdTestl, enable, startMessageId, endMessageId, ranType);
406 std::cout << "TestDisableCBRangeConfig:" << result << std::endl;
407 }
408
TestEnableCBConfig(const sptr<ISmsServiceInterface> &smsService) const409 void GsmSmsSenderTest::TestEnableCBConfig(const sptr<ISmsServiceInterface> &smsService) const
410 {
411 AccessMmsToken token;
412 if (smsService == nullptr) {
413 std::cout << "smsService is nullptr." << std::endl;
414 return;
415 }
416 std::string dest;
417 std::cout << "Please enter the card id" << std::endl;
418 int32_t slotIdTestm;
419 std::cin >> dest;
420 slotIdTestm = atoi(dest.c_str());
421 dest.clear();
422 bool enable = true;
423 uint32_t identifier = 0;
424 uint8_t ranType = 1;
425 std::string input;
426 std::cout << "Please enter identifier" << std::endl;
427 std::cin >> input;
428 identifier = std::atoi(input.c_str());
429 int32_t result = smsService->SetCBConfig(slotIdTestm, enable, identifier, identifier, ranType);
430 std::cout << "TestEnableCBConfig:" << result << std::endl;
431 }
432
TestDisableCBConfig(const sptr<ISmsServiceInterface> &smsService) const433 void GsmSmsSenderTest::TestDisableCBConfig(const sptr<ISmsServiceInterface> &smsService) const
434 {
435 AccessMmsToken token;
436 if (smsService == nullptr) {
437 std::cout << "smsService is nullptr." << std::endl;
438 return;
439 }
440 std::string dest;
441 std::cout << "Please enter the card id" << std::endl;
442 int32_t slotIdTestn;
443 std::cin >> dest;
444 slotIdTestn = atoi(dest.c_str());
445 dest.clear();
446 bool enable = false;
447 uint32_t identifier = 0;
448 uint8_t ranType = 1;
449 std::string input;
450 std::cout << "Please enter identifier" << std::endl;
451 std::cin >> input;
452 identifier = std::atoi(input.c_str());
453 int32_t result = smsService->SetCBConfig(slotIdTestn, enable, identifier, identifier, ranType);
454 std::cout << "TestDisableCBConfig:" << result << std::endl;
455 }
456
TestSetDefaultSmsSlotId(const sptr<ISmsServiceInterface> &smsService) const457 void GsmSmsSenderTest::TestSetDefaultSmsSlotId(const sptr<ISmsServiceInterface> &smsService) const
458 {
459 AccessMmsToken token;
460 if (smsService == nullptr) {
461 std::cout << "smsService is nullptr." << std::endl;
462 return;
463 }
464 int32_t slotId;
465 std::string input;
466 std::cout << "Please enter Slot Id" << std::endl;
467 std::cin >> input;
468 slotId = std::atoi(input.c_str());
469 int32_t result = smsService->SetDefaultSmsSlotId(slotId);
470 std::cout << "TestSetDefaultSmsSlotId:" << result << std::endl;
471 }
472
TestGetDefaultSmsSlotId(const sptr<ISmsServiceInterface> &smsService) const473 void GsmSmsSenderTest::TestGetDefaultSmsSlotId(const sptr<ISmsServiceInterface> &smsService) const
474 {
475 int32_t result;
476 if (smsService == nullptr) {
477 std::cout << "smsService is nullptr." << std::endl;
478 return;
479 }
480 result = smsService->GetDefaultSmsSlotId();
481 std::cout << "TestGetDefaultSmsSlotId:" << result << std::endl;
482 }
483
TestSplitMessage(const sptr<ISmsServiceInterface> &smsService) const484 void GsmSmsSenderTest::TestSplitMessage(const sptr<ISmsServiceInterface> &smsService) const
485 {
486 AccessMmsToken token;
487 std::vector<std::u16string> result;
488 if (smsService == nullptr) {
489 std::cout << "smsService is nullptr." << std::endl;
490 return;
491 }
492 std::string input;
493 std::cout << "Please enter message" << std::endl;
494 std::getline(std::cin, input);
495 smsService->SplitMessage(StringUtils::ToUtf16(input), result);
496 std::cout << "TestSplitMessage size:" << result.size() << std::endl;
497 for (auto &item : result) {
498 std::cout << StringUtils::ToUtf8(item) << std::endl;
499 }
500 }
501
TestGetSmsSegmentsInfo(const sptr<ISmsServiceInterface> &smsService) const502 void GsmSmsSenderTest::TestGetSmsSegmentsInfo(const sptr<ISmsServiceInterface> &smsService) const
503 {
504 if (smsService == nullptr) {
505 std::cout << "TestGetSmsSegmentsInfo smsService is nullptr." << std::endl;
506 return;
507 }
508 int32_t slotId;
509 std::string input;
510 std::cout << "TestGetSmsSegmentsInfo Please enter Slot Id" << std::endl;
511 std::getline(std::cin, input);
512 slotId = std::atoi(input.c_str());
513 input.clear();
514 std::cout << "Please enter message" << std::endl;
515 std::getline(std::cin, input);
516 ISmsServiceInterface::SmsSegmentsInfo result;
517 if (smsService->GetSmsSegmentsInfo(slotId, StringUtils::ToUtf16(input), false, result) != TELEPHONY_ERR_SUCCESS) {
518 std::cout << "Get Sms SegmentsInfo Fail." << std::endl;
519 return;
520 }
521
522 int32_t codeScheme = static_cast<int32_t>(result.msgCodeScheme);
523 std::cout << "msgSegCount:" << result.msgSegCount << " msgEncodingCount:" << result.msgEncodingCount << std::endl;
524 std::cout << "msgRemainCount:" << result.msgRemainCount << " msgCodeScheme:" << codeScheme << std::endl;
525 }
526
TestIsImsSmsSupported(const sptr<ISmsServiceInterface> &smsService) const527 void GsmSmsSenderTest::TestIsImsSmsSupported(const sptr<ISmsServiceInterface> &smsService) const
528 {
529 if (smsService == nullptr) {
530 std::cout << "TestIsImsSmsSupported smsService is nullptr." << std::endl;
531 return;
532 }
533 int32_t slotId;
534 std::string input;
535 std::cout << "TestIsImsSmsSupported Please enter Slot Id" << std::endl;
536 std::getline(std::cin, input);
537 slotId = std::atoi(input.c_str());
538 bool result = false;
539 smsService->IsImsSmsSupported(slotId, result);
540 std::string res = result ? "true" : "false";
541 std::cout << "IsImsSmsSupported:" << res << std::endl;
542 }
543
TestSetImsSmsConfig(const sptr<ISmsServiceInterface> &smsService) const544 void GsmSmsSenderTest::TestSetImsSmsConfig(const sptr<ISmsServiceInterface> &smsService) const
545 {
546 AccessMmsToken token;
547 if (smsService == nullptr) {
548 std::cout << "TestSetImsSmsConfig smsService is nullptr." << std::endl;
549 return;
550 }
551 int32_t slotId;
552 std::string input;
553 std::cout << "TestSetImsSmsConfig Please enter Slot Id" << std::endl;
554 std::getline(std::cin, input);
555 slotId = std::atoi(input.c_str());
556 int32_t enable;
557 std::cout << "Please enter enable" << std::endl;
558 std::getline(std::cin, input);
559 enable = std::atoi(input.c_str());
560 std::string res = smsService->SetImsSmsConfig(slotId, enable) ? "true" : "false";
561 std::cout << "SetImsSmsConfig:" << res << std::endl;
562 }
563
TestGetImsShortMessageFormat(const sptr<ISmsServiceInterface> &smsService) const564 void GsmSmsSenderTest::TestGetImsShortMessageFormat(const sptr<ISmsServiceInterface> &smsService) const
565 {
566 if (smsService == nullptr) {
567 std::cout << "smsService is nullptr." << std::endl;
568 return;
569 }
570 std::u16string format;
571 smsService->GetImsShortMessageFormat(format);
572 std::cout << "GetImsShortMessageFormat:" << StringUtils::ToUtf8(format) << std::endl;
573 }
574
TestAddBlockPhone() const575 void GsmSmsSenderTest::TestAddBlockPhone() const
576 {
577 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataAHelper();
578 if (helper == nullptr) {
579 std::cout << "Creator helper nullptr error." << std::endl;
580 return;
581 }
582 std::string input;
583 std::cout << "Please enter block phone number" << std::endl;
584 std::getline(std::cin, input);
585
586 Uri uri("datashare:///com.ohos.contactsdataability/contacts/contact_blocklist");
587 DataShare::DataShareValuesBucket value;
588 value.Put("phone_number", input);
589 int ret = helper->Insert(uri, value);
590 helper->Release();
591 std::cout << "add block:" << input << ((ret >= 0) ? " success" : " error") << std::endl;
592 }
593
TestRemoveBlockPhone() const594 void GsmSmsSenderTest::TestRemoveBlockPhone() const
595 {
596 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataAHelper();
597 if (helper == nullptr) {
598 std::cout << "Creator helper nullptr error." << std::endl;
599 return;
600 }
601 std::string input;
602 std::cout << "Please enter Remove phone number" << std::endl;
603 std::getline(std::cin, input);
604 Uri uri("datashare:///com.ohos.contactsdataability/contacts/contact_blocklist");
605 DataShare::DataSharePredicates predicates;
606 predicates.EqualTo("phone_number", input);
607 int ret = helper->Delete(uri, predicates);
608 helper->Release();
609 std::cout << "remove block:" << input << ((ret >= 0) ? " success" : " error") << std::endl;
610 }
611
TestHasSmsCapability(const sptr<ISmsServiceInterface> &smsService) const612 void GsmSmsSenderTest::TestHasSmsCapability(const sptr<ISmsServiceInterface> &smsService) const
613 {
614 if (smsService == nullptr) {
615 std::cout << "GsmSmsSenderTest smsService is nullptr error." << std::endl;
616 return;
617 }
618 std::string res = smsService->HasSmsCapability() ? "true" : "false";
619 std::cout << "HasSmsCapability:" << res << std::endl;
620 }
621
CreateDataAHelper() const622 std::shared_ptr<DataShare::DataShareHelper> GsmSmsSenderTest::CreateDataAHelper() const
623 {
624 auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
625 if (saManager == nullptr) {
626 std::cout << "Get system ability mgr failed." << std::endl;
627 return nullptr;
628 }
629 auto remoteObj = saManager->GetSystemAbility(TELEPHONY_SMS_MMS_SYS_ABILITY_ID);
630 if (remoteObj == nullptr) {
631 std::cout << "GetSystemAbility Service Failed." << std::endl;
632 return nullptr;
633 }
634 const std::string uriContact("datashare:///com.ohos.contactsdataability");
635 return DataShare::DataShareHelper::Creator(remoteObj, uriContact);
636 }
637 } // namespace Telephony
638 } // namespace OHOS
639