1 /*
2  * Copyright (C) 2021-2024 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 #define private public
17 #define protected public
18 #include "state_registry_test.h"
19 
20 #include "core_service_client.h"
21 #include "sim_state_type.h"
22 #include "telephony_ext_wrapper.h"
23 #include "telephony_log_wrapper.h"
24 #include "telephony_observer_client.h"
25 #include "telephony_observer_proxy.h"
26 #include "telephony_state_manager.h"
27 #include "telephony_state_registry_client.h"
28 #include "telephony_state_registry_service.h"
29 
30 namespace OHOS {
31 namespace Telephony {
32 using namespace testing::ext;
33 sptr<StateRegistryObserver> StateRegistryTest::telephonyObserver0_ = nullptr;
34 sptr<StateRegistryObserver> StateRegistryTest::telephonyObserver1_ = nullptr;
35 static constexpr int32_t SIM_SLOT_ID_1 = DEFAULT_SIM_SLOT_ID + 1;
36 static constexpr int32_t CALL_STATUS_ACTIVE = 0;
37 static constexpr int32_t SINGLE_MODE_SIM_CARD = 10;
38 static constexpr int32_t SIM_STATE_NOT_PRESENT = 1;
39 static constexpr int32_t SIM_PIN = 1;
40 static constexpr int32_t DATA_STATE_CONNECTING = 1;
41 static constexpr int32_t NETWORK_TYPE_GSM = 1;
42 static constexpr int32_t DATA_FLOW_TYPE_DOWN = 1;
43 
SetUpTestCase(void)44 void StateRegistryTest::SetUpTestCase(void)
45 {
46     ASSERT_TRUE(CoreServiceClient::GetInstance().GetProxy() != nullptr);
47     InitTelephonyObserver();
48 }
49 
TearDownTestCase(void)50 void StateRegistryTest::TearDownTestCase(void)
51 {
52     DisableTelephonyObserver();
53 }
54 
InitTelephonyObserver()55 void StateRegistryTest::InitTelephonyObserver()
56 {
57     TELEPHONY_LOGI("Init telephony observer");
58     AccessToken token;
59     if (!telephonyObserver0_) {
60         telephonyObserver0_ = std::make_unique<StateRegistryObserver>().release();
61     }
62     auto res =
63         Telephony::TelephonyObserverClient::GetInstance().AddStateObserver(telephonyObserver0_, DEFAULT_SIM_SLOT_ID,
64             Telephony::TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE |
65                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE |
66                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO |
67                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS |
68                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIM_STATE |
69                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE |
70                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW |
71                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_CFU_INDICATOR |
72                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_VOICE_MAIL_MSG_INDICATOR,
73             true);
74     TELEPHONY_LOGI("StateRegistryTest init telephony observer0 ret:%{public}d", res);
75     ASSERT_TRUE(res == TELEPHONY_SUCCESS);
76     if (!telephonyObserver1_) {
77         telephonyObserver1_ = std::make_unique<StateRegistryObserver>().release();
78     }
79     res = Telephony::TelephonyObserverClient::GetInstance().AddStateObserver(telephonyObserver1_, SIM_SLOT_ID_1,
80         Telephony::TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE |
81             Telephony::TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE |
82             Telephony::TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO |
83             Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS |
84             Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIM_STATE |
85             Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE |
86             Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW |
87             Telephony::TelephonyObserverBroker::OBSERVER_MASK_CFU_INDICATOR |
88             Telephony::TelephonyObserverBroker::OBSERVER_MASK_VOICE_MAIL_MSG_INDICATOR,
89         true);
90     TELEPHONY_LOGI("StateRegistryTest init telephony observer1 ret:%{public}d", res);
91     ASSERT_TRUE(res == TELEPHONY_SUCCESS);
92 }
93 
DisableTelephonyObserver()94 void StateRegistryTest::DisableTelephonyObserver()
95 {
96     TELEPHONY_LOGI("Disable telephony observer");
97     ASSERT_TRUE(telephonyObserver0_ != nullptr);
98     Telephony::TelephonyObserverClient::GetInstance().RemoveStateObserver(
99         DEFAULT_SIM_SLOT_ID, Telephony::TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE |
100                                  Telephony::TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE |
101                                  Telephony::TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO |
102                                  Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS |
103                                  Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIM_STATE |
104                                  Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE |
105                                  Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW);
106     telephonyObserver0_ = nullptr;
107     ASSERT_TRUE(telephonyObserver1_ != nullptr);
108     Telephony::TelephonyObserverClient::GetInstance().RemoveStateObserver(
109         SIM_SLOT_ID_1, Telephony::TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE |
110                            Telephony::TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE |
111                            Telephony::TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO |
112                            Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS |
113                            Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIM_STATE |
114                            Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE |
115                            Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW);
116     telephonyObserver1_ = nullptr;
117 }
118 
SetUp(void)119 void StateRegistryTest::SetUp(void)
120 {
121     // step 3: input testcase setup step
122 }
123 
TearDown(void)124 void StateRegistryTest::TearDown(void)
125 {
126     // step 3: input testcase teardown step
127 }
128 
HasSimCard(int32_t slotId)129 bool StateRegistryTest::HasSimCard(int32_t slotId)
130 {
131     bool hasSimCard = false;
132     CoreServiceClient::GetInstance().HasSimCard(slotId, hasSimCard);
133     return hasSimCard;
134 }
135 
IsSuccess(int32_t ret)136 bool StateRegistryTest::IsSuccess(int32_t ret)
137 {
138     TELEPHONY_LOGI("ret = %{public}d, TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST = %{public}d",
139         ret, TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST);
140     if (ret == TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST || ret == TELEPHONY_ERR_SUCCESS) {
141         return true;
142     }
143     return false;
144 }
145 
UpdateCallState(int32_t slotId)146 void StateRegistryTest::UpdateCallState(int32_t slotId)
147 {
148     AccessToken token;
149     int32_t callState = 16;
150     std::string phoneNumber("137xxxxxxxx");
151     std::u16string number = Str8ToStr16(phoneNumber);
152     int32_t ret =
153         DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateCallState(callState, number);
154     TELEPHONY_LOGI("StateRegistryTest::UpdateCallState ret = %{public}d", ret);
155     EXPECT_TRUE(IsSuccess(ret));
156 }
157 
UpdateCallStateForSlotId(int32_t slotId)158 void StateRegistryTest::UpdateCallStateForSlotId(int32_t slotId)
159 {
160     AccessToken token;
161     int32_t callState = 16;
162     std::string phoneNumber("137xxxxxxxx");
163     std::u16string number = Str8ToStr16(phoneNumber);
164     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateCallStateForSlotId(
165         slotId, callState, number);
166     TELEPHONY_LOGI("StateRegistryTest::UpdateCallStateForSlotId ret = %{public}d", ret);
167     EXPECT_TRUE(IsSuccess(ret));
168 }
169 
UpdateSignalInfo(int32_t slotId)170 void StateRegistryTest::UpdateSignalInfo(int32_t slotId)
171 {
172     AccessToken token;
173     std::vector<sptr<SignalInformation>> vec;
174     std::unique_ptr<SignalInformation> signal = std::make_unique<GsmSignalInformation>();
175     ASSERT_TRUE(signal != nullptr);
176     vec.push_back(signal.release());
177     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateSignalInfo(slotId, vec);
178     TELEPHONY_LOGI("StateRegistryTest::UpdateSignalInfo result = %{public}d", ret);
179     EXPECT_TRUE(IsSuccess(ret));
180 }
181 
UpdateCellularDataConnectState(int32_t slotId)182 void StateRegistryTest::UpdateCellularDataConnectState(int32_t slotId)
183 {
184     AccessToken token;
185     int32_t dataState = 1;
186     int32_t networkState = 1;
187     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateCellularDataConnectState(
188         slotId, dataState, networkState);
189     TELEPHONY_LOGI("StateRegistryTest::UpdateCellularDataConnectState ret = %{public}d", ret);
190     EXPECT_TRUE(IsSuccess(ret));
191 }
192 
UpdateCellularDataFlow(int32_t slotId)193 void StateRegistryTest::UpdateCellularDataFlow(int32_t slotId)
194 {
195     AccessToken token;
196     int32_t dataFlowType = 0;
197     int32_t ret =
198         DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateCellularDataFlow(slotId, dataFlowType);
199     TELEPHONY_LOGI("StateRegistryTest::UpdateCellularDataFlow ret = %{public}d", ret);
200     EXPECT_TRUE(IsSuccess(ret));
201 }
202 
UpdateSimState(int32_t slotId)203 void StateRegistryTest::UpdateSimState(int32_t slotId)
204 {
205     AccessToken token;
206     CardType type = CardType::UNKNOWN_CARD;
207     SimState state = SimState::SIM_STATE_UNKNOWN;
208     LockReason reason = LockReason::SIM_NONE;
209     int32_t ret =
210         DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateSimState(slotId, type, state, reason);
211     TELEPHONY_LOGI("StateRegistryTest::UpdateSimState ret = %{public}d", ret);
212     EXPECT_TRUE(IsSuccess(ret));
213 }
214 
UpdateNetworkState(int32_t slotId)215 void StateRegistryTest::UpdateNetworkState(int32_t slotId)
216 {
217     AccessToken token;
218     std::unique_ptr<NetworkState> networkState = std::make_unique<NetworkState>();
219     ASSERT_TRUE(networkState != nullptr);
220     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateNetworkState(
221         slotId, networkState.release());
222     TELEPHONY_LOGI("StateRegistryTest::UpdateNetworkState ret = %{public}d", ret);
223     EXPECT_TRUE(IsSuccess(ret));
224 }
225 
UpdateCfuIndicator(int32_t slotId)226 void StateRegistryTest::UpdateCfuIndicator(int32_t slotId)
227 {
228     AccessToken token;
229     bool cfuResult = true;
230     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateCfuIndicator(
231         slotId, cfuResult);
232     TELEPHONY_LOGI("StateRegistryTest::UpdateCfuIndicator ret = %{public}d", ret);
233     EXPECT_TRUE(IsSuccess(ret));
234 }
235 
UpdateVoiceMailMsgIndicator(int32_t slotId)236 void StateRegistryTest::UpdateVoiceMailMsgIndicator(int32_t slotId)
237 {
238     AccessToken token;
239     bool voiceMailMsgResult = true;
240     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateVoiceMailMsgIndicator(
241         slotId, voiceMailMsgResult);
242     TELEPHONY_LOGI("StateRegistryTest::UpdateVoiceMailMsgIndicator ret = %{public}d", ret);
243     EXPECT_TRUE(IsSuccess(ret));
244 }
245 
UpdateIccAccount()246 void StateRegistryTest::UpdateIccAccount()
247 {
248     AccessToken token;
249     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateIccAccount();
250     TELEPHONY_LOGI("StateRegistryTest::UpdateIccAccount ret = %{public}d", ret);
251     EXPECT_TRUE(IsSuccess(ret));
252 }
253 
254 #ifndef TEL_TEST_UNSUPPORT
255 /**
256  * @tc.number   StateRegistry_001
257  * @tc.name     Get System Services
258  * @tc.desc     Function test
259  */
HWTEST_F(StateRegistryTest, StateRegistry_001, Function | MediumTest | Level0)260 HWTEST_F(StateRegistryTest, StateRegistry_001, Function | MediumTest | Level0)
261 {
262     auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
263     ASSERT_TRUE(systemAbilityMgr != nullptr);
264     auto remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID);
265     ASSERT_TRUE(remote != nullptr);
266     auto stateRegistryService = iface_cast<ITelephonyStateNotify>(remote);
267     ASSERT_TRUE(stateRegistryService != nullptr);
268     TELEPHONY_LOGI("HWTEST_F StateRegistry_001");
269 }
270 
271 /**
272  * @tc.number   UpdateCallState_001
273  * @tc.name     update call state
274  * @tc.desc     Function test
275  */
HWTEST_F(StateRegistryTest, UpdateCallState_001, Function | MediumTest | Level1)276 HWTEST_F(StateRegistryTest, UpdateCallState_001, Function | MediumTest | Level1)
277 {
278     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
279         TELEPHONY_LOGI("no sim card!");
280     }
281     UpdateCallState(DEFAULT_SIM_SLOT_ID);
282 }
283 
284 /**
285  * @tc.number   UpdateCallState_002
286  * @tc.name     update call state
287  * @tc.desc     Function test
288  */
HWTEST_F(StateRegistryTest, UpdateCallState_002, Function | MediumTest | Level1)289 HWTEST_F(StateRegistryTest, UpdateCallState_002, Function | MediumTest | Level1)
290 {
291     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
292         TELEPHONY_LOGI("no sim card!");
293     }
294     UpdateCallState(SIM_SLOT_ID_1);
295 }
296 
297 /**
298  * @tc.number   UpdateCallStateForSlotId_001
299  * @tc.name     update call state by slotId
300  * @tc.desc     Function test
301  */
HWTEST_F(StateRegistryTest, UpdateCallStateForSlotId_001, Function | MediumTest | Level1)302 HWTEST_F(StateRegistryTest, UpdateCallStateForSlotId_001, Function | MediumTest | Level1)
303 {
304     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
305         TELEPHONY_LOGI("no sim card!");
306     }
307     UpdateCallStateForSlotId(DEFAULT_SIM_SLOT_ID);
308 }
309 
310 /**
311  * @tc.number   UpdateCallStateForSlotId_002
312  * @tc.name     update call state by slotId
313  * @tc.desc     Function test
314  */
HWTEST_F(StateRegistryTest, UpdateCallStateForSlotId_002, Function | MediumTest | Level1)315 HWTEST_F(StateRegistryTest, UpdateCallStateForSlotId_002, Function | MediumTest | Level1)
316 {
317     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
318         TELEPHONY_LOGI("no sim card!");
319     }
320     UpdateCallStateForSlotId(SIM_SLOT_ID_1);
321 }
322 
323 /**
324  * @tc.number   UpdateSignalInfo_001
325  * @tc.name     update signal info
326  * @tc.desc     Function test
327  */
HWTEST_F(StateRegistryTest, UpdateSignalInfo_001, Function | MediumTest | Level1)328 HWTEST_F(StateRegistryTest, UpdateSignalInfo_001, Function | MediumTest | Level1)
329 {
330     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
331         TELEPHONY_LOGI("no sim card!");
332     }
333     UpdateSignalInfo(DEFAULT_SIM_SLOT_ID);
334 }
335 
336 /**
337  * @tc.number   UpdateSignalInfo_002
338  * @tc.name     update signal info
339  * @tc.desc     Function test
340  */
HWTEST_F(StateRegistryTest, UpdateSignalInfo_002, Function | MediumTest | Level1)341 HWTEST_F(StateRegistryTest, UpdateSignalInfo_002, Function | MediumTest | Level1)
342 {
343     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
344         TELEPHONY_LOGI("no sim card!");
345     }
346     UpdateSignalInfo(SIM_SLOT_ID_1);
347 }
348 
349 /**
350  * @tc.number   UpdateCellularDataConnectState_001
351  * @tc.name     update cellular data connect state
352  * @tc.desc     Function test
353  */
HWTEST_F(StateRegistryTest, UpdateCellularDataConnectState_001, Function | MediumTest | Level1)354 HWTEST_F(StateRegistryTest, UpdateCellularDataConnectState_001, Function | MediumTest | Level1)
355 {
356     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
357         TELEPHONY_LOGI("no sim card!");
358     }
359     UpdateCellularDataConnectState(DEFAULT_SIM_SLOT_ID);
360 }
361 
362 /**
363  * @tc.number   UpdateCellularDataConnectState_002
364  * @tc.name     update cellular data connect state
365  * @tc.desc     Function test
366  */
HWTEST_F(StateRegistryTest, UpdateCellularDataConnectState_002, Function | MediumTest | Level1)367 HWTEST_F(StateRegistryTest, UpdateCellularDataConnectState_002, Function | MediumTest | Level1)
368 {
369     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
370         TELEPHONY_LOGI("no sim card!");
371     }
372     UpdateCellularDataConnectState(SIM_SLOT_ID_1);
373 }
374 
375 /**
376  * @tc.number   UpdateCellularDataFlow_001
377  * @tc.name     update cellular flow data
378  * @tc.desc     Function test
379  */
HWTEST_F(StateRegistryTest, UpdateCellularDataFlow_001, Function | MediumTest | Level1)380 HWTEST_F(StateRegistryTest, UpdateCellularDataFlow_001, Function | MediumTest | Level1)
381 {
382     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
383         TELEPHONY_LOGI("no sim card!");
384     }
385     UpdateCellularDataFlow(DEFAULT_SIM_SLOT_ID);
386 }
387 
388 /**
389  * @tc.number   UpdateCellularDataFlow_002
390  * @tc.name     update cellular flow data
391  * @tc.desc     Function test
392  */
HWTEST_F(StateRegistryTest, UpdateCellularDataFlow_002, Function | MediumTest | Level1)393 HWTEST_F(StateRegistryTest, UpdateCellularDataFlow_002, Function | MediumTest | Level1)
394 {
395     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
396         TELEPHONY_LOGI("no sim card!");
397     }
398     UpdateCellularDataFlow(SIM_SLOT_ID_1);
399 }
400 
401 /**
402  * @tc.number   UpdateSimState_001
403  * @tc.name     update sim state
404  * @tc.desc     Function test
405  */
HWTEST_F(StateRegistryTest, UpdateSimState_001, Function | MediumTest | Level1)406 HWTEST_F(StateRegistryTest, UpdateSimState_001, Function | MediumTest | Level1)
407 {
408     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
409         TELEPHONY_LOGI("no sim card!");
410     }
411     UpdateSimState(DEFAULT_SIM_SLOT_ID);
412 }
413 
414 /**
415  * @tc.number   UpdateSimState_002
416  * @tc.name     update sim state
417  * @tc.desc     Function test
418  */
HWTEST_F(StateRegistryTest, UpdateSimState_002, Function | MediumTest | Level1)419 HWTEST_F(StateRegistryTest, UpdateSimState_002, Function | MediumTest | Level1)
420 {
421     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
422         TELEPHONY_LOGI("no sim card!");
423     }
424     UpdateSimState(SIM_SLOT_ID_1);
425 }
426 
427 /**
428  * @tc.number   UpdateNetworkState_001
429  * @tc.name     update network state
430  * @tc.desc     Function test
431  */
HWTEST_F(StateRegistryTest, UpdateNetworkState_001, Function | MediumTest | Level1)432 HWTEST_F(StateRegistryTest, UpdateNetworkState_001, Function | MediumTest | Level1)
433 {
434     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
435         TELEPHONY_LOGI("no sim card!");
436     }
437     UpdateNetworkState(DEFAULT_SIM_SLOT_ID);
438 }
439 
440 /**
441  * @tc.number   UpdateNetworkState_002
442  * @tc.name     update network state
443  * @tc.desc     Function test
444  */
HWTEST_F(StateRegistryTest, UpdateNetworkState_002, Function | MediumTest | Level1)445 HWTEST_F(StateRegistryTest, UpdateNetworkState_002, Function | MediumTest | Level1)
446 {
447     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
448         TELEPHONY_LOGI("no sim card!");
449     }
450     UpdateNetworkState(SIM_SLOT_ID_1);
451 }
452 
453 /**
454  * @tc.number   UpdateCfuIndicator_001
455  * @tc.name     update the result of call forwarding
456  * @tc.desc     Function test
457  */
HWTEST_F(StateRegistryTest, UpdateCfuIndicator_001, Function | MediumTest | Level1)458 HWTEST_F(StateRegistryTest, UpdateCfuIndicator_001, Function | MediumTest | Level1)
459 {
460     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
461         TELEPHONY_LOGI("no sim card!");
462     }
463     UpdateCfuIndicator(DEFAULT_SIM_SLOT_ID);
464 }
465 
466 /**
467  * @tc.number   UpdateCfuIndicator_002
468  * @tc.name     update the result of call forwarding
469  * @tc.desc     Function test
470  */
HWTEST_F(StateRegistryTest, UpdateCfuIndicator_002, Function | MediumTest | Level1)471 HWTEST_F(StateRegistryTest, UpdateCfuIndicator_002, Function | MediumTest | Level1)
472 {
473     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
474         TELEPHONY_LOGI("no sim card!");
475     }
476     UpdateCfuIndicator(SIM_SLOT_ID_1);
477 }
478 
479 /**
480  * @tc.number   UpdateVoiceMailMsgIndicator_001
481  * @tc.name     update voice mail message indicator
482  * @tc.desc     Function test
483  */
HWTEST_F(StateRegistryTest, UpdateVoiceMailMsgIndicator_001, Function | MediumTest | Level1)484 HWTEST_F(StateRegistryTest, UpdateVoiceMailMsgIndicator_001, Function | MediumTest | Level1)
485 {
486     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
487         TELEPHONY_LOGI("no sim card!");
488     }
489     UpdateVoiceMailMsgIndicator(DEFAULT_SIM_SLOT_ID);
490 }
491 
492 /**
493  * @tc.number   UpdateVoiceMailMsgIndicator_002
494  * @tc.name     update voice mail message indicator
495  * @tc.desc     Function test
496  */
HWTEST_F(StateRegistryTest, UpdateVoiceMailMsgIndicator_002, Function | MediumTest | Level1)497 HWTEST_F(StateRegistryTest, UpdateVoiceMailMsgIndicator_002, Function | MediumTest | Level1)
498 {
499     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
500         TELEPHONY_LOGI("no sim card!");
501     }
502     UpdateVoiceMailMsgIndicator(SIM_SLOT_ID_1);
503 }
504 
505 /**
506  * @tc.number   UpdateIccAccount_001
507  * @tc.name     Update Icc Account
508  * @tc.desc     Function test
509  */
HWTEST_F(StateRegistryTest, UpdateIccAccount_001, Function | MediumTest | Level1)510 HWTEST_F(StateRegistryTest, UpdateIccAccount_001, Function | MediumTest | Level1)
511 {
512     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
513         TELEPHONY_LOGI("no sim card!");
514     }
515     UpdateIccAccount();
516 }
517 
518 /**
519  * @tc.number   UpdateIccAccount_002
520  * @tc.name     UpdateIccAccount
521  * @tc.desc     Function test
522  */
HWTEST_F(StateRegistryTest, UpdateIccAccount_002, Function | MediumTest | Level1)523 HWTEST_F(StateRegistryTest, UpdateIccAccount_002, Function | MediumTest | Level1)
524 {
525     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
526         TELEPHONY_LOGI("no sim card!");
527     }
528     UpdateIccAccount();
529 }
530 
531 /**
532  * @tc.number   TelephonyStateManagerTest_001
533  * @tc.name     telephony state manager add/remove state observer test
534  * @tc.desc     Function test
535  */
HWTEST_F(StateRegistryTest, TelephonyStateManagerTest_001, Function | MediumTest | Level1)536 HWTEST_F(StateRegistryTest, TelephonyStateManagerTest_001, Function | MediumTest | Level1)
537 {
538     TELEPHONY_LOGI("TelephonyStateManagerTest_001 start!");
539     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
540         TELEPHONY_LOGI("no sim card!");
541     }
542     TelephonyStateManager::AddStateObserver(
543         telephonyObserver0_, DEFAULT_SIM_SLOT_ID, TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE, true);
544     wptr<IRemoteObject> wptrDeath = nullptr;
545     int32_t ret = TelephonyStateManager::RemoveStateObserver(
546         DEFAULT_SIM_SLOT_ID, Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE);
547     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
548 }
549 
550 /**
551  * @tc.number   TelephonyObserverTest_001
552  * @tc.name     telephony observer test
553  * @tc.desc     Function test
554  */
HWTEST_F(StateRegistryTest, TelephonyObserverTest_001, Function | MediumTest | Level1)555 HWTEST_F(StateRegistryTest, TelephonyObserverTest_001, Function | MediumTest | Level1)
556 {
557     TELEPHONY_LOGI("TelephonyObserverTest_001 start!");
558     MessageParcel dataParcel;
559     MessageParcel reply;
560     MessageOption option;
561     option.SetFlags(MessageOption::TF_ASYNC);
562     std::u16string testStr = u"test";
563     if (!dataParcel.WriteInterfaceToken(testStr)) {
564         TELEPHONY_LOGE("TelephonyObserverTest_001 WriteInterfaceToken failed!");
565         return;
566     }
567     int32_t ret = telephonyObserver.OnRemoteRequest(
568         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_CALL_STATE_UPDATED), dataParcel, reply,
569         option);
570     EXPECT_EQ(TELEPHONY_ERR_DESCRIPTOR_MISMATCH, ret);
571 }
572 
573 /**
574  * @tc.number   TelephonyObserverTest_002
575  * @tc.name     telephony observer test
576  * @tc.desc     Function test
577  */
HWTEST_F(StateRegistryTest, TelephonyObserverTest_002, Function | MediumTest | Level1)578 HWTEST_F(StateRegistryTest, TelephonyObserverTest_002, Function | MediumTest | Level1)
579 {
580     TELEPHONY_LOGI("TelephonyObserverTest_002 start!");
581     MessageParcel dataParcel;
582     MessageParcel reply;
583     MessageOption option;
584     std::u16string phoneNumber = u"123456";
585     option.SetFlags(MessageOption::TF_ASYNC);
586     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
587         TELEPHONY_LOGE("TelephonyObserverTest_002 WriteInterfaceToken failed!");
588         return;
589     }
590     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
591     dataParcel.WriteInt32(CALL_STATUS_ACTIVE);
592     dataParcel.WriteString16(phoneNumber);
593     int32_t ret = telephonyObserver.OnRemoteRequest(
594         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_CALL_STATE_UPDATED), dataParcel, reply,
595         option);
596     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
597 }
598 
599 /**
600  * @tc.number   TelephonyObserverTest_003
601  * @tc.name     telephony observer test
602  * @tc.desc     Function test
603  */
HWTEST_F(StateRegistryTest, TelephonyObserverTest_003, Function | MediumTest | Level1)604 HWTEST_F(StateRegistryTest, TelephonyObserverTest_003, Function | MediumTest | Level1)
605 {
606     TELEPHONY_LOGI("TelephonyObserverTest_003 start!");
607     MessageOption option;
608     MessageParcel dataParcel;
609     MessageParcel reply;
610     option.SetFlags(MessageOption::TF_ASYNC);
611     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
612         TELEPHONY_LOGE("TelephonyObserverTest_003 WriteInterfaceToken failed!");
613         return;
614     }
615     std::vector<sptr<SignalInformation>> vec;
616     std::unique_ptr<SignalInformation> gsmSignal = std::make_unique<GsmSignalInformation>();
617     ASSERT_TRUE(gsmSignal != nullptr);
618     vec.push_back(gsmSignal.release());
619     std::unique_ptr<WcdmaSignalInformation> wcdmaSignal = std::make_unique<WcdmaSignalInformation>();
620     ASSERT_TRUE(wcdmaSignal != nullptr);
621     vec.push_back(wcdmaSignal.release());
622     std::unique_ptr<TdScdmaSignalInformation> tdScdmaSignal = std::make_unique<TdScdmaSignalInformation>();
623     ASSERT_TRUE(tdScdmaSignal != nullptr);
624     vec.push_back(tdScdmaSignal.release());
625     std::unique_ptr<CdmaSignalInformation> cdmaSignal = std::make_unique<CdmaSignalInformation>();
626     ASSERT_TRUE(cdmaSignal != nullptr);
627     vec.push_back(cdmaSignal.release());
628     std::unique_ptr<LteSignalInformation> lteSignal = std::make_unique<LteSignalInformation>();
629     ASSERT_TRUE(lteSignal != nullptr);
630     vec.push_back(lteSignal.release());
631     int32_t size = static_cast<int32_t>(vec.size());
632     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
633     dataParcel.WriteInt32(size);
634     for (const auto &v : vec) {
635         v->Marshalling(dataParcel);
636     }
637     int32_t ret = telephonyObserver.OnRemoteRequest(
638         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_SIGNAL_INFO_UPDATED), dataParcel, reply,
639         option);
640     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
641 }
642 
643 /**
644  * @tc.number   TelephonyObserverTest_004
645  * @tc.name     telephony observer test
646  * @tc.desc     Function test
647  */
HWTEST_F(StateRegistryTest, TelephonyObserverTest_004, Function | MediumTest | Level1)648 HWTEST_F(StateRegistryTest, TelephonyObserverTest_004, Function | MediumTest | Level1)
649 {
650     TELEPHONY_LOGI("TelephonyObserverTest_004 start!");
651     MessageOption option;
652     MessageParcel dataParcel;
653     MessageParcel reply;
654     option.SetFlags(MessageOption::TF_ASYNC);
655     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
656         TELEPHONY_LOGE("TelephonyObserverTest_004 WriteInterfaceToken failed!");
657         return;
658     }
659     std::vector<sptr<CellInformation>> vec;
660     std::unique_ptr<GsmCellInformation> gsmCell = std::make_unique<GsmCellInformation>();
661     ASSERT_TRUE(gsmCell != nullptr);
662     vec.push_back(gsmCell.release());
663     std::unique_ptr<LteCellInformation> lteCell = std::make_unique<LteCellInformation>();
664     ASSERT_TRUE(lteCell != nullptr);
665     vec.push_back(lteCell.release());
666     std::unique_ptr<WcdmaCellInformation> wcdmaCell = std::make_unique<WcdmaCellInformation>();
667     ASSERT_TRUE(wcdmaCell != nullptr);
668     vec.push_back(wcdmaCell.release());
669     std::unique_ptr<NrCellInformation> nrCell = std::make_unique<NrCellInformation>();
670     ASSERT_TRUE(nrCell != nullptr);
671     vec.push_back(nrCell.release());
672     int32_t size = static_cast<int32_t>(vec.size());
673     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
674     if (!dataParcel.WriteInt32(size)) {
675         TELEPHONY_LOGE("Failed to write Cellinformation array size!");
676         return;
677     }
678     for (const auto &v : vec) {
679         v->Marshalling(dataParcel);
680     }
681     int32_t ret = telephonyObserver.OnRemoteRequest(
682         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_CELL_INFO_UPDATED), dataParcel, reply,
683         option);
684     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
685 }
686 
687 /**
688  * @tc.number   TelephonyObserverTest_005
689  * @tc.name     telephony observer test
690  * @tc.desc     Function test
691  */
HWTEST_F(StateRegistryTest, TelephonyObserverTest_005, Function | MediumTest | Level1)692 HWTEST_F(StateRegistryTest, TelephonyObserverTest_005, Function | MediumTest | Level1)
693 {
694     TELEPHONY_LOGI("TelephonyObserverTest_005 start!");
695     MessageOption option;
696     MessageParcel dataParcel;
697     MessageParcel reply;
698     option.SetFlags(MessageOption::TF_ASYNC);
699     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
700         TELEPHONY_LOGE("TelephonyObserverTest_005 WriteInterfaceToken failed!");
701         return;
702     }
703     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
704     std::unique_ptr<NetworkState> networkState = std::make_unique<NetworkState>();
705     ASSERT_TRUE(networkState != nullptr);
706     (networkState.release())->Marshalling(dataParcel);
707     int32_t ret = telephonyObserver.OnRemoteRequest(
708         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_NETWORK_STATE_UPDATED), dataParcel, reply,
709         option);
710     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
711 }
712 
713 /**
714  * @tc.number   TelephonyObserverTest_006
715  * @tc.name     telephony observer test
716  * @tc.desc     Function test
717  */
HWTEST_F(StateRegistryTest, TelephonyObserverTest_006, Function | MediumTest | Level1)718 HWTEST_F(StateRegistryTest, TelephonyObserverTest_006, Function | MediumTest | Level1)
719 {
720     TELEPHONY_LOGI("TelephonyObserverTest_006 start!");
721     MessageOption option;
722     MessageParcel dataParcel;
723     MessageParcel reply;
724     option.SetFlags(MessageOption::TF_ASYNC);
725     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
726         TELEPHONY_LOGE("TelephonyObserverTest_006 WriteInterfaceToken failed!");
727         return;
728     }
729     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
730     dataParcel.WriteInt32(SINGLE_MODE_SIM_CARD);
731     dataParcel.WriteInt32(SIM_STATE_NOT_PRESENT);
732     dataParcel.WriteInt32(SIM_PIN);
733     int32_t ret = telephonyObserver.OnRemoteRequest(
734         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_SIM_STATE_UPDATED), dataParcel, reply,
735         option);
736     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
737 }
738 
739 /**
740  * @tc.number   TelephonyObserverTest_007
741  * @tc.name     telephony observer test
742  * @tc.desc     Function test
743  */
HWTEST_F(StateRegistryTest, TelephonyObserverTest_007, Function | MediumTest | Level1)744 HWTEST_F(StateRegistryTest, TelephonyObserverTest_007, Function | MediumTest | Level1)
745 {
746     TELEPHONY_LOGI("TelephonyObserverTest_007 start!");
747     MessageOption option;
748     MessageParcel dataParcel;
749     MessageParcel reply;
750     option.SetFlags(MessageOption::TF_ASYNC);
751     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
752         TELEPHONY_LOGE("TelephonyObserverTest_007 WriteInterfaceToken failed!");
753         return;
754     }
755     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
756     dataParcel.WriteInt32(DATA_STATE_CONNECTING);
757     dataParcel.WriteInt32(NETWORK_TYPE_GSM);
758     int32_t ret = telephonyObserver.OnRemoteRequest(
759         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_CELLULAR_DATA_CONNECT_STATE_UPDATED),
760         dataParcel, reply, option);
761     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
762 }
763 
764 /**
765  * @tc.number   TelephonyObserverTest_008
766  * @tc.name     telephony observer test
767  * @tc.desc     Function test
768  */
HWTEST_F(StateRegistryTest, TelephonyObserverTest_008, Function | MediumTest | Level1)769 HWTEST_F(StateRegistryTest, TelephonyObserverTest_008, Function | MediumTest | Level1)
770 {
771     TELEPHONY_LOGI("TelephonyObserverTest_008 start!");
772     MessageOption option;
773     MessageParcel dataParcel;
774     MessageParcel reply;
775     option.SetFlags(MessageOption::TF_ASYNC);
776     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
777         TELEPHONY_LOGE("TelephonyObserverTest_008 WriteInterfaceToken failed!");
778         return;
779     }
780     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
781     dataParcel.WriteInt32(DATA_FLOW_TYPE_DOWN);
782     int32_t ret = telephonyObserver.OnRemoteRequest(
783         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_CELLULAR_DATA_FLOW_UPDATED), dataParcel,
784         reply, option);
785     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
786 }
787 
788 /**
789  * @tc.number   TelephonyObserverTest_009
790  * @tc.name     telephony observer test
791  * @tc.desc     Function test
792  */
HWTEST_F(StateRegistryTest, TelephonyObserverTest_009, Function | MediumTest | Level1)793 HWTEST_F(StateRegistryTest, TelephonyObserverTest_009, Function | MediumTest | Level1)
794 {
795     TELEPHONY_LOGI("TelephonyObserverTest_009 start!");
796     MessageOption option;
797     MessageParcel dataParcel;
798     MessageParcel reply;
799     option.SetFlags(MessageOption::TF_ASYNC);
800     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
801         TELEPHONY_LOGE("TelephonyObserverTest_009 WriteInterfaceToken failed!");
802         return;
803     }
804     uint32_t testId = 123;
805     int32_t ret = telephonyObserver.OnRemoteRequest(testId, dataParcel, reply, option);
806     EXPECT_NE(TELEPHONY_ERR_SUCCESS, ret);
807 }
808 
809 /**
810  * @tc.number   TelephonyObserverTest_010
811  * @tc.name     telephony observer test
812  * @tc.desc     Function test
813  */
HWTEST_F(StateRegistryTest, TelephonyObserverTest_010, Function | MediumTest | Level1)814 HWTEST_F(StateRegistryTest, TelephonyObserverTest_010, Function | MediumTest | Level1)
815 {
816     int32_t signalSize = 5;
817     int32_t cellInfoMaxSize = 11;
818     int32_t callState = 16;
819     std::u16string number = u"137xxxxxxxx";
820     std::unique_ptr<Telephony::TelephonyObserverClient> telephonyObserverClient =
821         std::make_unique<Telephony::TelephonyObserverClient>();
822     telephonyObserverClient->OnRemoteDied(nullptr);
823     telephonyObserverClient->proxy_ = nullptr;
824     sptr<ISystemAbilityManager> sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
825     sptr<IRemoteObject> obj = sam->CheckSystemAbility(TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID);
826     telephonyObserverClient->OnRemoteDied(obj);
827     telephonyObserverClient->proxy_ = iface_cast<ITelephonyStateNotify>(obj);
828     telephonyObserverClient->OnRemoteDied(obj);
829     std::shared_ptr<OHOS::Telephony::TelephonyObserverProxy> telephonyObserverProxy =
830         std::make_shared<OHOS::Telephony::TelephonyObserverProxy>(obj);
831     telephonyObserverProxy->OnCallStateUpdated(DEFAULT_SIM_SLOT_ID, callState, number);
832     std::vector<sptr<SignalInformation>> signalInformations;
833     telephonyObserverProxy->OnSignalInfoUpdated(DEFAULT_SIM_SLOT_ID, signalInformations);
834     for (int32_t i = 0; i < signalSize; i++) {
835         sptr<SignalInformation> signalInformation = sptr<SignalInformation>();
836         signalInformations.push_back(signalInformation);
837     }
838     telephonyObserverProxy->OnSignalInfoUpdated(DEFAULT_SIM_SLOT_ID, signalInformations);
839     std::vector<sptr<CellInformation>> cellInformations;
840     telephonyObserverProxy->OnCellInfoUpdated(DEFAULT_SIM_SLOT_ID, cellInformations);
841     for (int32_t i = 0; i < cellInfoMaxSize; i++) {
842         sptr<CellInformation> cellInfo = sptr<CellInformation>();
843         cellInformations.push_back(cellInfo);
844     }
845     telephonyObserverProxy->OnCellInfoUpdated(DEFAULT_SIM_SLOT_ID, cellInformations);
846     EXPECT_TRUE(telephonyObserverClient != nullptr);
847     EXPECT_TRUE(telephonyObserverProxy != nullptr);
848     EXPECT_GE(signalInformations.size(), static_cast<size_t>(0));
849     EXPECT_GE(cellInformations.size(), static_cast<size_t>(0));
850 }
851 
852 /**
853  * @tc.number   TelephonyObserverTest_011
854  * @tc.name     telephony observer test
855  * @tc.desc     Function test
856  */
HWTEST_F(StateRegistryTest, TelephonyObserverTest_011, Function | MediumTest | Level1)857 HWTEST_F(StateRegistryTest, TelephonyObserverTest_011, Function | MediumTest | Level1)
858 {
859     int32_t slotId = 0;
860     bool cfuResult = false;
861     std::shared_ptr<OHOS::Telephony::TelephonyObserver> telephonyObserver =
862         std::make_shared<OHOS::Telephony::TelephonyObserver>();
863     telephonyObserver->OnCfuIndicatorUpdated(slotId, cfuResult);
864     telephonyObserver->OnVoiceMailMsgIndicatorUpdated(slotId, cfuResult);
865     MessageParcel data;
866     MessageParcel reply;
867     sptr<ISystemAbilityManager> sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
868     telephonyObserver->OnIccAccountUpdatedInner(data, reply);
869     sptr<IRemoteObject> obj = sam->CheckSystemAbility(TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID);
870     std::shared_ptr<OHOS::Telephony::TelephonyObserverProxy> telephonyObserverProxy =
871         std::make_shared<OHOS::Telephony::TelephonyObserverProxy>(obj);
872     telephonyObserverProxy->OnIccAccountUpdated();
873     EXPECT_TRUE(telephonyObserver != nullptr);
874     EXPECT_TRUE(telephonyObserverProxy != nullptr);
875 }
876 
877 /**
878  * @tc.number   TelephonyObserverTest_012
879  * @tc.name     telephony observer test
880  * @tc.desc     Function test
881  */
HWTEST_F(StateRegistryTest, TelephonyObserverTest_012, Function | MediumTest | Level1)882 HWTEST_F(StateRegistryTest, TelephonyObserverTest_012, Function | MediumTest | Level1)
883 {
884     MessageOption option;
885     MessageParcel dataParcel;
886     MessageParcel reply;
887     option.SetFlags(MessageOption::TF_ASYNC);
888     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
889         TELEPHONY_LOGE("TelephonyObserverTest_003 WriteInterfaceToken failed!");
890         return;
891     }
892     std::vector<sptr<SignalInformation>> vec;
893     std::unique_ptr<NrSignalInformation> nrSignal = std::make_unique<NrSignalInformation>();
894     ASSERT_TRUE(nrSignal != nullptr);
895     vec.push_back(nrSignal.release());
896     int32_t size = static_cast<int32_t>(vec.size());
897     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
898     dataParcel.WriteInt32(size);
899     for (const auto &v : vec) {
900         v->Marshalling(dataParcel);
901     }
902     std::vector<sptr<SignalInformation>> signalInfos;
903     telephonyObserver.ConvertLteNrSignalInfoList(dataParcel, signalInfos, SignalInformation::NetworkType::GSM);
904     int32_t ret = telephonyObserver.OnRemoteRequest(
905         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_SIGNAL_INFO_UPDATED), dataParcel, reply,
906         option);
907     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
908 }
909 
910 /**
911  * @tc.number   TelephonyStateRegistryServiceTest_001
912  * @tc.name     telephony state registry service test
913  * @tc.desc     Function test
914  */
HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_001, Function | MediumTest | Level1)915 HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_001, Function | MediumTest | Level1)
916 {
917     auto service = DelayedSingleton<TelephonyStateRegistryService>::GetInstance();
918     if (service == nullptr) {
919         TELEPHONY_LOGE("TelephonyStateRegistryServiceTest_001 service is nullptr");
920         return;
921     }
922     EXPECT_TRUE(service->IsCommonEventServiceAbilityExist());
923     EXPECT_EQ(TELEPHONY_ERROR, service->GetLockReason(0));
924     EXPECT_EQ(TELEPHONY_ERROR, service->GetCellularDataConnectionNetworkType(0));
925     EXPECT_EQ(TELEPHONY_ERROR, service->GetCellularDataFlow(0));
926     EXPECT_EQ(TELEPHONY_ERROR, service->GetCellularDataConnectionState(0));
927     EXPECT_EQ(TELEPHONY_ERROR, service->GetCardType(0));
928     EXPECT_EQ(TELEPHONY_ERROR, service->GetCallState(0));
929     EXPECT_EQ(TELEPHONY_ERROR, service->GetSimState(0));
930     service->simReason_[0] = LockReason::SIM_NONE;
931     EXPECT_EQ(TELEPHONY_ERROR, service->GetLockReason(1));
932     EXPECT_NE(TELEPHONY_ERROR, service->GetLockReason(0));
933     service->cellularDataConnectionNetworkType_[0] = 0;
934     EXPECT_EQ(TELEPHONY_ERROR, service->GetCellularDataConnectionNetworkType(1));
935     EXPECT_EQ(0, service->GetCellularDataConnectionNetworkType(0));
936     service->cellularDataFlow_[0] = 0;
937     EXPECT_EQ(TELEPHONY_ERROR, service->GetCellularDataFlow(1));
938     EXPECT_EQ(0, service->GetCellularDataFlow(0));
939     service->cellularDataConnectionState_[0] = 0;
940     EXPECT_EQ(TELEPHONY_ERROR, service->GetCellularDataConnectionState(1));
941     EXPECT_EQ(0, service->GetCellularDataConnectionState(0));
942     service->cardType_[0] = CardType::UNKNOWN_CARD;
943     EXPECT_EQ(TELEPHONY_ERROR, service->GetCardType(1));
944     EXPECT_EQ(TELEPHONY_ERROR, service->GetCardType(0));
945     service->callState_[0] = 0;
946     EXPECT_EQ(TELEPHONY_ERROR, service->GetCallState(1));
947     EXPECT_EQ(0, service->GetCallState(0));
948     service->simState_[0] = SimState::SIM_STATE_UNKNOWN;
949     EXPECT_EQ(TELEPHONY_ERROR, service->GetSimState(1));
950     EXPECT_EQ(0, service->GetSimState(0));
951 }
952 
953 /**
954  * @tc.number   TelephonyStateRegistryServiceTest_002
955  * @tc.name     telephony state registry service test
956  * @tc.desc     Function test
957  */
HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_002, Function | MediumTest | Level1)958 HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_002, Function | MediumTest | Level1)
959 {
960     auto service = DelayedSingleton<TelephonyStateRegistryService>::GetInstance();
961     if (service == nullptr) {
962         TELEPHONY_LOGE("TelephonyStateRegistryServiceTest_002 service is nullptr");
963         return;
964     }
965     int32_t fd = -1;
966     std::vector<std::u16string> args;
967     EXPECT_EQ(TELEPHONY_ERR_FAIL, service->Dump(fd, args));
968     fd = 1;
969     EXPECT_EQ(TELEPHONY_SUCCESS, service->Dump(fd, args));
970     sptr<NetworkState> networkState = nullptr;
971     service->SendNetworkStateChanged(0, networkState);
972     TELEPHONY_EXT_WRAPPER.sendNetworkStateChanged_ = nullptr;
973     networkState = std::make_unique<NetworkState>().release();
974     service->SendNetworkStateChanged(0, networkState);
975     std::vector<sptr<SignalInformation>> vec;
976     service->SendSignalInfoChanged(0, vec);
977     TELEPHONY_EXT_WRAPPER.sendNetworkStateChanged_ = nullptr;
978     vec.push_back(std::make_unique<LteSignalInformation>().release());
979     service->SendSignalInfoChanged(0, vec);
980     std::u16string number = u"123456";
981     service->SendCallStateChanged(0, 0);
982     service->SendCallStateChangedAsUserMultiplePermission(0, 0, number);
983     TelephonyStateRegistryRecord record;
984     service->UpdateData(record);
985     record.telephonyObserver_ = std::make_unique<TelephonyObserver>().release();
986     service->UpdateData(record);
987     record.mask_ = TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE |
988                    TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE |
989                    TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO |
990                    TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS |
991                    TelephonyObserverBroker::OBSERVER_MASK_SIM_STATE |
992                    TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE |
993                    TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW |
994                    TelephonyObserverBroker::OBSERVER_MASK_CFU_INDICATOR |
995                    TelephonyObserverBroker::OBSERVER_MASK_VOICE_MAIL_MSG_INDICATOR |
996                    TelephonyObserverBroker::OBSERVER_MASK_ICC_ACCOUNT;
997     service->UpdateData(record);
998     EXPECT_EQ(Str8ToStr16(""), service->GetCallIncomingNumberForSlotId(record, 0));
999     TELEPHONY_EXT_WRAPPER.InitTelephonyExtWrapper();
1000 }
1001 
1002 /**
1003  * @tc.number   TelephonyStateRegistryServiceTest_003
1004  * @tc.name     telephony state registry service test
1005  * @tc.desc     Function test
1006  */
HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_003, Function | MediumTest | Level1)1007 HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_003, Function | MediumTest | Level1)
1008 {
1009     auto service = DelayedSingleton<TelephonyStateRegistryService>::GetInstance();
1010     if (service == nullptr) {
1011         TELEPHONY_LOGE("TelephonyStateRegistryServiceTest_003 service is nullptr");
1012         return;
1013     }
1014     EXPECT_TRUE(service->CheckPermission(0));
1015     EXPECT_TRUE(service->CheckCallerIsSystemApp(0));
1016     EXPECT_FALSE(service->CheckPermission(TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE));
1017     EXPECT_FALSE(service->CheckPermission(TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO));
1018     EXPECT_TRUE(service->CheckCallerIsSystemApp(TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO));
1019     EXPECT_TRUE(service->CheckCallerIsSystemApp(TelephonyObserverBroker::OBSERVER_MASK_CFU_INDICATOR));
1020     EXPECT_TRUE(service->CheckCallerIsSystemApp(TelephonyObserverBroker::OBSERVER_MASK_VOICE_MAIL_MSG_INDICATOR));
1021     uint32_t mask = TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE;
1022     int32_t tokenId = 123456789;
1023     pid_t pid = 1234;
1024     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UnregisterStateChange(0, mask, tokenId, pid));
1025     mask = TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO;
1026     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UnregisterStateChange(0, mask, tokenId, pid));
1027 
1028     TelephonyStateRegistryRecord record;
1029     service->stateRecords_.push_back(record);
1030     service->stateRecords_[0].tokenId_ = 123456789;
1031     service->stateRecords_[0].pid_ = 1234;
1032     EXPECT_EQ(TELEPHONY_SUCCESS, service->UnregisterStateChange(0, 0, tokenId, pid));
1033     service->stateRecords_[0].tokenId_ = 123456788;
1034     EXPECT_EQ(TELEPHONY_STATE_UNREGISTRY_DATA_NOT_EXIST, service->UnregisterStateChange(0, 0, tokenId, pid));
1035     service->stateRecords_[0].tokenId_ = -1;
1036     EXPECT_EQ(TELEPHONY_STATE_UNREGISTRY_DATA_NOT_EXIST, service->UnregisterStateChange(0, 0, tokenId, pid));
1037     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW;
1038     EXPECT_EQ(TELEPHONY_STATE_UNREGISTRY_DATA_NOT_EXIST, service->UnregisterStateChange(0, 0, tokenId, pid));
1039     service->stateRecords_[0].slotId_ = 1;
1040     EXPECT_EQ(TELEPHONY_STATE_UNREGISTRY_DATA_NOT_EXIST, service->UnregisterStateChange(0, 0, tokenId, pid));
1041 }
1042 
1043 /**
1044  * @tc.number   TelephonyStateRegistryServiceTest_004
1045  * @tc.name     telephony state registry service test
1046  * @tc.desc     Function test
1047  */
HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_004, Function | MediumTest | Level1)1048 HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_004, Function | MediumTest | Level1)
1049 {
1050     auto service = DelayedSingleton<TelephonyStateRegistryService>::GetInstance();
1051     if (service == nullptr) {
1052         TELEPHONY_LOGE("TelephonyStateRegistryServiceTest_004 service is nullptr");
1053         return;
1054     }
1055     if (service->state_ == ServiceRunningState::STATE_RUNNING) {
1056         service->OnStart();
1057     }
1058     sptr<TelephonyObserverBroker> telephonyObserver = nullptr;
1059     uint32_t mask = TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE;
1060     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED,
1061         service->RegisterStateChange(telephonyObserver, 0, mask, "", true, 0, 0, 0));
1062     mask = TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO;
1063     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED,
1064         service->RegisterStateChange(telephonyObserver, 0, mask, "", true, 0, 0, 0));
1065     TelephonyStateRegistryRecord record;
1066     service->stateRecords_.push_back(record);
1067     int32_t invalidSlotId = 5;
1068     EXPECT_EQ(TELEPHONY_SUCCESS, service->RegisterStateChange(telephonyObserver, invalidSlotId, 0, "", true, 0, 0, 0));
1069     EXPECT_EQ(TELEPHONY_SUCCESS, service->RegisterStateChange(telephonyObserver, 0, 0, "", true, 0, 0, 0));
1070     EXPECT_EQ(TELEPHONY_SUCCESS, service->RegisterStateChange(telephonyObserver, 0, 0, "", false, 0, 0, 0));
1071     service->stateRecords_[0].tokenId_ = 1;
1072     EXPECT_EQ(TELEPHONY_SUCCESS, service->RegisterStateChange(telephonyObserver, 0, 0, "", true, 0, 0, 0));
1073     service->stateRecords_[0].tokenId_ = 123456789;
1074     EXPECT_EQ(TELEPHONY_SUCCESS, service->RegisterStateChange(telephonyObserver, 0, 0, "", true, 0, 0, 0));
1075     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW;
1076     EXPECT_EQ(TELEPHONY_SUCCESS, service->RegisterStateChange(telephonyObserver, 0, 0, "", true, 0, 0, 0));
1077     service->stateRecords_[0].slotId_ = 1;
1078     EXPECT_EQ(TELEPHONY_SUCCESS, service->RegisterStateChange(telephonyObserver, 0, 0, "", true, 0, 0, 0));
1079 }
1080 
1081 /**
1082  * @tc.number   TelephonyStateRegistryServiceTest_005
1083  * @tc.name     telephony state registry service test
1084  * @tc.desc     Function test
1085  */
HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_005, Function | MediumTest | Level1)1086 HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_005, Function | MediumTest | Level1)
1087 {
1088     auto service = DelayedSingleton<TelephonyStateRegistryService>::GetInstance();
1089     if (service == nullptr) {
1090         TELEPHONY_LOGE("TelephonyStateRegistryServiceTest_005 service is nullptr");
1091         return;
1092     }
1093     TelephonyStateRegistryRecord record;
1094     service->stateRecords_.push_back(record);
1095     int32_t invalidSlotId = 5;
1096     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_SLODID_ERROR, service->UpdateVoiceMailMsgIndicator(invalidSlotId, true));
1097     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UpdateVoiceMailMsgIndicator(0, true));
1098     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UpdateIccAccount());
1099     service->stateRecords_[0].telephonyObserver_ = std::make_unique<TelephonyObserver>().release();
1100     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UpdateIccAccount());
1101     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_ICC_ACCOUNT;
1102     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UpdateIccAccount());
1103     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_SLODID_ERROR, service->UpdateCfuIndicator(invalidSlotId, true));
1104     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UpdateCfuIndicator(0, true));
1105     sptr<NetworkState> networkState = std::make_unique<NetworkState>().release();
1106     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_SLODID_ERROR, service->UpdateNetworkState(invalidSlotId, networkState));
1107     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UpdateNetworkState(0, networkState));
1108     std::vector<sptr<CellInformation>> vecCellInfo;
1109     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_SLODID_ERROR, service->UpdateCellInfo(invalidSlotId, vecCellInfo));
1110     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UpdateCellInfo(0, vecCellInfo));
1111     std::vector<sptr<SignalInformation>> vecSignalInfo;
1112     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_SLODID_ERROR, service->UpdateSignalInfo(invalidSlotId, vecSignalInfo));
1113     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UpdateSignalInfo(0, vecSignalInfo));
1114     CardType type = CardType::UNKNOWN_CARD;
1115     SimState state = SimState::SIM_STATE_UNKNOWN;
1116     LockReason reason = LockReason::SIM_NONE;
1117     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_SLODID_ERROR, service->UpdateSimState(invalidSlotId, type, state, reason));
1118     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UpdateSimState(0, type, state, reason));
1119     std::u16string number = u"123";
1120     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_SLODID_ERROR, service->UpdateCallStateForSlotId(invalidSlotId, 0, number));
1121     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UpdateCallStateForSlotId(0, 0, number));
1122     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UpdateCallState(0, number));
1123     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_SLODID_ERROR, service->UpdateCellularDataFlow(invalidSlotId, 0));
1124     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UpdateCellularDataFlow(0, 0));
1125     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_SLODID_ERROR, service->UpdateCellularDataConnectState(invalidSlotId, 0, 0));
1126     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED, service->UpdateCellularDataConnectState(0, 0, 0));
1127 }
1128 
1129 /**
1130  * @tc.number   TelephonyStateRegistryServiceTest_006
1131  * @tc.name     telephony state registry service test
1132  * @tc.desc     Function test
1133  */
HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_006, Function | MediumTest | Level1)1134 HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_006, Function | MediumTest | Level1)
1135 {
1136     auto service = DelayedSingleton<TelephonyStateRegistryService>::GetInstance();
1137     if (service == nullptr) {
1138         TELEPHONY_LOGE("TelephonyStateRegistryServiceTest_006 service is nullptr");
1139         return;
1140     }
1141     AccessToken token;
1142     std::u16string number = u"123";
1143     TelephonyStateRegistryRecord record;
1144     EXPECT_FALSE(record.IsCanReadCallHistory());
1145     service->stateRecords_.push_back(record);
1146     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateCellularDataConnectState(0, 0, 0));
1147     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateCellularDataFlow(0, 0));
1148     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateCallStateForSlotId(0, 0, number));
1149     CardType type = CardType::UNKNOWN_CARD;
1150     SimState state = SimState::SIM_STATE_UNKNOWN;
1151     LockReason reason = LockReason::SIM_NONE;
1152     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateSimState(0, type, state, reason));
1153 
1154     service->stateRecords_[0].telephonyObserver_ = std::make_unique<TelephonyObserver>().release();
1155     service->stateRecords_[0].slotId_ = 3;
1156     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE;
1157     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateCellularDataConnectState(0, 0, 0));
1158     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW;
1159     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateCellularDataFlow(0, 0));
1160     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE;
1161     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateCallState(0, number));
1162     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateCallStateForSlotId(0, 0, number));
1163     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_SIM_STATE;
1164     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateSimState(0, type, state, reason));
1165 
1166     service->stateRecords_[0].slotId_ = 0;
1167     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE;
1168     EXPECT_EQ(TELEPHONY_SUCCESS, service->UpdateCellularDataConnectState(0, 0, 0));
1169     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW;
1170     EXPECT_EQ(TELEPHONY_SUCCESS, service->UpdateCellularDataFlow(0, 0));
1171     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE;
1172     service->stateRecords_[0].slotId_ = -1;
1173     EXPECT_EQ(TELEPHONY_SUCCESS, service->UpdateCallState(-1, number));
1174     service->stateRecords_[0].slotId_ = 0;
1175     EXPECT_EQ(TELEPHONY_SUCCESS, service->UpdateCallStateForSlotId(0, 0, number));
1176     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_SIM_STATE;
1177     EXPECT_EQ(TELEPHONY_SUCCESS, service->UpdateSimState(0, type, state, reason));
1178 }
1179 
1180 /**
1181  * @tc.number   TelephonyStateRegistryServiceTest_007
1182  * @tc.name     telephony state registry service test
1183  * @tc.desc     Function test
1184  */
HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_007, Function | MediumTest | Level1)1185 HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_007, Function | MediumTest | Level1)
1186 {
1187     auto service = DelayedSingleton<TelephonyStateRegistryService>::GetInstance();
1188     if (service == nullptr) {
1189         TELEPHONY_LOGE("TelephonyStateRegistryServiceTest_007 service is nullptr");
1190         return;
1191     }
1192     AccessToken token;
1193     TelephonyStateRegistryRecord record;
1194     service->stateRecords_.push_back(record);
1195     sptr<NetworkState> networkState = std::make_unique<NetworkState>().release();
1196     std::vector<sptr<SignalInformation>> vecSignalInfo;
1197     EXPECT_NE(TELEPHONY_SUCCESS, service->UpdateSignalInfo(0, vecSignalInfo));
1198     std::vector<sptr<CellInformation>> vecCellInfo;
1199     EXPECT_NE(TELEPHONY_SUCCESS, service->UpdateCellInfo(0, vecCellInfo));
1200     EXPECT_NE(TELEPHONY_SUCCESS, service->UpdateNetworkState(0, networkState));
1201     EXPECT_NE(TELEPHONY_SUCCESS, service->UpdateCfuIndicator(0, true));
1202     EXPECT_NE(TELEPHONY_SUCCESS, service->UpdateVoiceMailMsgIndicator(0, true));
1203 
1204     service->stateRecords_[0].telephonyObserver_ = std::make_unique<TelephonyObserver>().release();
1205     service->stateRecords_[0].slotId_ = 3;
1206     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS;
1207     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateSignalInfo(0, vecSignalInfo));
1208     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO;
1209     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateCellInfo(0, vecCellInfo));
1210     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE;
1211     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateNetworkState(0, networkState));
1212     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_CFU_INDICATOR;
1213     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateCfuIndicator(0, true));
1214     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_VOICE_MAIL_MSG_INDICATOR;
1215     EXPECT_EQ(TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST, service->UpdateVoiceMailMsgIndicator(0, true));
1216 
1217     service->stateRecords_[0].slotId_ = 0;
1218     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS;
1219     EXPECT_EQ(TELEPHONY_SUCCESS, service->UpdateSignalInfo(0, vecSignalInfo));
1220     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO;
1221     EXPECT_EQ(TELEPHONY_SUCCESS, service->UpdateCellInfo(0, vecCellInfo));
1222     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE;
1223     EXPECT_EQ(TELEPHONY_SUCCESS, service->UpdateNetworkState(0, networkState));
1224     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_CFU_INDICATOR;
1225     EXPECT_EQ(TELEPHONY_SUCCESS, service->UpdateCfuIndicator(0, true));
1226     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_VOICE_MAIL_MSG_INDICATOR;
1227     EXPECT_EQ(TELEPHONY_SUCCESS, service->UpdateVoiceMailMsgIndicator(0, true));
1228 }
1229 
1230 /**
1231  * @tc.number   TelephonyStateRegistryServiceTest_008
1232  * @tc.name     telephony state registry service test
1233  * @tc.desc     Function test
1234  */
HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_008, Function | MediumTest | Level1)1235 HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_008, Function | MediumTest | Level1)
1236 {
1237     auto service = DelayedSingleton<TelephonyStateRegistryService>::GetInstance();
1238     if (service == nullptr) {
1239         TELEPHONY_LOGE("TelephonyStateRegistryServiceTest_008 service is nullptr");
1240         return;
1241     }
1242     AccessToken token;
1243     MessageParcel dataParcel;
1244     dataParcel.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::GSM));
1245     dataParcel.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::CDMA));
1246     dataParcel.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::LTE));
1247     dataParcel.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::NR));
1248     dataParcel.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::WCDMA));
1249     dataParcel.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::UNKNOWN));
1250     int32_t size = 6;
1251     std::vector<sptr<SignalInformation>> result;
1252     service->parseSignalInfos(dataParcel, size, result);
1253     MessageParcel dataSignal;
1254     service->ParseLteNrSignalInfos(dataSignal, result, SignalInformation::NetworkType::UNKNOWN);
1255     MessageParcel dataSignalNr;
1256     dataSignalNr.WriteInt32(0);
1257     dataSignalNr.WriteInt32(0);
1258     dataSignalNr.WriteInt32(0);
1259     service->ParseLteNrSignalInfos(dataSignalNr, result, SignalInformation::NetworkType::NR);
1260     MessageParcel dataSignalLte;
1261     dataSignalLte.WriteInt32(0);
1262     dataSignalLte.WriteInt32(0);
1263     dataSignalLte.WriteInt32(0);
1264     dataSignalLte.WriteInt32(0);
1265     service->ParseLteNrSignalInfos(dataSignalLte, result, SignalInformation::NetworkType::LTE);
1266 
1267     TelephonyStateRegistryRecord record;
1268     std::u16string testNumber = u"123";
1269     service->callIncomingNumber_[0] = testNumber;
1270     EXPECT_EQ(u"", service->GetCallIncomingNumberForSlotId(record, 0));
1271     EXPECT_TRUE(service->CheckPermission(TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE));
1272     EXPECT_TRUE(service->CheckPermission(TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO));
1273     EXPECT_TRUE(service->CheckCallerIsSystemApp(TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO));
1274     EXPECT_TRUE(service->CheckCallerIsSystemApp(TelephonyObserverBroker::OBSERVER_MASK_CFU_INDICATOR));
1275     EXPECT_TRUE(service->CheckCallerIsSystemApp(TelephonyObserverBroker::OBSERVER_MASK_VOICE_MAIL_MSG_INDICATOR));
1276 }
1277 
1278 /**
1279  * @tc.number   TelephonyStateRegistryServiceTest_009
1280  * @tc.name     telephony state registry service test
1281  * @tc.desc     Function test
1282  */
HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_009, Function | MediumTest | Level1)1283 HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_009, Function | MediumTest | Level1)
1284 {
1285     auto service = DelayedSingleton<TelephonyStateRegistryService>::GetInstance();
1286     if (service == nullptr) {
1287         TELEPHONY_LOGE("TelephonyStateRegistryServiceTest_009 service is nullptr");
1288         return;
1289     }
1290     MessageParcel dataCellInfo;
1291     int32_t size = 4;
1292     dataCellInfo.WriteInt32(0);
1293     dataCellInfo.WriteInt32(size);
1294     dataCellInfo.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::GSM));
1295     dataCellInfo.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::LTE));
1296     dataCellInfo.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::NR));
1297     dataCellInfo.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::UNKNOWN));
1298     std::vector<sptr<SignalInformation>> result;
1299     MessageParcel reply;
1300     service->OnUpdateCellInfo(dataCellInfo, reply);
1301 
1302     MessageParcel dataNetworkState;
1303     dataNetworkState.WriteInt32(0);
1304     service->OnUpdateNetworkState(dataNetworkState, reply);
1305     MessageParcel dataRegisterState;
1306     dataNetworkState.WriteInt32(0);
1307     dataNetworkState.WriteInt32(0);
1308     dataNetworkState.WriteBool(true);
1309     service->OnRegisterStateChange(dataRegisterState, reply);
1310 
1311     MessageParcel dataRead;
1312     sptr<TelephonyObserverBroker> callback = nullptr;
1313     EXPECT_NE(TELEPHONY_SUCCESS, service->ReadData(dataRead, reply, callback));
1314 }
1315 
1316 /**
1317  * @tc.number   TelephonyStateRegistryServiceTest_010
1318  * @tc.name     telephony state registry service test
1319  * @tc.desc     Function test
1320  */
HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_010, Function | MediumTest | Level1)1321 HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_010, Function | MediumTest | Level1)
1322 {
1323     auto service = DelayedSingleton<TelephonyStateRegistryService>::GetInstance();
1324     if (service == nullptr) {
1325         TELEPHONY_LOGE("TelephonyStateRegistryServiceTest_010 service is nullptr");
1326         return;
1327     }
1328     AccessToken token;
1329     TelephonyStateRegistryRecord record;
1330     service->stateRecords_.push_back(record);
1331     service->stateRecords_[0].telephonyObserver_ = std::make_unique<TelephonyObserver>().release();
1332     service->stateRecords_[0].slotId_ = 0;
1333     TELEPHONY_EXT_WRAPPER.onSignalInfoUpdated_ = nullptr;
1334     std::vector<sptr<SignalInformation>> vecSignalInfo;
1335     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS;
1336     EXPECT_EQ(TELEPHONY_SUCCESS, service->UpdateSignalInfo(0, vecSignalInfo));
1337     TELEPHONY_EXT_WRAPPER.onCellInfoUpdated_ = nullptr;
1338     std::vector<sptr<CellInformation>> vecCellInfo;
1339     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO;
1340     EXPECT_EQ(TELEPHONY_SUCCESS, service->UpdateCellInfo(0, vecCellInfo));
1341     TELEPHONY_EXT_WRAPPER.onNetworkStateUpdated_ = nullptr;
1342     sptr<NetworkState> networkState = std::make_unique<NetworkState>().release();
1343     service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE;
1344     EXPECT_EQ(TELEPHONY_SUCCESS, service->UpdateNetworkState(0, networkState));
1345     TELEPHONY_EXT_WRAPPER.InitTelephonyExtWrapper();
1346 }
1347 
1348 /**
1349  * @tc.number   TelephonyStateRegistrySimCountTest_001
1350  * @tc.name     telephony state registry service test
1351  * @tc.desc     Function test
1352  */
HWTEST_F(StateRegistryTest, TelephonyStateRegistrySimCountTest_001, Function | MediumTest | Level1)1353 HWTEST_F(StateRegistryTest, TelephonyStateRegistrySimCountTest_001, Function | MediumTest | Level1)
1354 {
1355     auto service = DelayedSingleton<TelephonyStateRegistryService>::GetInstance();
1356     if (service == nullptr) {
1357         TELEPHONY_LOGE("TelephonyStateRegistryServiceTest_001 service is nullptr");
1358         return;
1359     }
1360     service->slotSize_ = MAX_SLOT_COUNT;
1361     EXPECT_TRUE(service->VerifySlotId(0));
1362     EXPECT_TRUE(service->VerifySlotId(1));
1363     EXPECT_TRUE(service->VerifySlotId(2));
1364     EXPECT_FALSE(service->VerifySlotId(3));
1365     EXPECT_FALSE(service->VerifySlotId(-1));
1366 }
1367 
1368 /**
1369  * @tc.number   TelephonyStateRegistrySimCountTest_002
1370  * @tc.name     telephony state registry service test
1371  * @tc.desc     Function test
1372  */
HWTEST_F(StateRegistryTest, TelephonyStateRegistrySimCountTest_002, Function | MediumTest | Level1)1373 HWTEST_F(StateRegistryTest, TelephonyStateRegistrySimCountTest_002, Function | MediumTest | Level1)
1374 {
1375     auto service = DelayedSingleton<TelephonyStateRegistryService>::GetInstance();
1376     if (service == nullptr) {
1377         TELEPHONY_LOGE("TelephonyStateRegistryServiceTest_001 service is nullptr");
1378         return;
1379     }
1380     service->slotSize_ = DUAL_SLOT_COUNT;
1381     EXPECT_TRUE(service->VerifySlotId(0));
1382     EXPECT_TRUE(service->VerifySlotId(1));
1383     EXPECT_FALSE(service->VerifySlotId(2));
1384     EXPECT_FALSE(service->VerifySlotId(3));
1385     EXPECT_FALSE(service->VerifySlotId(-1));
1386 }
1387 
1388 #else // TEL_TEST_UNSUPPORT
1389 /**
1390  * @tc.number   State_MockTest_001
1391  * @tc.name     Mock test for unsupport platform
1392  * @tc.desc     Function test
1393  */
HWTEST_F(StateRegistryTest, State_MockTest_001, Function | MediumTest | Level1)1394 HWTEST_F(StateRegistryTest, State_MockTest_001, Function | MediumTest | Level1)
1395 {
1396     EXPECT_TRUE(true);
1397 }
1398 #endif // TEL_TEST_UNSUPPORT
1399 } // namespace Telephony
1400 } // namespace OHOS
1401