• 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 
23 #include "i_locator_callback.h"
24 #include "location.h"
25 #include "request.h"
26 
27 namespace OHOS {
28 namespace Location {
29 class ReportManager : public DelayedSingleton<ReportManager>  {
30 public:
31     ReportManager();
32     ~ReportManager();
33     bool ReportRemoteCallback(sptr<ILocatorCallback>& locatorCallback, int type, int result);
34     bool OnReportLocation(const std::unique_ptr<Location>& location, std::string abilityName);
35     bool ResultCheck(const std::unique_ptr<Location>& location, const std::shared_ptr<Request>& request);
36     void UpdateCacheLocation(const std::unique_ptr<Location>& location, std::string abilityName);
37     std::unique_ptr<Location> GetLastLocation();
38     std::unique_ptr<Location> GetCacheLocation(const std::shared_ptr<Request>& request);
39     std::unique_ptr<Location> GetPermittedLocation(pid_t uid, uint32_t tokenId, uint32_t firstTokenId,
40         const std::unique_ptr<Location>& location);
41     void UpdateRandom();
42     bool IsRequestFuse(const std::shared_ptr<Request>& request);
43     void UpdateLocationByRequest(const uint32_t tokenId, const uint32_t tokenIdEx,
44         std::unique_ptr<Location>& location);
45 private:
46     struct timespec lastUpdateTime_;
47     double offsetRandom_;
48     Location lastLocation_;
49     Location cacheGnssLocation_;
50     Location cacheNlpLocation_;
51     std::unique_ptr<Location> ApproximatelyLocation(const std::unique_ptr<Location>& location);
52     bool ProcessRequestForReport(std::shared_ptr<Request>& request,
53         std::unique_ptr<std::list<std::shared_ptr<Request>>>& deadRequests, const std::unique_ptr<Location>& location);
54     void WriteNetWorkReportEvent(std::string abilityName, const std::shared_ptr<Request>& request,
55         const std::unique_ptr<Location>& location);
56     bool IsAppInLocationContinuousTasks(pid_t uid);
57 };
58 } // namespace OHOS
59 } // namespace Location
60 #endif // REPORT_MANAGER_H
61