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
TestSetCBConfigList(const sptr<ISmsServiceInterface> & smsService) const457 void GsmSmsSenderTest::TestSetCBConfigList(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 = 0;
465 std::vector<int32_t> messageIds1 = {4352, 4355, 4388, 4390};
466 std::vector<int32_t> messageIds2 = {4352, 4388, 4390};
467 std::vector<int32_t> messageIds3 = {4355, 4352, 4388, 4390};
468 int32_t ranType = 1;
469 EXPECT_EQ(smsService->SetCBConfigList(slotId, messageIds1, ranType), TELEPHONY_ERR_SUCCESS);
470 EXPECT_EQ(smsService->SetCBConfigList(slotId, messageIds2, ranType), TELEPHONY_ERR_ARGUMENT_INVALID);
471 EXPECT_EQ(smsService->SetCBConfigList(slotId, messageIds3, ranType), TELEPHONY_ERR_ARGUMENT_INVALID);
472 }
473
TestSetDefaultSmsSlotId(const sptr<ISmsServiceInterface> & smsService) const474 void GsmSmsSenderTest::TestSetDefaultSmsSlotId(const sptr<ISmsServiceInterface> &smsService) const
475 {
476 AccessMmsToken token;
477 if (smsService == nullptr) {
478 std::cout << "smsService is nullptr." << std::endl;
479 return;
480 }
481 int32_t slotId;
482 std::string input;
483 std::cout << "Please enter Slot Id" << std::endl;
484 std::cin >> input;
485 slotId = std::atoi(input.c_str());
486 int32_t result = smsService->SetDefaultSmsSlotId(slotId);
487 std::cout << "TestSetDefaultSmsSlotId:" << result << std::endl;
488 }
489
TestGetDefaultSmsSlotId(const sptr<ISmsServiceInterface> & smsService) const490 void GsmSmsSenderTest::TestGetDefaultSmsSlotId(const sptr<ISmsServiceInterface> &smsService) const
491 {
492 int32_t result;
493 if (smsService == nullptr) {
494 std::cout << "smsService is nullptr." << std::endl;
495 return;
496 }
497 result = smsService->GetDefaultSmsSlotId();
498 std::cout << "TestGetDefaultSmsSlotId:" << result << std::endl;
499 }
500
TestSplitMessage(const sptr<ISmsServiceInterface> & smsService) const501 void GsmSmsSenderTest::TestSplitMessage(const sptr<ISmsServiceInterface> &smsService) const
502 {
503 AccessMmsToken token;
504 std::vector<std::u16string> result;
505 if (smsService == nullptr) {
506 std::cout << "smsService is nullptr." << std::endl;
507 return;
508 }
509 std::string input;
510 std::cout << "Please enter message" << std::endl;
511 std::getline(std::cin, input);
512 smsService->SplitMessage(StringUtils::ToUtf16(input), result);
513 std::cout << "TestSplitMessage size:" << result.size() << std::endl;
514 for (auto &item : result) {
515 std::cout << StringUtils::ToUtf8(item) << std::endl;
516 }
517 }
518
TestGetSmsSegmentsInfo(const sptr<ISmsServiceInterface> & smsService) const519 void GsmSmsSenderTest::TestGetSmsSegmentsInfo(const sptr<ISmsServiceInterface> &smsService) const
520 {
521 if (smsService == nullptr) {
522 std::cout << "TestGetSmsSegmentsInfo smsService is nullptr." << std::endl;
523 return;
524 }
525 int32_t slotId;
526 std::string input;
527 std::cout << "TestGetSmsSegmentsInfo Please enter Slot Id" << std::endl;
528 std::getline(std::cin, input);
529 slotId = std::atoi(input.c_str());
530 input.clear();
531 std::cout << "Please enter message" << std::endl;
532 std::getline(std::cin, input);
533 ISmsServiceInterface::SmsSegmentsInfo result;
534 if (smsService->GetSmsSegmentsInfo(slotId, StringUtils::ToUtf16(input), false, result) != TELEPHONY_ERR_SUCCESS) {
535 std::cout << "Get Sms SegmentsInfo Fail." << std::endl;
536 return;
537 }
538
539 int32_t codeScheme = static_cast<int32_t>(result.msgCodeScheme);
540 std::cout << "msgSegCount:" << result.msgSegCount << " msgEncodingCount:" << result.msgEncodingCount << std::endl;
541 std::cout << "msgRemainCount:" << result.msgRemainCount << " msgCodeScheme:" << codeScheme << std::endl;
542 }
543
TestIsImsSmsSupported(const sptr<ISmsServiceInterface> & smsService) const544 void GsmSmsSenderTest::TestIsImsSmsSupported(const sptr<ISmsServiceInterface> &smsService) const
545 {
546 if (smsService == nullptr) {
547 std::cout << "TestIsImsSmsSupported smsService is nullptr." << std::endl;
548 return;
549 }
550 int32_t slotId;
551 std::string input;
552 std::cout << "TestIsImsSmsSupported Please enter Slot Id" << std::endl;
553 std::getline(std::cin, input);
554 slotId = std::atoi(input.c_str());
555 bool result = false;
556 smsService->IsImsSmsSupported(slotId, result);
557 std::string res = result ? "true" : "false";
558 std::cout << "IsImsSmsSupported:" << res << std::endl;
559 }
560
TestSetImsSmsConfig(const sptr<ISmsServiceInterface> & smsService) const561 void GsmSmsSenderTest::TestSetImsSmsConfig(const sptr<ISmsServiceInterface> &smsService) const
562 {
563 AccessMmsToken token;
564 if (smsService == nullptr) {
565 std::cout << "TestSetImsSmsConfig smsService is nullptr." << std::endl;
566 return;
567 }
568 int32_t slotId;
569 std::string input;
570 std::cout << "TestSetImsSmsConfig Please enter Slot Id" << std::endl;
571 std::getline(std::cin, input);
572 slotId = std::atoi(input.c_str());
573 int32_t enable;
574 std::cout << "Please enter enable" << std::endl;
575 std::getline(std::cin, input);
576 enable = std::atoi(input.c_str());
577 std::string res = smsService->SetImsSmsConfig(slotId, enable) ? "true" : "false";
578 std::cout << "SetImsSmsConfig:" << res << std::endl;
579 }
580
TestGetImsShortMessageFormat(const sptr<ISmsServiceInterface> & smsService) const581 void GsmSmsSenderTest::TestGetImsShortMessageFormat(const sptr<ISmsServiceInterface> &smsService) const
582 {
583 if (smsService == nullptr) {
584 std::cout << "smsService is nullptr." << std::endl;
585 return;
586 }
587 std::u16string format;
588 smsService->GetImsShortMessageFormat(format);
589 std::cout << "GetImsShortMessageFormat:" << StringUtils::ToUtf8(format) << std::endl;
590 }
591
TestAddBlockPhone() const592 void GsmSmsSenderTest::TestAddBlockPhone() const
593 {
594 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataAHelper();
595 if (helper == nullptr) {
596 std::cout << "Creator helper nullptr error." << std::endl;
597 return;
598 }
599 std::string input;
600 std::cout << "Please enter block phone number" << std::endl;
601 std::getline(std::cin, input);
602
603 Uri uri("datashare:///com.ohos.contactsdataability/contacts/contact_blocklist");
604 DataShare::DataShareValuesBucket value;
605 value.Put("phone_number", input);
606 int ret = helper->Insert(uri, value);
607 helper->Release();
608 std::cout << "add block:" << input << ((ret >= 0) ? " success" : " error") << std::endl;
609 }
610
TestRemoveBlockPhone() const611 void GsmSmsSenderTest::TestRemoveBlockPhone() const
612 {
613 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataAHelper();
614 if (helper == nullptr) {
615 std::cout << "Creator helper nullptr error." << std::endl;
616 return;
617 }
618 std::string input;
619 std::cout << "Please enter Remove phone number" << std::endl;
620 std::getline(std::cin, input);
621 Uri uri("datashare:///com.ohos.contactsdataability/contacts/contact_blocklist");
622 DataShare::DataSharePredicates predicates;
623 predicates.EqualTo("phone_number", input);
624 int ret = helper->Delete(uri, predicates);
625 helper->Release();
626 std::cout << "remove block:" << input << ((ret >= 0) ? " success" : " error") << std::endl;
627 }
628
TestHasSmsCapability(const sptr<ISmsServiceInterface> & smsService) const629 void GsmSmsSenderTest::TestHasSmsCapability(const sptr<ISmsServiceInterface> &smsService) const
630 {
631 if (smsService == nullptr) {
632 std::cout << "GsmSmsSenderTest smsService is nullptr error." << std::endl;
633 return;
634 }
635 std::string res = smsService->HasSmsCapability() ? "true" : "false";
636 std::cout << "HasSmsCapability:" << res << std::endl;
637 }
638
CreateDataAHelper() const639 std::shared_ptr<DataShare::DataShareHelper> GsmSmsSenderTest::CreateDataAHelper() const
640 {
641 auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
642 if (saManager == nullptr) {
643 std::cout << "Get system ability mgr failed." << std::endl;
644 return nullptr;
645 }
646 auto remoteObj = saManager->GetSystemAbility(TELEPHONY_SMS_MMS_SYS_ABILITY_ID);
647 if (remoteObj == nullptr) {
648 std::cout << "GetSystemAbility Service Failed." << std::endl;
649 return nullptr;
650 }
651 const std::string uriContact("datashare:///com.ohos.contactsdataability");
652 return DataShare::DataShareHelper::Creator(remoteObj, uriContact);
653 }
654 } // namespace Telephony
655 } // namespace OHOS
656