/* * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef LOCATOR_ABILITY_H #define LOCATOR_ABILITY_H #include #include #include #include "event_handler.h" #include "system_ability.h" #include "app_identity.h" #include "common_utils.h" #include "country_code_manager.h" #include "country_code.h" #include "geo_coding_mock_info.h" #include "i_switch_callback.h" #include "i_cached_locations_callback.h" #include "locator_event_subscriber.h" #include "locator_skeleton.h" #include "permission_status_change_cb.h" #include "request.h" #include "request_manager.h" #include "report_manager.h" namespace OHOS { namespace Location { class LocatorHandler : public AppExecFwk::EventHandler { public: explicit LocatorHandler(const std::shared_ptr& runner); ~LocatorHandler() override; void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override; }; class LocatorAbility : public SystemAbility, public LocatorAbilityStub, DelayedSingleton { DECLEAR_SYSTEM_ABILITY(LocatorAbility); public: DISALLOW_COPY_AND_MOVE(LocatorAbility); LocatorAbility(); ~LocatorAbility() override; void OnStart() override; void OnStop() override; void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; ServiceRunningState QueryServiceState() const { return state_; } void InitSaAbility(); void InitRequestManagerMap(); LocationErrCode UpdateSaAbility(); LocationErrCode GetSwitchState(int& state); LocationErrCode EnableAbility(bool isEnabled); LocationErrCode RegisterSwitchCallback(const sptr& callback, pid_t uid); LocationErrCode UnregisterSwitchCallback(const sptr& callback); LocationErrCode RegisterGnssStatusCallback(const sptr& callback, pid_t uid); LocationErrCode UnregisterGnssStatusCallback(const sptr& callback); LocationErrCode RegisterNmeaMessageCallback(const sptr& callback, pid_t uid); LocationErrCode UnregisterNmeaMessageCallback(const sptr& callback); LocationErrCode RegisterCountryCodeCallback(const sptr& callback, pid_t uid); LocationErrCode UnregisterCountryCodeCallback(const sptr& callback); LocationErrCode StartLocating(std::unique_ptr& requestConfig, sptr& callback, AppIdentity &identity); LocationErrCode StopLocating(sptr& callback); LocationErrCode GetCacheLocation(std::unique_ptr& loc, AppIdentity &identity); LocationErrCode IsGeoConvertAvailable(bool &isAvailable); void GetAddressByCoordinate(MessageParcel &data, MessageParcel &reply); void GetAddressByLocationName(MessageParcel &data, MessageParcel &reply); LocationErrCode IsLocationPrivacyConfirmed(const int type, bool& isConfirmed); LocationErrCode SetLocationPrivacyConfirmStatus(const int type, bool isConfirmed); LocationErrCode RegisterCachedLocationCallback(std::unique_ptr& request, sptr& callback, std::string bundleName); LocationErrCode UnregisterCachedLocationCallback(sptr& callback); LocationErrCode GetCachedGnssLocationsSize(int& size); LocationErrCode FlushCachedGnssLocations(); LocationErrCode SendCommand(std::unique_ptr& commands); LocationErrCode AddFence(std::unique_ptr& request); LocationErrCode RemoveFence(std::unique_ptr& request); LocationErrCode GetIsoCountryCode(std::shared_ptr& country); LocationErrCode EnableLocationMock(); LocationErrCode DisableLocationMock(); LocationErrCode SetMockedLocations( const int timeInterval, const std::vector> &location); LocationErrCode EnableReverseGeocodingMock(); LocationErrCode DisableReverseGeocodingMock(); LocationErrCode SetReverseGeocodingMockInfo(std::vector>& mockInfo); LocationErrCode ReportLocation(const std::unique_ptr& location, std::string abilityName); LocationErrCode ReportLocationStatus(sptr& callback, int result); LocationErrCode ReportErrorStatus(sptr& callback, int result); LocationErrCode ProcessLocationMockMsg( const int timeInterval, const std::vector> &location, int msgId); LocationErrCode SendLocationMockMsgToGnssSa(const sptr obj, const int timeInterval, const std::vector> &location, int msgId); LocationErrCode SendLocationMockMsgToNetworkSa(const sptr obj, const int timeInterval, const std::vector> &location, int msgId); LocationErrCode SendLocationMockMsgToPassiveSa(const sptr obj, const int timeInterval, const std::vector> &location, int msgId); std::shared_ptr>>> GetRequests(); std::shared_ptr, std::list>>> GetReceivers(); std::shared_ptr>> GetProxyMap(); void UpdateSaAbilityHandler(); void ApplyRequests(); void RegisterAction(); LocationErrCode ProxyUidForFreeze(int32_t uid, bool isProxy); LocationErrCode ResetAllProxy(); bool IsProxyUid(int32_t uid); int GetActiveRequestNum(); void RegisterPermissionCallback(const uint32_t callingTokenId, const std::vector& permissionNameList); void UnregisterPermissionCallback(const uint32_t callingTokenId); private: bool Init(); bool CheckSaValid(); static int QuerySwitchState(); LocationErrCode SendGeoRequest(int type, MessageParcel &data, MessageParcel &reply); LocationErrCode SendGnssRequest(int type, MessageParcel &data, MessageParcel &reply); bool registerToAbility_ = false; bool isActionRegistered = false; bool isEnabled_ = false; std::string deviceId_; ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START; std::shared_ptr locatorEventSubscriber_; std::unique_ptr>> switchCallbacks_; std::shared_ptr>>> requests_; std::shared_ptr, std::list>>> receivers_; std::shared_ptr>> proxyMap_; std::shared_ptr>> permissionMap_; std::shared_ptr locatorHandler_; std::shared_ptr requestManager_; std::shared_ptr reportManager_; std::shared_ptr countryCodeManager_ = nullptr; std::mutex proxyMutex_; std::mutex permissionMutex_; std::mutex switchMutex_; std::set proxyUids_; }; } // namespace Location } // namespace OHOS #endif // LOCATOR_ABILITY_H