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