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 REQUEST_MANAGER_H 17 #define REQUEST_MANAGER_H 18 19 #include <list> 20 #include <mutex> 21 #include <singleton.h> 22 #include <string> 23 24 #include "iremote_object.h" 25 26 #include "i_locator_callback.h" 27 #include "request.h" 28 #include "work_record.h" 29 30 namespace OHOS { 31 namespace Location { 32 class RequestManager : public DelayedSingleton<RequestManager> { 33 public: 34 RequestManager(); 35 ~RequestManager(); 36 bool InitSystemListeners(); 37 void HandleStartLocating(std::shared_ptr<Request> request); 38 void HandleStopLocating(sptr<ILocatorCallback> callback); 39 void HandlePowerSuspendChanged(int32_t pid, int32_t uid, int32_t flag); 40 void UpdateRequestRecord(std::shared_ptr<Request> request, bool shouldInsert); 41 void HandleRequest(); 42 void UpdateUsingPermission(std::shared_ptr<Request> request); 43 void HandlePermissionChanged(uint32_t tokenId); 44 private: 45 bool RestorRequest(std::shared_ptr<Request> request); 46 void UpdateRequestRecord(std::shared_ptr<Request> request, std::string abilityName, bool shouldInsert); 47 void DeleteRequestRecord(std::shared_ptr<std::list<std::shared_ptr<Request>>> requests); 48 void HandleRequest(std::string abilityName, std::list<std::shared_ptr<Request>> list); 49 void ProxySendLocationRequest(std::string abilityName, WorkRecord& workRecord); 50 sptr<IRemoteObject> GetRemoteObject(std::string abilityName); 51 bool IsUidInProcessing(int32_t uid); 52 void UpdateUsingLocationPermission(std::shared_ptr<Request> request); 53 void UpdateUsingApproximatelyPermission(std::shared_ptr<Request> request); 54 void UpdateUsingBackgroundPermission(std::shared_ptr<Request> request); 55 bool ActiveLocatingStrategies(const std::shared_ptr<Request>& request); 56 bool AddRequestToWorkRecord(std::shared_ptr<Request>& request, std::shared_ptr<WorkRecord>& workRecord); 57 58 std::list<int32_t> runningUids_; 59 static std::mutex requestMutex_; 60 std::mutex permissionRecordMutex_; 61 }; 62 } // namespace Location 63 } // namespace OHOS 64 #endif // REQUEST_MANAGER_H 65