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