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 = 6;
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(), ACCESS_CONTROL_LOCATION_SWITCH.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, CheckMaxRequestNumTest005, TestSize.Level1)
464 {
465 GTEST_LOG_(INFO)
466 << "LocatorBackgroundProxyTest, CheckMaxRequestNumTest005, TestSize.Level1";
467 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] CheckMaxRequestNumTest005 begin");
468 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
469 ASSERT_TRUE(locatorBackgroundProxy != nullptr);
470 int32_t userId = locatorBackgroundProxy->GetUserId(VAL_UID);
471 auto list = std::make_shared<std::list<std::shared_ptr<Request>>>();
472 auto request = std::make_shared<Request>();
473 request->SetUid(VAL_UID);
474 request->SetPackageName("PKG_FOR_TEST");
475 list->push_back(request);
476 (locatorBackgroundProxy->requestsMap_)->insert(make_pair(userId, list));
477 int uid = 1000;
478 locatorBackgroundProxy->CheckMaxRequestNum(uid, "PKG_FOR_TEST");
479 (locatorBackgroundProxy->requestsMap_)->clear();
480 list->clear();
481 request->SetUid(VAL_UID);
482 request->SetPackageName("test_packageName");
483 list->push_back(request);
484 (locatorBackgroundProxy->requestsMap_)->insert(make_pair(userId, list));
485 locatorBackgroundProxy->CheckMaxRequestNum(uid, "PKG_FOR_TEST");
486 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] CheckMaxRequestNumTest005 end");
487 }
488
489 HWTEST_F(LocatorBackgroundProxyTest, MLocatorCallbackTest001, TestSize.Level1)
490 {
491 GTEST_LOG_(INFO)
492 << "LocatorBackgroundProxyTest, MLocatorCallbackTest002, TestSize.Level1";
493 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] MLocatorCallbackTest002 begin");
494 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
495 ASSERT_TRUE(locatorBackgroundProxy != nullptr);
496 auto callback =
497 sptr<LocatorBackgroundProxy::mLocatorCallback>(new (std::nothrow) LocatorBackgroundProxy::mLocatorCallback());
498 ASSERT_TRUE(callback != nullptr);
499 auto request = std::make_shared<Request>();
500 request->SetUid(VAL_UID);
501 request->SetPackageName("PKG_NAME");
502 (locatorBackgroundProxy->requestsList_)->clear();
503
504 auto location = std::make_unique<Location>();
505 MessageParcel parcel;
506 parcel.WriteDouble(1.0); // latitude
507 parcel.WriteDouble(2.0); // longitude
508 parcel.WriteDouble(3.0); // altitude
509 parcel.WriteDouble(4.0); // accuracy
510 parcel.WriteDouble(5.0); // speed
511 parcel.WriteDouble(6.0); // direction
512 parcel.WriteInt64(1000000000); // timeStamp
513 parcel.WriteInt64(1000000000); // timeSinceBoot
514 parcel.WriteString16(u"additions"); // additions
515 parcel.WriteInt64(1); // additionSize
516 parcel.WriteInt32(1); // isFromMock
517 EXPECT_NE(nullptr, location);
518 location->ReadFromParcel(parcel);
519 callback->OnLocationReport(location);
520 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] MLocatorCallbackTest002 end");
521 }
522
523 HWTEST_F(LocatorBackgroundProxyTest, MLocatorCallbackTest003, TestSize.Level1)
524 {
525 GTEST_LOG_(INFO)
526 << "LocatorBackgroundProxyTest, MLocatorCallbackTest003, TestSize.Level1";
527 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] MLocatorCallbackTest003 begin");
528 auto callback =
529 sptr<LocatorBackgroundProxy::mLocatorCallback>(new (std::nothrow) LocatorBackgroundProxy::mLocatorCallback());
530 ASSERT_TRUE(callback != nullptr);
531 callback->OnLocatingStatusChange(0);
532 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] MLocatorCallbackTest003 end");
533 }
534
535 HWTEST_F(LocatorBackgroundProxyTest, MLocatorCallbackTest004, TestSize.Level1)
536 {
537 GTEST_LOG_(INFO)
538 << "LocatorBackgroundProxyTest, MLocatorCallbackTest004, TestSize.Level1";
539 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] MLocatorCallbackTest004 begin");
540 auto callback =
541 sptr<LocatorBackgroundProxy::mLocatorCallback>(new (std::nothrow) LocatorBackgroundProxy::mLocatorCallback());
542 ASSERT_TRUE(callback != nullptr);
543 callback->OnErrorReport(0);
544 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] MLocatorCallbackTest004 end");
545 }
546
547 HWTEST_F(LocatorBackgroundProxyTest, UserSwitchSubscriberOnReceiveEventTest001, TestSize.Level1)
548 {
549 GTEST_LOG_(INFO)
550 << "LocatorBackgroundProxyTest, UserSwitchSubscriberOnReceiveEventTest001, TestSize.Level1";
551 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UserSwitchSubscriberOnReceiveEventTest001 begin");
552 OHOS::EventFwk::MatchingSkills matchingSkills;
553 matchingSkills.AddEvent(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
554 OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
555 std::shared_ptr<LocatorBackgroundProxy::UserSwitchSubscriber> subscriber =
556 std::make_shared<LocatorBackgroundProxy::UserSwitchSubscriber>(subscriberInfo);
557 Want want;
558 want.SetAction(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
559 OHOS::EventFwk::CommonEventData event;
560 event.SetWant(want);
561 event.SetCode(0);
562 ASSERT_TRUE(subscriber != nullptr);
563 subscriber->OnReceiveEvent(event);
564 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UserSwitchSubscriberOnReceiveEventTest001 end");
565 }
566
567 HWTEST_F(LocatorBackgroundProxyTest, UserSwitchSubscriberOnReceiveEventTest002, TestSize.Level1)
568 {
569 GTEST_LOG_(INFO)
570 << "LocatorBackgroundProxyTest, UserSwitchSubscriberOnReceiveEventTest002, TestSize.Level1";
571 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UserSwitchSubscriberOnReceiveEventTest002 begin");
572 OHOS::EventFwk::MatchingSkills matchingSkills;
573 matchingSkills.AddEvent(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
574 OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
575 std::shared_ptr<LocatorBackgroundProxy::UserSwitchSubscriber> subscriber =
576 std::make_shared<LocatorBackgroundProxy::UserSwitchSubscriber>(subscriberInfo);
577 Want want;
578 want.SetAction(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED);
579 OHOS::EventFwk::CommonEventData event;
580 event.SetWant(want);
581 event.SetCode(0);
582 subscriber->OnReceiveEvent(event);
583 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
584 ASSERT_TRUE(locatorBackgroundProxy != nullptr);
585 auto iter = (locatorBackgroundProxy->requestsMap_)->find(0);
586 EXPECT_EQ(true, iter == (locatorBackgroundProxy->requestsMap_)->end());
587 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UserSwitchSubscriberOnReceiveEventTest002 end");
588 }
589
590 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread001, TestSize.Level1)
591 {
592 GTEST_LOG_(INFO)
593 << "LocatorBackgroundProxyTest, StartLocatorThread001, TestSize.Level1";
594 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread001 begin");
595 auto locatorBackgroundProxy1 = LocatorBackgroundProxy::GetInstance();
596 ASSERT_TRUE(locatorBackgroundProxy1 != nullptr);
597 locatorBackgroundProxy1->isLocating_ = true;
598 locatorBackgroundProxy1->proxySwtich_ = true;
599 std::shared_ptr<Request> request = std::make_shared<Request>();
600 locatorBackgroundProxy1->requestsList_->push_back(request);
601 locatorBackgroundProxy1->StartLocator();
602 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread001 end");
603 }
604
605 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread002, TestSize.Level1)
606 {
607 GTEST_LOG_(INFO)
608 << "LocatorBackgroundProxyTest, StartLocatorThread002, TestSize.Level1";
609 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread002 begin");
610 auto locatorBackgroundProxy2 = LocatorBackgroundProxy::GetInstance();
611 ASSERT_TRUE(locatorBackgroundProxy2 != nullptr);
612 locatorBackgroundProxy2->isLocating_ = true;
613 locatorBackgroundProxy2->proxySwtich_ = true;
614 locatorBackgroundProxy2->StartLocator();
615 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread002 end");
616 }
617
618 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread003, TestSize.Level1)
619 {
620 GTEST_LOG_(INFO)
621 << "LocatorBackgroundProxyTest, StartLocatorThread003, TestSize.Level1";
622 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread003 begin");
623 auto locatorBackgroundProxy3 = LocatorBackgroundProxy::GetInstance();
624 ASSERT_TRUE(locatorBackgroundProxy3 != nullptr);
625 locatorBackgroundProxy3->isLocating_ = true;
626 locatorBackgroundProxy3->proxySwtich_ = false;
627 std::shared_ptr<Request> request1 = std::make_shared<Request>();
628 locatorBackgroundProxy3->requestsList_->push_back(request1);
629 locatorBackgroundProxy3->StartLocator();
630 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread003 end");
631 }
632
633 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread004, TestSize.Level1)
634 {
635 GTEST_LOG_(INFO)
636 << "LocatorBackgroundProxyTest, StartLocatorThread004, TestSize.Level1";
637 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread004 begin");
638 auto locatorBackgroundProxy4 = LocatorBackgroundProxy::GetInstance();
639 ASSERT_TRUE(locatorBackgroundProxy4 != nullptr);
640 locatorBackgroundProxy4->isLocating_ = false;
641 locatorBackgroundProxy4->proxySwtich_ = true;
642 std::shared_ptr<Request> request2 = std::make_shared<Request>();
643 locatorBackgroundProxy4->requestsList_->push_back(request2);
644 locatorBackgroundProxy4->StartLocator();
645 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread004 end");
646 }
647
648 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread005, TestSize.Level1)
649 {
650 GTEST_LOG_(INFO)
651 << "LocatorBackgroundProxyTest, StartLocatorThread005, TestSize.Level1";
652 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread005 begin");
653 auto locatorBackgroundProxy5 = LocatorBackgroundProxy::GetInstance();
654 ASSERT_TRUE(locatorBackgroundProxy5 != nullptr);
655 locatorBackgroundProxy5->isLocating_ = true;
656 locatorBackgroundProxy5->proxySwtich_ = false;
657 locatorBackgroundProxy5->StartLocator();
658 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread005 end");
659 }
660
661 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread006, TestSize.Level1)
662 {
663 GTEST_LOG_(INFO)
664 << "LocatorBackgroundProxyTest, StartLocatorThread006, TestSize.Level1";
665 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread006 begin");
666 auto locatorBackgroundProxy6 = LocatorBackgroundProxy::GetInstance();
667 ASSERT_TRUE(locatorBackgroundProxy6 != nullptr);
668 locatorBackgroundProxy6->isLocating_ = false;
669 locatorBackgroundProxy6->proxySwtich_ = false;
670 std::shared_ptr<Request> request3 = std::make_shared<Request>();
671 locatorBackgroundProxy6->requestsList_->push_back(request3);
672 locatorBackgroundProxy6->StartLocator();
673 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread006 end");
674 }
675
676 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread007, TestSize.Level1)
677 {
678 GTEST_LOG_(INFO)
679 << "LocatorBackgroundProxyTest, StartLocatorThread007, TestSize.Level1";
680 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread007 begin");
681 auto locatorBackgroundProxy7 = LocatorBackgroundProxy::GetInstance();
682 ASSERT_TRUE(locatorBackgroundProxy7 != nullptr);
683 locatorBackgroundProxy7->isLocating_ = false;
684 locatorBackgroundProxy7->proxySwtich_ = false;
685 locatorBackgroundProxy7->StartLocator();
686 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread007 end");
687 }
688
689 HWTEST_F(LocatorBackgroundProxyTest, StartLocatorThread008, TestSize.Level1)
690 {
691 GTEST_LOG_(INFO)
692 << "LocatorBackgroundProxyTest, StartLocatorThread008, TestSize.Level1";
693 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread008 begin");
694 auto locatorBackgroundProxy1 = LocatorBackgroundProxy::GetInstance();
695 ASSERT_TRUE(locatorBackgroundProxy1 != nullptr);
696 locatorBackgroundProxy1->isLocating_ = false;
697 locatorBackgroundProxy1->StopLocator();
698
699 auto locatorBackgroundProxy2 = LocatorBackgroundProxy::GetInstance();
700 ASSERT_TRUE(locatorBackgroundProxy2 != nullptr);
701 locatorBackgroundProxy2->isLocating_ = true;
702 locatorBackgroundProxy2->StopLocator();
703 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] StartLocatorThread008 end");
704 }
705
706 HWTEST_F(LocatorBackgroundProxyTest, OnSuspend001, TestSize.Level1)
707 {
708 GTEST_LOG_(INFO)
709 << "LocatorBackgroundProxyTest, OnSuspend001, TestSize.Level1";
710 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSuspend001 begin");
711 auto locatorBackgroundProxy1 = LocatorBackgroundProxy::GetInstance();
712 ASSERT_TRUE(locatorBackgroundProxy1 != nullptr);
713 locatorBackgroundProxy1->featureSwitch_ = true;
714 locatorBackgroundProxy1->isUserSwitchSubscribed_ = true;
715 std::shared_ptr<Request> request1 = std::make_shared<Request>();
716 locatorBackgroundProxy1->OnSuspend(request1, true);
717
718 auto locatorBackgroundProxy2 = LocatorBackgroundProxy::GetInstance();
719 ASSERT_TRUE(locatorBackgroundProxy2 != nullptr);
720 locatorBackgroundProxy2->featureSwitch_ = true;
721 locatorBackgroundProxy1->isUserSwitchSubscribed_ = false;
722 std::shared_ptr<Request> request2 = std::make_shared<Request>();
723 locatorBackgroundProxy2->OnSuspend(request2, false);
724 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSuspend001 end");
725 }
726
727 HWTEST_F(LocatorBackgroundProxyTest, OnSaStateChangeTest002, TestSize.Level1)
728 {
729 GTEST_LOG_(INFO)
730 << "LocatorBackgroundProxyTest, OnSaStateChangeTest002, TestSize.Level1";
731 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSaStateChangeTest002 begin");
732 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
733 EXPECT_NE(nullptr, locatorBackgroundProxy);
734 locatorBackgroundProxy->proxySwtich_ = true;
735 locatorBackgroundProxy->OnSaStateChange(true);
736
737 locatorBackgroundProxy->proxySwtich_ = false;
738 std::shared_ptr<Request> request = std::make_shared<Request>();
739 locatorBackgroundProxy->requestsList_->push_back(request);
740 locatorBackgroundProxy->OnSaStateChange(true);
741
742 locatorBackgroundProxy->proxySwtich_ = true;
743 locatorBackgroundProxy->OnSaStateChange(false);
744
745 locatorBackgroundProxy->proxySwtich_ = false;
746 locatorBackgroundProxy->OnSaStateChange(false);
747 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnSaStateChangeTest002 end");
748 }
749
750 HWTEST_F(LocatorBackgroundProxyTest, OnDeleteRequestRecord002, TestSize.Level1)
751 {
752 GTEST_LOG_(INFO)
753 << "LocatorBackgroundProxyTest, OnDeleteRequestRecord002, TestSize.Level1";
754 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnDeleteRequestRecord002 begin");
755 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
756 EXPECT_NE(nullptr, locatorBackgroundProxy);
757 std::shared_ptr<Request> request1 = std::make_shared<Request>();
758
759 locatorBackgroundProxy->featureSwitch_ = false;
760 locatorBackgroundProxy->OnDeleteRequestRecord(request1);
761
762 locatorBackgroundProxy->featureSwitch_ = true;
763 request1->SetUid(1000);
764 request1->SetPid(0);
765 request1->SetTokenId(tokenId_);
766 request1->SetFirstTokenId(0);
767 request1->SetPackageName("LocatorBackgroundProxyTest");
768 locatorBackgroundProxy->requestsList_->push_back(request1);
769 locatorBackgroundProxy->OnDeleteRequestRecord(request1);
770 (locatorBackgroundProxy->requestsList_)->clear();
771 locatorBackgroundProxy->OnDeleteRequestRecord(request1);
772 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnDeleteRequestRecord002 end");
773 }
774
775 HWTEST_F(LocatorBackgroundProxyTest, UpdateListOnSuspend001, TestSize.Level1)
776 {
777 GTEST_LOG_(INFO)
778 << "LocatorBackgroundProxyTest, UpdateListOnSuspend001, TestSize.Level1";
779 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UpdateListOnSuspend001 begin");
780 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
781 EXPECT_NE(nullptr, locatorBackgroundProxy);
782 locatorBackgroundProxy->UpdateListOnSuspend(nullptr, true);
783 std::shared_ptr<Request> request1 = std::make_shared<Request>();
784 request1->SetUid(1000);
785 request1->SetPid(0);
786 request1->SetTokenId(tokenId_);
787 request1->SetFirstTokenId(0);
788 request1->SetPackageName("LocatorBackgroundProxyTest");
789 request1->requestConfig_ = nullptr;
790 locatorBackgroundProxy->UpdateListOnSuspend(request1, true);
791 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UpdateListOnSuspend001 end");
792 }
793
794 HWTEST_F(LocatorBackgroundProxyTest, IsCallbackInProxyTest003, TestSize.Level1)
795 {
796 GTEST_LOG_(INFO)
797 << "LocatorBackgroundProxyTest, IsCallbackInProxyTest003, TestSize.Level1";
798 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsCallbackInProxyTest003 begin");
799 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
800 EXPECT_NE(nullptr, locatorBackgroundProxy);
801 locatorBackgroundProxy->featureSwitch_ = false;
802 sptr<ILocatorCallback> newCallback = new (std::nothrow) LocatorCallbackStub();
803 bool ret = locatorBackgroundProxy->IsCallbackInProxy(newCallback);
804 EXPECT_EQ(false, ret);
805 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsCallbackInProxyTest003 end");
806 }
807
808 HWTEST_F(LocatorBackgroundProxyTest, OnUserSwitchTest003, TestSize.Level1)
809 {
810 GTEST_LOG_(INFO)
811 << "LocatorBackgroundProxyTest, OnUserSwitchTest003, TestSize.Level1";
812 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnUserSwitchTest003 begin");
813 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
814 EXPECT_NE(nullptr, locatorBackgroundProxy);
815 locatorBackgroundProxy->requestsMap_->clear();
816 int32_t userId = 0;
817 auto list = std::make_shared<std::list<std::shared_ptr<Request>>>();
818 auto request = std::make_shared<Request>();
819 request->SetUid(VAL_UID);
820 request->SetPackageName("INVALID_PKG_NAME");
821 list->push_back(request);
822 (locatorBackgroundProxy->requestsMap_)->insert(make_pair(userId, list));
823 locatorBackgroundProxy->OnUserSwitch(userId);
824 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnUserSwitchTest003 end");
825 }
826
827 HWTEST_F(LocatorBackgroundProxyTest, UnregisterAppStateObserverTest001, TestSize.Level1)
828 {
829 GTEST_LOG_(INFO)
830 << "LocatorBackgroundProxyTest, UnregisterAppStateObserverTest001, TestSize.Level1";
831 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UnregisterAppStateObserverTest001 begin");
832 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
833 EXPECT_NE(nullptr, locatorBackgroundProxy);
834 locatorBackgroundProxy->iAppMgr_ = nullptr;
835 locatorBackgroundProxy->appStateObserver_ = nullptr;
836 EXPECT_EQ(true, locatorBackgroundProxy->UnregisterAppStateObserver());
837
838 locatorBackgroundProxy->RegisterAppStateObserver();
839 locatorBackgroundProxy->iAppMgr_ = nullptr;
840 EXPECT_EQ(true, locatorBackgroundProxy->UnregisterAppStateObserver());
841
842 EXPECT_EQ(true, locatorBackgroundProxy->RegisterAppStateObserver());
843 locatorBackgroundProxy->appStateObserver_ = nullptr;
844 EXPECT_EQ(true, locatorBackgroundProxy->UnregisterAppStateObserver());
845
846 EXPECT_EQ(true, locatorBackgroundProxy->RegisterAppStateObserver());
847 EXPECT_EQ(true, locatorBackgroundProxy->UnregisterAppStateObserver());
848 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] UnregisterAppStateObserverTest001 end");
849 }
850
851 HWTEST_F(LocatorBackgroundProxyTest, IsAppHasFormVisible001, TestSize.Level1)
852 {
853 GTEST_LOG_(INFO)
854 << "LocatorBackgroundProxyTest, IsAppHasFormVisible001, TestSize.Level1";
855 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppHasFormVisible001 begin");
856 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
857 auto ret = locatorBackgroundProxy->IsAppHasFormVisible(tokenId_, 0);
858 EXPECT_EQ(false, ret);
859 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppHasFormVisible001 end");
860 }
861
862 HWTEST_F(LocatorBackgroundProxyTest, IsAppHasFormVisible002, TestSize.Level1)
863 {
864 GTEST_LOG_(INFO)
865 << "LocatorBackgroundProxyTest, IsAppHasFormVisible002, TestSize.Level1";
866 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppHasFormVisible002 begin");
867 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
868 auto ret = locatorBackgroundProxy->IsAppHasFormVisible(0, 0);
869 EXPECT_EQ(false, ret);
870 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppHasFormVisible002 end");
871 }
872
873 HWTEST_F(LocatorBackgroundProxyTest, OnAddSystemAbility001, TestSize.Level1)
874 {
875 GTEST_LOG_(INFO)
876 << "LocatorBackgroundProxyTest, OnAddSystemAbility001, TestSize.Level1";
877 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnAddSystemAbility001 begin");
878 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
879 auto systemAbilityStatusChangeListener = locatorBackgroundProxy->statusChangeListener_;
880 int32_t systemAbilityId = 1000;
881 const std::string& deviceId = "0123456789ABCDEF";
882 systemAbilityStatusChangeListener->OnAddSystemAbility(systemAbilityId, deviceId);
883 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnAddSystemAbility001 end");
884 }
885
886 HWTEST_F(LocatorBackgroundProxyTest, OnRemoveSystemAbility001, TestSize.Level1)
887 {
888 GTEST_LOG_(INFO)
889 << "LocatorBackgroundProxyTest, OnRemoveSystemAbility001, TestSize.Level1";
890 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnRemoveSystemAbility001 begin");
891 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
892 auto systemAbilityStatusChangeListener = locatorBackgroundProxy->statusChangeListener_;
893 int32_t systemAbilityId = COMMON_EVENT_SERVICE_ID;
894 const std::string& deviceId = "0123456789ABCDEF";
895 systemAbilityStatusChangeListener->OnRemoveSystemAbility(systemAbilityId, deviceId);
896 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnRemoveSystemAbility001 end");
897 }
898
899 HWTEST_F(LocatorBackgroundProxyTest, OnRemoveSystemAbility002, TestSize.Level1)
900 {
901 GTEST_LOG_(INFO)
902 << "LocatorBackgroundProxyTest, OnRemoveSystemAbility002, TestSize.Level1";
903 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnRemoveSystemAbility002 begin");
904 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
905 auto systemAbilityStatusChangeListener = locatorBackgroundProxy->statusChangeListener_;
906 int32_t systemAbilityId = 1;
907 const std::string& deviceId = "0123456789ABCDEF";
908 systemAbilityStatusChangeListener->OnRemoveSystemAbility(systemAbilityId, deviceId);
909 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] OnRemoveSystemAbility002 end");
910 }
911
912 HWTEST_F(LocatorBackgroundProxyTest, IsAppInLocationContinuousTasks001, TestSize.Level1)
913 {
914 GTEST_LOG_(INFO)
915 << "LocatorBackgroundProxyTest, IsAppInLocationContinuousTasks001, TestSize.Level1";
916 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppInLocationContinuousTasks001 begin");
917 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
918
919 locatorBackgroundProxy->IsAppInLocationContinuousTasks(0, 0);
920 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "[LocatorBackgroundProxyTest] IsAppInLocationContinuousTasks001 end");
921 }
922 } // namespace Location
923 } // namespace OHOS