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 slotId;
47 std::cin >> dest;
48 slotId = atoi(dest.c_str());
49 dest.clear();
50 std::cout << "Please enter the receiver's telephone number" << std::endl;
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 smsService->SendMessage(slotId, StringUtils::ToUtf16(dest), StringUtils::ToUtf16(sca), port, data,
58 (sizeof(data) / sizeof(data[0]) - 1), sendCallBackPtr, deliveryCallBackPtr);
59 std::cout << "TestGsmSendShortData" << std::endl;
60 }
61
TestGsmSendLongData(const sptr<ISmsServiceInterface> & smsService) const62 void GsmSmsSenderTest::TestGsmSendLongData(const sptr<ISmsServiceInterface> &smsService) const
63 {
64 AccessMmsToken token;
65 if (smsService == nullptr) {
66 std::cout << "smsService is nullptr." << std::endl;
67 return;
68 }
69 std::string dest;
70 std::cout << "Please enter the card id" << std::endl;
71 int32_t slotId;
72 std::cin >> dest;
73 slotId = atoi(dest.c_str());
74 dest.clear();
75 std::cout << "Please enter the receiver's telephone number" << std::endl;
76 std::cin >> dest;
77 std::string sca("");
78 OHOS::sptr<SmsSendCallbackTest> sendCallBackPtr(new SmsSendCallbackTest());
79 OHOS::sptr<SmsDeliveryCallbackTest> deliveryCallBackPtr(new SmsDeliveryCallbackTest());
80 uint8_t data[] =
81 R"(This is the test data!This is the test data!This is the test data!
82 This is the test data!This is the test data!This is the test data!
83 This is the test data!This is the test data!This is the test data!
84 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 uint16_t port = 100;
88
89 smsService->SendMessage(slotId, StringUtils::ToUtf16(dest), StringUtils::ToUtf16(sca), port, data,
90 sizeof(data) / sizeof(data[0]), sendCallBackPtr, deliveryCallBackPtr);
91 std::cout << "TestGsmSendLongData" << std::endl;
92 }
93
TestSendShortText(const sptr<ISmsServiceInterface> & smsService) const94 void GsmSmsSenderTest::TestSendShortText(const sptr<ISmsServiceInterface> &smsService) const
95 {
96 AccessMmsToken token;
97 if (smsService == nullptr) {
98 std::cout << "smsService is nullptr." << std::endl;
99 return;
100 }
101 std::string dest;
102 std::cout << "Please enter the card id" << std::endl;
103 int32_t slotId;
104 std::cin >> dest;
105 slotId = atoi(dest.c_str());
106 dest.clear();
107 std::string text;
108 std::cin.ignore();
109 std::cout << "Please enter the receiver's telephone number" << std::endl;
110 getline(std::cin, dest);
111 std::cout << "Please enter text" << std::endl;
112 getline(std::cin, text);
113 std::string sca("");
114 OHOS::sptr<SmsSendCallbackTest> sendCallBackPtr(new SmsSendCallbackTest());
115 OHOS::sptr<SmsDeliveryCallbackTest> deliveryCallBackPtr(new SmsDeliveryCallbackTest());
116 smsService->SendMessage(slotId, StringUtils::ToUtf16(dest), StringUtils::ToUtf16(sca),
117 StringUtils::ToUtf16(text), sendCallBackPtr, deliveryCallBackPtr);
118 std::cout << "TestGsmSendShortText" << std::endl;
119 }
120
TestSendMms(const sptr<ISmsServiceInterface> & smsService) const121 void GsmSmsSenderTest::TestSendMms(const sptr<ISmsServiceInterface> &smsService) const
122 {
123 AccessMmsToken token;
124 if (smsService == nullptr) {
125 std::cout << "smsService is nullptr." << std::endl;
126 return;
127 }
128 std::string dest;
129 std::cout << "Please enter the card id" << std::endl;
130 int32_t slotId;
131 std::cin >> dest;
132 slotId = atoi(dest.c_str());
133 dest.clear();
134 std::u16string mmsc(StringUtils::ToUtf16(CU_MMSC));
135 std::u16string data(StringUtils::ToUtf16(SEND_MMS_FILE_URL));
136 std::u16string ua(u"");
137 std::u16string uaprof(u"");
138 int32_t result = smsService->SendMms(slotId, mmsc, data, ua, uaprof);
139 if (result == 0) {
140 std::cout << "send mms success" << std::endl;
141 } else {
142 std::cout << "send mms fail" << std::endl;
143 }
144 }
145
TestSendLongText(const sptr<ISmsServiceInterface> & smsService) const146 void GsmSmsSenderTest::TestSendLongText(const sptr<ISmsServiceInterface> &smsService) const
147 {
148 AccessMmsToken token;
149 if (smsService == nullptr) {
150 std::cout << "smsService is nullptr." << std::endl;
151 return;
152 }
153 std::string dest;
154 std::cout << "Please enter the card id" << std::endl;
155 int32_t slotId;
156 std::cin >> dest;
157 slotId = atoi(dest.c_str());
158 dest.clear();
159 std::cout << "Please enter the receiver's telephone number" << std::endl;
160 std::cin >> dest;
161 std::string sca("");
162 std::string text(
163 R"(This is the test data!This is the test data!This is the test data!
164 This is the test data!This is the test data!This is the test data!
165 This is the test data!This is the test data!This is the test data!
166 This is the test data!This is the test data!This is the test data!
167 This is the test data!This is the test data!This is the test data!
168 This is the test data!This is the test data!This is the test data!)");
169 OHOS::sptr<SmsSendCallbackTest> sendCallBackPtr(new SmsSendCallbackTest());
170 OHOS::sptr<SmsDeliveryCallbackTest> deliveryCallBackPtr(new SmsDeliveryCallbackTest());
171 smsService->SendMessage(slotId, StringUtils::ToUtf16(dest), StringUtils::ToUtf16(sca),
172 StringUtils::ToUtf16(text), sendCallBackPtr, deliveryCallBackPtr);
173 std::cout << "TestGsmSendLongText" << std::endl;
174 }
175
TestSetSmscAddr(const sptr<ISmsServiceInterface> & smsService) const176 void GsmSmsSenderTest::TestSetSmscAddr(const sptr<ISmsServiceInterface> &smsService) const
177 {
178 AccessMmsToken token;
179 bool result = false;
180 if (smsService == nullptr) {
181 std::cout << "smsService is nullptr." << std::endl;
182 return;
183 }
184 std::string dest;
185 std::cout << "Please enter the card id" << std::endl;
186 int32_t slotId;
187 std::cin >> dest;
188 slotId = atoi(dest.c_str());
189 dest.clear();
190 std::string sca;
191 std::cout << "Please enter smsc" << std::endl;
192 std::cin >> sca;
193 result = smsService->SetSmscAddr(slotId, StringUtils::ToUtf16(sca));
194 if (result) {
195 std::cout << "TestSetSmscAddr OK!" << std::endl;
196 } else {
197 std::cout << "TestSetSmscAddr failed!" << std::endl;
198 }
199 }
200
TestGetSmscAddr(const sptr<ISmsServiceInterface> & smsService) const201 void GsmSmsSenderTest::TestGetSmscAddr(const sptr<ISmsServiceInterface> &smsService) const
202 {
203 AccessMmsToken token;
204 std::u16string result;
205 if (smsService == nullptr) {
206 std::cout << "smsService is nullptr." << std::endl;
207 return;
208 }
209 std::string dest;
210 std::cout << "Please enter the card id" << std::endl;
211 int32_t slotId;
212 std::cin >> dest;
213 slotId = atoi(dest.c_str());
214 dest.clear();
215 smsService->GetSmscAddr(slotId, result);
216 std::cout << "TestGetSmscAddr:" << StringUtils::ToUtf8(result) << std::endl;
217 }
218
TestAddSimMessage(const sptr<ISmsServiceInterface> & smsService) const219 void GsmSmsSenderTest::TestAddSimMessage(const sptr<ISmsServiceInterface> &smsService) const
220 {
221 AccessMmsToken token;
222 bool result = false;
223 if (smsService == nullptr) {
224 std::cout << "smsService is nullptr." << std::endl;
225 return;
226 }
227 std::string dest;
228 std::cout << "Please enter the card id" << std::endl;
229 int32_t slotId;
230 std::cin >> dest;
231 slotId = atoi(dest.c_str());
232 dest.clear();
233 std::string smsc;
234 std::cout << "Please enter smsc" << std::endl;
235 std::cin >> smsc;
236 std::string pdu;
237 std::cout << "Please enter pdu" << std::endl;
238 std::cin >> pdu;
239 std::string input;
240 std::cout << "Please enter status" << std::endl;
241 std::cin >> input;
242 uint32_t status = std::atoi(input.c_str());
243 result = smsService->AddSimMessage(slotId, StringUtils::ToUtf16(smsc), StringUtils::ToUtf16(pdu),
244 static_cast<ISmsServiceInterface::SimMessageStatus>(status));
245 if (result) {
246 std::cout << "TestAddSimMessage OK!" << std::endl;
247 } else {
248 std::cout << "TestAddSimMessage failed!" << std::endl;
249 }
250 }
251
TestDelSimMessage(const sptr<ISmsServiceInterface> & smsService) const252 void GsmSmsSenderTest::TestDelSimMessage(const sptr<ISmsServiceInterface> &smsService) const
253 {
254 AccessMmsToken token;
255 bool result = false;
256 if (smsService == nullptr) {
257 std::cout << "smsService is nullptr." << std::endl;
258 return;
259 }
260 std::string dest;
261 std::cout << "Please enter the card id" << std::endl;
262 int32_t slotId;
263 std::cin >> dest;
264 slotId = atoi(dest.c_str());
265 dest.clear();
266 std::string input;
267 std::cout << "Please enter msgIndex" << std::endl;
268 std::cin >> input;
269 uint32_t msgIndex = std::atoi(input.c_str());
270 result = smsService->DelSimMessage(slotId, msgIndex);
271 if (result) {
272 std::cout << "TestDelSimMessage OK!" << std::endl;
273 } else {
274 std::cout << "TestDelSimMessage failed!" << std::endl;
275 }
276 }
277
TestUpdateSimMessage(const sptr<ISmsServiceInterface> & smsService) const278 void GsmSmsSenderTest::TestUpdateSimMessage(const sptr<ISmsServiceInterface> &smsService) const
279 {
280 AccessMmsToken token;
281 bool result = false;
282 if (smsService == nullptr) {
283 std::cout << "smsService is nullptr." << std::endl;
284 return;
285 }
286 std::string dest;
287 std::cout << "Please enter the card id" << std::endl;
288 int32_t slotId;
289 std::cin >> dest;
290 slotId = atoi(dest.c_str());
291 dest.clear();
292 std::string input;
293 std::cout << "Please enter msgIndex" << std::endl;
294 std::cin >> input;
295 uint32_t msgIndex = std::atoi(input.c_str());
296 std::string pdu;
297 std::cout << "Please enter pdu" << std::endl;
298 std::cin >> pdu;
299 std::string smsc;
300 std::cout << "Please enter smsc" << std::endl;
301 std::cin >> smsc;
302 int32_t status;
303 std::cout << "Please enter status" << std::endl;
304 std::cin >> status;
305 std::u16string pduData = StringUtils::ToUtf16(pdu);
306 std::u16string smscData = StringUtils::ToUtf16(smsc);
307 result = smsService->UpdateSimMessage(
308 slotId, msgIndex, static_cast<ISmsServiceInterface::SimMessageStatus>(status), pduData, smscData);
309 if (result) {
310 std::cout << "TestUpdateSimMessage OK!" << std::endl;
311 } else {
312 std::cout << "TestUpdateSimMessage failed!" << std::endl;
313 }
314 }
315
TestGetAllSimMessages(const sptr<ISmsServiceInterface> & smsService) const316 void GsmSmsSenderTest::TestGetAllSimMessages(const sptr<ISmsServiceInterface> &smsService) const
317 {
318 AccessMmsToken token;
319 std::vector<ShortMessage> result;
320 if (smsService == nullptr) {
321 std::cout << "smsService is nullptr." << std::endl;
322 return;
323 }
324 std::string dest;
325 std::cout << "Please enter the card id" << std::endl;
326 int32_t slotId;
327 std::cin >> dest;
328 slotId = atoi(dest.c_str());
329 dest.clear();
330 smsService->GetAllSimMessages(slotId, result);
331 std::cout << "TestGetAllSimMessages Begin:" << std::endl;
332 for (auto &item : result) {
333 std::cout << "[" << item.GetIndexOnSim() << "] " << StringUtils::StringToHex(item.GetPdu()) << std::endl;
334 std::cout << "status:" << item.GetIccMessageStatus()
335 << " message:" << StringUtils::ToUtf8(item.GetVisibleMessageBody()) << std::endl;
336 }
337 std::cout << "TestGetAllSimMessages End!" << std::endl;
338 }
339
TestEnableCBRangeConfig(const sptr<ISmsServiceInterface> & smsService) const340 void GsmSmsSenderTest::TestEnableCBRangeConfig(const sptr<ISmsServiceInterface> &smsService) const
341 {
342 AccessMmsToken token;
343 if (smsService == nullptr) {
344 std::cout << "smsService is nullptr." << std::endl;
345 return;
346 }
347 std::string dest;
348 std::cout << "Please enter the card id" << std::endl;
349 int32_t slotId;
350 std::cin >> dest;
351 slotId = atoi(dest.c_str());
352 dest.clear();
353 bool enable = true;
354 uint32_t startMessageId = 0;
355 uint32_t endMessageId = 0;
356 uint8_t ranType = 1;
357 std::string input;
358 std::cout << "Please enter startMessageId" << std::endl;
359 std::cin >> input;
360 startMessageId = std::atoi(input.c_str());
361 std::cout << "Please enter endMessageId" << std::endl;
362 std::cin >> input;
363 endMessageId = std::atoi(input.c_str());
364 int32_t result = smsService->SetCBConfig(slotId, enable, startMessageId, endMessageId, ranType);
365 std::cout << "TestEnableCBRangeConfig:" << result << std::endl;
366 }
367
TestDisableCBRangeConfig(const sptr<ISmsServiceInterface> & smsService) const368 void GsmSmsSenderTest::TestDisableCBRangeConfig(const sptr<ISmsServiceInterface> &smsService) const
369 {
370 AccessMmsToken token;
371 if (smsService == nullptr) {
372 std::cout << "smsService is nullptr." << std::endl;
373 return;
374 }
375 std::string dest;
376 std::cout << "Please enter the card id" << std::endl;
377 int32_t slotId;
378 std::cin >> dest;
379 slotId = atoi(dest.c_str());
380 dest.clear();
381 bool enable = false;
382 uint32_t startMessageId = 0;
383 uint32_t endMessageId = 0;
384 uint8_t ranType = 1;
385 std::string input;
386 std::cout << "Please enter startMessageId" << std::endl;
387 std::cin >> input;
388 startMessageId = std::atoi(input.c_str());
389 std::cout << "Please enter endMessageId" << std::endl;
390 std::cin >> input;
391 endMessageId = std::atoi(input.c_str());
392 int32_t result = smsService->SetCBConfig(slotId, enable, startMessageId, endMessageId, ranType);
393 std::cout << "TestDisableCBRangeConfig:" << result << std::endl;
394 }
395
TestEnableCBConfig(const sptr<ISmsServiceInterface> & smsService) const396 void GsmSmsSenderTest::TestEnableCBConfig(const sptr<ISmsServiceInterface> &smsService) const
397 {
398 AccessMmsToken token;
399 if (smsService == nullptr) {
400 std::cout << "smsService is nullptr." << std::endl;
401 return;
402 }
403 std::string dest;
404 std::cout << "Please enter the card id" << std::endl;
405 int32_t slotId;
406 std::cin >> dest;
407 slotId = atoi(dest.c_str());
408 dest.clear();
409 bool enable = true;
410 uint32_t identifier = 0;
411 uint8_t ranType = 1;
412 std::string input;
413 std::cout << "Please enter identifier" << std::endl;
414 std::cin >> input;
415 identifier = std::atoi(input.c_str());
416 int32_t result = smsService->SetCBConfig(slotId, enable, identifier, identifier, ranType);
417 std::cout << "TestEnableCBConfig:" << result << std::endl;
418 }
419
TestDisableCBConfig(const sptr<ISmsServiceInterface> & smsService) const420 void GsmSmsSenderTest::TestDisableCBConfig(const sptr<ISmsServiceInterface> &smsService) const
421 {
422 AccessMmsToken token;
423 if (smsService == nullptr) {
424 std::cout << "smsService is nullptr." << std::endl;
425 return;
426 }
427 std::string dest;
428 std::cout << "Please enter the card id" << std::endl;
429 int32_t slotId;
430 std::cin >> dest;
431 slotId = atoi(dest.c_str());
432 dest.clear();
433 bool enable = false;
434 uint32_t identifier = 0;
435 uint8_t ranType = 1;
436 std::string input;
437 std::cout << "Please enter identifier" << std::endl;
438 std::cin >> input;
439 identifier = std::atoi(input.c_str());
440 int32_t result = smsService->SetCBConfig(slotId, enable, identifier, identifier, ranType);
441 std::cout << "TestDisableCBConfig:" << result << std::endl;
442 }
443
TestSetDefaultSmsSlotId(const sptr<ISmsServiceInterface> & smsService) const444 void GsmSmsSenderTest::TestSetDefaultSmsSlotId(const sptr<ISmsServiceInterface> &smsService) const
445 {
446 AccessMmsToken token;
447 if (smsService == nullptr) {
448 std::cout << "smsService is nullptr." << std::endl;
449 return;
450 }
451 int32_t slotId;
452 std::string input;
453 std::cout << "Please enter Slot Id" << std::endl;
454 std::cin >> input;
455 slotId = std::atoi(input.c_str());
456 int32_t result = smsService->SetDefaultSmsSlotId(slotId);
457 std::cout << "TestSetDefaultSmsSlotId:" << result << std::endl;
458 }
459
TestGetDefaultSmsSlotId(const sptr<ISmsServiceInterface> & smsService) const460 void GsmSmsSenderTest::TestGetDefaultSmsSlotId(const sptr<ISmsServiceInterface> &smsService) const
461 {
462 int32_t result;
463 if (smsService == nullptr) {
464 std::cout << "smsService is nullptr." << std::endl;
465 return;
466 }
467 result = smsService->GetDefaultSmsSlotId();
468 std::cout << "TestGetDefaultSmsSlotId:" << result << std::endl;
469 }
470
TestSplitMessage(const sptr<ISmsServiceInterface> & smsService) const471 void GsmSmsSenderTest::TestSplitMessage(const sptr<ISmsServiceInterface> &smsService) const
472 {
473 AccessMmsToken token;
474 std::vector<std::u16string> result;
475 if (smsService == nullptr) {
476 std::cout << "smsService is nullptr." << std::endl;
477 return;
478 }
479 std::string input;
480 std::cout << "Please enter message" << std::endl;
481 std::getline(std::cin, input);
482 smsService->SplitMessage(StringUtils::ToUtf16(input), result);
483 std::cout << "TestSplitMessage size:" << result.size() << std::endl;
484 for (auto &item : result) {
485 std::cout << StringUtils::ToUtf8(item) << std::endl;
486 }
487 }
488
TestGetSmsSegmentsInfo(const sptr<ISmsServiceInterface> & smsService) const489 void GsmSmsSenderTest::TestGetSmsSegmentsInfo(const sptr<ISmsServiceInterface> &smsService) const
490 {
491 if (smsService == nullptr) {
492 std::cout << "TestGetSmsSegmentsInfo smsService is nullptr." << std::endl;
493 return;
494 }
495 int32_t slotId;
496 std::string input;
497 std::cout << "TestGetSmsSegmentsInfo Please enter Slot Id" << std::endl;
498 std::getline(std::cin, input);
499 slotId = std::atoi(input.c_str());
500 input.clear();
501 std::cout << "Please enter message" << std::endl;
502 std::getline(std::cin, input);
503 ISmsServiceInterface::SmsSegmentsInfo result;
504 if (smsService->GetSmsSegmentsInfo(slotId, StringUtils::ToUtf16(input), false, result) != TELEPHONY_ERR_SUCCESS) {
505 std::cout << "Get Sms SegmentsInfo Fail." << std::endl;
506 return;
507 }
508
509 int32_t codeScheme = static_cast<int32_t>(result.msgCodeScheme);
510 std::cout << "msgSegCount:" << result.msgSegCount << " msgEncodingCount:" << result.msgEncodingCount << std::endl;
511 std::cout << "msgRemainCount:" << result.msgRemainCount << " msgCodeScheme:" << codeScheme << std::endl;
512 }
513
TestIsImsSmsSupported(const sptr<ISmsServiceInterface> & smsService) const514 void GsmSmsSenderTest::TestIsImsSmsSupported(const sptr<ISmsServiceInterface> &smsService) const
515 {
516 if (smsService == nullptr) {
517 std::cout << "TestIsImsSmsSupported smsService is nullptr." << std::endl;
518 return;
519 }
520 int32_t slotId;
521 std::string input;
522 std::cout << "TestIsImsSmsSupported Please enter Slot Id" << std::endl;
523 std::getline(std::cin, input);
524 slotId = std::atoi(input.c_str());
525 bool result = false;
526 smsService->IsImsSmsSupported(slotId, result);
527 std::string res = result ? "true" : "false";
528 std::cout << "IsImsSmsSupported:" << res << std::endl;
529 }
530
TestSetImsSmsConfig(const sptr<ISmsServiceInterface> & smsService) const531 void GsmSmsSenderTest::TestSetImsSmsConfig(const sptr<ISmsServiceInterface> &smsService) const
532 {
533 AccessMmsToken token;
534 if (smsService == nullptr) {
535 std::cout << "TestSetImsSmsConfig smsService is nullptr." << std::endl;
536 return;
537 }
538 int32_t slotId;
539 std::string input;
540 std::cout << "TestSetImsSmsConfig Please enter Slot Id" << std::endl;
541 std::getline(std::cin, input);
542 slotId = std::atoi(input.c_str());
543 int32_t enable;
544 std::cout << "Please enter enable" << std::endl;
545 std::getline(std::cin, input);
546 enable = std::atoi(input.c_str());
547 std::string res = smsService->SetImsSmsConfig(slotId, enable) ? "true" : "false";
548 std::cout << "SetImsSmsConfig:" << res << std::endl;
549 }
550
TestGetImsShortMessageFormat(const sptr<ISmsServiceInterface> & smsService) const551 void GsmSmsSenderTest::TestGetImsShortMessageFormat(const sptr<ISmsServiceInterface> &smsService) const
552 {
553 if (smsService == nullptr) {
554 std::cout << "smsService is nullptr." << std::endl;
555 return;
556 }
557 std::u16string format;
558 smsService->GetImsShortMessageFormat(format);
559 std::cout << "GetImsShortMessageFormat:" << StringUtils::ToUtf8(format) << std::endl;
560 }
561
TestAddBlockPhone() const562 void GsmSmsSenderTest::TestAddBlockPhone() const
563 {
564 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataAHelper();
565 if (helper == nullptr) {
566 std::cout << "Creator helper nullptr error." << std::endl;
567 return;
568 }
569 std::string input;
570 std::cout << "Please enter block phone number" << std::endl;
571 std::getline(std::cin, input);
572
573 Uri uri("datashare:///com.ohos.contactsdataability/contacts/contact_blocklist");
574 DataShare::DataShareValuesBucket value;
575 value.Put("phone_number", input);
576 int ret = helper->Insert(uri, value);
577 helper->Release();
578 std::cout << "add block:" << input << ((ret >= 0) ? " success" : " error") << std::endl;
579 }
580
TestRemoveBlockPhone() const581 void GsmSmsSenderTest::TestRemoveBlockPhone() const
582 {
583 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataAHelper();
584 if (helper == nullptr) {
585 std::cout << "Creator helper nullptr error." << std::endl;
586 return;
587 }
588 std::string input;
589 std::cout << "Please enter Remove phone number" << std::endl;
590 std::getline(std::cin, input);
591 Uri uri("datashare:///com.ohos.contactsdataability/contacts/contact_blocklist");
592 DataShare::DataSharePredicates predicates;
593 predicates.EqualTo("phone_number", input);
594 int ret = helper->Delete(uri, predicates);
595 helper->Release();
596 std::cout << "remove block:" << input << ((ret >= 0) ? " success" : " error") << std::endl;
597 }
598
TestHasSmsCapability(const sptr<ISmsServiceInterface> & smsService) const599 void GsmSmsSenderTest::TestHasSmsCapability(const sptr<ISmsServiceInterface> &smsService) const
600 {
601 if (smsService == nullptr) {
602 std::cout << "GsmSmsSenderTest smsService is nullptr error." << std::endl;
603 return;
604 }
605 std::string res = smsService->HasSmsCapability() ? "true" : "false";
606 std::cout << "HasSmsCapability:" << res << std::endl;
607 }
608
CreateDataAHelper() const609 std::shared_ptr<DataShare::DataShareHelper> GsmSmsSenderTest::CreateDataAHelper() const
610 {
611 auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
612 if (saManager == nullptr) {
613 std::cout << "Get system ability mgr failed." << std::endl;
614 return nullptr;
615 }
616 auto remoteObj = saManager->GetSystemAbility(TELEPHONY_SMS_MMS_SYS_ABILITY_ID);
617 if (remoteObj == nullptr) {
618 std::cout << "GetSystemAbility Service Failed." << std::endl;
619 return nullptr;
620 }
621 const std::string uriContact("datashare:///com.ohos.contactsdataability");
622 return DataShare::DataShareHelper::Creator(remoteObj, uriContact);
623 }
624 } // namespace Telephony
625 } // namespace OHOS
626