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