/* * 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 REQUEST_MANAGER_H #define REQUEST_MANAGER_H #include #include #include #include #include #include "ffrt.h" #include "iremote_object.h" #include "i_locator_callback.h" #include "request.h" #include "work_record.h" namespace OHOS { namespace Location { class LocationErrRequest { public: LocationErrRequest(); ~LocationErrRequest(); pid_t GetUid(); void SetUid(pid_t uid); pid_t GetPid(); void SetPid(pid_t pid); int32_t GetLastReportErrcode(); void SetLastReportErrcode(int32_t lastReportErrcode); void SetLocatorErrCallbackRecipient(const sptr& recipient); sptr GetLocatorErrCallbackRecipient(); private: void GetProxyNameByPriority(std::shared_ptr> proxys); pid_t uid_; pid_t pid_; int32_t lastReportErrcode_; sptr locatorErrCallbackRecipient_; }; class RequestManager { public: RequestManager(); ~RequestManager(); bool InitSystemListeners(); void HandleStartLocating(std::shared_ptr request); void HandleStopLocating(sptr callback); void HandlePowerSuspendChanged(int32_t pid, int32_t uid, int32_t flag); void UpdateRequestRecord(std::shared_ptr request, bool shouldInsert); void HandleRequest(); bool UpdateUsingPermission(std::shared_ptr request, const bool isStart); void IncreaseWorkingPidsCount(const pid_t pid); void DecreaseWorkingPidsCount(const pid_t pid); bool IsNeedStartUsingPermission(const pid_t pid); bool IsNeedStopUsingPermission(const pid_t pid); void RegisterLocationErrorCallback(sptr callback, AppIdentity appIdentity); void UnRegisterLocationErrorCallback(sptr callback); void ReportLocationError(const int errorCode, std::shared_ptr request); void SyncStillMovementState(bool state); void SyncIdleState(bool state); static RequestManager* GetInstance(); void IsStandby(); void UpdateLocationError(std::shared_ptr request); private: bool RestorRequest(std::shared_ptr request); void HandleChrEvent(std::list> requests); void UpdateRequestRecord(std::shared_ptr request, std::string abilityName, bool shouldInsert); void DeleteRequestRecord(std::shared_ptr>> requests); void HandleRequest(std::string abilityName, std::list> list); void ProxySendLocationRequest(std::string abilityName, WorkRecord& workRecord); sptr GetRemoteObject(std::string abilityName); bool IsUidInProcessing(int32_t uid); bool UpdateUsingApproximatelyPermission(std::shared_ptr request, const bool isStart); bool ActiveLocatingStrategies(const std::shared_ptr& request); bool AddRequestToWorkRecord(std::string abilityName, std::shared_ptr& request, std::shared_ptr& workRecord); bool IsRequestAvailable(std::shared_ptr& request); void UpdateRunningUids(const std::shared_ptr& request, std::string abilityName, bool isAdd); void ReportDataToResSched(std::string state, const pid_t pid, const pid_t uid); std::map runningUidMap_; std::map, std::shared_ptr> locationErrorCallbackMap_; static ffrt::mutex requestMutex_; ffrt::mutex runningUidsMutex_; ffrt::mutex locationErrorCallbackMutex_; ffrt::mutex permissionRecordMutex_; std::atomic_bool isDeviceIdleMode_; std::atomic_bool isDeviceStillState_; ffrt::mutex workingPidsCountMutex_; std::map workingPidsCountMap_; }; class LocatorErrCallbackDeathRecipient : public IRemoteObject::DeathRecipient { public: void OnRemoteDied(const wptr &remote) override; LocatorErrCallbackDeathRecipient(int32_t tokenId); ~LocatorErrCallbackDeathRecipient() override; private: int32_t tokenId_; }; } // namespace Location } // namespace OHOS #endif // REQUEST_MANAGER_H