• 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 SUBABILITY_COMMON_H
17 #define SUBABILITY_COMMON_H
18 
19 #include <vector>
20 
21 #include "iremote_broker.h"
22 
23 #include "constant_definition.h"
24 #include "i_locator_callback.h"
25 #include "location.h"
26 #include "hilog/log.h"
27 #include "work_record.h"
28 
29 namespace OHOS {
30 namespace Location {
31 class ISubAbility : public IRemoteBroker {
32 public:
33     enum {
34         SEND_LOCATION_REQUEST = 1,
35         GET_CACHED_LOCATION = 2,
36         SET_ENABLE = 3,
37         SELF_REQUEST = 4,
38         HANDLE_REMOTE_REQUEST = 5,
39         REFRESH_REQUESTS = 6,
40         REG_GNSS_STATUS = 7,
41         UNREG_GNSS_STATUS = 8,
42         REG_NMEA = 9,
43         UNREG_NMEA = 10,
44         REG_CACHED = 11,
45         UNREG_CACHED = 12,
46         GET_CACHED_SIZE = 13,
47         FLUSH_CACHED = 14,
48         SEND_COMMANDS = 15,
49         ADD_FENCE_INFO = 16,
50         REMOVE_FENCE_INFO = 17,
51         REPORT_GNSS_SESSION_STATUS = 18,
52         REPORT_SV = 19,
53         REPORT_NMEA = 20,
54         GET_ISO_COUNTRY_CODE = 21,
55         ENABLE_LOCATION_MOCK = 22,
56         DISABLE_LOCATION_MOCK = 23,
57         SET_MOCKED_LOCATIONS = 24,
58         ENABLE_REV_GEOCODE_MOCK = 25,
59         DISABLE_REV_GEOCODE_MOCK = 26,
60     };
61     virtual LocationErrCode SendLocationRequest(WorkRecord &workrecord) = 0;
62     virtual LocationErrCode SetEnable(bool state) = 0;
63     virtual LocationErrCode EnableMock() = 0;
64     virtual LocationErrCode DisableMock() = 0;
65     virtual LocationErrCode SetMocked(const int timeInterval,
66         const std::vector<std::shared_ptr<Location>> &location) = 0;
67 };
68 
69 class SubAbility {
70 public:
71     SubAbility();
72     virtual ~SubAbility();
73     void SetAbility(std::string name);
74     void LocationRequest(WorkRecord &workrecord);
75     void Enable(bool state, const sptr<IRemoteObject> ability);
76     void HandleSelfRequest(pid_t pid, pid_t uid, bool state);
77     void HandleRefrashRequirements();
78     int GetRequestNum();
79     bool EnableLocationMock();
80     bool DisableLocationMock();
81     bool SetMockedLocations(const int timeInterval, const std::vector<std::shared_ptr<Location>> &location);
82 
83     int GetTimeIntervalMock();
84     bool IsLocationMocked();
85     std::vector<std::shared_ptr<Location>> GetLocationMock();
86     void ClearLocationMock();
87 private:
88     void HandleLocalRequest(WorkRecord &record);
89     void HandleRemoveRecord(WorkRecord &newRecord);
90     void HandleAddRecord(WorkRecord &newRecord);
91     void CacheLocationMock(const std::vector<std::shared_ptr<Location>> &location);
92     virtual void RequestRecord(WorkRecord &workRecord, bool isAdded) = 0;
93     virtual void SendReportMockLocationEvent() = 0;
94 
95     OHOS::HiviewDFX::HiLogLabel label_;
96     int interval_ = 0;
97     std::string name_ = "";
98     std::u16string capability_ = u"";
99     std::unique_ptr<WorkRecord> lastRecord_;
100     std::unique_ptr<WorkRecord> newRecord_;
101     int mockTimeInterval_ = 0;
102     bool mockEnabled_ = false;
103     std::vector<std::shared_ptr<Location>> mockLoc_;
104 };
105 } // namespace Location
106 } // namespace OHOS
107 #endif // SUBABILITY_COMMON_H
108