• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "locator_background_proxy_test.h"
17 
18 #include "accesstoken_kit.h"
19 #include "app_state_data.h"
20 #include "bundle_mgr_interface.h"
21 #include "bundle_mgr_proxy.h"
22 #include "common_event_manager.h"
23 #include "common_event_subscriber.h"
24 #include "common_event_support.h"
25 #include "if_system_ability_manager.h"
26 #include "ipc_skeleton.h"
27 #include "iservice_registry.h"
28 #include "message_parcel.h"
29 #include "nativetoken_kit.h"
30 #include "system_ability_definition.h"
31 #include "token_setproc.h"
32 #include "want.h"
33 
34 #include "common_utils.h"
35 #include "constant_definition.h"
36 #include "location.h"
37 #include "location_log.h"
38 #include "locator_callback_napi.h"
39 #include "locator_callback_proxy.h"
40 #include "permission_manager.h"
41 
42 using namespace testing::ext;
43 namespace OHOS {
44 namespace Location {
45 using Want = OHOS::AAFwk::Want;
46 const int32_t LOCATION_PERM_NUM = 5;
47 const int VAL_UID = 20010044;
48 const std::string RUNNING_STATE_OBSERVER = "ohos.permission.RUNNING_STATE_OBSERVER";
SetUp()49 void LocatorBackgroundProxyTest::SetUp()
50 {
51     MockNativePermission();
52 }
53 
TearDown()54 void LocatorBackgroundProxyTest::TearDown()
55 {
56 }
57 
MockNativePermission()58 void LocatorBackgroundProxyTest::MockNativePermission()
59 {
60     const char *perms[] = {
61         ACCESS_LOCATION.c_str(), ACCESS_APPROXIMATELY_LOCATION.c_str(),
62         ACCESS_BACKGROUND_LOCATION.c_str(), MANAGE_SECURE_SETTINGS.c_str(),
63         RUNNING_STATE_OBSERVER.c_str(),
64     };
65     NativeTokenInfoParams infoInstance = {
66         .dcapsNum = 0,
67         .permsNum = LOCATION_PERM_NUM,
68         .aclsNum = 0,
69         .dcaps = nullptr,
70         .perms = perms,
71         .acls = nullptr,
72         .processName = "LocatorBackgroundProxyTest",
73         .aplStr = "system_basic",
74     };
75     tokenId_ = GetAccessTokenId(&infoInstance);
76     SetSelfTokenID(tokenId_);
77     Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
78 }
79 
80 HWTEST_F(LocatorBackgroundProxyTest, AppStateChangeCallbackTest001, TestSize.Level1)
81 {
82     GTEST_LOG_(INFO)
83         << "LocatorBackgroundProxyTest, AppStateChangeCallbackTest001, TestSize.Level1";
84     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] AppStateChangeCallbackTest001 begin");
85     auto appStateObserver =
86         sptr<AppStateChangeCallback>(new (std::nothrow) AppStateChangeCallback());
87     int32_t state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_FOREGROUND);
88     AppExecFwk::AppStateData appStateData;
89     appStateData.uid = 1;
90     appStateData.pid = 0;
91     appStateData.state = state;
92     ASSERT_TRUE(appStateObserver != nullptr);
93     appStateObserver->OnForegroundApplicationChanged(appStateData);
94     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] AppStateChangeCallbackTest001 end");
95 }
96 
97 HWTEST_F(LocatorBackgroundProxyTest, UpdateListOnRequestChangeTest001, TestSize.Level1)
98 {
99     GTEST_LOG_(INFO)
100         << "LocatorBackgroundProxyTest, UpdateListOnRequestChangeTest001, TestSize.Level1";
101     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UpdateListOnRequestChangeTest001 begin");
102     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
103     EXPECT_NE(nullptr, locatorBackgroundProxy);
104     std::shared_ptr<Request> request1 = std::make_shared<Request>();
105     request1->SetUid(1000);
106     request1->SetPid(0);
107     request1->SetTokenId(tokenId_);
108     request1->SetFirstTokenId(0);
109     request1->SetPackageName("LocatorBackgroundProxyTest");
110     locatorBackgroundProxy->UpdateListOnRequestChange(request1);
111     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UpdateListOnRequestChangeTest001 end");
112 }
113 
114 HWTEST_F(LocatorBackgroundProxyTest, UpdateListOnRequestChangeTest002, TestSize.Level1)
115 {
116     GTEST_LOG_(INFO)
117         << "LocatorBackgroundProxyTest, UpdateListOnRequestChangeTest002, TestSize.Level1";
118     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UpdateListOnRequestChangeTest002 begin");
119     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
120     EXPECT_NE(nullptr, locatorBackgroundProxy);
121     locatorBackgroundProxy->UpdateListOnRequestChange(nullptr);
122     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UpdateListOnRequestChangeTest002 end");
123 }
124 
125 HWTEST_F(LocatorBackgroundProxyTest, OnSuspendTest001, TestSize.Level1)
126 {
127     GTEST_LOG_(INFO)
128         << "LocatorBackgroundProxyTest, OnSuspendTest001, TestSize.Level1";
129     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSuspendTest001 begin");
130     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
131     EXPECT_NE(nullptr, locatorBackgroundProxy);
132     std::shared_ptr<Request> request1 = std::make_shared<Request>();
133     request1->SetUid(1000);
134     request1->SetPid(0);
135     request1->SetTokenId(tokenId_);
136     request1->SetFirstTokenId(0);
137     request1->SetPackageName("LocatorBackgroundProxyTest");
138     locatorBackgroundProxy->OnSuspend(request1, true); // cant find uid in requestMap
139 
140     locatorBackgroundProxy->OnSuspend(request1, false); // cant find uid in requestMap
141     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSuspendTest001 end");
142 }
143 
144 HWTEST_F(LocatorBackgroundProxyTest, OnSuspendTest002, TestSize.Level1)
145 {
146     GTEST_LOG_(INFO)
147         << "LocatorBackgroundProxyTest, OnSuspendTest002, TestSize.Level1";
148     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSuspendTest002 begin");
149     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
150     EXPECT_NE(nullptr, locatorBackgroundProxy);
151     std::shared_ptr<Request> request1 = std::make_shared<Request>();
152     request1->SetUid(VAL_UID);
153     request1->SetPid(0);
154     request1->SetTokenId(tokenId_);
155     request1->SetFirstTokenId(0);
156     request1->SetPackageName("name");
157     auto requestConfig = std::make_unique<RequestConfig>();
158     EXPECT_NE(nullptr, requestConfig);
159     requestConfig->SetPriority(PRIORITY_FAST_FIRST_FIX);
160     requestConfig->SetFixNumber(0);
161     request1->SetRequestConfig(*requestConfig);
162     locatorBackgroundProxy->OnSuspend(request1, true); // cant find request in list
163     locatorBackgroundProxy->OnSuspend(request1, false); // add to requestsList
164     locatorBackgroundProxy->OnSuspend(request1, false); // max num is 1, cant add request
165     locatorBackgroundProxy->OnSuspend(request1, true); // remove from requestList
166     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSuspendTest002 end");
167 }
168 
169 HWTEST_F(LocatorBackgroundProxyTest, OnSuspendTest003, TestSize.Level1)
170 {
171     GTEST_LOG_(INFO)
172         << "LocatorBackgroundProxyTest, OnSuspendTest003, TestSize.Level1";
173     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSuspendTest003 begin");
174     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
175     EXPECT_NE(nullptr, locatorBackgroundProxy);
176     std::shared_ptr<Request> request1 = std::make_shared<Request>();
177     request1->SetUid(VAL_UID);
178     request1->SetPid(0);
179     request1->SetTokenId(tokenId_);
180     request1->SetFirstTokenId(0);
181     request1->SetPackageName("name");
182     auto requestConfig = std::make_unique<RequestConfig>();
183     EXPECT_NE(nullptr, requestConfig);
184     requestConfig->SetPriority(PRIORITY_FAST_FIRST_FIX);
185     requestConfig->SetFixNumber(1); // fix number is 1
186     request1->SetRequestConfig(*requestConfig);
187     locatorBackgroundProxy->OnSuspend(request1, false); // add to requestsList
188     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSuspendTest003 end");
189 }
190 
191 HWTEST_F(LocatorBackgroundProxyTest, OnSuspendTest004, TestSize.Level1)
192 {
193     GTEST_LOG_(INFO)
194         << "LocatorBackgroundProxyTest, OnSuspendTest004, TestSize.Level1";
195     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSuspendTest004 begin");
196     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
197     EXPECT_NE(nullptr, locatorBackgroundProxy);
198     std::shared_ptr<Request> request1 = std::make_shared<Request>();
199     request1->SetUid(VAL_UID);
200     request1->SetPid(0);
201     request1->SetTokenId(0); // invalid token id
202     request1->SetFirstTokenId(0);
203     request1->SetPackageName("name");
204     auto requestConfig = std::make_unique<RequestConfig>();
205     EXPECT_NE(nullptr, requestConfig);
206     requestConfig->SetPriority(PRIORITY_FAST_FIRST_FIX);
207     requestConfig->SetFixNumber(0);
208     request1->SetRequestConfig(*requestConfig);
209     locatorBackgroundProxy->OnSuspend(request1, false); // permission denied, cant add to requestsList
210     locatorBackgroundProxy->OnSuspend(request1, true); // permission denied, cant remove from requestList
211     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSuspendTest004 end");
212 }
213 
214 HWTEST_F(LocatorBackgroundProxyTest, OnSaStateChangeTest001, TestSize.Level1)
215 {
216     GTEST_LOG_(INFO)
217         << "LocatorBackgroundProxyTest, OnSaStateChangeTest001, TestSize.Level1";
218     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSaStateChangeTest001 begin");
219     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
220     EXPECT_NE(nullptr, locatorBackgroundProxy);
221     locatorBackgroundProxy->OnSaStateChange(true);
222 
223     locatorBackgroundProxy->OnSaStateChange(false);
224 
225     locatorBackgroundProxy->OnSaStateChange(true);
226     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSaStateChangeTest001 end");
227 }
228 
229 HWTEST_F(LocatorBackgroundProxyTest, OnDeleteRequestRecord001, TestSize.Level1)
230 {
231     GTEST_LOG_(INFO)
232         << "LocatorBackgroundProxyTest, OnDeleteRequestRecord001, TestSize.Level1";
233     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnDeleteRequestRecord001 begin");
234     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
235     EXPECT_NE(nullptr, locatorBackgroundProxy);
236     std::shared_ptr<Request> request1 = std::make_shared<Request>();
237     request1->SetUid(1000);
238     request1->SetPid(0);
239     request1->SetTokenId(tokenId_);
240     request1->SetFirstTokenId(0);
241     request1->SetPackageName("LocatorBackgroundProxyTest");
242     locatorBackgroundProxy->OnDeleteRequestRecord(request1);
243     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnDeleteRequestRecord001 end");
244 }
245 
246 HWTEST_F(LocatorBackgroundProxyTest, IsCallbackInProxyTest001, TestSize.Level1)
247 {
248     GTEST_LOG_(INFO)
249         << "LocatorBackgroundProxyTest, IsCallbackInProxyTest001, TestSize.Level1";
250     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsCallbackInProxyTest001 begin");
251     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
252     EXPECT_NE(nullptr, locatorBackgroundProxy);
253     sptr<LocatorCallbackNapi> locatorCallbackHost =
254         sptr<LocatorCallbackNapi>(new (std::nothrow)LocatorCallbackNapi());
255     auto callback = sptr<ILocatorCallback>(locatorCallbackHost);
256     EXPECT_EQ(false, locatorBackgroundProxy->IsCallbackInProxy(callback));
257 
258     std::shared_ptr<Request> request1 = std::make_shared<Request>();
259     request1->SetUid(1000);
260     request1->SetPid(0);
261     request1->SetTokenId(tokenId_);
262     request1->SetFirstTokenId(0);
263     request1->SetLocatorCallBack(callback);
264     request1->SetPackageName("LocatorBackgroundProxyTest");
265     auto requestConfig1 = std::make_unique<RequestConfig>();
266     EXPECT_NE(nullptr, requestConfig1);
267     requestConfig1->SetPriority(PRIORITY_FAST_FIRST_FIX);
268     requestConfig1->SetMaxAccuracy(1000.0);
269     requestConfig1->SetFixNumber(0);
270     request1->SetRequestConfig(*requestConfig1);
271     locatorBackgroundProxy->OnSuspend(request1, false);
272     EXPECT_EQ(false, locatorBackgroundProxy->IsCallbackInProxy(callback));
273     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsCallbackInProxyTest001 end");
274 }
275 
276 HWTEST_F(LocatorBackgroundProxyTest, IsAppBackgroundTest001, TestSize.Level1)
277 {
278     GTEST_LOG_(INFO)
279         << "LocatorBackgroundProxyTest, IsAppBackgroundTest001, TestSize.Level1";
280     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppBackgroundTest001 begin");
281     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
282     EXPECT_NE(nullptr, locatorBackgroundProxy);
283     EXPECT_EQ(true, locatorBackgroundProxy->IsAppBackground("LocatorBackgroundProxyTest"));
284     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppBackgroundTest001 end");
285 }
286 
287 HWTEST_F(LocatorBackgroundProxyTest, RegisterAppStateObserverTest001, TestSize.Level1)
288 {
289     GTEST_LOG_(INFO)
290         << "LocatorBackgroundProxyTest, RegisterAppStateObserverTest001, TestSize.Level1";
291     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] RegisterAppStateObserverTest001 begin");
292     MockNativePermission();
293     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
294     EXPECT_NE(nullptr, locatorBackgroundProxy);
295     EXPECT_EQ(true, locatorBackgroundProxy->UnregisterAppStateObserver()); // unreg first
296     locatorBackgroundProxy->RegisterAppStateObserver();
297     EXPECT_EQ(true, locatorBackgroundProxy->RegisterAppStateObserver()); // register again
298     EXPECT_EQ(true, locatorBackgroundProxy->UnregisterAppStateObserver());
299     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] RegisterAppStateObserverTest001 end");
300 }
301 
302 HWTEST_F(LocatorBackgroundProxyTest, UpdateListOnUserSwitchTest001, TestSize.Level1)
303 {
304     GTEST_LOG_(INFO)
305         << "LocatorBackgroundProxyTest, UpdateListOnUserSwitchTest001, TestSize.Level1";
306     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UpdateListOnUserSwitchTest001 begin");
307     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
308     ASSERT_TRUE(locatorBackgroundProxy != nullptr);
309     int userId = 0;
310     CommonUtils::GetCurrentUserId(userId);
311     locatorBackgroundProxy->UpdateListOnUserSwitch(userId);
312     EXPECT_EQ(userId, locatorBackgroundProxy->curUserId_);
313     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UpdateListOnUserSwitchTest001 end");
314 }
315 
316 HWTEST_F(LocatorBackgroundProxyTest, UpdateListOnUserSwitchTest002, TestSize.Level1)
317 {
318     GTEST_LOG_(INFO)
319         << "LocatorBackgroundProxyTest, UpdateListOnUserSwitchTest002, TestSize.Level1";
320     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UpdateListOnUserSwitchTest002 begin");
321     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
322     ASSERT_TRUE(locatorBackgroundProxy != nullptr);
323     locatorBackgroundProxy->UpdateListOnUserSwitch(0); // requestsMap cant find userid
324     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UpdateListOnUserSwitchTest002 end");
325 }
326 
327 HWTEST_F(LocatorBackgroundProxyTest, IsCallbackInProxyTest002, TestSize.Level1)
328 {
329     GTEST_LOG_(INFO)
330         << "LocatorBackgroundProxyTest, IsCallbackInProxyTest001, TestSize.Level1";
331     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsCallbackInProxyTest001 begin");
332     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
333     ASSERT_TRUE(locatorBackgroundProxy != nullptr);
334     std::shared_ptr<Request> request = std::make_shared<Request>();
335     request->SetLocatorCallBack(locatorBackgroundProxy->callback_);
336     locatorBackgroundProxy->requestsList_->push_back(request);
337     EXPECT_EQ(true,
338         locatorBackgroundProxy->IsCallbackInProxy(locatorBackgroundProxy->callback_));
339     sptr<ILocatorCallback> newCallback = new (std::nothrow) LocatorCallbackStub();
340     EXPECT_EQ(false,
341         locatorBackgroundProxy->IsCallbackInProxy(newCallback));
342     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsCallbackInProxyTest001 end");
343 }
344 
345 HWTEST_F(LocatorBackgroundProxyTest, OnUserSwitchTest001, TestSize.Level1)
346 {
347     GTEST_LOG_(INFO)
348         << "LocatorBackgroundProxyTest, OnUserSwitchTest001, TestSize.Level1";
349     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnUserSwitchTest001 begin");
350     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
351     ASSERT_TRUE(locatorBackgroundProxy != nullptr);
352     int userId = 0;
353     CommonUtils::GetCurrentUserId(userId);
354     std::shared_ptr<Request> request = std::make_shared<Request>();
355     locatorBackgroundProxy->requestsList_->push_back(request);
356     locatorBackgroundProxy->OnUserSwitch(userId);
357     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnUserSwitchTest001 end");
358 }
359 
360 HWTEST_F(LocatorBackgroundProxyTest, OnUserSwitchTest002, TestSize.Level1)
361 {
362     GTEST_LOG_(INFO)
363         << "LocatorBackgroundProxyTest, OnUserSwitchTest002, TestSize.Level1";
364     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnUserSwitchTest002 begin");
365     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
366     ASSERT_TRUE(locatorBackgroundProxy != nullptr);
367     int userId = 0;
368     CommonUtils::GetCurrentUserId(userId);
369     locatorBackgroundProxy->requestsList_->clear();
370     locatorBackgroundProxy->OnUserSwitch(userId);
371     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnUserSwitchTest002 end");
372 }
373 
374 HWTEST_F(LocatorBackgroundProxyTest, OnUserRemoveTest001, TestSize.Level1)
375 {
376     GTEST_LOG_(INFO)
377         << "LocatorBackgroundProxyTest, OnUserRemoveTest001, TestSize.Level1";
378     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnUserRemoveTest001 begin");
379     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
380     ASSERT_TRUE(locatorBackgroundProxy != nullptr);
381     int userId = 0;
382     CommonUtils::GetCurrentUserId(userId);
383     locatorBackgroundProxy->OnUserRemove(userId);
384     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnUserRemoveTest001 end");
385 }
386 
387 HWTEST_F(LocatorBackgroundProxyTest, OnUserRemoveTest002, TestSize.Level1)
388 {
389     GTEST_LOG_(INFO)
390         << "LocatorBackgroundProxyTest, OnUserRemoveTest002, TestSize.Level1";
391     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnUserRemoveTest002 begin");
392     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
393     ASSERT_TRUE(locatorBackgroundProxy != nullptr);
394     locatorBackgroundProxy->OnUserRemove(0);
395     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnUserRemoveTest002 end");
396 }
397 
398 HWTEST_F(LocatorBackgroundProxyTest, CheckMaxRequestNumTest001, TestSize.Level1)
399 {
400     GTEST_LOG_(INFO)
401         << "LocatorBackgroundProxyTest, CheckMaxRequestNumTest001, TestSize.Level1";
402     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] CheckMaxRequestNumTest001 begin");
403     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
404     ASSERT_TRUE(locatorBackgroundProxy != nullptr);
405     locatorBackgroundProxy->CheckMaxRequestNum(0, "PKG_FOR_TEST"); // cant find userId
406     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] CheckMaxRequestNumTest001 end");
407 }
408 
409 HWTEST_F(LocatorBackgroundProxyTest, CheckMaxRequestNumTest002, TestSize.Level1)
410 {
411     GTEST_LOG_(INFO)
412         << "LocatorBackgroundProxyTest, CheckMaxRequestNumTest002, TestSize.Level1";
413     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] CheckMaxRequestNumTest002 begin");
414     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
415     ASSERT_TRUE(locatorBackgroundProxy != nullptr);
416     int32_t userId = locatorBackgroundProxy->GetUserId(VAL_UID);
417     auto list = std::make_shared<std::list<std::shared_ptr<Request>>>();
418     auto request = std::make_shared<Request>();
419     request->SetUid(VAL_UID);
420     request->SetPackageName("PKG_FOR_TEST");
421     list->push_back(request);
422     (locatorBackgroundProxy->requestsMap_)->insert(make_pair(userId, list));
423     EXPECT_EQ(false, locatorBackgroundProxy->CheckMaxRequestNum(VAL_UID, "PKG_FOR_TEST")); // matched request
424     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] CheckMaxRequestNumTest002 end");
425 }
426 
427 HWTEST_F(LocatorBackgroundProxyTest, CheckMaxRequestNumTest003, TestSize.Level1)
428 {
429     GTEST_LOG_(INFO)
430         << "LocatorBackgroundProxyTest, CheckMaxRequestNumTest003, TestSize.Level1";
431     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] CheckMaxRequestNumTest003 begin");
432     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
433     ASSERT_TRUE(locatorBackgroundProxy != nullptr);
434     int32_t userId = locatorBackgroundProxy->GetUserId(VAL_UID);
435     auto list = std::make_shared<std::list<std::shared_ptr<Request>>>();
436     auto request = std::make_shared<Request>();
437     request->SetUid(-1);
438     request->SetPackageName("PKG_FOR_TEST");
439     list->push_back(request);
440     (locatorBackgroundProxy->requestsMap_)->insert(make_pair(userId, list));
441     EXPECT_EQ(false, locatorBackgroundProxy->CheckMaxRequestNum(VAL_UID, "PKG_FOR_TEST")); // uid is wrong
442     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] CheckMaxRequestNumTest003 end");
443 }
444 
445 HWTEST_F(LocatorBackgroundProxyTest, CheckMaxRequestNumTest004, TestSize.Level1)
446 {
447     GTEST_LOG_(INFO)
448         << "LocatorBackgroundProxyTest, CheckMaxRequestNumTest004, TestSize.Level1";
449     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] CheckMaxRequestNumTest004 begin");
450     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
451     ASSERT_TRUE(locatorBackgroundProxy != nullptr);
452     int32_t userId = locatorBackgroundProxy->GetUserId(VAL_UID);
453     auto list = std::make_shared<std::list<std::shared_ptr<Request>>>();
454     auto request = std::make_shared<Request>();
455     request->SetUid(VAL_UID);
456     request->SetPackageName("INVALID_PKG_NAME");
457     list->push_back(request);
458     (locatorBackgroundProxy->requestsMap_)->insert(make_pair(userId, list));
459     EXPECT_EQ(false, locatorBackgroundProxy->CheckMaxRequestNum(VAL_UID, "PKG_FOR_TEST")); // pkg name is wrong
460     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] CheckMaxRequestNumTest004 end");
461 }
462 
463 HWTEST_F(LocatorBackgroundProxyTest, MLocatorCallbackTest001, TestSize.Level1)
464 {
465     GTEST_LOG_(INFO)
466         << "LocatorBackgroundProxyTest, MLocatorCallbackTest002, TestSize.Level1";
467     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] MLocatorCallbackTest002 begin");
468     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
469     ASSERT_TRUE(locatorBackgroundProxy != nullptr);
470     auto callback =
471         sptr<LocatorBackgroundProxy::mLocatorCallback>(new (std::nothrow) LocatorBackgroundProxy::mLocatorCallback());
472     ASSERT_TRUE(callback != nullptr);
473     auto request = std::make_shared<Request>();
474     request->SetUid(VAL_UID);
475     request->SetPackageName("PKG_NAME");
476     (locatorBackgroundProxy->requestsList_)->clear();
477 
478     auto location = std::make_unique<Location>();
479     MessageParcel parcel;
480     parcel.WriteDouble(1.0); // latitude
481     parcel.WriteDouble(2.0); // longitude
482     parcel.WriteDouble(3.0); // altitude
483     parcel.WriteDouble(4.0); // accuracy
484     parcel.WriteDouble(5.0); // speed
485     parcel.WriteDouble(6.0); // direction
486     parcel.WriteInt64(1000000000); // timeStamp
487     parcel.WriteInt64(1000000000); // timeSinceBoot
488     parcel.WriteString16(u"additions"); // additions
489     parcel.WriteInt64(1); // additionSize
490     parcel.WriteInt32(1); // isFromMock
491     EXPECT_NE(nullptr, location);
492     location->ReadFromParcel(parcel);
493     callback->OnLocationReport(location);
494     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] MLocatorCallbackTest002 end");
495 }
496 
497 HWTEST_F(LocatorBackgroundProxyTest, MLocatorCallbackTest003, TestSize.Level1)
498 {
499     GTEST_LOG_(INFO)
500         << "LocatorBackgroundProxyTest, MLocatorCallbackTest003, TestSize.Level1";
501     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] MLocatorCallbackTest003 begin");
502     auto callback =
503         sptr<LocatorBackgroundProxy::mLocatorCallback>(new (std::nothrow) LocatorBackgroundProxy::mLocatorCallback());
504     ASSERT_TRUE(callback != nullptr);
505     callback->OnLocatingStatusChange(0);
506     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] MLocatorCallbackTest003 end");
507 }
508 
509 HWTEST_F(LocatorBackgroundProxyTest, MLocatorCallbackTest004, TestSize.Level1)
510 {
511     GTEST_LOG_(INFO)
512         << "LocatorBackgroundProxyTest, MLocatorCallbackTest004, TestSize.Level1";
513     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] MLocatorCallbackTest004 begin");
514     auto callback =
515         sptr<LocatorBackgroundProxy::mLocatorCallback>(new (std::nothrow) LocatorBackgroundProxy::mLocatorCallback());
516     ASSERT_TRUE(callback != nullptr);
517     callback->OnErrorReport(0);
518     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] MLocatorCallbackTest004 end");
519 }
520 
521 HWTEST_F(LocatorBackgroundProxyTest, UserSwitchSubscriberOnReceiveEventTest001, TestSize.Level1)
522 {
523     GTEST_LOG_(INFO)
524         << "LocatorBackgroundProxyTest, UserSwitchSubscriberOnReceiveEventTest001, TestSize.Level1";
525     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UserSwitchSubscriberOnReceiveEventTest001 begin");
526     OHOS::EventFwk::MatchingSkills matchingSkills;
527     matchingSkills.AddEvent(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
528     OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
529     std::shared_ptr<LocatorBackgroundProxy::UserSwitchSubscriber> subscriber =
530         std::make_shared<LocatorBackgroundProxy::UserSwitchSubscriber>(subscriberInfo);
531     Want want;
532     want.SetAction(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
533     OHOS::EventFwk::CommonEventData event;
534     event.SetWant(want);
535     event.SetCode(0);
536     ASSERT_TRUE(subscriber != nullptr);
537     subscriber->OnReceiveEvent(event);
538     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UserSwitchSubscriberOnReceiveEventTest001 end");
539 }
540 
541 HWTEST_F(LocatorBackgroundProxyTest, UserSwitchSubscriberOnReceiveEventTest002, TestSize.Level1)
542 {
543     GTEST_LOG_(INFO)
544         << "LocatorBackgroundProxyTest, UserSwitchSubscriberOnReceiveEventTest002, TestSize.Level1";
545     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UserSwitchSubscriberOnReceiveEventTest002 begin");
546     OHOS::EventFwk::MatchingSkills matchingSkills;
547     matchingSkills.AddEvent(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
548     OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
549     std::shared_ptr<LocatorBackgroundProxy::UserSwitchSubscriber> subscriber =
550         std::make_shared<LocatorBackgroundProxy::UserSwitchSubscriber>(subscriberInfo);
551     Want want;
552     want.SetAction(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED);
553     OHOS::EventFwk::CommonEventData event;
554     event.SetWant(want);
555     event.SetCode(0);
556     subscriber->OnReceiveEvent(event);
557     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
558     ASSERT_TRUE(locatorBackgroundProxy != nullptr);
559     auto iter = (locatorBackgroundProxy->requestsMap_)->find(0);
560     EXPECT_EQ(true, iter == (locatorBackgroundProxy->requestsMap_)->end());
561     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UserSwitchSubscriberOnReceiveEventTest002 end");
562 }
563 
564 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread001, TestSize.Level1)
565 {
566     GTEST_LOG_(INFO)
567         << "LocatorBackgroundProxyTest, StartLocatorThread001, TestSize.Level1";
568     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread001 begin");
569     auto locatorBackgroundProxy1 = LocatorBackgroundProxy::GetInstance();
570     ASSERT_TRUE(locatorBackgroundProxy1 != nullptr);
571     locatorBackgroundProxy1->isLocating_ = true;
572     locatorBackgroundProxy1->proxySwtich_ = true;
573     std::shared_ptr<Request> request = std::make_shared<Request>();
574     locatorBackgroundProxy1->requestsList_->push_back(request);
575     locatorBackgroundProxy1->StartLocator();
576     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread001 end");
577 }
578 
579 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread002, TestSize.Level1)
580 {
581     GTEST_LOG_(INFO)
582         << "LocatorBackgroundProxyTest, StartLocatorThread002, TestSize.Level1";
583     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread002 begin");
584     auto locatorBackgroundProxy2 = LocatorBackgroundProxy::GetInstance();
585     ASSERT_TRUE(locatorBackgroundProxy2 != nullptr);
586     locatorBackgroundProxy2->isLocating_ = true;
587     locatorBackgroundProxy2->proxySwtich_ = true;
588     locatorBackgroundProxy2->StartLocator();
589     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread002 end");
590 }
591 
592 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread003, TestSize.Level1)
593 {
594     GTEST_LOG_(INFO)
595         << "LocatorBackgroundProxyTest, StartLocatorThread003, TestSize.Level1";
596     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread003 begin");
597     auto locatorBackgroundProxy3 = LocatorBackgroundProxy::GetInstance();
598     ASSERT_TRUE(locatorBackgroundProxy3 != nullptr);
599     locatorBackgroundProxy3->isLocating_ = true;
600     locatorBackgroundProxy3->proxySwtich_ = false;
601     std::shared_ptr<Request> request1 = std::make_shared<Request>();
602     locatorBackgroundProxy3->requestsList_->push_back(request1);
603     locatorBackgroundProxy3->StartLocator();
604     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread003 end");
605 }
606 
607 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread004, TestSize.Level1)
608 {
609     GTEST_LOG_(INFO)
610         << "LocatorBackgroundProxyTest, StartLocatorThread004, TestSize.Level1";
611     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread004 begin");
612     auto locatorBackgroundProxy4 = LocatorBackgroundProxy::GetInstance();
613     ASSERT_TRUE(locatorBackgroundProxy4 != nullptr);
614     locatorBackgroundProxy4->isLocating_ = false;
615     locatorBackgroundProxy4->proxySwtich_ = true;
616     std::shared_ptr<Request> request2 = std::make_shared<Request>();
617     locatorBackgroundProxy4->requestsList_->push_back(request2);
618     locatorBackgroundProxy4->StartLocator();
619     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread004 end");
620 }
621 
622 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread005, TestSize.Level1)
623 {
624     GTEST_LOG_(INFO)
625         << "LocatorBackgroundProxyTest, StartLocatorThread005, TestSize.Level1";
626     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread005 begin");
627     auto locatorBackgroundProxy5 = LocatorBackgroundProxy::GetInstance();
628     ASSERT_TRUE(locatorBackgroundProxy5 != nullptr);
629     locatorBackgroundProxy5->isLocating_ = true;
630     locatorBackgroundProxy5->proxySwtich_ = false;
631     locatorBackgroundProxy5->StartLocator();
632     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread005 end");
633 }
634 
635 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread006, TestSize.Level1)
636 {
637     GTEST_LOG_(INFO)
638         << "LocatorBackgroundProxyTest, StartLocatorThread006, TestSize.Level1";
639     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread006 begin");
640     auto locatorBackgroundProxy6 = LocatorBackgroundProxy::GetInstance();
641     ASSERT_TRUE(locatorBackgroundProxy6 != nullptr);
642     locatorBackgroundProxy6->isLocating_ = false;
643     locatorBackgroundProxy6->proxySwtich_ = false;
644     std::shared_ptr<Request> request3 = std::make_shared<Request>();
645     locatorBackgroundProxy6->requestsList_->push_back(request3);
646     locatorBackgroundProxy6->StartLocator();
647     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread006 end");
648 }
649 
650 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread007, TestSize.Level1)
651 {
652     GTEST_LOG_(INFO)
653         << "LocatorBackgroundProxyTest, StartLocatorThread007, TestSize.Level1";
654     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread007 begin");
655     auto locatorBackgroundProxy7 = LocatorBackgroundProxy::GetInstance();
656     ASSERT_TRUE(locatorBackgroundProxy7 != nullptr);
657     locatorBackgroundProxy7->isLocating_ = false;
658     locatorBackgroundProxy7->proxySwtich_ = false;
659     locatorBackgroundProxy7->StartLocator();
660     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread007 end");
661 }
662 
663 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread008, TestSize.Level1)
664 {
665     GTEST_LOG_(INFO)
666         << "LocatorBackgroundProxyTest, StartLocatorThread008, TestSize.Level1";
667     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread008 begin");
668     auto locatorBackgroundProxy1 = LocatorBackgroundProxy::GetInstance();
669     ASSERT_TRUE(locatorBackgroundProxy1 != nullptr);
670     locatorBackgroundProxy1->isLocating_ = false;
671     locatorBackgroundProxy1->StopLocator();
672 
673     auto locatorBackgroundProxy2 = LocatorBackgroundProxy::GetInstance();
674     ASSERT_TRUE(locatorBackgroundProxy2 != nullptr);
675     locatorBackgroundProxy2->isLocating_ = true;
676     locatorBackgroundProxy2->StopLocator();
677     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread008 end");
678 }
679 
680 HWTEST_F(LocatorBackgroundProxyTest, OnSuspend001, TestSize.Level1)
681 {
682     GTEST_LOG_(INFO)
683         << "LocatorBackgroundProxyTest, OnSuspend001, TestSize.Level1";
684     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSuspend001 begin");
685     auto locatorBackgroundProxy1 = LocatorBackgroundProxy::GetInstance();
686     ASSERT_TRUE(locatorBackgroundProxy1 != nullptr);
687     locatorBackgroundProxy1->featureSwitch_ = true;
688     locatorBackgroundProxy1->isUserSwitchSubscribed_ = true;
689     std::shared_ptr<Request> request1 = std::make_shared<Request>();
690     locatorBackgroundProxy1->OnSuspend(request1, true);
691 
692     auto locatorBackgroundProxy2 = LocatorBackgroundProxy::GetInstance();
693     ASSERT_TRUE(locatorBackgroundProxy2 != nullptr);
694     locatorBackgroundProxy2->featureSwitch_ = true;
695     locatorBackgroundProxy1->isUserSwitchSubscribed_ = false;
696     std::shared_ptr<Request> request2 = std::make_shared<Request>();
697     locatorBackgroundProxy2->OnSuspend(request2, false);
698     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSuspend001 end");
699 }
700 
701 HWTEST_F(LocatorBackgroundProxyTest, OnSaStateChangeTest002, TestSize.Level1)
702 {
703     GTEST_LOG_(INFO)
704         << "LocatorBackgroundProxyTest, OnSaStateChangeTest002, TestSize.Level1";
705     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSaStateChangeTest002 begin");
706     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
707     EXPECT_NE(nullptr, locatorBackgroundProxy);
708     locatorBackgroundProxy->proxySwtich_ = true;
709     locatorBackgroundProxy->OnSaStateChange(true);
710 
711     locatorBackgroundProxy->proxySwtich_ = false;
712     std::shared_ptr<Request> request = std::make_shared<Request>();
713     locatorBackgroundProxy->requestsList_->push_back(request);
714     locatorBackgroundProxy->OnSaStateChange(true);
715 
716     locatorBackgroundProxy->proxySwtich_ = true;
717     locatorBackgroundProxy->OnSaStateChange(false);
718 
719     locatorBackgroundProxy->proxySwtich_ = false;
720     locatorBackgroundProxy->OnSaStateChange(false);
721     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSaStateChangeTest002 end");
722 }
723 
724 HWTEST_F(LocatorBackgroundProxyTest, OnDeleteRequestRecord002, TestSize.Level1)
725 {
726     GTEST_LOG_(INFO)
727         << "LocatorBackgroundProxyTest, OnDeleteRequestRecord002, TestSize.Level1";
728     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnDeleteRequestRecord002 begin");
729     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
730     EXPECT_NE(nullptr, locatorBackgroundProxy);
731     std::shared_ptr<Request> request1 = std::make_shared<Request>();
732 
733     locatorBackgroundProxy->featureSwitch_ = false;
734     locatorBackgroundProxy->OnDeleteRequestRecord(request1);
735 
736     locatorBackgroundProxy->featureSwitch_ = true;
737     request1->SetUid(1000);
738     request1->SetPid(0);
739     request1->SetTokenId(tokenId_);
740     request1->SetFirstTokenId(0);
741     request1->SetPackageName("LocatorBackgroundProxyTest");
742     locatorBackgroundProxy->OnDeleteRequestRecord(request1);
743     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnDeleteRequestRecord002 end");
744 }
745 
746 HWTEST_F(LocatorBackgroundProxyTest, UpdateListOnSuspend001, TestSize.Level1)
747 {
748     GTEST_LOG_(INFO)
749         << "LocatorBackgroundProxyTest, UpdateListOnSuspend001, TestSize.Level1";
750     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UpdateListOnSuspend001 begin");
751     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
752     EXPECT_NE(nullptr, locatorBackgroundProxy);
753     locatorBackgroundProxy->UpdateListOnSuspend(nullptr, true);
754     std::shared_ptr<Request> request1 = std::make_shared<Request>();
755     request1->SetUid(1000);
756     request1->SetPid(0);
757     request1->SetTokenId(tokenId_);
758     request1->SetFirstTokenId(0);
759     request1->SetPackageName("LocatorBackgroundProxyTest");
760     request1->requestConfig_ = nullptr;
761     locatorBackgroundProxy->UpdateListOnSuspend(request1, true);
762     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UpdateListOnSuspend001 end");
763 }
764 
765 HWTEST_F(LocatorBackgroundProxyTest, IsCallbackInProxyTest003, TestSize.Level1)
766 {
767     GTEST_LOG_(INFO)
768         << "LocatorBackgroundProxyTest, IsCallbackInProxyTest003, TestSize.Level1";
769     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsCallbackInProxyTest003 begin");
770     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
771     EXPECT_NE(nullptr, locatorBackgroundProxy);
772     locatorBackgroundProxy->featureSwitch_ = false;
773     sptr<ILocatorCallback> newCallback = new (std::nothrow) LocatorCallbackStub();
774     bool ret = locatorBackgroundProxy->IsCallbackInProxy(newCallback);
775     EXPECT_EQ(false, ret);
776     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsCallbackInProxyTest003 end");
777 }
778 
779 HWTEST_F(LocatorBackgroundProxyTest, OnUserSwitchTest003, TestSize.Level1)
780 {
781     GTEST_LOG_(INFO)
782         << "LocatorBackgroundProxyTest, OnUserSwitchTest003, TestSize.Level1";
783     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnUserSwitchTest003 begin");
784     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
785     EXPECT_NE(nullptr, locatorBackgroundProxy);
786     locatorBackgroundProxy->requestsMap_->clear();
787     int32_t userId = 0;
788     auto list = std::make_shared<std::list<std::shared_ptr<Request>>>();
789     auto request = std::make_shared<Request>();
790     request->SetUid(VAL_UID);
791     request->SetPackageName("INVALID_PKG_NAME");
792     list->push_back(request);
793     (locatorBackgroundProxy->requestsMap_)->insert(make_pair(userId, list));
794     locatorBackgroundProxy->OnUserSwitch(userId);
795     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnUserSwitchTest003 end");
796 }
797 
798 HWTEST_F(LocatorBackgroundProxyTest, UnregisterAppStateObserverTest001, TestSize.Level1)
799 {
800     GTEST_LOG_(INFO)
801         << "LocatorBackgroundProxyTest, UnregisterAppStateObserverTest001, TestSize.Level1";
802     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UnregisterAppStateObserverTest001 begin");
803     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
804     EXPECT_NE(nullptr, locatorBackgroundProxy);
805     locatorBackgroundProxy->iAppMgr_  = nullptr;
806     locatorBackgroundProxy->appStateObserver_  = nullptr;
807     EXPECT_EQ(true, locatorBackgroundProxy->UnregisterAppStateObserver());
808 
809     locatorBackgroundProxy->RegisterAppStateObserver();
810     locatorBackgroundProxy->iAppMgr_  = nullptr;
811     EXPECT_EQ(true, locatorBackgroundProxy->UnregisterAppStateObserver());
812 
813     EXPECT_EQ(true, locatorBackgroundProxy->RegisterAppStateObserver());
814     locatorBackgroundProxy->appStateObserver_  = nullptr;
815     EXPECT_EQ(true, locatorBackgroundProxy->UnregisterAppStateObserver());
816 
817     EXPECT_EQ(true, locatorBackgroundProxy->RegisterAppStateObserver());
818     EXPECT_EQ(true, locatorBackgroundProxy->UnregisterAppStateObserver());
819     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UnregisterAppStateObserverTest001 end");
820 }
821 
822 HWTEST_F(LocatorBackgroundProxyTest, IsAppHasFormVisible001, TestSize.Level1)
823 {
824     GTEST_LOG_(INFO)
825         << "LocatorBackgroundProxyTest, IsAppHasFormVisible001, TestSize.Level1";
826     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppHasFormVisible001 begin");
827     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
828     auto ret = locatorBackgroundProxy->IsAppHasFormVisible(tokenId_, 0);
829     EXPECT_EQ(false, ret);
830     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppHasFormVisible001 end");
831 }
832 
833 HWTEST_F(LocatorBackgroundProxyTest, IsAppHasFormVisible002, TestSize.Level1)
834 {
835     GTEST_LOG_(INFO)
836         << "LocatorBackgroundProxyTest, IsAppHasFormVisible002, TestSize.Level1";
837     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppHasFormVisible002 begin");
838     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
839     auto ret = locatorBackgroundProxy->IsAppHasFormVisible(0, 0);
840     EXPECT_EQ(false, ret);
841     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppHasFormVisible002 end");
842 }
843 
844 HWTEST_F(LocatorBackgroundProxyTest, OnAddSystemAbility001, TestSize.Level1)
845 {
846     GTEST_LOG_(INFO)
847         << "LocatorBackgroundProxyTest, OnAddSystemAbility001, TestSize.Level1";
848     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnAddSystemAbility001 begin");
849     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
850     auto systemAbilityStatusChangeListener = locatorBackgroundProxy->statusChangeListener_;
851     int32_t systemAbilityId = 1000;
852     const std::string& deviceId = "0123456789ABCDEF";
853     systemAbilityStatusChangeListener->OnAddSystemAbility(systemAbilityId, deviceId);
854     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnAddSystemAbility001 end");
855 }
856 
857 HWTEST_F(LocatorBackgroundProxyTest, OnRemoveSystemAbility001, TestSize.Level1)
858 {
859     GTEST_LOG_(INFO)
860         << "LocatorBackgroundProxyTest, OnRemoveSystemAbility001, TestSize.Level1";
861     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnRemoveSystemAbility001 begin");
862     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
863     auto systemAbilityStatusChangeListener = locatorBackgroundProxy->statusChangeListener_;
864     int32_t systemAbilityId = COMMON_EVENT_SERVICE_ID;
865     const std::string& deviceId = "0123456789ABCDEF";
866     systemAbilityStatusChangeListener->OnRemoveSystemAbility(systemAbilityId, deviceId);
867     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnRemoveSystemAbility001 end");
868 }
869 
870 HWTEST_F(LocatorBackgroundProxyTest, OnRemoveSystemAbility002, TestSize.Level1)
871 {
872     GTEST_LOG_(INFO)
873         << "LocatorBackgroundProxyTest, OnRemoveSystemAbility002, TestSize.Level1";
874     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnRemoveSystemAbility002 begin");
875     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
876     auto systemAbilityStatusChangeListener = locatorBackgroundProxy->statusChangeListener_;
877     int32_t systemAbilityId = 1;
878     const std::string& deviceId = "0123456789ABCDEF";
879     systemAbilityStatusChangeListener->OnRemoveSystemAbility(systemAbilityId, deviceId);
880     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnRemoveSystemAbility002 end");
881 }
882 
883 HWTEST_F(LocatorBackgroundProxyTest, IsAppInLocationContinuousTasks001, TestSize.Level1)
884 {
885     GTEST_LOG_(INFO)
886         << "LocatorBackgroundProxyTest, IsAppInLocationContinuousTasks001, TestSize.Level1";
887     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppInLocationContinuousTasks001 begin");
888     auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
889 
890     locatorBackgroundProxy->IsAppInLocationContinuousTasks(1000);
891     LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppInLocationContinuousTasks001 end");
892 }
893 }  // namespace Location
894 }  // namespace OHOS