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 DECLEAR_SYSTEM_ABILITY(PassiveAbility); 44 45 public: 46 DISALLOW_COPY_AND_MOVE(PassiveAbility); 47 48 static PassiveAbility* GetInstance(); 49 PassiveAbility(); 50 ~PassiveAbility() override; 51 void OnStart() override; 52 void OnStop() override; QueryServiceState()53 ServiceRunningState QueryServiceState() const 54 { 55 return state_; 56 } 57 LocationErrCode SendLocationRequest(WorkRecord &workrecord) override; 58 LocationErrCode SetEnable(bool state) override; 59 int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override; 60 void RequestRecord(WorkRecord &workRecord, bool isAdded) override; 61 LocationErrCode EnableMock() override; 62 LocationErrCode DisableMock() override; 63 LocationErrCode SetMocked(const int timeInterval, const std::vector<std::shared_ptr<Location>> &location) override; 64 void SendReportMockLocationEvent() override; 65 bool IsMockEnabled(); 66 void SendMessage(uint32_t code, MessageParcel &data, MessageParcel &reply) override; 67 bool CancelIdleState() override; 68 void UnloadPassiveSystemAbility() override; 69 private: 70 bool Init(); 71 static void SaDumpInfo(std::string& result); 72 bool CheckIfPassiveConnecting(); 73 74 std::shared_ptr<PassiveHandler> passiveHandler_; 75 bool registerToAbility_ = false; 76 ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START; 77 }; 78 } // namespace Location 79 } // namespace OHOS 80 #endif // FEATURE_PASSIVE_SUPPORT 81 #endif // PASSIVE_ABILITY_H 82