1 /* 2 * Copyright (C) 2024 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 LOCATION_HOOK_UTILS_H 17 #define LOCATION_HOOK_UTILS_H 18 19 #include "hookmgr.h" 20 #include "constant_definition.h" 21 #include "request.h" 22 #include "location.h" 23 24 namespace OHOS { 25 namespace Location { 26 enum class LocationProcessStage { 27 LOCATOR_SA_START_LOCATING = 0, 28 LOCATOR_SA_REQUEST_PROCESS, 29 GNSS_SA_REQUEST_PROCESS, 30 NETWORK_SA_REQUEST_PROCESS, 31 GNSS_SA_LOCATION_REPORT_PROCESS, 32 NETWORK_SA_LOCATION_REPORT_PROCESS, 33 LOCATOR_SA_LOCATION_REPORT_PROCESS, 34 START_GNSS_PROCESS, 35 STOP_GNSS_PROCESS, 36 CHECK_GNSS_LOCATION_VALIDITY, 37 MOCK_LOCATION_PROCESS, 38 FENCE_REQUEST_PROCESS, 39 REQUEST_MANAGER_HANDLE_STOP, 40 LOCATOR_SA_GET_ADDRESSES_FROM_LOCATION_PROCESS, 41 LOCATOR_SA_GET_ADDRESSES_FROM_LOCATIONNAME_PROCESS, 42 WRITE_DFX_INNER_EVENT_PROCESS, 43 ADD_REQUEST_TO_WORK_RECORD, 44 }; 45 46 typedef struct { 47 Location location; 48 Request request; 49 std::string abilityName; 50 int retCode; 51 } LocationSupplicantInfo; 52 53 typedef struct { 54 Location location; 55 bool result; 56 } GnssLocationValidStruct; 57 58 typedef struct { 59 bool enableMock; 60 } MockLocationStruct; 61 62 typedef struct { 63 int32_t eventId; 64 std::vector<std::string> names; 65 std::vector<std::string> values; 66 } DfxInnerInfo; 67 68 typedef struct { 69 bool deviceStillState; 70 bool deviceIdleState; 71 bool result; 72 std::string abilityName; 73 std::string bundleName; 74 } LocatorRequestStruct; 75 76 class HookUtils { 77 public: 78 static HOOK_MGR* GetLocationExtHookMgr(); 79 static LocationErrCode RegisterHook(LocationProcessStage stage, int prio, OhosHook hook); 80 static void UnregisterHook(LocationProcessStage stage, OhosHook hook); 81 static LocationErrCode ExecuteHook(LocationProcessStage stage, void *executionContext, 82 const HOOK_EXEC_OPTIONS *options); 83 static void ExecuteHookWhenStartLocation(std::shared_ptr<Request> request); 84 static void ExecuteHookWhenStopLocation(std::shared_ptr<Request> request); 85 static void ExecuteHookWhenGetAddressFromLocation(std::string packageName); 86 static void ExecuteHookWhenGetAddressFromLocationName(std::string packageName); 87 static void ExecuteHookWhenReportInnerInfo( 88 int32_t event, std::vector<std::string>& names, std::vector<std::string>& values); 89 static bool ExecuteHookWhenAddWorkRecord(bool stillState, bool idleState, std::string abilityName, 90 std::string bundleName); 91 static bool CheckGnssLocationValidity(const std::unique_ptr<Location>& location); 92 }; 93 } // namespace Location 94 } // namespace OHOS 95 #endif // LOCATION_HOOK_UTILS_H