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 smsService->SendMessage(slotIdTesta, 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 int32_t slotIdTestb;
70 std::string dest;
71 std::cout << "Please enter the card id" << std::endl;
72 std::cin >> dest;
73 slotIdTestb = 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(slotIdTestb, 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 slotIdTestc;
104 std::cin >> dest;
105 slotIdTestc = 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(slotIdTestc, 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 int32_t slotIdTestd;
154 std::string dest;
155 std::cout << "Please enter the card id" << std::endl;
156 std::cin >> dest;
157 slotIdTestd = 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(slotIdTestd, 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 slotIdTeste;
187 std::cin >> dest;
188 slotIdTeste = 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(slotIdTeste, 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 slotIdTestf;
212 std::cin >> dest;
213 slotIdTestf = atoi(dest.c_str());
214 dest.clear();
215 smsService->GetSmscAddr(slotIdTestf, 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 slotIdTestg;
230 std::cin >> dest;
231 slotIdTestg = atoi(dest.c_str());
232 std::string smsc;
233 std::cout << "Please enter smsc" << std::endl;
234 std::cin >> smsc;
235 std::string pdu;
236 std::cout << "Please enter pdu" << std::endl;
237 std::cin >> pdu;
238 std::string input;
239 std::cout << "Please enter status" << std::endl;
240 std::cin >> input;
241 uint32_t status = std::atoi(input.c_str());
242 result = smsService->AddSimMessage(slotIdTestg, StringUtils::ToUtf16(smsc), StringUtils::ToUtf16(pdu),
243 static_cast<ISmsServiceInterface::SimMessageStatus>(status));
244 if (result == 0) {
245 std::cout << "TestAddSimMessage OK!" << std::endl;
246 } else {
247 std::cout << "TestAddSimMessage failed!" << std::endl;
248 }
249 }
250
TestDelSimMessage(const sptr<ISmsServiceInterface> & smsService) const251 void GsmSmsSenderTest::TestDelSimMessage(const sptr<ISmsServiceInterface> &smsService) const
252 {
253 AccessMmsToken token;
254 if (smsService == nullptr) {
255 std::cout << "smsService is nullptr." << std::endl;
256 return;
257 }
258 bool result = false;
259 int32_t slotIdTesth;
260 std::string dest;
261 std::cout << "Please enter the card id" << std::endl;
262 std::cin >> dest;
263 slotIdTesth = atoi(dest.c_str());
264 dest.clear();
265 std::string input;
266 std::cout << "Please enter msgIndex" << std::endl;
267 std::cin >> input;
268 uint32_t msgIndex = std::atoi(input.c_str());
269 result = smsService->DelSimMessage(slotIdTesth, msgIndex);
270 if (result == 0) {
271 std::cout << "TestDelSimMessage OK!" << std::endl;
272 } else {
273 std::cout << "TestDelSimMessage failed!" << std::endl;
274 }
275 }
276
TestUpdateSimMessage(const sptr<ISmsServiceInterface> & smsService) const277 void GsmSmsSenderTest::TestUpdateSimMessage(const sptr<ISmsServiceInterface> &smsService) const
278 {
279 AccessMmsToken token;
280 if (smsService == nullptr) {
281 std::cout << "smsService is nullptr." << std::endl;
282 return;
283 }
284 bool result = false;
285 std::string dest;
286 std::cout << "Please enter the card id" << std::endl;
287 int32_t slotIdTesti;
288 std::cin >> dest;
289 slotIdTesti = atoi(dest.c_str());
290 dest.clear();
291 std::string input;
292 std::cout << "Please enter msgIndex" << std::endl;
293 std::cin >> input;
294 uint32_t msgIndex = std::atoi(input.c_str());
295 std::string pdu;
296 std::cout << "Please enter pdu" << std::endl;
297 std::cin >> pdu;
298 std::string smsc;
299 std::cout << "Please enter smsc" << std::endl;
300 std::cin >> smsc;
301 int32_t status;
302 std::cout << "Please enter status" << std::endl;
303 std::cin >> status;
304 std::u16string pduData = StringUtils::ToUtf16(pdu);
305 std::u16string smscData = StringUtils::ToUtf16(smsc);
306 result = smsService->UpdateSimMessage(
307 slotIdTesti, msgIndex, static_cast<ISmsServiceInterface::SimMessageStatus>(status), pduData, smscData);
308 if (result) {
309 std::cout << "TestUpdateSimMessage OK!" << std::endl;
310 } else {
311 std::cout << "TestUpdateSimMessage failed!" << std::endl;
312 }
313 }
314
TestGetAllSimMessages(const sptr<ISmsServiceInterface> & smsService) const315 void GsmSmsSenderTest::TestGetAllSimMessages(const sptr<ISmsServiceInterface> &smsService) const
316 {
317 AccessMmsToken token;
318 std::vector<ShortMessage> result;
319 if (smsService == nullptr) {
320 std::cout << "smsService is nullptr." << std::endl;
321 return;
322 }
323 std::string dest;
324 std::cout << "Please enter the card id" << std::endl;
325 int32_t slotIdTestj;
326 std::cin >> dest;
327 slotIdTestj = atoi(dest.c_str());
328 dest.clear();
329 smsService->GetAllSimMessages(slotIdTestj, result);
330 std::cout << "TestGetAllSimMessages Begin:" << std::endl;
331 for (auto &item : result) {
332 std::cout << "[" << item.GetIndexOnSim() << "] " << StringUtils::StringToHex(item.GetPdu()) << std::endl;
333 std::cout << "status:" << item.GetIccMessageStatus()
334 << " message:" << StringUtils::ToUtf8(item.GetVisibleMessageBody()) << std::endl;
335 }
336 std::cout << "TestGetAllSimMessages End!" << std::endl;
337 }
338
TestEnableCBRangeConfig(const sptr<ISmsServiceInterface> & smsService) const339 void GsmSmsSenderTest::TestEnableCBRangeConfig(const sptr<ISmsServiceInterface> &smsService) const
340 {
341 AccessMmsToken token;
342 if (smsService == nullptr) {
343 std::cout << "smsService is nullptr." << std::endl;
344 return;
345 }
346 std::string dest;
347 std::cout << "Please enter the card id" << std::endl;
348 int32_t slotIdTestk;
349 std::cin >> dest;
350 bool enable = true;
351 slotIdTestk = atoi(dest.c_str());
352 dest.clear();
353 uint8_t ranType = 1;
354 uint32_t startMessageId = 0;
355 uint32_t endMessageId = 0;
356 std::cout << "Please enter startMessageId" << std::endl;
357 std::string input;
358 std::cin >> input;
359 startMessageId = std::atoi(input.c_str());
360 std::cout << "Please enter endMessageId" << std::endl;
361 std::cin >> input;
362 endMessageId = std::atoi(input.c_str());
363 int32_t result = smsService->SetCBConfig(slotIdTestk, enable, startMessageId, endMessageId, ranType);
364 std::cout << "TestEnableCBRangeConfig:" << result << std::endl;
365 }
366
TestDisableCBRangeConfig(const sptr<ISmsServiceInterface> & smsService) const367 void GsmSmsSenderTest::TestDisableCBRangeConfig(const sptr<ISmsServiceInterface> &smsService) const
368 {
369 AccessMmsToken token;
370 if (smsService == nullptr) {
371 std::cout << "smsService is nullptr." << std::endl;
372 return;
373 }
374 std::string dest;
375 std::cout << "Please enter the card id" << std::endl;
376 std::cin >> dest;
377 int32_t slotIdTestl = atoi(dest.c_str());
378 bool enable = false;
379 uint32_t startMessageId = 0;
380 uint32_t endMessageId = 0;
381 uint8_t ranType = 1;
382 std::string input;
383 std::cout << "Please enter startMessageId" << std::endl;
384 std::cin >> input;
385 startMessageId = std::atoi(input.c_str());
386 std::cout << "Please enter endMessageId" << std::endl;
387 std::cin >> input;
388 endMessageId = std::atoi(input.c_str());
389 int32_t result = smsService->SetCBConfig(slotIdTestl, enable, startMessageId, endMessageId, ranType);
390 std::cout << "TestDisableCBRangeConfig:" << result << std::endl;
391 }
392
TestEnableCBConfig(const sptr<ISmsServiceInterface> & smsService) const393 void GsmSmsSenderTest::TestEnableCBConfig(const sptr<ISmsServiceInterface> &smsService) const
394 {
395 AccessMmsToken token;
396 if (smsService == nullptr) {
397 std::cout << "smsService is nullptr." << std::endl;
398 return;
399 }
400 std::string dest;
401 std::cout << "Please enter the card id" << std::endl;
402 int32_t slotIdTestm;
403 std::cin >> dest;
404 slotIdTestm = atoi(dest.c_str());
405 dest.clear();
406 bool enable = true;
407 uint32_t identifier = 0;
408 uint8_t ranType = 1;
409 std::string input;
410 std::cout << "Please enter identifier" << std::endl;
411 std::cin >> input;
412 identifier = std::atoi(input.c_str());
413 int32_t result = smsService->SetCBConfig(slotIdTestm, enable, identifier, identifier, ranType);
414 std::cout << "TestEnableCBConfig:" << result << std::endl;
415 }
416
TestDisableCBConfig(const sptr<ISmsServiceInterface> & smsService) const417 void GsmSmsSenderTest::TestDisableCBConfig(const sptr<ISmsServiceInterface> &smsService) const
418 {
419 AccessMmsToken token;
420 if (smsService == nullptr) {
421 std::cout << "smsService is nullptr." << std::endl;
422 return;
423 }
424 std::string dest;
425 std::cout << "Please enter the card id" << std::endl;
426 int32_t slotIdTestn;
427 std::cin >> dest;
428 slotIdTestn = atoi(dest.c_str());
429 dest.clear();
430 bool enable = false;
431 uint32_t identifier = 0;
432 uint8_t ranType = 1;
433 std::string input;
434 std::cout << "Please enter identifier" << std::endl;
435 std::cin >> input;
436 identifier = std::atoi(input.c_str());
437 int32_t result = smsService->SetCBConfig(slotIdTestn, enable, identifier, identifier, ranType);
438 std::cout << "TestDisableCBConfig:" << result << std::endl;
439 }
440
TestSetDefaultSmsSlotId(const sptr<ISmsServiceInterface> & smsService) const441 void GsmSmsSenderTest::TestSetDefaultSmsSlotId(const sptr<ISmsServiceInterface> &smsService) const
442 {
443 AccessMmsToken token;
444 if (smsService == nullptr) {
445 std::cout << "smsService is nullptr." << std::endl;
446 return;
447 }
448 int32_t slotId;
449 std::string input;
450 std::cout << "Please enter Slot Id" << std::endl;
451 std::cin >> input;
452 slotId = std::atoi(input.c_str());
453 int32_t result = smsService->SetDefaultSmsSlotId(slotId);
454 std::cout << "TestSetDefaultSmsSlotId:" << result << std::endl;
455 }
456
TestGetDefaultSmsSlotId(const sptr<ISmsServiceInterface> & smsService) const457 void GsmSmsSenderTest::TestGetDefaultSmsSlotId(const sptr<ISmsServiceInterface> &smsService) const
458 {
459 int32_t result;
460 if (smsService == nullptr) {
461 std::cout << "smsService is nullptr." << std::endl;
462 return;
463 }
464 result = smsService->GetDefaultSmsSlotId();
465 std::cout << "TestGetDefaultSmsSlotId:" << result << std::endl;
466 }
467
TestSplitMessage(const sptr<ISmsServiceInterface> & smsService) const468 void GsmSmsSenderTest::TestSplitMessage(const sptr<ISmsServiceInterface> &smsService) const
469 {
470 AccessMmsToken token;
471 std::vector<std::u16string> result;
472 if (smsService == nullptr) {
473 std::cout << "smsService is nullptr." << std::endl;
474 return;
475 }
476 std::string input;
477 std::cout << "Please enter message" << std::endl;
478 std::getline(std::cin, input);
479 smsService->SplitMessage(StringUtils::ToUtf16(input), result);
480 std::cout << "TestSplitMessage size:" << result.size() << std::endl;
481 for (auto &item : result) {
482 std::cout << StringUtils::ToUtf8(item) << std::endl;
483 }
484 }
485
TestGetSmsSegmentsInfo(const sptr<ISmsServiceInterface> & smsService) const486 void GsmSmsSenderTest::TestGetSmsSegmentsInfo(const sptr<ISmsServiceInterface> &smsService) const
487 {
488 if (smsService == nullptr) {
489 std::cout << "TestGetSmsSegmentsInfo smsService is nullptr." << std::endl;
490 return;
491 }
492 int32_t slotId;
493 std::string input;
494 std::cout << "TestGetSmsSegmentsInfo Please enter Slot Id" << std::endl;
495 std::getline(std::cin, input);
496 slotId = std::atoi(input.c_str());
497 input.clear();
498 std::cout << "Please enter message" << std::endl;
499 std::getline(std::cin, input);
500 ISmsServiceInterface::SmsSegmentsInfo result;
501 if (smsService->GetSmsSegmentsInfo(slotId, StringUtils::ToUtf16(input), false, result) != TELEPHONY_ERR_SUCCESS) {
502 std::cout << "Get Sms SegmentsInfo Fail." << std::endl;
503 return;
504 }
505
506 int32_t codeScheme = static_cast<int32_t>(result.msgCodeScheme);
507 std::cout << "msgSegCount:" << result.msgSegCount << " msgEncodingCount:" << result.msgEncodingCount << std::endl;
508 std::cout << "msgRemainCount:" << result.msgRemainCount << " msgCodeScheme:" << codeScheme << std::endl;
509 }
510
TestIsImsSmsSupported(const sptr<ISmsServiceInterface> & smsService) const511 void GsmSmsSenderTest::TestIsImsSmsSupported(const sptr<ISmsServiceInterface> &smsService) const
512 {
513 if (smsService == nullptr) {
514 std::cout << "TestIsImsSmsSupported smsService is nullptr." << std::endl;
515 return;
516 }
517 int32_t slotId;
518 std::string input;
519 std::cout << "TestIsImsSmsSupported Please enter Slot Id" << std::endl;
520 std::getline(std::cin, input);
521 slotId = std::atoi(input.c_str());
522 bool result = false;
523 smsService->IsImsSmsSupported(slotId, result);
524 std::string res = result ? "true" : "false";
525 std::cout << "IsImsSmsSupported:" << res << std::endl;
526 }
527
TestSetImsSmsConfig(const sptr<ISmsServiceInterface> & smsService) const528 void GsmSmsSenderTest::TestSetImsSmsConfig(const sptr<ISmsServiceInterface> &smsService) const
529 {
530 AccessMmsToken token;
531 if (smsService == nullptr) {
532 std::cout << "TestSetImsSmsConfig smsService is nullptr." << std::endl;
533 return;
534 }
535 int32_t slotId;
536 std::string input;
537 std::cout << "TestSetImsSmsConfig Please enter Slot Id" << std::endl;
538 std::getline(std::cin, input);
539 slotId = std::atoi(input.c_str());
540 int32_t enable;
541 std::cout << "Please enter enable" << std::endl;
542 std::getline(std::cin, input);
543 enable = std::atoi(input.c_str());
544 std::string res = smsService->SetImsSmsConfig(slotId, enable) ? "true" : "false";
545 std::cout << "SetImsSmsConfig:" << res << std::endl;
546 }
547
TestGetImsShortMessageFormat(const sptr<ISmsServiceInterface> & smsService) const548 void GsmSmsSenderTest::TestGetImsShortMessageFormat(const sptr<ISmsServiceInterface> &smsService) const
549 {
550 if (smsService == nullptr) {
551 std::cout << "smsService is nullptr." << std::endl;
552 return;
553 }
554 std::u16string format;
555 smsService->GetImsShortMessageFormat(format);
556 std::cout << "GetImsShortMessageFormat:" << StringUtils::ToUtf8(format) << std::endl;
557 }
558
TestAddBlockPhone() const559 void GsmSmsSenderTest::TestAddBlockPhone() const
560 {
561 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataAHelper();
562 if (helper == nullptr) {
563 std::cout << "Creator helper nullptr error." << std::endl;
564 return;
565 }
566 std::string input;
567 std::cout << "Please enter block phone number" << std::endl;
568 std::getline(std::cin, input);
569
570 Uri uri("datashare:///com.ohos.contactsdataability/contacts/contact_blocklist");
571 DataShare::DataShareValuesBucket value;
572 value.Put("phone_number", input);
573 int ret = helper->Insert(uri, value);
574 helper->Release();
575 std::cout << "add block:" << input << ((ret >= 0) ? " success" : " error") << std::endl;
576 }
577
TestRemoveBlockPhone() const578 void GsmSmsSenderTest::TestRemoveBlockPhone() const
579 {
580 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataAHelper();
581 if (helper == nullptr) {
582 std::cout << "Creator helper nullptr error." << std::endl;
583 return;
584 }
585 std::string input;
586 std::cout << "Please enter Remove phone number" << std::endl;
587 std::getline(std::cin, input);
588 Uri uri("datashare:///com.ohos.contactsdataability/contacts/contact_blocklist");
589 DataShare::DataSharePredicates predicates;
590 predicates.EqualTo("phone_number", input);
591 int ret = helper->Delete(uri, predicates);
592 helper->Release();
593 std::cout << "remove block:" << input << ((ret >= 0) ? " success" : " error") << std::endl;
594 }
595
TestHasSmsCapability(const sptr<ISmsServiceInterface> & smsService) const596 void GsmSmsSenderTest::TestHasSmsCapability(const sptr<ISmsServiceInterface> &smsService) const
597 {
598 if (smsService == nullptr) {
599 std::cout << "GsmSmsSenderTest smsService is nullptr error." << std::endl;
600 return;
601 }
602 std::string res = smsService->HasSmsCapability() ? "true" : "false";
603 std::cout << "HasSmsCapability:" << res << std::endl;
604 }
605
CreateDataAHelper() const606 std::shared_ptr<DataShare::DataShareHelper> GsmSmsSenderTest::CreateDataAHelper() const
607 {
608 auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
609 if (saManager == nullptr) {
610 std::cout << "Get system ability mgr failed." << std::endl;
611 return nullptr;
612 }
613 auto remoteObj = saManager->GetSystemAbility(TELEPHONY_SMS_MMS_SYS_ABILITY_ID);
614 if (remoteObj == nullptr) {
615 std::cout << "GetSystemAbility Service Failed." << std::endl;
616 return nullptr;
617 }
618 const std::string uriContact("datashare:///com.ohos.contactsdataability");
619 return DataShare::DataShareHelper::Creator(remoteObj, uriContact);
620 }
621 } // namespace Telephony
622 } // namespace OHOS
623