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