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 <cstdio>
17 #include <cstring>
18 #include <iostream>
19 #include <map>
20
21 #include "ability_context.h"
22 #include "accesstoken_kit.h"
23 #include "common_event_manager.h"
24 #include "common_event_test.h"
25 #include "core_service_client.h"
26 #include "if_system_ability_manager.h"
27 #include "ipc_skeleton.h"
28 #include "iservice_registry.h"
29 #include "sim_account_manager.h"
30 #include "sim_state_type.h"
31 #include "string_ex.h"
32 #include "system_ability_definition.h"
33 #include "token_setproc.h"
34 #include "want.h"
35
36 using namespace std;
37 using namespace OHOS::Telephony;
38 using namespace OHOS::Security::AccessToken;
39 using OHOS::Security::AccessToken::AccessTokenID;
40
41 HapInfoParams testInfoParams = {
42 .bundleName = "tel_sim_test",
43 .userID = 1,
44 .instIndex = 0,
45 .appIDDesc = "test",
46 .isSystemApp = true,
47 };
48
49 PermissionDef testPermGetTelephonyStateDef = {
50 .permissionName = "ohos.permission.GET_TELEPHONY_STATE",
51 .bundleName = "tel_sim_test",
52 .grantMode = 1, // SYSTEM_GRANT
53 .label = "label",
54 .labelId = 1,
55 .description = "Test core service",
56 .descriptionId = 1,
57 .availableLevel = APL_SYSTEM_BASIC,
58 };
59
60 PermissionStateFull testGetTelephonyState = {
61 .grantFlags = { 2 }, // PERMISSION_USER_SET
62 .grantStatus = { PermissionState::PERMISSION_GRANTED },
63 .isGeneral = true,
64 .permissionName = "ohos.permission.GET_TELEPHONY_STATE",
65 .resDeviceID = { "local" },
66 };
67
68 PermissionDef testPermSetTelephonyStateDef = {
69 .permissionName = "ohos.permission.SET_TELEPHONY_STATE",
70 .bundleName = "tel_sim_test",
71 .grantMode = 1, // SYSTEM_GRANT
72 .label = "label",
73 .labelId = 1,
74 .description = "Test core service",
75 .descriptionId = 1,
76 .availableLevel = APL_SYSTEM_BASIC,
77 };
78
79 PermissionStateFull testSetTelephonyState = {
80 .grantFlags = { 2 }, // PERMISSION_USER_SET
81 .grantStatus = { PermissionState::PERMISSION_GRANTED },
82 .isGeneral = true,
83 .permissionName = "ohos.permission.SET_TELEPHONY_STATE",
84 .resDeviceID = { "local" },
85 };
86
87 PermissionDef testPermGetNetworkInfoDef = {
88 .permissionName = "ohos.permission.GET_NETWORK_INFO",
89 .bundleName = "tel_core_service_gtest",
90 .grantMode = 1, // SYSTEM_GRANT
91 .label = "label",
92 .labelId = 1,
93 .description = "Test core service",
94 .descriptionId = 1,
95 .availableLevel = APL_SYSTEM_BASIC,
96 };
97
98 PermissionStateFull testPermGetNetworkInfo = {
99 .grantFlags = { 2 }, // PERMISSION_USER_SET
100 .grantStatus = { PermissionState::PERMISSION_GRANTED },
101 .isGeneral = true,
102 .permissionName = "ohos.permission.GET_NETWORK_INFO",
103 .resDeviceID = { "local" },
104 };
105
106 PermissionDef testPermReadContactsDef = {
107 .permissionName = "ohos.permission.READ_CONTACTS",
108 .bundleName = "tel_sim_test",
109 .grantMode = 1, // SYSTEM_GRANT
110 .label = "label",
111 .labelId = 1,
112 .description = "Test core service",
113 .descriptionId = 1,
114 .availableLevel = APL_SYSTEM_BASIC,
115 };
116
117 PermissionStateFull testPermReadContacts = {
118 .grantFlags = { 2 }, // PERMISSION_USER_SET
119 .grantStatus = { PermissionState::PERMISSION_GRANTED },
120 .isGeneral = true,
121 .permissionName = "ohos.permission.READ_CONTACTS",
122 .resDeviceID = { "local" },
123 };
124
125 PermissionDef testPermWriteContactsDef = {
126 .permissionName = "ohos.permission.WRITE_CONTACTS",
127 .bundleName = "tel_sim_test",
128 .grantMode = 1, // SYSTEM_GRANT
129 .label = "label",
130 .labelId = 1,
131 .description = "Test core service",
132 .descriptionId = 1,
133 .availableLevel = APL_SYSTEM_BASIC,
134 };
135
136 PermissionStateFull testPermWriteContacts = {
137 .grantFlags = { 2 }, // PERMISSION_USER_SET
138 .grantStatus = { PermissionState::PERMISSION_GRANTED },
139 .isGeneral = true,
140 .permissionName = "ohos.permission.WRITE_CONTACTS",
141 .resDeviceID = { "local" },
142 };
143
144 HapPolicyParams testPolicyParams = {
145 .apl = APL_SYSTEM_BASIC,
146 .domain = "test.domain",
147 .permList = { testPermGetTelephonyStateDef, testPermSetTelephonyStateDef, testPermGetNetworkInfoDef,
148 testPermReadContactsDef, testPermWriteContactsDef },
149 .permStateList = { testGetTelephonyState, testSetTelephonyState, testPermGetNetworkInfo, testPermReadContacts,
150 testPermWriteContacts },
151 };
152
153 class AccessToken {
154 public:
AccessToken()155 AccessToken()
156 {
157 currentID_ = GetSelfTokenID();
158 AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testPolicyParams);
159 accessID_ = tokenIdEx.tokenIdExStruct.tokenID;
160 SetSelfTokenID(tokenIdEx.tokenIDEx);
161 }
~AccessToken()162 ~AccessToken()
163 {
164 AccessTokenKit::DeleteToken(accessID_);
165 SetSelfTokenID(currentID_);
166 }
167
168 private:
169 AccessTokenID currentID_ = 0;
170 AccessTokenID accessID_ = 0;
171 };
172
173 namespace OHOS {
174 namespace Telephony {
175 using CmdProcessFunc = bool (*)();
176 static sptr<ICoreService> g_telephonyService = nullptr;
177 std::unique_ptr<Telephony::SimAccountManager> g_simAccountManager = nullptr;
178
179 const int32_t SLOT_ID = DEFAULT_SIM_SLOT_ID;
180 const int32_t DEFAULT_VALUE = 0;
181 const int32_t FIX_DAILING = 2;
182 static bool g_simDiallingNumbersRead = false;
183
184 enum class InputCmd {
185 INPUT_HASSIMCARD = 0,
186 INPUT_GETSIMSTATE = 1,
187 INPUT_GETISOCOUNTRYCODE = 2,
188 INPUT_GETSPN = 3,
189 INPUT_GETICCID = 4,
190 INPUT_GETIMSI = 5,
191 INPUT_ISSIMACTIVE = 6,
192 INPUT_GETSIMOPERATOR = 7,
193 INPUT_GETGID1 = 8,
194 INPUT_GETGID2 = 9,
195 INPUT_GETSIMSUB = 10,
196 INPUT_SETDEFAULTCALL = 11,
197 INPUT_GETDEFAULTCALL = 12,
198 INPUT_GETSIMEONS = 13,
199 INPUT_UNLOCK_PIN = 21,
200 INPUT_UNLOCK_PUK = 22,
201 INPUT_ALTER_PIN = 23,
202 INPUT_CHECK_LOCK = 24,
203 INPUT_ENABLE_LOCK = 25,
204 INPUT_REFRESHSIMSTATE = 26,
205 INPUT_UNLOCK_PIN2 = 31,
206 INPUT_UNLOCK_PUK2 = 32,
207 INPUT_ALTER_PIN2 = 33,
208 INPUT_SET_ACTIVE_SIM = 34,
209 INPUT_SETSHOWNUMBER = 42,
210 INPUT_GETSHOWNUMBER = 43,
211 INPUT_SETSHOWNAME = 44,
212 INPUT_GETSHOWNAME = 45,
213 INPUT_GETACTIVEACCOUNTLIST = 46,
214 INPUT_GETOPERATORCONFIG = 47,
215 INPUT_GET_VOICEMAIL_NAME = 49,
216 INPUT_GET_VOICEMAIL_NUMBER = 50,
217 INPUT_DIALLING_NUMBERS_GET = 51,
218 INPUT_DIALLING_NUMBERS_INSERT = 52,
219 INPUT_DIALLING_NUMBERS_DELETE = 53,
220 INPUT_DIALLING_NUMBERS_UPDATE = 54,
221 INPUT_SET_VOICEMAIL = 55,
222 INPUT_GET_MAX_SIM_COUNT = 56,
223 INPUT_STK_CMD_FROM_APP = 57,
224 INPUT_STK_TERMINAL_RESPONSE = 58,
225 INPUT_STK_CALL_SETUP_REQUEST_RESULT_FROM_APP = 59,
226 INPUT_GET_OPKEY = 60,
227 INPUT_GET_PHONENUMBER = 61,
228 INPUT_GET_SIM_TELENUMBER_IDENTIFIER = 62,
229 INPUT_GET_CARD_TYPE = 63,
230 INPUT_UNLOCK_SIMLOCK = 64,
231 INPUT_SET_PRIMARY_SLOTID = 65,
232 INPUT_GET_PRIMARY_SLOTID = 66,
233 INPUT_GET_OPNAME = 67,
234 INPUT_GET_OPKEY_EXT = 68,
235 INPUT_HAS_OPERATOR_PRIVILEGES = 70,
236 INPUT_GETSIMID = 71,
237 INPUT_GETSLOTID = 72,
238 INPUT_GETDEFAULTCALLSIMID = 73,
239 INPUT_QUIT = 100,
240 INPUT_GET_VOICEMAIL_COUNT = 130,
241 INPUT_SET_VOICEMAIL_COUNT = 131,
242 INPUT_SET_VOICECALL_FORWARDING = 132,
243 INPUT_IS_CT_SIM_CARD = 133,
244 };
245
246 enum class PinWordSize {
247 PIN_MIN_SIZE = 4,
248 PIN_MAX_SIZE = 8,
249 };
250
251 enum class PinLockEnable {
252 PIN_LOCK_RESET = 0,
253 PIN_LOCK_SET,
254 };
255
256 enum class LockTypeTest {
257 PIN_LOCK_TYPE = 1,
258 FDN_LOCK_TTPE,
259 };
260
261 enum class PersoLockTypeTest {
262 SIM_PN_PIN_TYPE, // Network Personalization (refer 3GPP TS 22.022 [33])
263 SIM_PN_PUK_TYPE,
264 SIM_PU_PIN_TYPE, // network sUbset Personalization (refer 3GPP TS 22.022 [33])
265 SIM_PU_PUK_TYPE,
266 SIM_PP_PIN_TYPE, // service supplier Personalization (refer 3GPP TS 22.022 [33])
267 SIM_PP_PUK_TYPE,
268 SIM_PC_PIN_TYPE, // Corporate Personalization (refer 3GPP TS 22.022 [33])
269 SIM_PC_PUK_TYPE,
270 SIM_SIM_PIN_TYPE, // SIM/USIM personalisation (refer 3GPP TS 22.022 [33])
271 SIM_SIM_PUK_TYPE,
272 };
273
274 static std::map<InputCmd, CmdProcessFunc> g_funcMap;
275
GetProxy()276 static sptr<ICoreService> GetProxy()
277 {
278 std::cout << "TelephonyTestService GetProxy ... " << std::endl;
279 sptr<ISystemAbilityManager> systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
280 if (systemAbilityMgr == nullptr) {
281 std::cout << "TelephonyTestService Get ISystemAbilityManager failed ... " << std::endl;
282 return nullptr;
283 }
284
285 sptr<IRemoteObject> remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CORE_SERVICE_SYS_ABILITY_ID);
286 if (remote) {
287 sptr<ICoreService> telephonyService = iface_cast<ICoreService>(remote);
288 std::cout << "TelephonyTestService Get TELEPHONY_CORE_SERVICE_SYS_ABILITY_ID success ... " << std::endl;
289 return telephonyService;
290 } else {
291 std::cout << "TelephonyTestService Get TELEPHONY_CORE_SERVICE_SYS_ABILITY_ID fail ... " << std::endl;
292 return nullptr;
293 }
294 }
295
Among(int mid,PinWordSize min,PinWordSize max)296 static bool Among(int mid, PinWordSize min, PinWordSize max)
297 {
298 int minValue = static_cast<int>(min);
299 int maxValue = static_cast<int>(max);
300 return ((mid >= minValue) && (mid <= maxValue));
301 }
302
AmongLock(int mid,PinLockEnable min,PinLockEnable max)303 static bool AmongLock(int mid, PinLockEnable min, PinLockEnable max)
304 {
305 int minValue = static_cast<int>(min);
306 int maxValue = static_cast<int>(max);
307 return ((mid >= minValue) && (mid <= maxValue));
308 }
309
TestHasSimCard()310 static bool TestHasSimCard()
311 {
312 AccessToken token;
313 static int32_t testSlot = SLOT_ID;
314 std::cout << "please input Slot Id" << std::endl;
315 std::cin >> testSlot;
316 bool result = false;
317 g_telephonyService->HasSimCard(testSlot, result);
318 string expect = result ? "success" : "fail";
319 std::cout << "TelephonyTestService Remote HasSimCard result [" << result << "] " << expect << std::endl;
320 return true;
321 }
322
AmongLockType(int mid,LockTypeTest min,LockTypeTest max)323 static bool AmongLockType(int mid, LockTypeTest min, LockTypeTest max)
324 {
325 int minValue = static_cast<int>(min);
326 int maxValue = static_cast<int>(max);
327 return ((mid >= minValue) && (mid <= maxValue));
328 }
329
AmongPersoLockType(int mid,PersoLockTypeTest min,PersoLockTypeTest max)330 static bool AmongPersoLockType(int mid, PersoLockTypeTest min, PersoLockTypeTest max)
331 {
332 int minValue = static_cast<int>(min);
333 int maxValue = static_cast<int>(max);
334 return ((mid >= minValue) && (mid <= maxValue));
335 }
336
TestGetSimState()337 static bool TestGetSimState()
338 {
339 AccessToken token;
340 const int simReady = 4;
341 static int32_t testSlot = SLOT_ID;
342 std::cout << "please input Slot Id" << std::endl;
343 std::cin >> testSlot;
344 SimState simState = SimState::SIM_STATE_UNKNOWN;
345 g_telephonyService->GetSimState(testSlot, simState);
346 int32_t result = static_cast<int32_t>(simState);
347 string expect = (result == simReady) ? "success" : "fail";
348 std::cout << "TelephonyTestService Remote GetSimState result [" << result << "] " << expect << std::endl;
349 return true;
350 }
351
TestGetCardType()352 static bool TestGetCardType()
353 {
354 AccessToken token;
355 static int32_t testSlot = SLOT_ID;
356 std::cout << "please input Slot Id" << std::endl;
357 std::cin >> testSlot;
358 CardType cardType = CardType::UNKNOWN_CARD;
359 g_telephonyService->GetCardType(testSlot, cardType);
360 int32_t result = static_cast<int32_t>(cardType);
361 std::cout << "TelephonyTestService Remote GetCardType result [" << result << "] " << std::endl;
362 return true;
363 }
364
TestSetPrimarySlotId()365 static bool TestSetPrimarySlotId()
366 {
367 AccessToken token;
368 static int32_t testDefaultPrimarySlot = SLOT_ID;
369 std::cout << "please input Primary Slot Id" << std::endl;
370 std::cin >> testDefaultPrimarySlot;
371 bool result = g_telephonyService->SetPrimarySlotId(testDefaultPrimarySlot);
372 string expect = result ? "success" : "fail";
373 std::cout << "TelephonyTestService Remote SetPrimarySlotId result [" << result << "] " << expect << std::endl;
374 return true;
375 }
376
TestGetPrimarySlotId()377 static bool TestGetPrimarySlotId()
378 {
379 AccessToken token;
380 int32_t slotId;
381 int32_t result = INVALID_VALUE;
382 g_telephonyService->GetPrimarySlotId(slotId);
383 string expect = (result >= INVALID_VALUE) ? "success" : "fail";
384 std::cout << "TelephonyTestService Remote GetPrimarySlotId result [" << slotId << "] " << expect << std::endl;
385 return true;
386 }
387
TestGetISOCountryCodeForSim()388 static bool TestGetISOCountryCodeForSim()
389 {
390 AccessToken token;
391 static int32_t testSlot = SLOT_ID;
392 std::cout << "please input Slot Id" << std::endl;
393 std::cin >> testSlot;
394 std::u16string result;
395 g_telephonyService->GetISOCountryCodeForSim(testSlot, result);
396 std::string str = Str16ToStr8(result);
397 string expect = str.empty() ? "fail" : "success";
398 std::cout << "TelephonyTestService Remote GetISOCountryCodeForSim result [" << str << "] " << expect << std::endl;
399 return true;
400 }
401
TestGetSimSpn()402 static bool TestGetSimSpn()
403 {
404 AccessToken token;
405 static int32_t testSlot = SLOT_ID;
406 std::cout << "please input Slot Id" << std::endl;
407 std::cin >> testSlot;
408 std::u16string result = u"test";
409 g_telephonyService->GetSimSpn(testSlot, result);
410 std::string str = Str16ToStr8(result);
411 string expect = strcmp(str.c_str(), "test") ? "success" : "fail";
412 std::cout << "TelephonyTestService Remote GetSimSpn result [" << str << "] " << expect << std::endl;
413 return true;
414 }
415
TestGetSimIccId()416 static bool TestGetSimIccId()
417 {
418 AccessToken token;
419 int32_t slotId = 0;
420 std::cout << "please input soltid:" << std::endl;
421 std::cin >> slotId;
422 std::u16string result;
423 g_telephonyService->GetSimIccId(slotId, result);
424 std::string str = Str16ToStr8(result);
425 string expect = str.empty() ? "fail" : "success";
426 std::cout << "TelephonyTestService Remote GetSimIccId result [" << str << "] " << expect << std::endl;
427 return true;
428 }
429
TestGetSlotId()430 static bool TestGetSlotId()
431 {
432 AccessToken token;
433 int32_t simId = 0;
434 std::cout << "please input simId:" << std::endl;
435 std::cin >> simId;
436 int32_t result = -1;
437 result = g_telephonyService->GetSlotId(simId);
438 string expect = (result == -1) ? "fail" : "success";
439 std::cout << "TelephonyTestService Remote GetSlotId result [" << result << "] " << expect << std::endl;
440 return true;
441 }
442
TestGetSimId()443 static bool TestGetSimId()
444 {
445 AccessToken token;
446 int32_t slotId = 0;
447 std::cout << "please input slotId:" << std::endl;
448 std::cin >> slotId;
449 int32_t result = -1;
450 result = g_telephonyService->GetSimId(slotId);
451 string expect = (result == -1) ? "fail" : "success";
452 std::cout << "TelephonyTestService Remote GetSimId result [" << result << "] " << expect << std::endl;
453 return true;
454 }
455
TestGetSimEons()456 static bool TestGetSimEons()
457 {
458 AccessToken token;
459 int32_t slotId = 0;
460 std::cout << "please input soltId:" << std::endl;
461 std::cin >> slotId;
462 std::string plmn = "46001";
463 std::cout << "please input plmn:" << std::endl;
464 std::cin >> plmn;
465 int32_t lac = 1;
466 std::cout << "please input lac:" << std::endl;
467 std::cin >> lac;
468 bool longNameRequired = true;
469 std::cout << "please input longNameRequired:" << std::endl;
470 std::cin >> longNameRequired;
471 std::u16string result = g_telephonyService->GetSimEons(slotId, plmn, lac, longNameRequired);
472 std::string str = Str16ToStr8(result);
473 string expect = str.empty() ? "fail" : "success";
474 std::cout << "TelephonyTestService Remote GetSimEons result [" << str << "] " << expect << std::endl;
475 return true;
476 }
477
TestGetSimOperatorNumeric()478 static bool TestGetSimOperatorNumeric()
479 {
480 AccessToken token;
481 static int32_t testSlot = SLOT_ID;
482 std::cout << "please input Slot Id" << std::endl;
483 std::cin >> testSlot;
484 std::u16string result;
485 g_telephonyService->GetSimOperatorNumeric(testSlot, result);
486 std::string str = Str16ToStr8(result);
487 string expect = str.empty() ? "fail" : "success";
488 std::cout << "TelephonyTestService Remote GetSimOperatorNumeric result [" << str << "] " << expect << std::endl;
489 return true;
490 }
491
TestGetIMSI()492 static bool TestGetIMSI()
493 {
494 AccessToken token;
495 static int32_t testSlot = SLOT_ID;
496 std::cout << "please input Slot Id" << std::endl;
497 std::cin >> testSlot;
498 std::u16string imsi;
499 g_telephonyService->GetIMSI(testSlot, imsi);
500 std::string str = Str16ToStr8(imsi);
501 string expect = str.empty() ? "fail" : "success";
502 std::cout << "TelephonyTestService Remote GetIMSI result [" << str << "] " << expect << std::endl;
503 return true;
504 }
505
TestIsSimActive()506 static bool TestIsSimActive()
507 {
508 AccessToken token;
509 std::cout << "please input slot Id" << std::endl;
510 int testSim = DEFAULT_VALUE;
511 std::cin >> testSim;
512 bool result = g_telephonyService->IsSimActive(testSim);
513 string expect = result ? "success" : "fail";
514 std::cout << "TelephonyTestService Remote IsSimActive result [" << result << "] " << expect << std::endl;
515 return true;
516 }
517
TestGetSimGid1()518 static bool TestGetSimGid1()
519 {
520 AccessToken token;
521
522 static int32_t testSlot = SLOT_ID;
523 std::cout << "please input Slot Id" << std::endl;
524 std::cin >> testSlot;
525 std::u16string gid1;
526 g_telephonyService->GetSimGid1(testSlot, gid1);
527 std::string str = Str16ToStr8(gid1);
528 string expect = str.empty() ? "fail" : "success";
529 std::cout << "TelephonyTestService Remote GetSimGid1 result [" << str << "] " << expect << std::endl;
530 return true;
531 }
532
TestGetSimGid2()533 static bool TestGetSimGid2()
534 {
535 AccessToken token;
536 static int32_t testSlot = SLOT_ID;
537 std::cout << "please input Slot Id" << std::endl;
538 std::cin >> testSlot;
539 std::u16string result = g_telephonyService->GetSimGid2(testSlot);
540 std::string str = Str16ToStr8(result);
541 string expect = str.empty() ? "fail" : "success";
542 std::cout << "TelephonyTestService Remote GetSimGid2 result [" << str << "] " << expect << std::endl;
543 return true;
544 }
545
TestGetSimTelephoneNumber()546 static bool TestGetSimTelephoneNumber()
547 {
548 AccessToken token;
549 static int32_t testSlot = SLOT_ID;
550 std::cout << "please input Slot Id" << std::endl;
551 std::cin >> testSlot;
552 std::u16string result;
553 g_telephonyService->GetSimTelephoneNumber(testSlot, result);
554 std::string str = Str16ToStr8(result);
555 string expect = str.empty() ? "fail" : "success";
556 std::cout << "TelephonyTestService Remote GetSimTelephoneNumber result [" << str << "] " << expect << std::endl;
557 return true;
558 }
559
TestGetSimTeleNumberIdentifier()560 static bool TestGetSimTeleNumberIdentifier()
561 {
562 AccessToken token;
563 static int32_t testSlot = SLOT_ID;
564 std::cout << "please input Slot Id" << std::endl;
565 std::cin >> testSlot;
566 std::u16string result = g_telephonyService->GetSimTeleNumberIdentifier(testSlot);
567 std::string str = Str16ToStr8(result);
568 string expect = str.empty() ? "fail" : "success";
569 std::cout << "TelephonyTestService Remote getSimTeleNumberIdentifier result [" << str << "] " << expect
570 << std::endl;
571 return true;
572 }
573
TestGetVoiceMailIdentifier()574 static bool TestGetVoiceMailIdentifier()
575 {
576 AccessToken token;
577 static int32_t testSlot = SLOT_ID;
578 std::cout << "please input Slot Id" << std::endl;
579 std::cin >> testSlot;
580 std::u16string result;
581 g_telephonyService->GetVoiceMailIdentifier(testSlot, result);
582 std::string str = Str16ToStr8(result);
583 string expect = str.empty() ? "fail" : "success";
584 std::cout << "TelephonyTestService Remote GetVoiceMailIdentifier result [" << str << "] " << expect << std::endl;
585 return true;
586 }
587
TestGetVoiceMailNumber()588 static bool TestGetVoiceMailNumber()
589 {
590 AccessToken token;
591 static int32_t testSlot = SLOT_ID;
592 std::cout << "please input Slot Id" << std::endl;
593 std::cin >> testSlot;
594 std::u16string result;
595 g_telephonyService->GetVoiceMailNumber(testSlot, result);
596 std::string str = Str16ToStr8(result);
597 string expect = str.empty() ? "fail" : "success";
598 std::cout << "TelephonyTestService Remote GetVoiceMailNumber result [" << str << "] " << expect << std::endl;
599 return true;
600 }
601
TestGetVoiceMailCount()602 static bool TestGetVoiceMailCount()
603 {
604 AccessToken token;
605 static int32_t testSlot = SLOT_ID;
606 std::cout << "please input Slot Id" << std::endl;
607 std::cin >> testSlot;
608 int32_t result;
609 g_telephonyService->GetVoiceMailCount(testSlot, result);
610 std::cout << "TelephonyTestService Remote GetVoiceMailCount result [" << result << "] " << std::endl;
611 return true;
612 }
613
TestSetVoiceMailCount()614 static bool TestSetVoiceMailCount()
615 {
616 static int32_t testSlot = SLOT_ID;
617 int32_t voiceMailCount;
618 std::cout << "please input Slot Id" << std::endl;
619 std::cin >> testSlot;
620 std::cout << "please input voiceMailCount" << std::endl;
621 std::cin >> voiceMailCount;
622 int32_t result = g_telephonyService->SetVoiceMailCount(testSlot, voiceMailCount);
623 std::cout << "TelephonyTestService Remote SetVoiceMailCount result [" << result << "] " << std::endl;
624 return true;
625 }
626
TestSetVoiceCallForwarding()627 static bool TestSetVoiceCallForwarding()
628 {
629 static int32_t testSlot = SLOT_ID;
630 std::cout << "please input Slot Id" << std::endl;
631 std::cin >> testSlot;
632 std::string number;
633 std::cout << "please input number" << endl;
634 std::cin >> number;
635 int32_t result = g_telephonyService->SetVoiceCallForwarding(testSlot, true, number);
636 std::cout << "TelephonyTestService Remote SetVoiceCallForwarding result [" << result << "] " << std::endl;
637 return true;
638 }
639
TestIsCTSimCard()640 static bool TestIsCTSimCard()
641 {
642 AccessToken token;
643 static int32_t testSlot = SLOT_ID;
644 std::cout << "please input Slot Id" << std::endl;
645 std::cin >> testSlot;
646 bool result = false;
647 g_telephonyService->IsCTSimCard(testSlot, result);
648 string expect = result ? "success" : "fail";
649 std::cout << "TelephonyTestService Remote IsCTSimCard result [" << result << "] " << expect << std::endl;
650 return true;
651 }
652
TestQueryIccDiallingNumbers()653 static bool TestQueryIccDiallingNumbers()
654 {
655 AccessToken token;
656 int testType = 0;
657 static int32_t testSlot = SLOT_ID;
658 std::cout << "please input Slot Id" << std::endl;
659 std::cin >> testSlot;
660 int type = DiallingNumbersInfo::SIM_ADN;
661 std::cout << "please select type: 1.public dialling numbers 2.fix dialing numbers" << std::endl;
662 std::cin >> testType;
663 if (testType == FIX_DAILING) {
664 type = DiallingNumbersInfo::SIM_FDN;
665 }
666 std::cout << "TestQueryIccDiallingNumbers loading " << testType << std::endl;
667 std::vector<std::shared_ptr<DiallingNumbersInfo>> diallingNumbers;
668 int32_t result = g_telephonyService->QueryIccDiallingNumbers(testSlot, type, diallingNumbers);
669 if (result == TELEPHONY_ERR_SUCCESS) {
670 g_simDiallingNumbersRead = true;
671 }
672 if (diallingNumbers.empty()) {
673 std::cout << "no dialling numbers in sim" << std::endl;
674 return true;
675 }
676 int id = 0;
677 for (std::vector<std::shared_ptr<DiallingNumbersInfo>>::iterator it = diallingNumbers.begin();
678 it != diallingNumbers.end(); ++it) {
679 std::shared_ptr<DiallingNumbersInfo> item = *it;
680 std::string name = Str16ToStr8(item->GetName());
681 std::string number = Str16ToStr8(item->GetNumber());
682 int index = item->GetIndex();
683 int diallingNumbertype = item->GetFileId();
684 std::cout << ++id << " " << index << " " << name << " " << number << " " << diallingNumbertype << std::endl;
685 }
686 return true;
687 }
688
TestAddIccDiallingNumbers()689 static bool TestAddIccDiallingNumbers()
690 {
691 AccessToken token;
692 if (!g_simDiallingNumbersRead) {
693 std::cout << "you need run QueryIccDiallingNumbers once at least" << std::endl;
694 return true;
695 }
696 std::string name = "";
697 std::string number = "";
698 std::string pin2 = "";
699 int type = 0;
700 static int32_t testSlot = SLOT_ID;
701 std::cout << "please input Slot Id" << std::endl;
702 std::cin >> testSlot;
703 std::cout << "input name:" << std::endl;
704 std::cin >> name;
705 std::cout << "input number:" << std::endl;
706 std::cin >> number;
707 std::cout << "please select type: 1.public dialling numbers 2.fix dialing numbers" << std::endl;
708 std::cin >> type;
709 if (type == FIX_DAILING) {
710 type = DiallingNumbersInfo::SIM_FDN;
711 std::cout << "input pin2:" << std::endl;
712 std::cin >> pin2;
713 } else {
714 type = DiallingNumbersInfo::SIM_ADN;
715 }
716
717 std::shared_ptr<DiallingNumbersInfo> diallingNumber = std::make_shared<DiallingNumbersInfo>(type, 0);
718 diallingNumber->name_ = Str8ToStr16(name);
719 diallingNumber->number_ = Str8ToStr16(number);
720 diallingNumber->pin2_ = Str8ToStr16(pin2);
721 std::cout << "start insert " << Str16ToStr8(diallingNumber->name_) << " " << Str16ToStr8(diallingNumber->number_)
722 << std::endl;
723 int32_t result = g_telephonyService->AddIccDiallingNumbers(testSlot, type, diallingNumber);
724 std::cout << "TelephonyTestService Remote TestAddIccDiallingNumbers result [" << result << "] " << std::endl;
725 return true;
726 }
727
TestDelIccDiallingNumbers()728 static bool TestDelIccDiallingNumbers()
729 {
730 AccessToken token;
731 if (!g_simDiallingNumbersRead) {
732 std::cout << "you need run QueryIccDiallingNumbers once at least" << std::endl;
733 return true;
734 }
735 int type = 0;
736 int index = 0;
737 std::string pin2 = "";
738 static int32_t testSlot = SLOT_ID;
739 std::cout << "please input Slot Id" << std::endl;
740 std::cin >> testSlot;
741 std::cout << "select id:" << std::endl;
742 std::cin >> index;
743 std::cout << "please select type: 1.public dialling numbers 2.fix dialing numbers" << std::endl;
744 std::cin >> type;
745 if (type == FIX_DAILING) {
746 type = DiallingNumbersInfo::SIM_FDN;
747 std::cout << "input pin2:" << std::endl;
748 std::cin >> pin2;
749 } else {
750 type = DiallingNumbersInfo::SIM_ADN;
751 }
752
753 std::shared_ptr<DiallingNumbersInfo> diallingNumber = std::make_shared<DiallingNumbersInfo>(type, 0);
754 diallingNumber->index_ = index;
755 diallingNumber->pin2_ = Str8ToStr16(pin2);
756 int32_t result = g_telephonyService->DelIccDiallingNumbers(testSlot, type, diallingNumber);
757 std::cout << "TelephonyTestService Remote DelIccDiallingNumbers result [" << result << "] " << std::endl;
758 return true;
759 }
760
TestUpdateIccDiallingNumbers()761 static bool TestUpdateIccDiallingNumbers()
762 {
763 AccessToken token;
764 if (!g_simDiallingNumbersRead) {
765 std::cout << "you need run QueryIccDiallingNumbers once at least" << std::endl;
766 return true;
767 }
768 std::string name = "";
769 std::string number = "";
770 std::string pin2 = "";
771 int type = 0;
772 int index = 0;
773 static int32_t testSlot = SLOT_ID;
774 std::cout << "please input Slot Id" << std::endl;
775 std::cin >> testSlot;
776 std::cout << "select id:" << std::endl;
777 std::cin >> index;
778 std::cout << "input name:" << std::endl;
779 std::cin >> name;
780 std::cout << "input number:" << std::endl;
781 std::cin >> number;
782 std::cout << "please select type: 1.public dialling numbers 2.fix dialing numbers" << std::endl;
783 std::cin >> type;
784 if (type == FIX_DAILING) {
785 type = DiallingNumbersInfo::SIM_FDN;
786 std::cout << "input pin2:" << std::endl;
787 std::cin >> pin2;
788 } else {
789 type = DiallingNumbersInfo::SIM_ADN;
790 }
791
792 std::shared_ptr<DiallingNumbersInfo> diallingNumber = std::make_shared<DiallingNumbersInfo>(type, 0);
793 diallingNumber->name_ = Str8ToStr16(name);
794 diallingNumber->number_ = Str8ToStr16(number);
795 diallingNumber->pin2_ = Str8ToStr16(pin2);
796 diallingNumber->index_ = index;
797 int32_t result = g_telephonyService->UpdateIccDiallingNumbers(testSlot, type, diallingNumber);
798 std::cout << "TelephonyTestService Remote UpdateIccDiallingNumbers result [" << result << "] " << std::endl;
799 return true;
800 }
801
TestSetVoiceMailInfo()802 static bool TestSetVoiceMailInfo()
803 {
804 AccessToken token;
805 static int32_t testSlot = SLOT_ID;
806 std::cout << "please input Slot Id" << std::endl;
807 std::cin >> testSlot;
808 std::string name = "";
809 std::string number = "";
810 std::cout << "input name:" << std::endl;
811 std::cin >> name;
812 std::cout << "input number:" << std::endl;
813 std::cin >> number;
814 std::u16string mailName = Str8ToStr16(name);
815 std::u16string mailNumber = Str8ToStr16(number);
816 int32_t result = g_telephonyService->SetVoiceMailInfo(testSlot, mailName, mailNumber);
817 std::cout << "TelephonyTestService Remote SetVoiceMailInfo result [" << result << "] " << std::endl;
818 return true;
819 }
820
TestGetSimSubscriptionInfo()821 static bool TestGetSimSubscriptionInfo()
822 {
823 AccessToken token;
824 const std::u16string defaultName = u"testShowName";
825 const std::u16string defaultNumber = u"testShowNumber";
826 std::cout << "please input Sub Id" << std::endl;
827 int testSim = DEFAULT_VALUE;
828 std::cin >> testSim;
829 IccAccountInfo iccAccountInfo;
830 iccAccountInfo.Init(SLOT_ID, SLOT_ID);
831 iccAccountInfo.showName = defaultName;
832 iccAccountInfo.showNumber = defaultNumber;
833 int32_t result = g_telephonyService->GetSimAccountInfo(testSim, iccAccountInfo);
834 string expect = (result == TELEPHONY_ERR_SUCCESS) ? "success" : "fail";
835 std::cout << "TelephonyTestService Remote GetSimAccountInfo result [" << result << "] " << expect << std::endl
836 << "receive slotIndex = [" << iccAccountInfo.slotIndex << "]" << std::endl
837 << "receive showName = [" << Str16ToStr8(iccAccountInfo.showName) << "]" << std::endl
838 << "receive showNumber = [" << Str16ToStr8(iccAccountInfo.showNumber) << "]" << std::endl
839 << "receive simId = [" << iccAccountInfo.simId << "]" << std::endl
840 << "receive isEsim = [" << iccAccountInfo.isEsim << "]" << std::endl
841 << "receive isActive = [" << iccAccountInfo.isActive << "]" << std::endl
842 << "receive iccId = [" << Str16ToStr8(iccAccountInfo.iccId) << "]" << std::endl;
843 return true;
844 }
845
TestSetDefaultVoiceSlotId()846 static bool TestSetDefaultVoiceSlotId()
847 {
848 AccessToken token;
849 static int32_t testDefaultVoiceSlot = SLOT_ID;
850 std::cout << "please input Default Voice Slot Id" << std::endl;
851 std::cin >> testDefaultVoiceSlot;
852 int32_t result = g_telephonyService->SetDefaultVoiceSlotId(testDefaultVoiceSlot);
853 string expect = (result == TELEPHONY_ERR_SUCCESS) ? "success" : "fail";
854 std::cout << "TelephonyTestService Remote SetDefaultVoiceSlotId result [" << result << "] " << expect << std::endl;
855 return true;
856 }
857
TestGetDefaultVoiceSlotId()858 static bool TestGetDefaultVoiceSlotId()
859 {
860 AccessToken token;
861 int32_t result = g_telephonyService->GetDefaultVoiceSlotId();
862 string expect = (result >= INVALID_VALUE) ? "success" : "fail";
863 std::cout << "TelephonyTestService Remote GetDefaultVoiceSlotId result [" << result << "] " << expect << std::endl;
864 return true;
865 }
866
TestGetDefaultVoiceSimId()867 static bool TestGetDefaultVoiceSimId()
868 {
869 AccessToken token;
870 int32_t simId = 0;
871 int32_t result = g_telephonyService->GetDefaultVoiceSimId(simId);
872 string expect = (result >= INVALID_VALUE) ? "success" : "fail";
873 std::cout << "TelephonyTestService Remote GetDefaultVoiceSimId result [" << result << "] " << expect << std::endl;
874 return true;
875 }
876
TestSetShowNumber()877 static bool TestSetShowNumber()
878 {
879 AccessToken token;
880 int32_t slot;
881 std::cout << "please input Slot Id" << std::endl;
882 std::cin >> slot;
883 std::string showNumber;
884 std::cout << "please input showNumber" << std::endl;
885 std::cin >> showNumber;
886 int32_t result = g_telephonyService->SetShowNumber(slot, Str8ToStr16(showNumber));
887 string expect = (result == TELEPHONY_ERR_SUCCESS) ? "success" : "fail";
888 std::cout << "TelephonyTestService Remote SetShowNumber result [" << result << "] " << expect << std::endl;
889 return true;
890 }
891
TestSetShowName()892 static bool TestSetShowName()
893 {
894 AccessToken token;
895 int32_t slot;
896 std::cout << "please input Slot Id" << std::endl;
897 std::cin >> slot;
898 std::string showName;
899 std::cout << "please input showName" << std::endl;
900 std::cin >> showName;
901 int32_t result = g_telephonyService->SetShowName(slot, Str8ToStr16(showName));
902 string expect = (result == TELEPHONY_ERR_SUCCESS) ? "success" : "fail";
903 std::cout << "TelephonyTestService Remote SetShowName result [" << result << "] " << expect << std::endl;
904 return true;
905 }
906
TestGetShowNumber()907 static bool TestGetShowNumber()
908 {
909 AccessToken token;
910 int32_t slot;
911 std::cout << "please input Slot Id" << std::endl;
912 std::cin >> slot;
913 std::u16string result;
914 g_telephonyService->GetShowNumber(slot, result);
915 string expect = (!result.empty()) ? "success" : "fail";
916 std::cout << "TelephonyTestService Remote SetShowNumber result [" << Str16ToStr8(result) << "] " << expect
917 << std::endl;
918 return true;
919 }
920
TestGetShowName()921 static bool TestGetShowName()
922 {
923 AccessToken token;
924 int32_t slot;
925 std::cout << "please input Slot Id" << std::endl;
926 std::cin >> slot;
927 std::u16string result;
928 g_telephonyService->GetShowName(slot, result);
929 string expect = (!result.empty()) ? "success" : "fail";
930 std::cout << "TelephonyTestService Remote GetShowName result [" << Str16ToStr8(result) << "] " << expect
931 << std::endl;
932 return true;
933 }
934
TestGetActiveSimAccountInfoList()935 static bool TestGetActiveSimAccountInfoList()
936 {
937 AccessToken token;
938 std::vector<IccAccountInfo> iccAccountInfoList;
939 int32_t result = g_telephonyService->GetActiveSimAccountInfoList(iccAccountInfoList);
940 string expect = (result == TELEPHONY_ERR_SUCCESS) ? "success" : "fail";
941 int i = 1;
942 std::cout << "TelephonyTestService Remote GetActiveSimAccountInfoList result [" << result << "] " << expect
943 << std::endl;
944 for (IccAccountInfo iccAccountInfo : iccAccountInfoList) {
945 std::cout << i << ". receive slotIndex = [" << iccAccountInfo.slotIndex << "]" << std::endl
946 << i << ". receive showName = [" << Str16ToStr8(iccAccountInfo.showName) << "]" << std::endl
947 << i << ". receive showNumber = [" << Str16ToStr8(iccAccountInfo.showNumber) << "]" << std::endl
948 << i << ". receive simId = [" << iccAccountInfo.simId << "]" << std::endl
949 << i << ". receive isEsim = [" << iccAccountInfo.isEsim << "]" << std::endl
950 << i << ". receive isActive = [" << iccAccountInfo.isActive << "]" << std::endl
951 << i << ". receive iccId = [" << Str16ToStr8(iccAccountInfo.iccId) << "]" << std::endl;
952 i++;
953 }
954 return true;
955 }
956
TestGetOperatorConfig()957 static bool TestGetOperatorConfig()
958 {
959 AccessToken token;
960 OperatorConfig oc;
961 int32_t result = g_telephonyService->GetOperatorConfigs(DEFAULT_SIM_SLOT_ID, oc);
962 string expect = (result == TELEPHONY_ERR_SUCCESS) ? "success" : "fail";
963 std::cout << "TelephonyTestService Remote GetOperatorConfigs result [" << result << "] " << expect << std::endl;
964 std::map<std::u16string, std::u16string>::iterator valueIt = oc.configValue.begin();
965 while (valueIt != oc.configValue.end()) {
966 std::cout << "configValue key = " << Str16ToStr8(valueIt->first).c_str() << std::endl
967 << "configValue value = " << Str16ToStr8(valueIt->second).c_str() << std::endl;
968 ++valueIt;
969 }
970 return true;
971 }
972
TestUnlockPin()973 static bool TestUnlockPin()
974 {
975 AccessToken token;
976 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
977 std::string pin = " ";
978 int size = 0;
979 static int32_t testSlot = SLOT_ID;
980 std::cout << "please input Slot Id" << std::endl;
981 std::cin >> testSlot;
982 while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
983 std::cout << "\n Unlock pin start, Please input pin \n";
984 std::cin >> pin;
985 size = pin.size();
986 }
987 std::cout << "Unlock pin: pin = " << pin << endl;
988 g_telephonyService->UnlockPin(testSlot, Str8ToStr16(pin.c_str()), response);
989 std::cout << "Unlock pin complete:" << response.result << " " << response.remain << std::endl;
990 return true;
991 }
992
TestUnlockPuk()993 static bool TestUnlockPuk()
994 {
995 AccessToken token;
996 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
997 std::string newPin = " ";
998 std::string puk = " ";
999 int size = 0;
1000 static int32_t testSlot = SLOT_ID;
1001 std::cout << "please input Slot Id" << std::endl;
1002 std::cin >> testSlot;
1003 while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
1004 std::cout << "\n Unlock puk start, Please input new pin \n";
1005 std::cin >> newPin;
1006 size = newPin.size();
1007 }
1008 size = 0;
1009 while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
1010 std::cout << "\n Unlock puk start, Please input puk \n";
1011 std::cin >> puk;
1012 size = puk.size();
1013 }
1014 std::cout << "Unlock puk: newPin = " << newPin << " puk = " << puk << endl;
1015 g_telephonyService->UnlockPuk(testSlot, Str8ToStr16(newPin.c_str()), Str8ToStr16(puk.c_str()), response);
1016 std::cout << "Unlock puk complete:" << response.result << " " << response.remain << std::endl;
1017 return true;
1018 }
1019
TestAlterPin()1020 static bool TestAlterPin()
1021 {
1022 AccessToken token;
1023 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1024 std::string oldPin = " ";
1025 std::string newPin = " ";
1026 int size = 0;
1027 static int32_t testSlot = SLOT_ID;
1028 std::cout << "please input Slot Id" << std::endl;
1029 std::cin >> testSlot;
1030 while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
1031 std::cout << "\n Alter pin start, Please input old pin \n";
1032 std::cin >> oldPin;
1033 size = oldPin.size();
1034 }
1035 size = 0;
1036 while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
1037 std::cout << "\n Alter pin start, Please input new pin \n";
1038 std::cin >> newPin;
1039 size = newPin.size();
1040 }
1041 std::cout << "Unlock pin: oldPin = " << oldPin << " newPin = " << newPin << endl;
1042 g_telephonyService->AlterPin(testSlot, Str8ToStr16(newPin.c_str()), Str8ToStr16(oldPin.c_str()), response);
1043 std::cout << "Alter pin complete:" << response.result << " " << response.remain << std::endl;
1044 return true;
1045 }
1046
TestUnlockPin2()1047 static bool TestUnlockPin2()
1048 {
1049 AccessToken token;
1050 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1051 std::string pin2 = " ";
1052 int size = 0;
1053 static int32_t testSlot = SLOT_ID;
1054 std::cout << "please input Slot Id" << std::endl;
1055 std::cin >> testSlot;
1056 while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
1057 std::cout << "\n Unlock pin2 start, Please input pin2 \n";
1058 std::cin >> pin2;
1059 size = pin2.size();
1060 }
1061 std::cout << "Unlock pin2: pin2 = " << pin2 << endl;
1062 g_telephonyService->UnlockPin2(testSlot, Str8ToStr16(pin2.c_str()), response);
1063 std::cout << "Unlock pin2 complete:" << response.result << " " << response.remain << std::endl;
1064 return true;
1065 }
1066
TestUnlockPuk2()1067 static bool TestUnlockPuk2()
1068 {
1069 AccessToken token;
1070 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1071 std::string newPin2 = " ";
1072 std::string puk2 = " ";
1073 int size = 0;
1074 static int32_t testSlot = SLOT_ID;
1075 std::cout << "please input Slot Id" << std::endl;
1076 std::cin >> testSlot;
1077 while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
1078 std::cout << "\n Unlock puk2 start, Please input new pin2 \n";
1079 std::cin >> newPin2;
1080 size = newPin2.size();
1081 }
1082 size = 0;
1083 while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
1084 std::cout << "\n Unlock puk2 start, Please input puk2 \n";
1085 std::cin >> puk2;
1086 size = puk2.size();
1087 }
1088 std::cout << "Unlock puk2: newPin2 = " << newPin2 << " puk2 = " << puk2 << endl;
1089 g_telephonyService->UnlockPuk2(testSlot, Str8ToStr16(newPin2.c_str()), Str8ToStr16(puk2.c_str()), response);
1090 std::cout << "Unlock puk complete:" << response.result << " " << response.remain << std::endl;
1091 return true;
1092 }
1093
TestAlterPin2()1094 static bool TestAlterPin2()
1095 {
1096 AccessToken token;
1097 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1098 std::string oldPin2 = " ";
1099 std::string newPin2 = " ";
1100 int size = 0;
1101 static int32_t testSlot = SLOT_ID;
1102 std::cout << "please input Slot Id" << std::endl;
1103 std::cin >> testSlot;
1104 while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
1105 std::cout << "\n Alter pin2 start, Please input old pin2 \n";
1106 std::cin >> oldPin2;
1107 size = oldPin2.size();
1108 }
1109 size = 0;
1110 while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
1111 std::cout << "\n Alter pin2 start, Please input new pin2 \n";
1112 std::cin >> newPin2;
1113 size = newPin2.size();
1114 }
1115 std::cout << "Unlock pin2: oldPin2 = " << oldPin2 << " newPin2 = " << newPin2 << endl;
1116 g_telephonyService->AlterPin2(testSlot, Str8ToStr16(newPin2.c_str()), Str8ToStr16(oldPin2.c_str()), response);
1117 std::cout << "Alter pin2 complete:" << response.result << " " << response.remain << std::endl;
1118 return true;
1119 }
1120
TestSetLockState()1121 static bool TestSetLockState()
1122 {
1123 AccessToken token;
1124 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1125 int32_t testType = -1;
1126 std::string testPin = " ";
1127 int32_t mode = -1;
1128 int32_t size = 0;
1129 while (!AmongLockType(testType, LockTypeTest::PIN_LOCK_TYPE, LockTypeTest::FDN_LOCK_TTPE)) {
1130 std::cout << "\n Set lock switch, Please input lock type (1. PIN_LOCK 2. FDN_LOCK)\n";
1131 std::cin >> testType;
1132 }
1133 while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
1134 if (static_cast<int32_t>(LockTypeTest::PIN_LOCK_TYPE) == testType) {
1135 std::cout << "\n Set pin lock switch, Please input pin \n";
1136 } else {
1137 std::cout << "\n Set pin lock switch, Please input pin2 \n";
1138 }
1139 std::cin >> testPin;
1140 size = testPin.size();
1141 }
1142 size = 0;
1143 while (!AmongLock(mode, PinLockEnable::PIN_LOCK_RESET, PinLockEnable::PIN_LOCK_SET)) {
1144 std::cout << "\n Set lock switch, Please input switch (0. RESET 1. SET)\n";
1145 std::cin >> mode;
1146 }
1147 std::cout << "SetLockState: pin = " << testPin << " mode = " << mode << endl;
1148 LockInfo testInfo;
1149 testInfo.password = Str8ToStr16(testPin);
1150 testInfo.lockState = static_cast<LockState>(mode);
1151 testInfo.lockType = static_cast<LockType>(testType);
1152 static int32_t testSlot = SLOT_ID;
1153 std::cout << "please input Slot Id" << std::endl;
1154 std::cin >> testSlot;
1155 g_telephonyService->SetLockState(testSlot, testInfo, response);
1156 std::cout << "Set Lock complete:" << response.result << " " << response.remain << std::endl;
1157 return true;
1158 }
1159
TestGetLockState()1160 static bool TestGetLockState()
1161 {
1162 AccessToken token;
1163 int32_t testType = -1;
1164 while (!AmongLockType(testType, LockTypeTest::PIN_LOCK_TYPE, LockTypeTest::FDN_LOCK_TTPE)) {
1165 std::cout << "\n Set lock switch, Please input lock type (1. PIN_LOCK 2. FDN_LOCK)\n";
1166 std::cin >> testType;
1167 }
1168 LockState lockState = LockState::LOCK_ERROR;
1169 LockType lockType = static_cast<LockType>(testType);
1170 static int32_t testSlot = SLOT_ID;
1171 std::cout << "please input Slot Id" << std::endl;
1172 std::cin >> testSlot;
1173 g_telephonyService->GetLockState(testSlot, lockType, lockState);
1174 std::cout << "TestGetLockState()" << static_cast<int32_t>(lockState) << endl;
1175 return true;
1176 }
1177
TestRefreshSimState()1178 static bool TestRefreshSimState()
1179 {
1180 AccessToken token;
1181 static int32_t testSlot = SLOT_ID;
1182 std::cout << "please input Slot Id" << std::endl;
1183 std::cin >> testSlot;
1184 int32_t ret = g_telephonyService->RefreshSimState(testSlot);
1185 std::cout << "TestRefreshSimState()" << ret << endl;
1186 return true;
1187 }
1188
TestSetActiveSim()1189 static bool TestSetActiveSim()
1190 {
1191 AccessToken token;
1192 int32_t enable = ACTIVE;
1193 int32_t slotId = DEFAULT_SIM_SLOT_ID;
1194 std::cout << "please input sim Id" << endl;
1195 std::cin >> slotId;
1196 std::cout << "\n Set active sim enable, Please input enable \n";
1197 std::cin >> enable;
1198
1199 int32_t result = g_telephonyService->SetActiveSim(slotId, enable);
1200 std::cout << "TestSetActiveSim(), result = " << result << endl;
1201 return true;
1202 }
1203
TestGetMaxSimCount()1204 static bool TestGetMaxSimCount()
1205 {
1206 AccessToken token;
1207 int32_t result = g_telephonyService->GetMaxSimCount();
1208 string expect = (result != INVALID_VALUE) ? "success" : "fail";
1209 std::cout << "TelephonyTestService Remote GetMaxSimCount result [" << result << "] " << expect << std::endl;
1210 return true;
1211 }
1212
TestGetOpKey()1213 static bool TestGetOpKey()
1214 {
1215 AccessToken token;
1216 std::u16string opkey;
1217 static int32_t testSlot = SLOT_ID;
1218 std::cout << "please input Slot Id" << std::endl;
1219 std::cin >> testSlot;
1220 int32_t result = g_telephonyService->GetOpKey(testSlot, opkey);
1221 std::string str = Str16ToStr8(opkey);
1222 string expect = (result == TELEPHONY_ERR_SUCCESS) ? "success" : "fail";
1223 std::cout << "TestGetOpKey Remote GetOpKey result [" << str << "] " << expect << std::endl;
1224 return true;
1225 }
1226
TestGetOpName()1227 static bool TestGetOpName()
1228 {
1229 AccessToken token;
1230 std::u16string opname;
1231 static int32_t testSlot = SLOT_ID;
1232 std::cout << "please input Slot Id" << std::endl;
1233 std::cin >> testSlot;
1234 int32_t result = g_telephonyService->GetOpName(testSlot, opname);
1235 std::string str = Str16ToStr8(opname);
1236 string expect = (result == TELEPHONY_ERR_SUCCESS) ? "success" : "fail";
1237 std::cout << "TestGetOpName Remote GetOpName result [" << str << "] " << expect << std::endl;
1238 return true;
1239 }
1240
TestGetOpKeyExt()1241 static bool TestGetOpKeyExt()
1242 {
1243 AccessToken token;
1244 std::u16string opkeyExt;
1245 static int32_t testSlot = SLOT_ID;
1246 std::cout << "please input Slot Id" << std::endl;
1247 std::cin >> testSlot;
1248 int32_t result = g_telephonyService->GetOpKeyExt(testSlot, opkeyExt);
1249 std::string str = Str16ToStr8(opkeyExt);
1250 string expect = (result == TELEPHONY_ERR_SUCCESS) ? "success" : "fail";
1251 std::cout << "TestGetOpKeyExt Remote GetOpKeyExt result [" << str << "] " << expect << std::endl;
1252 return true;
1253 }
1254
GetSimLockType()1255 static int32_t GetSimLockType()
1256 {
1257 AccessToken token;
1258 int32_t testType = -1;
1259 while (!AmongPersoLockType(testType, PersoLockTypeTest::SIM_PN_PIN_TYPE, PersoLockTypeTest::SIM_SIM_PUK_TYPE)) {
1260 std::cout << "\n Set lock switch, Please input lock type number(\n"
1261 " 0. Network Personalization PIN\n"
1262 " 1. Network Personalization PUK\n"
1263 " 2. Network sub Personalization PIN\n"
1264 " 3. Network sub Personalization PUK\n"
1265 " 4. service supplier Personalization PIN\n"
1266 " 5. service supplier Personalization PUK\n"
1267 " 6. Corporate Personalization PIN\n"
1268 " 7. Corporate Personalization PUK\n"
1269 " 8. SIM/USIM Personalization PIN\n"
1270 " 9. SIM/USIM Personalization PUK)\n";
1271 std::cin >> testType;
1272 }
1273 return testType;
1274 }
1275
GetSimLockPassword(int32_t testType)1276 static std::string GetSimLockPassword(int32_t testType)
1277 {
1278 AccessToken token;
1279 std::string password = "";
1280 int size = 0;
1281 while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
1282 PersoLockTypeTest lockType = static_cast<PersoLockTypeTest>(testType);
1283 switch (lockType) {
1284 case PersoLockTypeTest::SIM_PN_PIN_TYPE:
1285 std::cout << "\n select 0. Please input Network Personalization PIN \n";
1286 break;
1287 case PersoLockTypeTest::SIM_PN_PUK_TYPE:
1288 std::cout << "\n select 1. Please input Network Personalization PUK \n";
1289 break;
1290 case PersoLockTypeTest::SIM_PU_PIN_TYPE:
1291 std::cout << "\n select 2. Please input Network sub Personalization PIN \n";
1292 break;
1293 case PersoLockTypeTest::SIM_PU_PUK_TYPE:
1294 std::cout << "\n select 3. Please input Network sub Personalization PUK \n";
1295 break;
1296 case PersoLockTypeTest::SIM_PP_PIN_TYPE:
1297 std::cout << "\n select 4. Please input service supplier Personalization PIN \n";
1298 break;
1299 case PersoLockTypeTest::SIM_PP_PUK_TYPE:
1300 std::cout << "\n select 5. Please input service supplier Personalization PUK \n";
1301 break;
1302 case PersoLockTypeTest::SIM_PC_PIN_TYPE:
1303 std::cout << "\n select 6. Please input Corporate Personalization PIN \n";
1304 break;
1305 case PersoLockTypeTest::SIM_PC_PUK_TYPE:
1306 std::cout << "\n select 7. Please input Corporate Personalization PUK \n";
1307 break;
1308 case PersoLockTypeTest::SIM_SIM_PIN_TYPE:
1309 std::cout << "\n select 8. Please input SIM/USIM personalisation PIN \n";
1310 break;
1311 case PersoLockTypeTest::SIM_SIM_PUK_TYPE:
1312 std::cout << "\n select 9. Please input SIM/USIM personalisation PUK \n";
1313 break;
1314 default:
1315 break;
1316 }
1317 std::cin >> password;
1318 size = password.size();
1319 }
1320 return password;
1321 }
1322
TestUnlockSimLock()1323 static bool TestUnlockSimLock()
1324 {
1325 AccessToken token;
1326 int32_t slotId = DEFAULT_SIM_SLOT_ID;
1327 std::cout << "please input sim Id" << endl;
1328 std::cin >> slotId;
1329 if (slotId != DEFAULT_SIM_SLOT_ID) {
1330 std::cout << "incorrect slot ID" << endl;
1331 return true;
1332 }
1333 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
1334 PersoLockInfo lockInfo;
1335 int32_t testType = GetSimLockType();
1336 std::string password = GetSimLockPassword(testType);
1337 std::cout << "UnlockSimLock: password = " << password << endl;
1338 lockInfo.password = Str8ToStr16(password);
1339 lockInfo.lockType = static_cast<PersoLockType>(testType);
1340 g_telephonyService->UnlockSimLock(slotId, lockInfo, response);
1341 std::cout << "UnlockSimLock complete:" << response.result << " " << response.remain << std::endl;
1342 return true;
1343 }
1344
TestHasOperatorPrivileges()1345 static bool TestHasOperatorPrivileges()
1346 {
1347 AccessToken token;
1348 std::cout << "input slotId:" << std::endl;
1349 int32_t slotId = 0;
1350 std::cin >> slotId;
1351 bool hasOperatorPrivileges = false;
1352 int32_t result = g_telephonyService->HasOperatorPrivileges(slotId, hasOperatorPrivileges);
1353 std::cout << "TelephonyTestService Remote TestHasOperatorPrivileges result [" << result << "] " << std::endl;
1354 return true;
1355 }
1356
TestSendTerminalResponseCmd()1357 static bool TestSendTerminalResponseCmd()
1358 {
1359 AccessToken token;
1360 int32_t slotId = DEFAULT_SIM_SLOT_ID;
1361 std::cout << "please input slotId" << endl;
1362 std::cin >> slotId;
1363 std::string cmd = "";
1364 std::cout << "input terminal response command" << std::endl;
1365 std::cin >> cmd;
1366 int32_t result = g_telephonyService->SendTerminalResponseCmd(slotId, cmd);
1367 std::cout << "TelephonyTestService Remote SendTerminalResponseCmd result [" << result << "] " << std::endl;
1368 return true;
1369 }
1370
TestSendEnvelopeCmd()1371 static bool TestSendEnvelopeCmd()
1372 {
1373 AccessToken token;
1374 int32_t slotId = DEFAULT_SIM_SLOT_ID;
1375 std::cout << "please input slotId" << endl;
1376 std::cin >> slotId;
1377 std::string cmd = "";
1378 std::cout << "input envelope command" << std::endl;
1379 std::cin >> cmd;
1380 int32_t result = g_telephonyService->SendEnvelopeCmd(slotId, cmd);
1381 std::cout << "TelephonyTestService Remote SendEnvelopeCmd result [" << result << "] " << std::endl;
1382 return true;
1383 }
1384
TestSendCallSetupRequestResult()1385 static bool TestSendCallSetupRequestResult()
1386 {
1387 AccessToken token;
1388 int32_t slotId = DEFAULT_SIM_SLOT_ID;
1389 std::cout << "please input slotId" << endl;
1390 std::cin >> slotId;
1391 int32_t accept = 0;
1392 std::cout << "input call setup request result" << std::endl;
1393 std::cin >> accept;
1394 int32_t result = g_telephonyService->SendCallSetupRequestResult(slotId, accept);
1395 std::cout << "TelephonyTestService Remote SendCallSetupRequestResult result [" << result << "] " << std::endl;
1396 return true;
1397 }
1398
TestQuit()1399 static bool TestQuit()
1400 {
1401 std::cout << "exit..." << std::endl;
1402 g_funcMap.clear();
1403 return false;
1404 }
1405
Prompt()1406 static void Prompt()
1407 {
1408 std::cout << "\n start \nusage:please input a cmd num:\n"
1409 "0:HasSimCard\n1:GetSimState\n2:GetISOCountryCodeForSim\n3:GetSimSpn\n"
1410 "4:GetSimIccId\n5:GetIMSI\n6:IsSimActive\n7:GetSimOperatorNumeric\n"
1411 "8:GetSimGid1\n9:GetSimGid2\n10:GetSimAccountInfo\n11:SetDefaultVoiceSlotId\n"
1412 "12:GetDefaultVoiceSlotId\n13:GetSimEons\n21:UnlockPin\n"
1413 "22:UnlockPuk\n23:AlterPin\n24:GetLockState\n25:SetLockState\n"
1414 "26:RefreshSimState\n31:UnlockPin2\n32:UnlockPuk2\n"
1415 "33:AlterPin2\n34:SetActiveSim\n42:SetShowNumber\n"
1416 "43:GetShowNumber\n44:SetShowName\n45:GetShowName\n"
1417 "46:GetActiveSimAccountInfoList\n47:GetOperatorConfigs\n"
1418 "49:GetVoiceMailIdentifier\n50:GetVoiceMailNumber\n51:QueryIccDiallingNumbers\n"
1419 "52:AddIccDiallingNumbers\n53:DelIccDiallingNumbers\n54:UpdateIccDiallingNumbers\n"
1420 "55:SetVoiceMailInfo\n56:GetMaxSimCount\n57:TestSendEnvelopeCmd\n"
1421 "58:TestSendTerminalResponseCmd\n59:TestSendCallSetupRequestResult\n60:GetOpKey\n"
1422 "61:GetSimTelephoneNumber\n62:GetSimTeleNumberIdentifier\n63:GetCardType\n"
1423 "64:UnlockSimLock\n65:SetPrimarySlotId\n66:GetPrimarySlotId\n67:GetOpName\n"
1424 "68:GetOpKeyExt\n70:HasOperatorPrivileges\n71:TestGetSimId\n72:TestGetSlotId\n"
1425 "73:TestGetDefaultVoiceSimId\n"
1426 "130:GetVoiceMailCount\n131:SetVoiceMailCount\n132:SetVoiceCallForwarding\n"
1427 "133:TestIsCTSimCard\n"
1428 "100:exit\n"
1429 << std::endl;
1430 }
1431
InitFuncMap()1432 static void InitFuncMap()
1433 {
1434 g_funcMap[InputCmd::INPUT_HASSIMCARD] = TestHasSimCard;
1435 g_funcMap[InputCmd::INPUT_GETSIMSTATE] = TestGetSimState;
1436 g_funcMap[InputCmd::INPUT_GETISOCOUNTRYCODE] = TestGetISOCountryCodeForSim;
1437 g_funcMap[InputCmd::INPUT_GETSPN] = TestGetSimSpn;
1438 g_funcMap[InputCmd::INPUT_GETICCID] = TestGetSimIccId;
1439 g_funcMap[InputCmd::INPUT_GETSIMEONS] = TestGetSimEons;
1440 g_funcMap[InputCmd::INPUT_ISSIMACTIVE] = TestIsSimActive;
1441 g_funcMap[InputCmd::INPUT_GETSIMOPERATOR] = TestGetSimOperatorNumeric;
1442 g_funcMap[InputCmd::INPUT_GETGID1] = TestGetSimGid1;
1443 g_funcMap[InputCmd::INPUT_GETGID2] = TestGetSimGid2;
1444 g_funcMap[InputCmd::INPUT_GETSIMSUB] = TestGetSimSubscriptionInfo;
1445 g_funcMap[InputCmd::INPUT_SET_ACTIVE_SIM] = TestSetActiveSim;
1446 g_funcMap[InputCmd::INPUT_GETACTIVEACCOUNTLIST] = TestGetActiveSimAccountInfoList;
1447 g_funcMap[InputCmd::INPUT_REFRESHSIMSTATE] = TestRefreshSimState;
1448 g_funcMap[InputCmd::INPUT_GET_MAX_SIM_COUNT] = TestGetMaxSimCount;
1449 g_funcMap[InputCmd::INPUT_GET_PHONENUMBER] = TestGetSimTelephoneNumber;
1450 g_funcMap[InputCmd::INPUT_GET_SIM_TELENUMBER_IDENTIFIER] = TestGetSimTeleNumberIdentifier;
1451 g_funcMap[InputCmd::INPUT_UNLOCK_SIMLOCK] = TestUnlockSimLock;
1452 }
1453
InitFuncMapExt()1454 static void InitFuncMapExt()
1455 {
1456 g_funcMap[InputCmd::INPUT_GETIMSI] = TestGetIMSI;
1457 g_funcMap[InputCmd::INPUT_SETDEFAULTCALL] = TestSetDefaultVoiceSlotId;
1458 g_funcMap[InputCmd::INPUT_GETDEFAULTCALL] = TestGetDefaultVoiceSlotId;
1459 g_funcMap[InputCmd::INPUT_GETDEFAULTCALLSIMID] = TestGetDefaultVoiceSimId;
1460 g_funcMap[InputCmd::INPUT_UNLOCK_PIN] = TestUnlockPin;
1461 g_funcMap[InputCmd::INPUT_UNLOCK_PUK] = TestUnlockPuk;
1462 g_funcMap[InputCmd::INPUT_ALTER_PIN] = TestAlterPin;
1463 g_funcMap[InputCmd::INPUT_SETSHOWNAME] = TestSetShowName;
1464 g_funcMap[InputCmd::INPUT_SETSHOWNUMBER] = TestSetShowNumber;
1465 g_funcMap[InputCmd::INPUT_CHECK_LOCK] = TestGetLockState;
1466 g_funcMap[InputCmd::INPUT_ENABLE_LOCK] = TestSetLockState;
1467 g_funcMap[InputCmd::INPUT_UNLOCK_PIN2] = TestUnlockPin2;
1468 g_funcMap[InputCmd::INPUT_UNLOCK_PUK2] = TestUnlockPuk2;
1469 g_funcMap[InputCmd::INPUT_ALTER_PIN2] = TestAlterPin2;
1470 g_funcMap[InputCmd::INPUT_GETSHOWNUMBER] = TestGetShowNumber;
1471 g_funcMap[InputCmd::INPUT_GETSHOWNAME] = TestGetShowName;
1472 g_funcMap[InputCmd::INPUT_GETOPERATORCONFIG] = TestGetOperatorConfig;
1473 g_funcMap[InputCmd::INPUT_GET_VOICEMAIL_NAME] = TestGetVoiceMailIdentifier;
1474 g_funcMap[InputCmd::INPUT_GET_VOICEMAIL_NUMBER] = TestGetVoiceMailNumber;
1475 g_funcMap[InputCmd::INPUT_DIALLING_NUMBERS_GET] = TestQueryIccDiallingNumbers;
1476 g_funcMap[InputCmd::INPUT_DIALLING_NUMBERS_INSERT] = TestAddIccDiallingNumbers;
1477 g_funcMap[InputCmd::INPUT_DIALLING_NUMBERS_DELETE] = TestDelIccDiallingNumbers;
1478 g_funcMap[InputCmd::INPUT_DIALLING_NUMBERS_UPDATE] = TestUpdateIccDiallingNumbers;
1479 g_funcMap[InputCmd::INPUT_SET_VOICEMAIL] = TestSetVoiceMailInfo;
1480 g_funcMap[InputCmd::INPUT_STK_CMD_FROM_APP] = TestSendEnvelopeCmd;
1481 g_funcMap[InputCmd::INPUT_STK_TERMINAL_RESPONSE] = TestSendTerminalResponseCmd;
1482 g_funcMap[InputCmd::INPUT_STK_CALL_SETUP_REQUEST_RESULT_FROM_APP] = TestSendCallSetupRequestResult;
1483 g_funcMap[InputCmd::INPUT_GET_OPKEY] = TestGetOpKey;
1484 g_funcMap[InputCmd::INPUT_GET_OPNAME] = TestGetOpName;
1485 g_funcMap[InputCmd::INPUT_GET_OPKEY_EXT] = TestGetOpKeyExt;
1486 g_funcMap[InputCmd::INPUT_GET_CARD_TYPE] = TestGetCardType;
1487 g_funcMap[InputCmd::INPUT_HAS_OPERATOR_PRIVILEGES] = TestHasOperatorPrivileges;
1488 g_funcMap[InputCmd::INPUT_SET_PRIMARY_SLOTID] = TestSetPrimarySlotId;
1489 g_funcMap[InputCmd::INPUT_GET_PRIMARY_SLOTID] = TestGetPrimarySlotId;
1490 g_funcMap[InputCmd::INPUT_GETSIMID] = TestGetSimId;
1491 g_funcMap[InputCmd::INPUT_GETSLOTID] = TestGetSlotId;
1492 g_funcMap[InputCmd::INPUT_QUIT] = TestQuit;
1493 g_funcMap[InputCmd::INPUT_GET_VOICEMAIL_COUNT] = TestGetVoiceMailCount;
1494 g_funcMap[InputCmd::INPUT_SET_VOICEMAIL_COUNT] = TestSetVoiceMailCount;
1495 g_funcMap[InputCmd::INPUT_SET_VOICECALL_FORWARDING] = TestSetVoiceCallForwarding;
1496 g_funcMap[InputCmd::INPUT_IS_CT_SIM_CARD] = TestIsCTSimCard;
1497 }
1498
ProcessInput()1499 static bool ProcessInput()
1500 {
1501 int inputCMDKey = DEFAULT_VALUE;
1502 bool loopFlag = true;
1503 std::cin >> inputCMDKey;
1504 std::cout << "inputCMD is [" << inputCMDKey << "]" << std::endl;
1505 InputCmd inputCMD = static_cast<InputCmd>(inputCMDKey);
1506 auto itFunc = g_funcMap.find(inputCMD);
1507 if (itFunc != g_funcMap.end()) {
1508 auto cmdFunc = itFunc->second;
1509 if (cmdFunc != nullptr) {
1510 loopFlag = (*cmdFunc)();
1511 }
1512 } else {
1513 std::cout << "please input correct number..." << std::endl;
1514 }
1515 return loopFlag;
1516 }
1517 } // namespace Telephony
1518 } // namespace OHOS
1519
1520 using namespace OHOS::Telephony;
main()1521 int main()
1522 {
1523 g_telephonyService = GetProxy();
1524 if (g_telephonyService == nullptr) {
1525 return 1;
1526 }
1527
1528 OHOS::EventFwk::MatchingSkills matchingSkills;
1529 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED);
1530 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SIM_CARD_DEFAULT_VOICE_SUBSCRIPTION_CHANGED);
1531 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SIM_CARD_DEFAULT_SMS_SUBSCRIPTION_CHANGED);
1532 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SIM_CARD_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
1533 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SIM_CARD_DEFAULT_MAIN_SUBSCRIPTION_CHANGED);
1534 // STK
1535 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_STK_SESSION_END);
1536 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_STK_COMMAND);
1537 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_STK_ALPHA_IDENTIFIER);
1538 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_STK_CARD_STATE_CHANGED);
1539 OHOS::EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1540 subscribeInfo.SetPriority(1);
1541 std::shared_ptr<CommonEventTest> subScriber = std::make_shared<CommonEventTest>(subscribeInfo);
1542 OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subScriber);
1543
1544 InitFuncMap();
1545 InitFuncMapExt();
1546 bool loopFlag = true;
1547 while (loopFlag) {
1548 Prompt();
1549 loopFlag = ProcessInput();
1550 }
1551 std::cout << " exit test " << std::endl;
1552 }
1553