/* * Copyright (C) 2024 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 LOCATION_HOOK_UTILS_H #define LOCATION_HOOK_UTILS_H #include "hookmgr.h" #include "constant_definition.h" #include "request.h" #include "location.h" namespace OHOS { namespace Location { enum class LocationProcessStage { LOCATOR_SA_START_LOCATING = 0, LOCATOR_SA_REQUEST_PROCESS, GNSS_SA_REQUEST_PROCESS, NETWORK_SA_REQUEST_PROCESS, GNSS_SA_LOCATION_REPORT_PROCESS, NETWORK_SA_LOCATION_REPORT_PROCESS, LOCATOR_SA_LOCATION_REPORT_PROCESS, START_GNSS_PROCESS, STOP_GNSS_PROCESS, CHECK_GNSS_LOCATION_VALIDITY, MOCK_LOCATION_PROCESS, FENCE_REQUEST_PROCESS, REQUEST_MANAGER_HANDLE_STOP, LOCATOR_SA_GET_ADDRESSES_FROM_LOCATION_PROCESS, LOCATOR_SA_GET_ADDRESSES_FROM_LOCATIONNAME_PROCESS, WRITE_DFX_INNER_EVENT_PROCESS, ADD_REQUEST_TO_WORK_RECORD, LOCATOR_SA_LOCATION_PERMISSION_CHECK, REPORT_MANAGER_GET_CACHE_LOCATION_PROCESS, ENABLE_ABILITY_PROCESS, PRE_START_LOCATING_PROCESS, GNSS_REQUEST_RECORD_PROCESS, }; typedef struct { Location location; Request request; std::string abilityName; int retCode; } LocationSupplicantInfo; typedef struct { Location location; bool result; } GnssLocationValidStruct; typedef struct { bool enableMock; } MockLocationStruct; typedef struct { int32_t eventId; std::vector names; std::vector values; } DfxInnerInfo; typedef struct { bool deviceStillState; bool deviceIdleState; bool result; std::string abilityName; std::string bundleName; } LocatorRequestStruct; typedef struct { bool isEnabled; int32_t userId; std::string bundleName; bool result; } EnableAbilityStruct; class HookUtils { public: static HOOK_MGR* GetLocationExtHookMgr(); static LocationErrCode RegisterHook(LocationProcessStage stage, int prio, OhosHook hook); static void UnregisterHook(LocationProcessStage stage, OhosHook hook); static LocationErrCode ExecuteHook(LocationProcessStage stage, void *executionContext, const HOOK_EXEC_OPTIONS *options); static void ExecuteHookWhenStartLocation(std::shared_ptr request); static void ExecuteHookWhenStopLocation(std::shared_ptr request); static void ExecuteHookWhenGetAddressFromLocation(std::string packageName); static void ExecuteHookWhenGetAddressFromLocationName(std::string packageName); static void ExecuteHookWhenReportInnerInfo( int32_t event, std::vector& names, std::vector& values); static bool ExecuteHookWhenAddWorkRecord(bool stillState, bool idleState, std::string abilityName, std::string bundleName); static bool CheckGnssLocationValidity(const std::unique_ptr& location); static bool ExecuteHookWhenCheckAppForUser(std::string packageName); static bool ExecuteHookWhenCheckAppForCacheTime(std::string packageName); static bool ExecuteHookEnableAbility(std::string packageName, bool isEnabled, int32_t userId); static bool ExecuteHookWhenPreStartLocating(std::string packageName); }; } // namespace Location } // namespace OHOS #endif // LOCATION_HOOK_UTILS_H