• 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 REPORT_MANAGER_H
17 #define REPORT_MANAGER_H
18 
19 #include <singleton.h>
20 #include <string>
21 #include <time.h>
22 #include <map>
23 
24 #include "i_locator_callback.h"
25 #include "location.h"
26 #include "request.h"
27 #include <mutex>
28 
29 namespace OHOS {
30 namespace Location {
31 
32 class ReportManager {
33 public:
34     ReportManager();
35     ~ReportManager();
36     bool ReportRemoteCallback(const sptr<ILocatorCallback>& locatorCallback, int type, int result);
37     bool OnReportLocation(const std::unique_ptr<Location>& location, std::string abilityName);
38     bool ResultCheck(const std::unique_ptr<Location>& location, const std::shared_ptr<Request>& request);
39     void UpdateCacheLocation(const std::unique_ptr<Location>& location, std::string abilityName);
40     std::unique_ptr<Location> GetLastLocation();
41     std::unique_ptr<Location> GetCacheLocation(const std::shared_ptr<Request>& request);
42     std::unique_ptr<Location> GetPermittedLocation(const std::shared_ptr<Request>& request,
43         const std::unique_ptr<Location>& location);
44     void UpdateRandom();
45     bool IsRequestFuse(const std::shared_ptr<Request>& request);
46     void UpdateLocationByRequest(const uint32_t tokenId, const uint64_t tokenIdEx,
47         std::unique_ptr<Location>& location);
48     bool IsAppBackground(std::string bundleName, uint32_t tokenId, uint64_t tokenIdEx, pid_t uid, pid_t pid);
49     static ReportManager* GetInstance();
50     bool IsCacheGnssLocationValid();
51 
52 private:
53     struct timespec lastUpdateTime_;
54     double offsetRandom_;
55     std::map<int, std::shared_ptr<Location>> lastLocationsMap_;
56     Location cacheGnssLocation_;
57     Location cacheNlpLocation_;
58     std::mutex lastLocationMutex_;
59     std::atomic<int64_t> lastResetRecordTime_;
60     std::unique_ptr<Location> ApproximatelyLocation(const std::unique_ptr<Location>& location,
61         const std::shared_ptr<Request>& request);
62     bool ProcessRequestForReport(std::shared_ptr<Request>& request,
63         std::unique_ptr<std::list<std::shared_ptr<Request>>>& deadRequests,
64         const std::unique_ptr<Location>& location, std::string abilityName);
65     bool ReportLocationByCallback(std::shared_ptr<Request>& request,
66         const std::unique_ptr<Location>& finalLocation);
67     void WriteNetWorkReportEvent(std::string abilityName, const std::shared_ptr<Request>& request,
68         const std::unique_ptr<Location>& location);
69     std::unique_ptr<Location> ExecuteReportProcess(std::shared_ptr<Request>& request,
70         std::unique_ptr<Location>& location, std::string abilityName);
71     std::unique_ptr<Location> ExecuteLocationProcess(const std::shared_ptr<Request>& request,
72         const std::unique_ptr<Location>& location);
73     void UpdateLastLocation(const std::unique_ptr<Location>& location);
74     void LocationReportDelayTimeCheck(const std::unique_ptr<Location>& location,
75         const std::shared_ptr<Request>& request);
76     bool NeedUpdateTimeStamp(std::unique_ptr<Location>& fuseLocation, const std::shared_ptr<Request>& request);
77 };
78 } // namespace OHOS
79 } // namespace Location
80 #endif // REPORT_MANAGER_H
81