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 LOCATOR_PROXY_H
17 #define LOCATOR_PROXY_H
18 
19 #include <list>
20 #include <set>
21 #include <vector>
22 
23 #include "iremote_broker.h"
24 #include "iremote_object.h"
25 #include "iremote_proxy.h"
26 
27 #include "constant_definition.h"
28 #include "geo_coding_mock_info.h"
29 #include "i_cached_locations_callback.h"
30 #include "i_locator.h"
31 #include "i_locator_callback.h"
32 #include "location.h"
33 #include "request_config.h"
34 
35 #include "i_locating_required_data_callback.h"
36 #include "locating_required_data_config.h"
37 #include "locationhub_ipc_interface_code.h"
38 
39 namespace OHOS {
40 namespace Location {
41 class LocatorProxy : public IRemoteProxy<ILocator> {
42 public:
43     explicit LocatorProxy(const sptr<IRemoteObject> &impl);
44     ~LocatorProxy() = default;
45     void UpdateSaAbility();
46     int GetSwitchState();
47     void EnableAbility(bool isEnabled);
48     void RegisterSwitchCallback(const sptr<IRemoteObject> &callback, pid_t uid);
49     void UnregisterSwitchCallback(const sptr<IRemoteObject> &callback);
50     void RegisterGnssStatusCallback(const sptr<IRemoteObject> &callback, pid_t uid);
51     void UnregisterGnssStatusCallback(const sptr<IRemoteObject> &callback);
52     void RegisterNmeaMessageCallback(const sptr<IRemoteObject> &callback, pid_t uid);
53     void UnregisterNmeaMessageCallback(const sptr<IRemoteObject> &callback);
54     int StartLocating(std::unique_ptr<RequestConfig>& requestConfig,
55         sptr<ILocatorCallback>& callback, std::string bundleName, pid_t pid, pid_t uid);
56     int StopLocating(sptr<ILocatorCallback>& callback);
57     int GetCacheLocation(MessageParcel &replay);
58     int IsGeoConvertAvailable(MessageParcel &replay);
59     int GetAddressByCoordinate(MessageParcel &data, MessageParcel &replay);
60     int GetAddressByLocationName(MessageParcel &data, MessageParcel &replay);
61     bool IsLocationPrivacyConfirmed(const int type);
62     int SetLocationPrivacyConfirmStatus(const int type, bool isConfirmed);
63     int RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLocationsRequest>& request,
64         sptr<ICachedLocationsCallback>& callback, std::string bundleName);
65     int UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback);
66     int GetCachedGnssLocationsSize();
67     int FlushCachedGnssLocations();
68     void SendCommand(std::unique_ptr<LocationCommand>& commands);
69     bool EnableLocationMock();
70     bool DisableLocationMock();
71     bool SetMockedLocations(
72         const int timeInterval, const std::vector<std::shared_ptr<Location>> &location);
73     bool EnableReverseGeocodingMock();
74     bool DisableReverseGeocodingMock();
75     bool SetReverseGeocodingMockInfo(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo);
76     int SendMsgWithDataReply(const int msgId, MessageParcel& data, MessageParcel& reply);
77     int SendMsgWithReply(const int msgId, MessageParcel& reply);
78     int SendSimpleMsg(const int msgId);
79     int SendRegisterMsgToRemote(const int msgId, const sptr<IRemoteObject>& callback, pid_t uid);
80 
81     LocationErrCode UpdateSaAbilityV9();
82     LocationErrCode GetSwitchStateV9(bool &isEnabled);
83     LocationErrCode EnableAbilityV9(bool isEnabled);
84     LocationErrCode EnableAbilityForUser(bool isEnabled, int32_t userId);
85     LocationErrCode RegisterSwitchCallbackV9(const sptr<IRemoteObject> &callback);
86     LocationErrCode UnregisterSwitchCallbackV9(const sptr<IRemoteObject> &callback);
87     LocationErrCode RegisterGnssStatusCallbackV9(const sptr<IRemoteObject> &callback);
88     LocationErrCode UnregisterGnssStatusCallbackV9(const sptr<IRemoteObject> &callback);
89     LocationErrCode RegisterNmeaMessageCallbackV9(const sptr<IRemoteObject> &callback);
90     LocationErrCode UnregisterNmeaMessageCallbackV9(const sptr<IRemoteObject> &callback);
91     LocationErrCode StartLocatingV9(std::unique_ptr<RequestConfig>& requestConfig,
92         sptr<ILocatorCallback>& callback);
93     LocationErrCode StopLocatingV9(sptr<ILocatorCallback>& callback);
94     LocationErrCode GetCacheLocationV9(std::unique_ptr<Location> &loc);
95     LocationErrCode IsGeoConvertAvailableV9(bool &isAvailable);
96     LocationErrCode GetAddressByCoordinateV9(MessageParcel &data,
97         std::list<std::shared_ptr<GeoAddress>>& replyList);
98     LocationErrCode GetAddressByLocationNameV9(MessageParcel &data,
99         std::list<std::shared_ptr<GeoAddress>>& replyList);
100     LocationErrCode IsLocationPrivacyConfirmedV9(const int type, bool &isConfirmed);
101     LocationErrCode SetLocationPrivacyConfirmStatusV9(const int type, bool isConfirmed);
102     LocationErrCode RegisterCachedLocationCallbackV9(std::unique_ptr<CachedGnssLocationsRequest>& request,
103         sptr<ICachedLocationsCallback>& callback, std::string bundleName);
104     LocationErrCode UnregisterCachedLocationCallbackV9(sptr<ICachedLocationsCallback>& callback);
105     LocationErrCode GetCachedGnssLocationsSizeV9(int &size);
106     LocationErrCode FlushCachedGnssLocationsV9();
107     LocationErrCode SendCommandV9(std::unique_ptr<LocationCommand>& commands);
108     LocationErrCode EnableLocationMockV9();
109     LocationErrCode DisableLocationMockV9();
110     LocationErrCode SetMockedLocationsV9(
111         const int timeInterval, const std::vector<std::shared_ptr<Location>> &location);
112     LocationErrCode EnableReverseGeocodingMockV9();
113     LocationErrCode DisableReverseGeocodingMockV9();
114     LocationErrCode SetReverseGeocodingMockInfoV9(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo);
115     LocationErrCode SendMsgWithDataReplyV9(const int msgId, MessageParcel& data, MessageParcel& reply);
116     LocationErrCode SendMsgWithReplyV9(const int msgId, MessageParcel& reply);
117     LocationErrCode SendSimpleMsgV9(const int msgId);
118     LocationErrCode SendRegisterMsgToRemoteV9(const int msgId, const sptr<IRemoteObject>& callback);
119     LocationErrCode ProxyForFreeze(std::set<int> pidList, bool isProxy);
120     LocationErrCode ResetAllProxy();
121     LocationErrCode RegisterLocatingRequiredDataCallback(
122         std::unique_ptr<LocatingRequiredDataConfig>& dataConfig, sptr<ILocatingRequiredDataCallback>& callback);
123     LocationErrCode UnRegisterLocatingRequiredDataCallback(sptr<ILocatingRequiredDataCallback>& callback);
124     LocationErrCode SubscribeLocationError(sptr<ILocatorCallback>& callback);
125     LocationErrCode UnSubscribeLocationError(sptr<ILocatorCallback>& callback);
126     LocationErrCode GetCurrentWifiBssidForLocating(std::string& bssid);
127 private:
128 
129     static inline BrokerDelegator<LocatorProxy> delegator_;
130 };
131 } // namespace Location
132 } // namespace OHOS
133 #endif // LOCATOR_PROXY_H
134