• 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 "common_event_test.h"
22 #include "core_service_client.h"
23 #include "common_event_manager.h"
24 #include "if_system_ability_manager.h"
25 #include "ipc_skeleton.h"
26 #include "iservice_registry.h"
27 #include "string_ex.h"
28 #include "system_ability_definition.h"
29 #include "want.h"
30 #include "sim_account_manager.h"
31 #include "sim_state_type.h"
32 
33 using namespace std;
34 using namespace OHOS::Telephony;
35 namespace OHOS {
36 namespace Telephony {
37 using CmdProcessFunc = bool (*)();
38 static sptr<ICoreService> g_telephonyService = nullptr;
39 std::unique_ptr<Telephony::SimAccountManager> g_simAccountManager = nullptr;
40 
41 const int32_t SLOT_ID = DEFAULT_SIM_SLOT_ID;
42 const int32_t DEFAULT_VALUE = 0;
43 const int32_t FIX_DAILING = 2;
44 static bool g_simDiallingNumbersRead = false;
45 
46 enum class InputCmd {
47     INPUT_HASSIMCARD = 0,
48     INPUT_GETSIMSTATE = 1,
49     INPUT_GETISOCOUNTRYCODE = 2,
50     INPUT_GETSPN = 3,
51     INPUT_GETICCID = 4,
52     INPUT_GETIMSI = 5,
53     INPUT_ISSIMACTIVE = 6,
54     INPUT_GETSIMOPERATOR = 7,
55     INPUT_GETGID1 = 8,
56     INPUT_GETSIMSUB = 10,
57     INPUT_SETDEFAULTCALL = 11,
58     INPUT_GETDEFAULTCALL = 12,
59     INPUT_UNLOCK_PIN = 21,
60     INPUT_UNLOCK_PUK = 22,
61     INPUT_ALTER_PIN = 23,
62     INPUT_CHECK_LOCK = 24,
63     INPUT_ENABLE_LOCK = 25,
64     INPUT_REFRESHSIMSTATE = 26,
65     INPUT_UNLOCK_PIN2 = 31,
66     INPUT_UNLOCK_PUK2 = 32,
67     INPUT_ALTER_PIN2 = 33,
68     INPUT_SET_ACTIVE_SIM = 34,
69     INPUT_SETSHOWNUMBER = 42,
70     INPUT_GETSHOWNUMBER = 43,
71     INPUT_SETSHOWNAME = 44,
72     INPUT_GETSHOWNAME = 45,
73     INPUT_GETACTIVEACCOUNTLIST = 46,
74     INPUT_GETOPERATORCONFIG = 47,
75     INPUT_GET_VOICEMAIL_NAME = 49,
76     INPUT_GET_VOICEMAIL_NUMBER = 50,
77     INPUT_DIALLING_NUMBERS_GET = 51,
78     INPUT_DIALLING_NUMBERS_INSERT = 52,
79     INPUT_DIALLING_NUMBERS_DELETE = 53,
80     INPUT_DIALLING_NUMBERS_UPDATE = 54,
81     INPUT_SET_VOICEMAIL = 55,
82     INPUT_GET_MAX_SIM_COUNT = 56,
83     INPUT_STK_CMD_FROM_APP = 57,
84     INPUT_STK_TERMINAL_RESPONSE = 58,
85     INPUT_GET_PHONENUMBER = 60,
86     INPUT_GET_SIM_TELENUMBER_IDENTIFIER = 61,
87     INPUT_GET_CARD_TYPE = 62,
88     INPUT_UNLOCK_SIMLOCK = 63,
89     INPUT_SET_PRIMARY_SLOTID = 64,
90     INPUT_GET_PRIMARY_SLOTID = 65,
91     INPUT_HAS_OPERATOR_PRIVILEGES = 70,
92     INPUT_QUIT = 100,
93 };
94 
95 enum class PinWordSize {
96     PIN_MIN_SIZE = 4,
97     PIN_MAX_SIZE = 8,
98 };
99 
100 enum class PinLockEnable {
101     PIN_LOCK_RESET = 0,
102     PIN_LOCK_SET,
103 };
104 
105 enum class LockTypeTest {
106     PIN_LOCK_TYPE = 1,
107     FDN_LOCK_TTPE,
108 };
109 
110 enum class PersoLockTypeTest {
111     SIM_PN_PIN_TYPE, // Network Personalization (refer 3GPP TS 22.022 [33])
112     SIM_PN_PUK_TYPE,
113     SIM_PU_PIN_TYPE, // network sUbset Personalization (refer 3GPP TS 22.022 [33])
114     SIM_PU_PUK_TYPE,
115     SIM_PP_PIN_TYPE, // service supplier Personalization (refer 3GPP TS 22.022 [33])
116     SIM_PP_PUK_TYPE,
117     SIM_PC_PIN_TYPE, // Corporate Personalization (refer 3GPP TS 22.022 [33])
118     SIM_PC_PUK_TYPE,
119     SIM_SIM_PIN_TYPE, // SIM/USIM personalisation (refer 3GPP TS 22.022 [33])
120     SIM_SIM_PUK_TYPE,
121 };
122 
123 static std::map<InputCmd, CmdProcessFunc> g_funcMap;
124 
GetProxy()125 static sptr<ICoreService> GetProxy()
126 {
127     std::cout << "TelephonyTestService GetProxy ... " << std::endl;
128     sptr<ISystemAbilityManager> systemAbilityMgr =
129         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
130     if (systemAbilityMgr == nullptr) {
131         std::cout << "TelephonyTestService Get ISystemAbilityManager failed ... " << std::endl;
132         return nullptr;
133     }
134 
135     sptr<IRemoteObject> remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CORE_SERVICE_SYS_ABILITY_ID);
136     if (remote) {
137         sptr<ICoreService> telephonyService = iface_cast<ICoreService>(remote);
138         std::cout << "TelephonyTestService Get TELEPHONY_CORE_SERVICE_SYS_ABILITY_ID success ... " << std::endl;
139         return telephonyService;
140     } else {
141         std::cout << "TelephonyTestService Get TELEPHONY_CORE_SERVICE_SYS_ABILITY_ID fail ... " << std::endl;
142         return nullptr;
143     }
144 }
145 
Among(int mid,PinWordSize min,PinWordSize max)146 static bool Among(int mid, PinWordSize min, PinWordSize max)
147 {
148     int minValue = static_cast<int>(min);
149     int maxValue = static_cast<int>(max);
150     return ((mid >= minValue) && (mid <= maxValue));
151 }
152 
AmongLock(int mid,PinLockEnable min,PinLockEnable max)153 static bool AmongLock(int mid, PinLockEnable min, PinLockEnable max)
154 {
155     int minValue = static_cast<int>(min);
156     int maxValue = static_cast<int>(max);
157     return ((mid >= minValue) && (mid <= maxValue));
158 }
159 
TestHasSimCard()160 static bool TestHasSimCard()
161 {
162     bool result = g_telephonyService->HasSimCard(SLOT_ID);
163     string expect = result ? "success" : "fail";
164     std::cout << "TelephonyTestService Remote HasSimCard result [" << result << "] " << expect << std::endl;
165     return true;
166 }
167 
AmongLockType(int mid,LockTypeTest min,LockTypeTest max)168 static bool AmongLockType(int mid, LockTypeTest min, LockTypeTest max)
169 {
170     int minValue = static_cast<int>(min);
171     int maxValue = static_cast<int>(max);
172     return ((mid >= minValue) && (mid <= maxValue));
173 }
174 
AmongPersoLockType(int mid,PersoLockTypeTest min,PersoLockTypeTest max)175 static bool AmongPersoLockType(int mid, PersoLockTypeTest min, PersoLockTypeTest max)
176 {
177     int minValue = static_cast<int>(min);
178     int maxValue = static_cast<int>(max);
179     return ((mid >= minValue) && (mid <= maxValue));
180 }
181 
TestGetSimState()182 static bool TestGetSimState()
183 {
184     const int simReady = 4;
185     int32_t result = static_cast<int32_t>(g_telephonyService->GetSimState(SLOT_ID));
186     string expect = (result == simReady) ? "success" : "fail";
187     std::cout << "TelephonyTestService Remote GetSimState result [" << result << "] " << expect << std::endl;
188     return true;
189 }
190 
TestGetCardType()191 static bool TestGetCardType()
192 {
193     int32_t result = static_cast<int32_t>(g_telephonyService->GetCardType(SLOT_ID));
194     std::cout << "TelephonyTestService Remote GetCardType result [" << result << "] " << std::endl;
195     return true;
196 }
197 
TestSetPrimarySlotId()198 static bool TestSetPrimarySlotId()
199 {
200     static int32_t testDefaultPrimarySlot = SLOT_ID;
201     std::cout << "please input Primary Slot Id" << std::endl;
202     std::cin >> testDefaultPrimarySlot;
203     bool result = g_telephonyService->SetPrimarySlotId(testDefaultPrimarySlot);
204     string expect = result ? "success" : "fail";
205     std::cout << "TelephonyTestService Remote SetPrimarySlotId result [" << result << "] " << expect
206               << std::endl;
207     return true;
208 }
209 
TestGetPrimarySlotId()210 static bool TestGetPrimarySlotId()
211 {
212     int32_t result = g_telephonyService->GetPrimarySlotId();
213     string expect = (result != INVALID_VALUE) ? "success" : "fail";
214     std::cout << "TelephonyTestService Remote GetPrimarySlotId result [" << result << "] " << expect
215               << std::endl;
216     return true;
217 }
218 
TestGetISOCountryCodeForSim()219 static bool TestGetISOCountryCodeForSim()
220 {
221     std::u16string result = g_telephonyService->GetISOCountryCodeForSim(SLOT_ID);
222     std::string str = Str16ToStr8(result);
223     string expect = str.empty() ? "fail" : "success";
224     std::cout << "TelephonyTestService Remote GetISOCountryCodeForSim result [" << str << "] " << expect
225               << std::endl;
226     return true;
227 }
228 
TestGetSimSpn()229 static bool TestGetSimSpn()
230 {
231     std::u16string result = g_telephonyService->GetSimSpn(SLOT_ID);
232     std::string str = Str16ToStr8(result);
233     string expect = str.empty() ? "fail" : "success";
234     std::cout << "TelephonyTestService Remote GetSimSpn result [" << str << "] " << expect << std::endl;
235     return true;
236 }
237 
TestGetSimIccId()238 static bool TestGetSimIccId()
239 {
240     int32_t slotId = 0;
241     std::cout << "please input soltid:"<<std::endl;
242     std::cin >> slotId;
243     std::u16string result = g_telephonyService->GetSimIccId(slotId);
244     std::string str = Str16ToStr8(result);
245     string expect = str.empty() ? "fail" : "success";
246     std::cout << "TelephonyTestService Remote GetSimIccId result [" << str << "] " << expect << std::endl;
247     return true;
248 }
249 
TestGetSimOperatorNumeric()250 static bool TestGetSimOperatorNumeric()
251 {
252     std::u16string result = g_telephonyService->GetSimOperatorNumeric(SLOT_ID);
253     std::string str = Str16ToStr8(result);
254     string expect = str.empty() ? "fail" : "success";
255     std::cout << "TelephonyTestService Remote GetSimOperatorNumeric result [" << str << "] " << expect << std::endl;
256     return true;
257 }
258 
TestGetIMSI()259 static bool TestGetIMSI()
260 {
261     std::u16string result = g_telephonyService->GetIMSI(SLOT_ID);
262     std::string str = Str16ToStr8(result);
263     string expect = str.empty() ? "fail" : "success";
264     std::cout << "TelephonyTestService Remote GetIMSI result [" << str << "] " << expect << std::endl;
265     return true;
266 }
267 
TestIsSimActive()268 static bool TestIsSimActive()
269 {
270     std::cout << "please input slot Id" << std::endl;
271     int testSim = DEFAULT_VALUE;
272     std::cin >> testSim;
273     bool result = g_telephonyService->IsSimActive(testSim);
274     string expect = result ? "success" : "fail";
275     std::cout << "TelephonyTestService Remote IsSimActive result [" << result << "] " << expect << std::endl;
276     return true;
277 }
278 
TestGetSimGid1()279 static bool TestGetSimGid1()
280 {
281     std::u16string result = g_telephonyService->GetSimGid1(SLOT_ID);
282     std::string str = Str16ToStr8(result);
283     string expect = str.empty() ? "fail" : "success";
284     std::cout << "TelephonyTestService Remote GetSimGid1 result [" << str << "] " << expect << std::endl;
285     return true;
286 }
287 
TestGetSimTelephoneNumber()288 static bool TestGetSimTelephoneNumber()
289 {
290     std::u16string result = g_telephonyService->GetSimTelephoneNumber(SLOT_ID);
291     std::string str = Str16ToStr8(result);
292     string expect = str.empty() ? "fail" : "success";
293     std::cout << "TelephonyTestService Remote GetSimTelephoneNumber result [" << str << "] " << expect << std::endl;
294     return true;
295 }
296 
TestGetSimTeleNumberIdentifier()297 static bool TestGetSimTeleNumberIdentifier()
298 {
299     std::u16string result = g_telephonyService->GetSimTeleNumberIdentifier(SLOT_ID);
300     std::string str = Str16ToStr8(result);
301     string expect = str.empty() ? "fail" : "success";
302     std::cout << "TelephonyTestService Remote getSimTeleNumberIdentifier result [" << str << "] " << expect
303               << std::endl;
304     return true;
305 }
306 
TestGetVoiceMailIdentifier()307 static bool TestGetVoiceMailIdentifier()
308 {
309     std::u16string result = g_telephonyService->GetVoiceMailIdentifier(SLOT_ID);
310     std::string str = Str16ToStr8(result);
311     string expect = str.empty() ? "fail" : "success";
312     std::cout << "TelephonyTestService Remote GetVoiceMailIdentifier result [" << str << "] " << expect
313               << std::endl;
314     return true;
315 }
316 
TestGetVoiceMailNumber()317 static bool TestGetVoiceMailNumber()
318 {
319     std::u16string result = g_telephonyService->GetVoiceMailNumber(SLOT_ID);
320     std::string str = Str16ToStr8(result);
321     string expect = str.empty() ? "fail" : "success";
322     std::cout << "TelephonyTestService Remote GetVoiceMailNumber result [" << str << "] " << expect << std::endl;
323     return true;
324 }
325 
TestQueryIccDiallingNumbers()326 static bool TestQueryIccDiallingNumbers()
327 {
328     int testType = 0;
329     int type = DiallingNumbersInfo::SIM_ADN;
330     std::cout << "please select type: 1.public dialling numbers 2.fix dialing numbers" << std::endl;
331     std::cin >> testType;
332     if (testType == FIX_DAILING) {
333         type = DiallingNumbersInfo::SIM_FDN;
334     }
335     std::cout << "TestQueryIccDiallingNumbers loading " << testType << std::endl;
336     std::vector<std::shared_ptr<DiallingNumbersInfo>> diallingNumbers =
337         g_telephonyService->QueryIccDiallingNumbers(SLOT_ID, type);
338     g_simDiallingNumbersRead = true;
339     if (diallingNumbers.empty()) {
340         std::cout << "no dialling numbers in sim" << std::endl;
341         return true;
342     }
343     int id = 0;
344     for (std::vector<std::shared_ptr<DiallingNumbersInfo>>::iterator it = diallingNumbers.begin();
345          it != diallingNumbers.end(); it++) {
346         std::shared_ptr<DiallingNumbersInfo> item = *it;
347         std::string name = Str16ToStr8(item->GetName());
348         std::string number = Str16ToStr8(item->GetNumber());
349         int index = item->GetIndex();
350         int diallingNumbertype = item->GetFileId();
351         std::cout << ++id << "  " << index << " " << name << "  " << number << "  " << diallingNumbertype
352                   << std::endl;
353     }
354     return true;
355 }
356 
TestAddIccDiallingNumbers()357 static bool TestAddIccDiallingNumbers()
358 {
359     if (!g_simDiallingNumbersRead) {
360         std::cout << "you need run QueryIccDiallingNumbers once at least" << std::endl;
361         return true;
362     }
363     std::string name = "";
364     std::string number = "";
365     std::string pin2 = "";
366     int type = 0;
367     std::cout << "input name:" << std::endl;
368     std::cin >> name;
369     std::cout << "input number:" << std::endl;
370     std::cin >> number;
371     std::cout << "please select type: 1.public dialling numbers 2.fix dialing numbers" << std::endl;
372     std::cin >> type;
373     if (type == FIX_DAILING) {
374         type = DiallingNumbersInfo::SIM_FDN;
375         std::cout << "input pin2:" << std::endl;
376         std::cin >> pin2;
377     } else {
378         type = DiallingNumbersInfo::SIM_ADN;
379     }
380 
381     std::shared_ptr<DiallingNumbersInfo> diallingNumber = std::make_shared<DiallingNumbersInfo>(type, 0);
382     diallingNumber->name_ = Str8ToStr16(name);
383     diallingNumber->number_ = Str8ToStr16(number);
384     diallingNumber->pin2_ = Str8ToStr16(pin2);
385     std::cout << "start insert " << Str16ToStr8(diallingNumber->name_) << " "
386               << Str16ToStr8(diallingNumber->number_) << std::endl;
387     bool result = g_telephonyService->AddIccDiallingNumbers(SLOT_ID, type, diallingNumber);
388     std::cout << "TelephonyTestService Remote TestAddIccDiallingNumbers result [" << result << "] " << std::endl;
389     return true;
390 }
391 
TestDelIccDiallingNumbers()392 static bool TestDelIccDiallingNumbers()
393 {
394     if (!g_simDiallingNumbersRead) {
395         std::cout << "you need run QueryIccDiallingNumbers once at least" << std::endl;
396         return true;
397     }
398     int type = 0;
399     int index = 0;
400     std::string pin2 = "";
401     std::cout << "select id:" << std::endl;
402     std::cin >> index;
403     std::cout << "please select type: 1.public dialling numbers 2.fix dialing numbers" << std::endl;
404     std::cin >> type;
405     if (type == FIX_DAILING) {
406         type = DiallingNumbersInfo::SIM_FDN;
407         std::cout << "input pin2:" << std::endl;
408         std::cin >> pin2;
409     } else {
410         type = DiallingNumbersInfo::SIM_ADN;
411     }
412 
413     std::shared_ptr<DiallingNumbersInfo> diallingNumber = std::make_shared<DiallingNumbersInfo>(type, 0);
414     diallingNumber->index_ = index;
415     diallingNumber->pin2_ = Str8ToStr16(pin2);
416     bool result = g_telephonyService->DelIccDiallingNumbers(SLOT_ID, type, diallingNumber);
417     std::cout << "TelephonyTestService Remote DelIccDiallingNumbers result [" << result << "] " << std::endl;
418     return true;
419 }
420 
TestUpdateIccDiallingNumbers()421 static bool TestUpdateIccDiallingNumbers()
422 {
423     if (!g_simDiallingNumbersRead) {
424         std::cout << "you need run QueryIccDiallingNumbers once at least" << std::endl;
425         return true;
426     }
427     std::string name = "";
428     std::string number = "";
429     std::string pin2 = "";
430     int type = 0;
431     int index = 0;
432     std::cout << "select id:" << std::endl;
433     std::cin >> index;
434     std::cout << "input name:" << std::endl;
435     std::cin >> name;
436     std::cout << "input number:" << std::endl;
437     std::cin >> number;
438     std::cout << "please select type: 1.public dialling numbers 2.fix dialing numbers" << std::endl;
439     std::cin >> type;
440     if (type == FIX_DAILING) {
441         type = DiallingNumbersInfo::SIM_FDN;
442         std::cout << "input pin2:" << std::endl;
443         std::cin >> pin2;
444     } else {
445         type = DiallingNumbersInfo::SIM_ADN;
446     }
447 
448     std::shared_ptr<DiallingNumbersInfo> diallingNumber = std::make_shared<DiallingNumbersInfo>(type, 0);
449     diallingNumber->name_ = Str8ToStr16(name);
450     diallingNumber->number_ = Str8ToStr16(number);
451     diallingNumber->pin2_ = Str8ToStr16(pin2);
452     diallingNumber->index_ = index;
453     bool result = g_telephonyService->UpdateIccDiallingNumbers(SLOT_ID, type, diallingNumber);
454     std::cout << "TelephonyTestService Remote UpdateIccDiallingNumbers result [" << result << "] " << std::endl;
455     return true;
456 }
457 
TestSetVoiceMailInfo()458 static bool TestSetVoiceMailInfo()
459 {
460     std::string name = "";
461     std::string number = "";
462     std::cout << "input name:" << std::endl;
463     std::cin >> name;
464     std::cout << "input number:" << std::endl;
465     std::cin >> number;
466     std::u16string mailName = Str8ToStr16(name);
467     std::u16string mailNumber = Str8ToStr16(number);
468     bool result = g_telephonyService->SetVoiceMailInfo(SLOT_ID, mailName, mailNumber);
469     std::cout << "TelephonyTestService Remote SetVoiceMailInfo result [" << result << "] " << std::endl;
470     return true;
471 }
472 
TestGetSimSubscriptionInfo()473 static bool TestGetSimSubscriptionInfo()
474 {
475     const std::u16string defaultName = u"testShowName";
476     const std::u16string defaultNumber = u"testShowNumber";
477     std::cout << "please input Sub Id" << std::endl;
478     int testSim = DEFAULT_VALUE;
479     std::cin >> testSim;
480     IccAccountInfo iccAccountInfo;
481     iccAccountInfo.Init(SLOT_ID, SLOT_ID);
482     iccAccountInfo.showName = defaultName;
483     iccAccountInfo.showNumber = defaultNumber;
484     bool result = g_telephonyService->GetSimAccountInfo(testSim, iccAccountInfo);
485     string expect = result ? "success" : "fail";
486     std::cout << "TelephonyTestService Remote GetSimAccountInfo result [" << result << "] " << expect << std::endl
487               << "receive slotIndex = [" << iccAccountInfo.slotIndex << "]" << std::endl
488               << "receive showName = [" << Str16ToStr8(iccAccountInfo.showName) << "]" << std::endl
489               << "receive showNumber = [" << Str16ToStr8(iccAccountInfo.showNumber) << "]" << std::endl
490               << "receive simId = [" << iccAccountInfo.simId << "]" << std::endl
491               << "receive isEsim = [" << iccAccountInfo.isEsim << "]" << std::endl
492               << "receive isActive = [" << iccAccountInfo.isActive << "]" << std::endl
493               << "receive iccId = [" << Str16ToStr8(iccAccountInfo.iccId) << "]" << std::endl;
494     return true;
495 }
496 
TestSetDefaultVoiceSlotId()497 static bool TestSetDefaultVoiceSlotId()
498 {
499     static int32_t testDefaultVoiceSlot = SLOT_ID;
500     std::cout << "please input Default Voice Slot Id" << std::endl;
501     std::cin >> testDefaultVoiceSlot;
502     bool result = g_telephonyService->SetDefaultVoiceSlotId(testDefaultVoiceSlot);
503     string expect = result ? "success" : "fail";
504     std::cout << "TelephonyTestService Remote SetDefaultVoiceSlotId result [" << result << "] " << expect
505               << std::endl;
506     return true;
507 }
508 
TestGetDefaultVoiceSlotId()509 static bool TestGetDefaultVoiceSlotId()
510 {
511     int32_t result = g_telephonyService->GetDefaultVoiceSlotId();
512     string expect = (result != INVALID_VALUE) ? "success" : "fail";
513     std::cout << "TelephonyTestService Remote GetDefaultVoiceSlotId result [" << result << "] " << expect
514               << std::endl;
515     return true;
516 }
517 
TestSetShowNumber()518 static bool TestSetShowNumber()
519 {
520     int32_t slot;
521     std::cout << "please input Slot Id" << std::endl;
522     std::cin >> slot;
523     std::string showNumber;
524     std::cout << "please input showNumber" << std::endl;
525     std::cin >> showNumber;
526     bool result = g_telephonyService->SetShowNumber(slot, Str8ToStr16(showNumber));
527     string expect = result ? "success" : "fail";
528     std::cout << "TelephonyTestService Remote SetShowNumber result [" << result << "] " << expect << std::endl;
529     return true;
530 }
531 
TestSetShowName()532 static bool TestSetShowName()
533 {
534     int32_t slot;
535     std::cout << "please input Slot Id" << std::endl;
536     std::cin >> slot;
537     std::string showName;
538     std::cout << "please input showName" << std::endl;
539     std::cin >> showName;
540     bool result = g_telephonyService->SetShowName(slot, Str8ToStr16(showName));
541     string expect = result ? "success" : "fail";
542     std::cout << "TelephonyTestService Remote SetShowName result [" << result << "] " << expect << std::endl;
543     return true;
544 }
545 
TestGetShowNumber()546 static bool TestGetShowNumber()
547 {
548     int32_t slot;
549     std::cout << "please input Slot Id" << std::endl;
550     std::cin >> slot;
551     std::u16string result = g_telephonyService->GetShowNumber(slot);
552     string expect = (!result.empty()) ? "success" : "fail";
553     std::cout << "TelephonyTestService Remote SetShowNumber result [" << Str16ToStr8(result) << "] " << expect
554               << std::endl;
555     return true;
556 }
557 
TestGetShowName()558 static bool TestGetShowName()
559 {
560     int32_t slot;
561     std::cout << "please input Slot Id" << std::endl;
562     std::cin >> slot;
563     std::u16string result = g_telephonyService->GetShowName(slot);
564     string expect = (!result.empty()) ? "success" : "fail";
565     std::cout << "TelephonyTestService Remote GetShowName result [" << Str16ToStr8(result) << "] " << expect
566               << std::endl;
567     return true;
568 }
569 
TestGetActiveSimAccountInfoList()570 static bool TestGetActiveSimAccountInfoList()
571 {
572     std::vector<IccAccountInfo> iccAccountInfoList;
573     bool result = g_telephonyService->GetActiveSimAccountInfoList(iccAccountInfoList);
574     string expect = result ? "success" : "fail";
575     int i = 1;
576     std::cout << "TelephonyTestService Remote GetActiveSimAccountInfoList result [" << result << "] " << expect
577               << std::endl;
578     for (IccAccountInfo iccAccountInfo : iccAccountInfoList) {
579         std::cout << i << ". receive slotIndex = [" << iccAccountInfo.slotIndex << "]" << std::endl
580                   << i << ". receive showName = [" << Str16ToStr8(iccAccountInfo.showName) << "]" << std::endl
581                   << i << ". receive showNumber = [" << Str16ToStr8(iccAccountInfo.showNumber) << "]" << std::endl
582                   << i << ". receive simId = [" << iccAccountInfo.simId << "]" << std::endl
583                   << i << ". receive isEsim = [" << iccAccountInfo.isEsim << "]" << std::endl
584                   << i << ". receive isActive = [" << iccAccountInfo.isActive << "]" << std::endl
585                   << i << ". receive iccId = [" << Str16ToStr8(iccAccountInfo.iccId) << "]" << std::endl;
586         i++;
587     }
588     return true;
589 }
590 
TestGetOperatorConfig()591 static bool TestGetOperatorConfig()
592 {
593     OperatorConfig oc;
594     bool result = g_telephonyService->GetOperatorConfigs(DEFAULT_SIM_SLOT_ID, oc);
595     string expect = result ? "success" : "fail";
596     std::cout << "TelephonyTestService Remote GetOperatorConfigs result [" << result << "] " << expect << std::endl;
597     std::map<std::u16string, std::u16string>::iterator valueIt = oc.configValue.begin();
598     while (valueIt != oc.configValue.end()) {
599         std::cout << "configValue key = " << Str16ToStr8(valueIt->first).c_str() << std::endl
600                   << "configValue value = " << Str16ToStr8(valueIt->second).c_str() << std::endl;
601         valueIt++;
602     }
603     return true;
604 }
605 
TestUnlockPin()606 static bool TestUnlockPin()
607 {
608     LockStatusResponse response = {0};
609     std::string pin = " ";
610     int size = 0;
611     while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
612         std::cout << "\n Unlock pin start, Please input pin \n";
613         std::cin >> pin;
614         size = pin.size();
615     }
616     std::cout << "Unlock pin: pin = " << pin << endl;
617     g_telephonyService->UnlockPin(SLOT_ID, Str8ToStr16(pin.c_str()), response);
618     std::cout << "Unlock pin complete:" << response.result << " " << response.remain << std::endl;
619     return true;
620 }
621 
TestUnlockPuk()622 static bool TestUnlockPuk()
623 {
624     LockStatusResponse response = {0};
625     std::string newPin = " ";
626     std::string puk = " ";
627     int size = 0;
628     while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
629         std::cout << "\n Unlock puk start, Please input new pin \n";
630         std::cin >> newPin;
631         size = newPin.size();
632     }
633     size = 0;
634     while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
635         std::cout << "\n Unlock puk start, Please input puk \n";
636         std::cin >> puk;
637         size = puk.size();
638     }
639     std::cout << "Unlock puk: newPin = " << newPin << "  puk = " << puk << endl;
640     g_telephonyService->UnlockPuk(SLOT_ID, Str8ToStr16(newPin.c_str()), Str8ToStr16(puk.c_str()), response);
641     std::cout << "Unlock puk complete:" << response.result << " " << response.remain << std::endl;
642     return true;
643 }
644 
TestAlterPin()645 static bool TestAlterPin()
646 {
647     LockStatusResponse response = {0};
648     std::string oldPin = " ";
649     std::string newPin = " ";
650     int size = 0;
651     while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
652         std::cout << "\n Alter pin start, Please input old pin \n";
653         std::cin >> oldPin;
654         size = oldPin.size();
655     }
656     size = 0;
657     while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
658         std::cout << "\n Alter pin start, Please input new pin \n";
659         std::cin >> newPin;
660         size = newPin.size();
661     }
662     std::cout << "Unlock pin: oldPin = " << oldPin << "  newPin = " << newPin << endl;
663     g_telephonyService->AlterPin(SLOT_ID, Str8ToStr16(newPin.c_str()), Str8ToStr16(oldPin.c_str()), response);
664     std::cout << "Alter pin complete:" << response.result << " " << response.remain << std::endl;
665     return true;
666 }
667 
TestUnlockPin2()668 static bool TestUnlockPin2()
669 {
670     LockStatusResponse response = {0};
671     std::string pin2 = " ";
672     int size = 0;
673     while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
674         std::cout << "\n Unlock pin2 start, Please input pin2 \n";
675         std::cin >> pin2;
676         size = pin2.size();
677     }
678     std::cout << "Unlock pin2: pin2 = " << pin2 << endl;
679     g_telephonyService->UnlockPin2(SLOT_ID, Str8ToStr16(pin2.c_str()), response);
680     std::cout << "Unlock pin2 complete:" << response.result << " " << response.remain << std::endl;
681     return true;
682 }
683 
TestUnlockPuk2()684 static bool TestUnlockPuk2()
685 {
686     LockStatusResponse response = {0};
687     std::string newPin2 = " ";
688     std::string puk2 = " ";
689     int size = 0;
690     while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
691         std::cout << "\n Unlock puk2 start, Please input new pin2 \n";
692         std::cin >> newPin2;
693         size = newPin2.size();
694     }
695     size = 0;
696     while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
697         std::cout << "\n Unlock puk2 start, Please input puk2 \n";
698         std::cin >> puk2;
699         size = puk2.size();
700     }
701     std::cout << "Unlock puk2: newPin2 = " << newPin2 << "  puk2 = " << puk2 << endl;
702     g_telephonyService->UnlockPuk2(SLOT_ID, Str8ToStr16(newPin2.c_str()), Str8ToStr16(puk2.c_str()), response);
703     std::cout << "Unlock puk complete:" << response.result << " " << response.remain << std::endl;
704     return true;
705 }
706 
TestAlterPin2()707 static bool TestAlterPin2()
708 {
709     LockStatusResponse response = {0};
710     std::string oldPin2 = " ";
711     std::string newPin2 = " ";
712     int size = 0;
713     while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
714         std::cout << "\n Alter pin2 start, Please input old pin2 \n";
715         std::cin >> oldPin2;
716         size = oldPin2.size();
717     }
718     size = 0;
719     while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
720         std::cout << "\n Alter pin2 start, Please input new pin2 \n";
721         std::cin >> newPin2;
722         size = newPin2.size();
723     }
724     std::cout << "Unlock pin2: oldPin2 = " << oldPin2 << "  newPin2 = " << newPin2 << endl;
725     g_telephonyService->AlterPin2(SLOT_ID, Str8ToStr16(newPin2.c_str()), Str8ToStr16(oldPin2.c_str()), response);
726     std::cout << "Alter pin2 complete:" << response.result << " " << response.remain << std::endl;
727     return true;
728 }
729 
TestSetLockState()730 static bool TestSetLockState()
731 {
732     LockStatusResponse response = {0};
733     int32_t testType = -1;
734     std::string testPin = " ";
735     int32_t mode = -1;
736     int32_t size = 0;
737     while (!AmongLockType(testType, LockTypeTest::PIN_LOCK_TYPE, LockTypeTest::FDN_LOCK_TTPE)) {
738         std::cout << "\n Set lock switch, Please input lock type (1. PIN_LOCK  2. FDN_LOCK)\n";
739         std::cin >> testType;
740     }
741     while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
742         if (static_cast<int32_t>(LockTypeTest::PIN_LOCK_TYPE) == testType) {
743             std::cout << "\n Set pin lock switch, Please input pin \n";
744         } else {
745             std::cout << "\n Set pin lock switch, Please input pin2 \n";
746         }
747         std::cin >> testPin;
748         size = testPin.size();
749     }
750     size = 0;
751     while (!AmongLock(mode, PinLockEnable::PIN_LOCK_RESET, PinLockEnable::PIN_LOCK_SET)) {
752         std::cout << "\n Set lock switch, Please input switch (0. RESET  1. SET)\n";
753         std::cin >> mode;
754     }
755     std::cout << "SetLockState: pin = " << testPin << "  mode = " << mode << endl;
756     LockInfo testInfo;
757     testInfo.password = Str8ToStr16(testPin);
758     testInfo.lockState = static_cast<LockState>(mode);
759     testInfo.lockType = static_cast<LockType>(testType);
760     g_telephonyService->SetLockState(SLOT_ID, testInfo, response);
761     std::cout << "Set Lock complete:" << response.result << " " << response.remain << std::endl;
762     return true;
763 }
764 
TestGetLockState()765 static bool TestGetLockState()
766 {
767     int32_t testType = -1;
768     while (!AmongLockType(testType, LockTypeTest::PIN_LOCK_TYPE, LockTypeTest::FDN_LOCK_TTPE)) {
769         std::cout << "\n Set lock switch, Please input lock type (1. PIN_LOCK  2. FDN_LOCK)\n";
770         std::cin >> testType;
771     }
772     LockType lockType = static_cast<LockType>(testType);
773     int32_t ret = g_telephonyService->GetLockState(SLOT_ID, lockType);
774     std::cout << "TestGetLockState()" << ret << endl;
775     return true;
776 }
777 
TestRefreshSimState()778 static bool TestRefreshSimState()
779 {
780     int32_t ret = g_telephonyService->RefreshSimState(SLOT_ID);
781     std::cout << "TestRefreshSimState()" << ret << endl;
782     return true;
783 }
784 
TestSetActiveSim()785 static bool TestSetActiveSim()
786 {
787     int32_t enable = ACTIVE;
788     int32_t slotId = DEFAULT_SIM_SLOT_ID;
789     std::cout << "please input sim Id" << endl;
790     std::cin >> slotId;
791     std::cout << "\n Set active sim enable, Please input enable \n";
792     std::cin >> enable;
793 
794     bool result = g_telephonyService->SetActiveSim(slotId, enable);
795     std::cout << "TestSetActiveSim(), result = " << result << endl;
796     return true;
797 }
798 
TestGetMaxSimCount()799 static bool TestGetMaxSimCount()
800 {
801     int32_t result = g_telephonyService->GetMaxSimCount();
802     string expect = (result != INVALID_VALUE) ? "success" : "fail";
803     std::cout << "TelephonyTestService Remote GetMaxSimCount result [" << result << "] " << expect << std::endl;
804     return true;
805 }
806 
TestSendEnvelopeCmd()807 static bool TestSendEnvelopeCmd()
808 {
809     int32_t slotId = DEFAULT_SIM_SLOT_ID;
810     std::cout << "please input sim Id" << endl;
811     std::cin >> slotId;
812     std::string cmd = "";
813     std::cout << "input envelope cmd:" << std::endl;
814     std::cin >> cmd;
815     bool result = g_telephonyService->SendEnvelopeCmd(slotId, cmd);
816     std::cout << "TelephonyTestService Remote SendEnvelopeCmd result [" << result << "] " << std::endl;
817     return true;
818 }
819 
TestSendTerminalResponseCmd()820 static bool TestSendTerminalResponseCmd()
821 {
822     int32_t slotId = DEFAULT_SIM_SLOT_ID;
823     std::cout << "please input sim Id" << endl;
824     std::cin >> slotId;
825     std::string cmd = "";
826     std::cout << "input terminal response:" << std::endl;
827     std::cin >> cmd;
828     bool result = g_telephonyService->SendTerminalResponseCmd(slotId, cmd);
829     std::cout << "TelephonyTestService Remote SendTerminalResponseCmd result [" << result << "] " << std::endl;
830     return true;
831 }
832 
GetSimLockType()833 static int32_t GetSimLockType()
834 {
835     int32_t testType = -1;
836     while (!AmongPersoLockType(testType, PersoLockTypeTest::SIM_PN_PIN_TYPE,
837         PersoLockTypeTest::SIM_SIM_PUK_TYPE)) {
838         std::cout << "\n Set lock switch, Please input lock type number(\n"
839                      " 0. Network Personalization PIN\n"
840                      " 1. Network Personalization PUK\n"
841                      " 2. Network sub Personalization PIN\n"
842                      " 3. Network sub Personalization PUK\n"
843                      " 4. service supplier Personalization PIN\n"
844                      " 5. service supplier Personalization PUK\n"
845                      " 6. Corporate Personalization PIN\n"
846                      " 7. Corporate Personalization PUK\n"
847                      " 8. SIM/USIM Personalization PIN\n"
848                      " 9. SIM/USIM Personalization PUK)\n";
849         std::cin >> testType;
850     }
851     return testType;
852 }
853 
GetSimLockPassword(int32_t testType)854 static std::string GetSimLockPassword(int32_t testType)
855 {
856     std::string password = "";
857     int size = 0;
858     while (!Among(size, PinWordSize::PIN_MIN_SIZE, PinWordSize::PIN_MAX_SIZE)) {
859         PersoLockTypeTest lockType = static_cast<PersoLockTypeTest>(testType);
860         switch (lockType) {
861             case PersoLockTypeTest::SIM_PN_PIN_TYPE:
862                 std::cout << "\n select 0. Please input Network Personalization PIN \n";
863                 break;
864             case PersoLockTypeTest::SIM_PN_PUK_TYPE:
865                 std::cout << "\n select 1. Please input Network Personalization PUK \n";
866                 break;
867             case PersoLockTypeTest::SIM_PU_PIN_TYPE:
868                 std::cout << "\n select 2. Please input Network sub Personalization PIN \n";
869                 break;
870             case PersoLockTypeTest::SIM_PU_PUK_TYPE:
871                 std::cout << "\n select 3. Please input Network sub Personalization PUK \n";
872                 break;
873             case PersoLockTypeTest::SIM_PP_PIN_TYPE:
874                 std::cout << "\n select 4. Please input service supplier Personalization PIN \n";
875                 break;
876             case PersoLockTypeTest::SIM_PP_PUK_TYPE:
877                 std::cout << "\n select 5. Please input service supplier Personalization PUK \n";
878                 break;
879             case PersoLockTypeTest::SIM_PC_PIN_TYPE:
880                 std::cout << "\n select 6. Please input Corporate Personalization PIN \n";
881                 break;
882             case PersoLockTypeTest::SIM_PC_PUK_TYPE:
883                 std::cout << "\n select 7. Please input Corporate Personalization PUK \n";
884                 break;
885             case PersoLockTypeTest::SIM_SIM_PIN_TYPE:
886                 std::cout << "\n select 8. Please input SIM/USIM personalisation PIN \n";
887                 break;
888             case PersoLockTypeTest::SIM_SIM_PUK_TYPE:
889                 std::cout << "\n select 9. Please input SIM/USIM personalisation PUK \n";
890                 break;
891             default:
892                 break;
893         }
894         std::cin >> password;
895         size = password.size();
896     }
897     return password;
898 }
899 
TestUnlockSimLock()900 static bool TestUnlockSimLock()
901 {
902     int32_t slotId = DEFAULT_SIM_SLOT_ID;
903     std::cout << "please input sim Id" << endl;
904     std::cin >> slotId;
905     if (slotId != DEFAULT_SIM_SLOT_ID) {
906         std::cout << "incorrect slot ID" << endl;
907         return true;
908     }
909     LockStatusResponse response = {0};
910     PersoLockInfo lockInfo;
911     int32_t testType = GetSimLockType();
912     std::string password = GetSimLockPassword(testType);
913     std::cout << "UnlockSimLock: password = " << password << endl;
914     lockInfo.password =  Str8ToStr16(password);
915     lockInfo.lockType = static_cast<PersoLockType>(testType);
916     g_telephonyService->UnlockSimLock(slotId, lockInfo, response);
917     std::cout << "UnlockSimLock complete:" << response.result << " " << response.remain << std::endl;
918     return true;
919 }
920 
TestHasOperatorPrivileges()921 static bool TestHasOperatorPrivileges()
922 {
923     std::cout << "input slotId:" << std::endl;
924     int32_t slotId = 0;
925     std::cin >> slotId;
926     bool result = g_telephonyService->HasOperatorPrivileges(slotId);
927     std::cout << "TelephonyTestService Remote TestHasOperatorPrivileges result [" << result << "] " << std::endl;
928     return true;
929 }
930 
TestQuit()931 static bool TestQuit()
932 {
933     std::cout << "exit..." << std::endl;
934     g_funcMap.clear();
935     return false;
936 }
937 
Prompt()938 static void Prompt()
939 {
940     std::cout << "\n start \n"
941                  "usage:please input a cmd num:\n"
942                  "0:HasSimCard\n"
943                  "1:GetSimState\n"
944                  "2:GetISOCountryCodeForSim\n"
945                  "3:GetSimSpn\n"
946                  "4:GetSimIccId\n"
947                  "5:GetIMSI\n"
948                  "6:IsSimActive\n"
949                  "7:GetSimOperatorNumeric\n"
950                  "8:GetSimGid1\n"
951                  "10:GetSimAccountInfo\n"
952                  "11:SetDefaultVoiceSlotId\n"
953                  "12:GetDefaultVoiceSlotId\n"
954                  "21:UnlockPin\n"
955                  "22:UnlockPuk\n"
956                  "23:AlterPin\n"
957                  "24:GetLockState\n"
958                  "25:SetLockState\n"
959                  "26:RefreshSimState\n"
960                  "31:UnlockPin2\n"
961                  "32:UnlockPuk2\n"
962                  "33:AlterPin2\n"
963                  "34:SetActiveSim\n"
964                  "42:SetShowNumber\n"
965                  "43:GetShowNumber\n"
966                  "44:SetShowName\n"
967                  "45:GetShowName\n"
968                  "46:GetActiveSimAccountInfoList\n"
969                  "47:GetOperatorConfigs\n"
970                  "49:GetVoiceMailIdentifier\n"
971                  "50:GetVoiceMailNumber\n"
972                  "51:QueryIccDiallingNumbers\n"
973                  "52:AddIccDiallingNumbers\n"
974                  "53:DelIccDiallingNumbers\n"
975                  "54:UpdateIccDiallingNumbers\n"
976                  "55:SetVoiceMailInfo\n"
977                  "56:GetMaxSimCount\n"
978                  "57:TestSendEnvelopeCmd\n"
979                  "58:TestSendTerminalResponseCmd\n"
980                  "60:GetSimTelephoneNumber\n"
981                  "61:GetSimTeleNumberIdentifier\n"
982                  "62:GetCardType\n"
983                  "63:UnlockSimLock\n"
984                  "64:SetPrimarySlotId\n"
985                  "65:GetPrimarySlotId\n"
986                  "70:HasOperatorPrivileges\n"
987                  "100:exit\n"
988               << std::endl;
989 }
990 
InitFuncMap()991 static void InitFuncMap()
992 {
993     g_funcMap[InputCmd::INPUT_HASSIMCARD] = TestHasSimCard;
994     g_funcMap[InputCmd::INPUT_GETSIMSTATE] = TestGetSimState;
995     g_funcMap[InputCmd::INPUT_GETISOCOUNTRYCODE] = TestGetISOCountryCodeForSim;
996     g_funcMap[InputCmd::INPUT_GETSPN] = TestGetSimSpn;
997     g_funcMap[InputCmd::INPUT_GETICCID] = TestGetSimIccId;
998     g_funcMap[InputCmd::INPUT_GETIMSI] = TestGetIMSI;
999     g_funcMap[InputCmd::INPUT_ISSIMACTIVE] = TestIsSimActive;
1000     g_funcMap[InputCmd::INPUT_GETSIMOPERATOR] = TestGetSimOperatorNumeric;
1001     g_funcMap[InputCmd::INPUT_GETGID1] = TestGetSimGid1;
1002     g_funcMap[InputCmd::INPUT_GETSIMSUB] = TestGetSimSubscriptionInfo;
1003     g_funcMap[InputCmd::INPUT_SETDEFAULTCALL] = TestSetDefaultVoiceSlotId;
1004     g_funcMap[InputCmd::INPUT_GETDEFAULTCALL] = TestGetDefaultVoiceSlotId;
1005     g_funcMap[InputCmd::INPUT_UNLOCK_PIN] = TestUnlockPin;
1006     g_funcMap[InputCmd::INPUT_UNLOCK_PUK] = TestUnlockPuk;
1007     g_funcMap[InputCmd::INPUT_ALTER_PIN] = TestAlterPin;
1008     g_funcMap[InputCmd::INPUT_CHECK_LOCK] = TestGetLockState;
1009     g_funcMap[InputCmd::INPUT_ENABLE_LOCK] = TestSetLockState;
1010     g_funcMap[InputCmd::INPUT_UNLOCK_PIN2] = TestUnlockPin2;
1011     g_funcMap[InputCmd::INPUT_UNLOCK_PUK2] = TestUnlockPuk2;
1012     g_funcMap[InputCmd::INPUT_ALTER_PIN2] = TestAlterPin2;
1013     g_funcMap[InputCmd::INPUT_SET_ACTIVE_SIM] = TestSetActiveSim;
1014     g_funcMap[InputCmd::INPUT_SETSHOWNUMBER] = TestSetShowNumber;
1015     g_funcMap[InputCmd::INPUT_SETSHOWNAME] = TestSetShowName;
1016     g_funcMap[InputCmd::INPUT_GETSHOWNUMBER] = TestGetShowNumber;
1017     g_funcMap[InputCmd::INPUT_GETSHOWNAME] = TestGetShowName;
1018     g_funcMap[InputCmd::INPUT_GETACTIVEACCOUNTLIST] = TestGetActiveSimAccountInfoList;
1019     g_funcMap[InputCmd::INPUT_GETOPERATORCONFIG] = TestGetOperatorConfig;
1020     g_funcMap[InputCmd::INPUT_REFRESHSIMSTATE] = TestRefreshSimState;
1021     g_funcMap[InputCmd::INPUT_GET_VOICEMAIL_NAME] = TestGetVoiceMailIdentifier;
1022     g_funcMap[InputCmd::INPUT_GET_VOICEMAIL_NUMBER] = TestGetVoiceMailNumber;
1023     g_funcMap[InputCmd::INPUT_DIALLING_NUMBERS_GET] = TestQueryIccDiallingNumbers;
1024     g_funcMap[InputCmd::INPUT_DIALLING_NUMBERS_INSERT] = TestAddIccDiallingNumbers;
1025     g_funcMap[InputCmd::INPUT_DIALLING_NUMBERS_DELETE] = TestDelIccDiallingNumbers;
1026     g_funcMap[InputCmd::INPUT_DIALLING_NUMBERS_UPDATE] = TestUpdateIccDiallingNumbers;
1027     g_funcMap[InputCmd::INPUT_SET_VOICEMAIL] = TestSetVoiceMailInfo;
1028     g_funcMap[InputCmd::INPUT_GET_MAX_SIM_COUNT] = TestGetMaxSimCount;
1029     g_funcMap[InputCmd::INPUT_STK_CMD_FROM_APP] = TestSendEnvelopeCmd;
1030     g_funcMap[InputCmd::INPUT_STK_TERMINAL_RESPONSE] = TestSendTerminalResponseCmd;
1031     g_funcMap[InputCmd::INPUT_GET_PHONENUMBER] = TestGetSimTelephoneNumber;
1032     g_funcMap[InputCmd::INPUT_GET_SIM_TELENUMBER_IDENTIFIER] = TestGetSimTeleNumberIdentifier;
1033     g_funcMap[InputCmd::INPUT_GET_CARD_TYPE] = TestGetCardType;
1034     g_funcMap[InputCmd::INPUT_HAS_OPERATOR_PRIVILEGES] = TestHasOperatorPrivileges;
1035     g_funcMap[InputCmd::INPUT_UNLOCK_SIMLOCK] = TestUnlockSimLock;
1036     g_funcMap[InputCmd::INPUT_SET_PRIMARY_SLOTID] = TestSetPrimarySlotId;
1037     g_funcMap[InputCmd::INPUT_GET_PRIMARY_SLOTID] = TestGetPrimarySlotId;
1038     g_funcMap[InputCmd::INPUT_QUIT] = TestQuit;
1039 }
1040 
ProcessInput()1041 static bool ProcessInput()
1042 {
1043     int inputCMDKey = DEFAULT_VALUE;
1044     bool loopFlag = true;
1045     std::cin >> inputCMDKey;
1046     std::cout << "inputCMD is [" << inputCMDKey << "]" << std::endl;
1047     InputCmd inputCMD = static_cast<InputCmd>(inputCMDKey);
1048     auto itFunc = g_funcMap.find(inputCMD);
1049     if (itFunc != g_funcMap.end()) {
1050         auto cmdFunc = itFunc->second;
1051         if (cmdFunc != nullptr) {
1052             loopFlag = (*cmdFunc)();
1053         }
1054     } else {
1055         std::cout << "please input correct number..." << std::endl;
1056     }
1057     return loopFlag;
1058 }
1059 } // namespace Telephony
1060 } // namespace OHOS
1061 
1062 using namespace OHOS::Telephony;
main()1063 int main()
1064 {
1065     g_telephonyService = GetProxy();
1066     if (g_telephonyService == nullptr) {
1067         return 1;
1068     }
1069 
1070     OHOS::EventFwk::MatchingSkills matchingSkills;
1071     matchingSkills.AddEvent(SIM_STATE_CHANGE_ACTION);
1072     matchingSkills.AddEvent(DEFAULT_VOICE_SLOTID_CHANGE_ACTION);
1073     matchingSkills.AddEvent(DEFAULT_SMS_SLOTID_CHANGE_ACTION);
1074     matchingSkills.AddEvent(DEFAULT_DATA_SLOTID_CHANGE_ACTION);
1075     matchingSkills.AddEvent(DEFAULT_MAIN_SLOTID_CHANGE_ACTION);
1076     // STK
1077     matchingSkills.AddEvent(ACTION_SESSION_END);
1078     matchingSkills.AddEvent(ACTION_STK_COMMAND);
1079     matchingSkills.AddEvent(ACTION_ALPHA_IDENTIFIER);
1080     matchingSkills.AddEvent(ACTION_CARD_STATUS_INFORM);
1081 
1082     OHOS::EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1083     subscribeInfo.SetPriority(1);
1084     std::shared_ptr<CommonEventTest> subScriber = std::make_shared<CommonEventTest>(subscribeInfo);
1085     OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subScriber);
1086 
1087     InitFuncMap();
1088     bool loopFlag = true;
1089     while (loopFlag) {
1090         Prompt();
1091         loopFlag = ProcessInput();
1092     }
1093     std::cout << " exit test " << std::endl;
1094 }