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 class ReportManager { 32 public: 33 ReportManager(); 34 ~ReportManager(); 35 bool ReportRemoteCallback(sptr<ILocatorCallback>& locatorCallback, int type, int result); 36 bool OnReportLocation(const std::unique_ptr<Location>& location, std::string abilityName); 37 bool ResultCheck(const std::unique_ptr<Location>& location, const std::shared_ptr<Request>& request); 38 void UpdateCacheLocation(const std::unique_ptr<Location>& location, std::string abilityName); 39 std::unique_ptr<Location> GetLastLocation(); 40 std::unique_ptr<Location> GetCacheLocation(const std::shared_ptr<Request>& request); 41 std::unique_ptr<Location> GetPermittedLocation(const std::shared_ptr<Request>& request, 42 const std::unique_ptr<Location>& location); 43 void UpdateRandom(); 44 bool IsRequestFuse(const std::shared_ptr<Request>& request); 45 void UpdateLocationByRequest(const uint32_t tokenId, const uint64_t tokenIdEx, 46 std::unique_ptr<Location>& location); 47 bool IsAppBackground(std::string bundleName, uint32_t tokenId, uint64_t tokenIdEx, pid_t uid, pid_t pid); 48 static ReportManager* GetInstance(); 49 50 private: 51 struct timespec lastUpdateTime_; 52 double offsetRandom_; 53 std::map<int, std::shared_ptr<Location>> lastLocationsMap_; 54 Location cacheGnssLocation_; 55 Location cacheNlpLocation_; 56 std::mutex lastLocationMutex_; 57 std::unique_ptr<Location> ApproximatelyLocation(const std::unique_ptr<Location>& location); 58 bool ProcessRequestForReport(std::shared_ptr<Request>& request, 59 std::unique_ptr<std::list<std::shared_ptr<Request>>>& deadRequests, 60 const std::unique_ptr<Location>& location, std::string abilityName); 61 void WriteNetWorkReportEvent(std::string abilityName, const std::shared_ptr<Request>& request, 62 const std::unique_ptr<Location>& location); 63 std::unique_ptr<Location> ExecuteReportProcess(std::shared_ptr<Request>& request, 64 std::unique_ptr<Location>& location, std::string abilityName); 65 void UpdateLastLocation(const std::unique_ptr<Location>& location); 66 }; 67 } // namespace OHOS 68 } // namespace Location 69 #endif // REPORT_MANAGER_H 70