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