/* * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef REPORT_MANAGER_H #define REPORT_MANAGER_H #include #include #include #include #include "i_locator_callback.h" #include "location.h" #include "request.h" #include namespace OHOS { namespace Location { class ReportManager { public: ReportManager(); ~ReportManager(); bool ReportRemoteCallback(sptr& locatorCallback, int type, int result); bool OnReportLocation(const std::unique_ptr& location, std::string abilityName); bool ResultCheck(const std::unique_ptr& location, const std::shared_ptr& request); void UpdateCacheLocation(const std::unique_ptr& location, std::string abilityName); std::unique_ptr GetLastLocation(); std::unique_ptr GetCacheLocation(const std::shared_ptr& request); std::unique_ptr GetPermittedLocation(const std::shared_ptr& request, const std::unique_ptr& location); void UpdateRandom(); bool IsRequestFuse(const std::shared_ptr& request); void UpdateLocationByRequest(const uint32_t tokenId, const uint64_t tokenIdEx, std::unique_ptr& location); bool IsAppBackground(std::string bundleName, uint32_t tokenId, uint64_t tokenIdEx, pid_t uid, pid_t pid); static ReportManager* GetInstance(); bool IsCacheGnssLocationValid(); private: struct timespec lastUpdateTime_; double offsetRandom_; std::map> lastLocationsMap_; Location cacheGnssLocation_; Location cacheNlpLocation_; std::mutex lastLocationMutex_; std::atomic lastResetRecordTime_; std::unique_ptr ApproximatelyLocation(const std::unique_ptr& location); bool ProcessRequestForReport(std::shared_ptr& request, std::unique_ptr>>& deadRequests, const std::unique_ptr& location, std::string abilityName); void WriteNetWorkReportEvent(std::string abilityName, const std::shared_ptr& request, const std::unique_ptr& location); std::unique_ptr ExecuteReportProcess(std::shared_ptr& request, std::unique_ptr& location, std::string abilityName); void UpdateLastLocation(const std::unique_ptr& location); void LocationReportDelayTimeCheck(const std::unique_ptr& location, const std::shared_ptr& request); }; } // namespace OHOS } // namespace Location #endif // REPORT_MANAGER_H