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.h"
17
18 #include <thread>
19
20 #include "common_event_manager.h"
21 #include "common_event_support.h"
22 #include "iservice_registry.h"
23 #include "os_account_manager.h"
24 #include "system_ability_definition.h"
25
26 #include "common_utils.h"
27 #include "constant_definition.h"
28 #include "location_config_manager.h"
29 #include "location_log.h"
30 #include "locator_ability.h"
31 #include "request_manager.h"
32 #include "permission_manager.h"
33 #include "location_data_rdb_manager.h"
34
35 #include "accesstoken_kit.h"
36 #include "tokenid_kit.h"
37
38 #ifdef BGTASKMGR_SUPPORT
39 #include "background_mode.h"
40 #include "background_task_mgr_helper.h"
41 #endif
42
43 #ifdef FMSKIT_NATIVE_SUPPORT
44 #include "form_mgr.h"
45 #endif
46
47 namespace OHOS {
48 namespace Location {
49 std::mutex LocatorBackgroundProxy::requestListMutex_;
50 std::mutex LocatorBackgroundProxy::locatorMutex_;
GetInstance()51 LocatorBackgroundProxy* LocatorBackgroundProxy::GetInstance()
52 {
53 static LocatorBackgroundProxy data;
54 return &data;
55 }
56
LocatorBackgroundProxy()57 LocatorBackgroundProxy::LocatorBackgroundProxy()
58 {
59 InitArgsFromProp();
60 if (!featureSwitch_) {
61 return;
62 }
63 requestsMap_ = std::make_shared<std::map<int32_t, std::shared_ptr<std::list<std::shared_ptr<Request>>>>>();
64 requestsList_ = std::make_shared<std::list<std::shared_ptr<Request>>>();
65 CommonUtils::GetCurrentUserId(curUserId_);
66 requestsMap_->insert(make_pair(curUserId_, requestsList_));
67
68 auto requestConfig = std::make_unique<RequestConfig>();
69 requestConfig->SetPriority(PRIORITY_LOW_POWER);
70 requestConfig->SetTimeInterval(timeInterval_);
71 callback_ = sptr<mLocatorCallback>(new (std::nothrow) LocatorBackgroundProxy::mLocatorCallback());
72 if (callback_ == nullptr) {
73 return;
74 }
75 request_ = std::make_shared<Request>();
76 if (request_ == nullptr) {
77 return;
78 }
79 request_->SetUid(SYSTEM_UID);
80 request_->SetPid(getpid());
81 request_->SetPackageName(PROC_NAME);
82 request_->SetRequestConfig(*requestConfig);
83 request_->SetLocatorCallBack(callback_);
84 SubscribeSaStatusChangeListerner();
85 isUserSwitchSubscribed_ = LocatorBackgroundProxy::UserSwitchSubscriber::Subscribe();
86 proxySwtich_ = (LocationConfigManager::GetInstance()->GetLocationSwitchState() == ENABLED);
87 RegisterAppStateObserver();
88 }
89
~LocatorBackgroundProxy()90 LocatorBackgroundProxy::~LocatorBackgroundProxy()
91 {
92 UnregisterAppStateObserver();
93 }
94
95 // modify the parameters, in order to make the test easier
InitArgsFromProp()96 void LocatorBackgroundProxy::InitArgsFromProp()
97 {
98 featureSwitch_ = 1;
99 timeInterval_ = DEFAULT_TIME_INTERVAL;
100 }
101
SubscribeSaStatusChangeListerner()102 void LocatorBackgroundProxy::SubscribeSaStatusChangeListerner()
103 {
104 OHOS::EventFwk::MatchingSkills matchingSkills;
105 matchingSkills.AddEvent(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
106 OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
107 if (subscriber_ == nullptr) {
108 subscriber_ = std::make_shared<UserSwitchSubscriber>(subscriberInfo);
109 }
110 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
111 statusChangeListener_ = new (std::nothrow) SystemAbilityStatusChangeListener(subscriber_);
112 if (samgrProxy == nullptr || statusChangeListener_ == nullptr) {
113 LBSLOGE(LOCATOR_BACKGROUND_PROXY,
114 "SubscribeSaStatusChangeListerner samgrProxy or statusChangeListener_ is nullptr");
115 return;
116 }
117 int32_t ret = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_);
118 LBSLOGI(LOCATOR_BACKGROUND_PROXY,
119 "SubscribeSaStatusChangeListerner SubscribeSystemAbility COMMON_EVENT_SERVICE_ID result:%{public}d", ret);
120 }
121
StartLocatorThread()122 void LocatorBackgroundProxy::StartLocatorThread()
123 {
124 auto requestManager = RequestManager::GetInstance();
125 auto locatorAbility = LocatorAbility::GetInstance();
126 if (requestManager == nullptr || locatorAbility == nullptr) {
127 LBSLOGE(LOCATOR, "StartLocatorThread: RequestManager or LocatorAbility is nullptr");
128 return;
129 }
130 std::this_thread::sleep_for(std::chrono::seconds(timeInterval_));
131 std::unique_lock<std::mutex> lock(locatorMutex_, std::defer_lock);
132 lock.lock();
133 isWating_ = false;
134 if (isLocating_ || !proxySwtich_ || requestsList_->empty()) {
135 LBSLOGD(LOCATOR_BACKGROUND_PROXY, "cancel locating");
136 lock.unlock();
137 return;
138 }
139 isLocating_ = true;
140 lock.unlock();
141 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "real start locating");
142 requestManager->HandleStartLocating(request_);
143 locatorAbility->ReportLocationStatus(callback_, SESSION_START);
144 }
145
StopLocatorThread()146 void LocatorBackgroundProxy::StopLocatorThread()
147 {
148 auto locatorAbility = LocatorAbility::GetInstance();
149 if (locatorAbility == nullptr) {
150 LBSLOGE(LOCATOR, "StopLocatorThread: LocatorAbility is nullptr.");
151 return;
152 }
153 std::unique_lock<std::mutex> lock(locatorMutex_, std::defer_lock);
154 lock.lock();
155 if (!isLocating_) {
156 lock.unlock();
157 return;
158 }
159 isLocating_ = false;
160 lock.unlock();
161 locatorAbility->StopLocating(callback_);
162 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "end locating");
163 }
164
StopLocator()165 void LocatorBackgroundProxy::StopLocator()
166 {
167 }
168
StartLocator()169 void LocatorBackgroundProxy::StartLocator()
170 {
171 }
172
UpdateListOnRequestChange(const std::shared_ptr<Request> & request)173 void LocatorBackgroundProxy::UpdateListOnRequestChange(const std::shared_ptr<Request>& request)
174 {
175 }
176
177 // called when the app freezes or wakes up
178 // When the app enters frozen state, start proxy
179 // when the app wakes up, stop proxy
OnSuspend(const std::shared_ptr<Request> & request,bool active)180 void LocatorBackgroundProxy::OnSuspend(const std::shared_ptr<Request>& request, bool active)
181 {
182 }
183
184 // called when SA switch on or switch off
185 // when switch on, start proxy
186 // when switch off, stop proxy
OnSaStateChange(bool enable)187 void LocatorBackgroundProxy::OnSaStateChange(bool enable)
188 {
189 if (proxySwtich_ == enable || !featureSwitch_) {
190 return;
191 }
192 LBSLOGD(LOCATOR_BACKGROUND_PROXY, "OnSaStateChange %{public}d", enable);
193 proxySwtich_ = enable;
194 if (enable && !requestsList_->empty()) {
195 StartLocator();
196 } else {
197 StopLocator();
198 }
199 }
200
201 // called when deleteRequest called from locator ability (e.g. app stop locating)
OnDeleteRequestRecord(const std::shared_ptr<Request> & request)202 void LocatorBackgroundProxy::OnDeleteRequestRecord(const std::shared_ptr<Request>& request)
203 {
204 if (!featureSwitch_) {
205 return;
206 }
207 bool listEmpty = false;
208 std::unique_lock<std::mutex> lock(requestListMutex_, std::defer_lock);
209 lock.lock();
210 auto it = find(requestsList_->begin(), requestsList_->end(), request);
211 if (it != requestsList_->end()) {
212 requestsList_->remove(request);
213 if (requestsList_->empty()) {
214 listEmpty = true;
215 }
216 }
217 lock.unlock();
218 if (listEmpty) {
219 StopLocator();
220 }
221 }
222
CheckPermission(const std::shared_ptr<Request> & request) const223 bool LocatorBackgroundProxy::CheckPermission(const std::shared_ptr<Request>& request) const
224 {
225 uint32_t tokenId = request->GetTokenId();
226 uint32_t firstTokenId = request->GetFirstTokenId();
227 return ((PermissionManager::CheckLocationPermission(tokenId, firstTokenId) ||
228 PermissionManager::CheckApproximatelyPermission(tokenId, firstTokenId)) &&
229 PermissionManager::CheckBackgroundPermission(tokenId, firstTokenId));
230 }
231
UpdateListOnSuspend(const std::shared_ptr<Request> & request,bool active)232 void LocatorBackgroundProxy::UpdateListOnSuspend(const std::shared_ptr<Request>& request, bool active)
233 {
234 }
235
UpdateListOnUserSwitch(int32_t userId)236 void LocatorBackgroundProxy::UpdateListOnUserSwitch(int32_t userId)
237 {
238 std::unique_lock lock(requestListMutex_);
239 auto iter = requestsMap_->find(userId);
240 if (iter == requestsMap_->end()) {
241 auto mRequestsList = std::make_shared<std::list<std::shared_ptr<Request>>>();
242 requestsMap_->insert(make_pair(userId, mRequestsList));
243 LBSLOGD(LOCATOR_BACKGROUND_PROXY, "add requsetlist on user:%{public}d", userId);
244 }
245 // if change to another user, proxy requestList should change
246 requestsList_ = (*requestsMap_)[userId];
247 curUserId_ = userId;
248 }
249
250
GetRequestsInProxy() const251 const std::list<std::shared_ptr<Request>>& LocatorBackgroundProxy::GetRequestsInProxy() const
252 {
253 return *requestsList_;
254 }
255
256 // called in LocatorCallbackProxy::OnLocationReport
257 // check if callback is from proxy
IsCallbackInProxy(const sptr<ILocatorCallback> & callback) const258 bool LocatorBackgroundProxy::IsCallbackInProxy(const sptr<ILocatorCallback>& callback) const
259 {
260 if (!featureSwitch_) {
261 return false;
262 }
263 std::unique_lock lock(requestListMutex_);
264 for (auto request : *requestsList_) {
265 if (request->GetLocatorCallBack() == callback) {
266 return true;
267 }
268 }
269 return false;
270 }
271
GetUserId(int32_t uid) const272 int32_t LocatorBackgroundProxy::GetUserId(int32_t uid) const
273 {
274 int userId = 0;
275 AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId);
276 return userId;
277 }
278
OnUserSwitch(int32_t userId)279 void LocatorBackgroundProxy::OnUserSwitch(int32_t userId)
280 {
281 UpdateListOnUserSwitch(userId);
282 auto locatorAbility = LocatorAbility::GetInstance();
283 if (locatorAbility != nullptr) {
284 locatorAbility->ApplyRequests(0);
285 }
286 if (!requestsList_->empty()) {
287 StartLocator();
288 } else {
289 LBSLOGD(LOCATOR_BACKGROUND_PROXY, "OnUserSwitch stoplocator");
290 StopLocator();
291 }
292 }
293
OnUserRemove(int32_t userId)294 void LocatorBackgroundProxy::OnUserRemove(int32_t userId)
295 {
296 // if user is removed, remove the requestList from the user in requestsMap
297 std::unique_lock lock(requestListMutex_);
298 auto iter = requestsMap_->find(userId);
299 if (iter != requestsMap_->end()) {
300 requestsMap_->erase(iter);
301 LBSLOGD(LOCATOR_BACKGROUND_PROXY, "erase requsetlist on user:%{public}d", userId);
302 }
303 }
304
305 // limit the number of requests per app
CheckMaxRequestNum(pid_t uid,const std::string & packageName) const306 bool LocatorBackgroundProxy::CheckMaxRequestNum(pid_t uid, const std::string& packageName) const
307 {
308 int32_t num = 0;
309 auto iter = requestsMap_->find(GetUserId(uid));
310 if (iter == requestsMap_->end()) {
311 return false;
312 }
313 for (auto request : *(iter->second)) {
314 if (request->GetUid() == uid && packageName.compare(request->GetPackageName()) == 0) {
315 if (++num >= REQUESTS_NUM_MAX) {
316 return false;
317 }
318 }
319 }
320 return true;
321 }
322
OnLocationReport(const std::unique_ptr<Location> & location)323 void LocatorBackgroundProxy::mLocatorCallback::OnLocationReport(const std::unique_ptr<Location>& location)
324 {
325 LBSLOGD(LOCATOR_BACKGROUND_PROXY, "locator background OnLocationReport");
326 auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
327 if (locatorBackgroundProxy == nullptr) {
328 LBSLOGE(LOCATOR_BACKGROUND_PROXY, "OnLocationReport: LocatorBackgroundProxy is nullptr.");
329 return;
330 }
331 auto requestsList = locatorBackgroundProxy->GetRequestsInProxy();
332 if (requestsList.empty()) {
333 locatorBackgroundProxy->StopLocator();
334 return;
335 }
336 // call the callback of each proxy app
337 for (auto request : requestsList) {
338 request->GetLocatorCallBack()->OnLocationReport(location);
339 }
340 }
341
OnLocatingStatusChange(const int status)342 void LocatorBackgroundProxy::mLocatorCallback::OnLocatingStatusChange(const int status)
343 {
344 }
345
OnErrorReport(const int errorCode)346 void LocatorBackgroundProxy::mLocatorCallback::OnErrorReport(const int errorCode)
347 {
348 }
349
UserSwitchSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo & info)350 LocatorBackgroundProxy::UserSwitchSubscriber::UserSwitchSubscriber(
351 const OHOS::EventFwk::CommonEventSubscribeInfo &info)
352 : CommonEventSubscriber(info)
353 {
354 LBSLOGD(LOCATOR_BACKGROUND_PROXY, "create UserSwitchEventSubscriber");
355 }
356
OnReceiveEvent(const OHOS::EventFwk::CommonEventData & event)357 void LocatorBackgroundProxy::UserSwitchSubscriber::OnReceiveEvent(const OHOS::EventFwk::CommonEventData& event)
358 {
359 int32_t userId = event.GetCode();
360 const auto action = event.GetWant().GetAction();
361 auto locatorProxy = LocatorBackgroundProxy::GetInstance();
362 if (locatorProxy == nullptr) {
363 LBSLOGE(LOCATOR_BACKGROUND_PROXY, "OnReceiveEvent: LocatorBackgroundProxy is nullptr.");
364 return;
365 }
366 LBSLOGD(LOCATOR_BACKGROUND_PROXY, "action = %{public}s, userId = %{public}d", action.c_str(), userId);
367 if (action == OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
368 locatorProxy->OnUserSwitch(userId);
369 } else if (action == OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) {
370 locatorProxy->OnUserRemove(userId);
371 }
372 }
373
Subscribe()374 bool LocatorBackgroundProxy::UserSwitchSubscriber::Subscribe()
375 {
376 LBSLOGD(LOCATOR_BACKGROUND_PROXY, "subscribe common event");
377 OHOS::EventFwk::MatchingSkills matchingSkills;
378 matchingSkills.AddEvent(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
379 OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
380 std::shared_ptr<UserSwitchSubscriber> subscriber = std::make_shared<UserSwitchSubscriber>(subscriberInfo);
381 bool result = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber);
382 if (result) {
383 } else {
384 LBSLOGE(LOCATOR_BACKGROUND_PROXY, "Subscribe service event error.");
385 }
386 return result;
387 }
388
SystemAbilityStatusChangeListener(std::shared_ptr<UserSwitchSubscriber> & subscriber)389 LocatorBackgroundProxy::SystemAbilityStatusChangeListener::SystemAbilityStatusChangeListener(
390 std::shared_ptr<UserSwitchSubscriber> &subscriber) : subscriber_(subscriber)
391 {}
392
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)393 void LocatorBackgroundProxy::SystemAbilityStatusChangeListener::OnAddSystemAbility(
394 int32_t systemAbilityId, const std::string& deviceId)
395 {
396 if (systemAbilityId != COMMON_EVENT_SERVICE_ID) {
397 LBSLOGE(LOCATOR_BACKGROUND_PROXY, "systemAbilityId is not COMMON_EVENT_SERVICE_ID");
398 return;
399 }
400 if (subscriber_ == nullptr) {
401 LBSLOGE(LOCATOR_BACKGROUND_PROXY, "OnAddSystemAbility subscribeer is nullptr");
402 return;
403 }
404 bool result = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber_);
405 LBSLOGI(LOCATOR_BACKGROUND_PROXY, "SubscribeCommonEvent subscriber_ result = %{public}d", result);
406 }
407
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)408 void LocatorBackgroundProxy::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(
409 int32_t systemAbilityId, const std::string& deviceId)
410 {
411 if (systemAbilityId != COMMON_EVENT_SERVICE_ID) {
412 LBSLOGE(LOCATOR_BACKGROUND_PROXY, "systemAbilityId is not COMMON_EVENT_SERVICE_ID");
413 return;
414 }
415 if (subscriber_ == nullptr) {
416 LBSLOGE(LOCATOR_BACKGROUND_PROXY, "OnRemoveSystemAbility subscribeer is nullptr");
417 return;
418 }
419 bool result = OHOS::EventFwk::CommonEventManager::UnSubscribeCommonEvent(subscriber_);
420 LBSLOGE(LOCATOR_BACKGROUND_PROXY, "UnSubscribeCommonEvent subscriber_ result = %{public}d", result);
421 }
422
IsAppBackground(std::string bundleName)423 bool LocatorBackgroundProxy::IsAppBackground(std::string bundleName)
424 {
425 sptr<ISystemAbilityManager> samgrClient = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
426 if (samgrClient == nullptr) {
427 LBSLOGE(LOCATOR_BACKGROUND_PROXY, "Get system ability manager failed.");
428 return false;
429 }
430 sptr<AppExecFwk::IAppMgr> iAppManager =
431 iface_cast<AppExecFwk::IAppMgr>(samgrClient->GetSystemAbility(APP_MGR_SERVICE_ID));
432 if (iAppManager == nullptr) {
433 LBSLOGE(LOCATOR_BACKGROUND_PROXY, "Failed to get ability manager service.");
434 return false;
435 }
436 std::vector<AppExecFwk::AppStateData> foregroundAppList;
437 iAppManager->GetForegroundApplications(foregroundAppList);
438 auto it = std::find_if(foregroundAppList.begin(), foregroundAppList.end(), [bundleName] (auto foregroundApp) {
439 return bundleName.compare(foregroundApp.bundleName) == 0;
440 });
441 if (it != foregroundAppList.end()) {
442 LBSLOGD(LOCATOR_BACKGROUND_PROXY, "app : %{public}s is foreground.", bundleName.c_str());
443 return false;
444 }
445 return true;
446 }
447
RegisterAppStateObserver()448 bool LocatorBackgroundProxy::RegisterAppStateObserver()
449 {
450 if (appStateObserver_ != nullptr) {
451 LBSLOGI(REQUEST_MANAGER, "app state observer exist.");
452 return true;
453 }
454 appStateObserver_ = sptr<AppStateChangeCallback>(new (std::nothrow) AppStateChangeCallback());
455 sptr<ISystemAbilityManager> samgrClient = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
456 if (samgrClient == nullptr) {
457 LBSLOGE(REQUEST_MANAGER, "Get system ability manager failed.");
458 appStateObserver_ = nullptr;
459 return false;
460 }
461 iAppMgr_ = iface_cast<AppExecFwk::IAppMgr>(samgrClient->GetSystemAbility(APP_MGR_SERVICE_ID));
462 if (iAppMgr_ == nullptr) {
463 LBSLOGE(REQUEST_MANAGER, "Failed to get ability manager service.");
464 appStateObserver_ = nullptr;
465 return false;
466 }
467 int32_t result = iAppMgr_->RegisterApplicationStateObserver(appStateObserver_);
468 if (result != 0) {
469 LBSLOGE(REQUEST_MANAGER, "Failed to Register app state observer.");
470 iAppMgr_ = nullptr;
471 appStateObserver_ = nullptr;
472 return false;
473 }
474 return true;
475 }
476
UnregisterAppStateObserver()477 bool LocatorBackgroundProxy::UnregisterAppStateObserver()
478 {
479 if (iAppMgr_ != nullptr && appStateObserver_ != nullptr) {
480 iAppMgr_->UnregisterApplicationStateObserver(appStateObserver_);
481 }
482 iAppMgr_ = nullptr;
483 appStateObserver_ = nullptr;
484 return true;
485 }
486
IsAppInLocationContinuousTasks(pid_t uid,pid_t pid)487 bool LocatorBackgroundProxy::IsAppInLocationContinuousTasks(pid_t uid, pid_t pid)
488 {
489 #ifdef BGTASKMGR_SUPPORT
490 std::vector<std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo>> continuousTasks;
491 ErrCode result = BackgroundTaskMgr::BackgroundTaskMgrHelper::GetContinuousTaskApps(continuousTasks);
492 if (result != ERR_OK) {
493 return false;
494 }
495 for (auto iter = continuousTasks.begin(); iter != continuousTasks.end(); iter++) {
496 auto continuousTask = *iter;
497 if (continuousTask == nullptr) {
498 continue;
499 }
500 if (continuousTask->GetCreatorUid() != uid || continuousTask->GetCreatorPid() != pid) {
501 continue;
502 }
503 auto typeIds = continuousTask->GetTypeIds();
504 for (auto typeId : typeIds) {
505 if (typeId == BackgroundTaskMgr::BackgroundMode::Type::LOCATION) {
506 return true;
507 }
508 }
509 }
510 #endif
511 return false;
512 }
513
IsAppHasFormVisible(uint32_t tokenId,uint64_t tokenIdEx)514 bool LocatorBackgroundProxy::IsAppHasFormVisible(uint32_t tokenId, uint64_t tokenIdEx)
515 {
516 bool ret = false;
517 auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId);
518 if (tokenType != Security::AccessToken::ATokenTypeEnum::TOKEN_HAP) {
519 return ret;
520 }
521 #ifdef FMSKIT_NATIVE_SUPPORT
522 ret = OHOS::AppExecFwk::FormMgr::GetInstance().HasFormVisible(tokenId);
523 #endif
524 return ret;
525 }
526
AppStateChangeCallback()527 AppStateChangeCallback::AppStateChangeCallback()
528 {
529 }
530
~AppStateChangeCallback()531 AppStateChangeCallback::~AppStateChangeCallback()
532 {
533 }
534
OnForegroundApplicationChanged(const AppExecFwk::AppStateData & appStateData)535 void AppStateChangeCallback::OnForegroundApplicationChanged(const AppExecFwk::AppStateData& appStateData)
536 {
537 auto requestManager = RequestManager::GetInstance();
538 if (requestManager == nullptr) {
539 LBSLOGE(REQUEST_MANAGER, "OnForegroundApplicationChanged: RequestManager is nullptr.");
540 return;
541 }
542 int32_t pid = appStateData.pid;
543 int32_t uid = appStateData.uid;
544 int32_t state = appStateData.state;
545 LBSLOGD(REQUEST_MANAGER,
546 "The state of App changed, uid = %{public}d, pid = %{public}d, state = %{public}d", uid, pid, state);
547 requestManager->HandlePowerSuspendChanged(pid, uid, state);
548 }
549 } // namespace OHOS
550 } // namespace Location
551