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 #ifndef PASSIVE_ABILITY_H 17 #define PASSIVE_ABILITY_H 18 #ifdef FEATURE_PASSIVE_SUPPORT 19 20 #include <mutex> 21 #include <singleton.h> 22 23 #include "event_handler.h" 24 #include "event_runner.h" 25 #include "if_system_ability_manager.h" 26 #include "system_ability.h" 27 28 #include "common_utils.h" 29 #include "constant_definition.h" 30 #include "passive_ability_skeleton.h" 31 #include "subability_common.h" 32 33 namespace OHOS { 34 namespace Location { 35 class PassiveHandler : public AppExecFwk::EventHandler { 36 public: 37 explicit PassiveHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner); 38 ~PassiveHandler() override; 39 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override; 40 }; 41 42 class PassiveAbility : public SystemAbility, public PassiveAbilityStub, public SubAbility, 43 DelayedSingleton<PassiveAbility> { 44 DECLEAR_SYSTEM_ABILITY(PassiveAbility); 45 46 public: 47 DISALLOW_COPY_AND_MOVE(PassiveAbility); 48 PassiveAbility(); 49 ~PassiveAbility() override; 50 void OnStart() override; 51 void OnStop() override; QueryServiceState()52 ServiceRunningState QueryServiceState() const 53 { 54 return state_; 55 } 56 LocationErrCode SendLocationRequest(WorkRecord &workrecord) override; 57 LocationErrCode SetEnable(bool state) override; 58 int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override; 59 void RequestRecord(WorkRecord &workRecord, bool isAdded) override; 60 LocationErrCode EnableMock() override; 61 LocationErrCode DisableMock() override; 62 LocationErrCode SetMocked(const int timeInterval, const std::vector<std::shared_ptr<Location>> &location) override; 63 void SendReportMockLocationEvent() override; 64 bool IsMockEnabled(); 65 void SendMessage(uint32_t code, MessageParcel &data, MessageParcel &reply) override; 66 void UnloadPassiveSystemAbility() override; 67 private: 68 bool Init(); 69 static void SaDumpInfo(std::string& result); 70 bool CheckIfPassiveConnecting(); 71 72 std::shared_ptr<PassiveHandler> passiveHandler_; 73 bool registerToAbility_ = false; 74 ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START; 75 }; 76 } // namespace Location 77 } // namespace OHOS 78 #endif // FEATURE_PASSIVE_SUPPORT 79 #endif // PASSIVE_ABILITY_H 80