• 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_event_subscriber.h"
17 
18 #include "hook_utils.h"
19 #include "location_log.h"
20 #include "locator_ability.h"
21 #include "location_config_manager.h"
22 #include "beacon_fence_manager.h"
23 
24 namespace OHOS {
25 namespace Location {
26 constexpr const char* LOCATOR_STANDBY_NAP = "napped";
27 constexpr const char* LOCATOR_STANDBY_SLEEPING = "sleeping";
28 const uint32_t SIM_STATE_READY = 4; // Telephony::SimState::SIM_STATE_READY
29 
LocatorEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo & info)30 LocatorEventSubscriber::LocatorEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &info)
31     : CommonEventSubscriber(info) {}
32 
~LocatorEventSubscriber()33 LocatorEventSubscriber::~LocatorEventSubscriber() {}
34 
OnReceiveEvent(const OHOS::EventFwk::CommonEventData & event)35 void LocatorEventSubscriber::OnReceiveEvent(const OHOS::EventFwk::CommonEventData& event)
36 {
37     std::string action = event.GetWant().GetAction();
38     LBSLOGI(LOCATOR_EVENT, "received action = %{public}s", action.c_str());
39     if (OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED.compare(action) == 0) {
40         auto locatorAbility = LocatorAbility::GetInstance();
41         const bool napped = event.GetWant().GetBoolParam(LOCATOR_STANDBY_NAP, 0);
42         const bool sleeping = event.GetWant().GetBoolParam(LOCATOR_STANDBY_SLEEPING, 0);
43         LBSLOGD(LOCATOR_EVENT, "device idle napped: %{public}d, sleeping: %{public}d", napped, sleeping);
44         locatorAbility->SyncIdleState(sleeping);
45         return;
46     }
47     auto locatorAbility = LocatorAbility::GetInstance();
48     if (std::string(MODE_CHANGED_EVENT).compare(action) == 0) {
49         locatorAbility->UpdateSaAbility();
50     } else if (std::string(LOCATION_PRIVACY_ACCEPT_EVENT).compare(action) == 0) {
51         LocationConfigManager::GetInstance()->SetPrivacyTypeState(PRIVACY_TYPE_STARTUP, true);
52         locatorAbility->SetSwitchState(true);
53     } else if (std::string(LOCATION_PRIVACY_REJECT_EVENT).compare(action) == 0) {
54         locatorAbility->SetSwitchState(false);
55     } else if (OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED.compare(action) == 0) {
56         int stateCode = event.GetCode();
57         if (stateCode == static_cast<int>(SIM_STATE_READY)) {
58             HookUtils::ExecuteHookWhenSimStateChange(action);
59         }
60     } else if (std::string(LOCATION_CUST_CONFIG_POLICY_CHANGE).compare(action) == 0) {
61         HookUtils::ExecuteHookWhenCustConfigPolicyChange();
62     } else if (std::string(PACKAGE_REMOVED_EVENT).compare(action) == 0) {
63         std::string packageName = event.GetWant().GetStringParam(AppExecFwk::Constants::BUNDLE_NAME);
64         BeaconFenceManager::GetInstance()->RemoveBeaconFenceByPackageName(packageName);
65     }
66 }
67 } // namespace Location
68 } // namespace OHOS
69