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 LOCATION_REPORT_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 LOCATOR_SA_LOCATION_PERMISSION_CHECK, 45 LOCATOR_SA_COMMAND_PROCESS, 46 REPORT_MANAGER_GET_CACHE_LOCATION_PROCESS, 47 ENABLE_ABILITY_PROCESS, 48 PRE_START_LOCATING_PROCESS, 49 NETWORK_SA_ADD_REQUEST_PROCESS, 50 NETWORK_SA_REMOVE_REQUEST_PROCESS, 51 GNSS_REQUEST_RECORD_PROCESS, 52 FUSION_REPORT_PROCESS, 53 GNSS_STATUS_REPORT_PROCESS, 54 SET_AGNSS_SERVER_PROCESS, 55 SIM_STATE_CHANGED_PROCESS, 56 APPROXIMATELY_LOCATION_PROCESS, 57 }; 58 59 typedef struct { 60 Location location; 61 Request request; 62 std::string abilityName; 63 int retCode; 64 } LocationSupplicantInfo; 65 66 typedef struct { 67 Location location; 68 Location lastFuseLocation; 69 Location resultLocation; 70 } LocationFusionInfo; 71 72 typedef struct { 73 std::vector<float> cn0; 74 int64_t availableTimeStamp; 75 } GnssStatusInfo; 76 77 typedef struct { 78 Location location; 79 bool result; 80 } GnssLocationValidStruct; 81 82 typedef struct { 83 bool enableMock; 84 } MockLocationStruct; 85 86 typedef struct { 87 int32_t eventId; 88 std::vector<std::string> names; 89 std::vector<std::string> values; 90 } DfxInnerInfo; 91 92 typedef struct { 93 bool deviceStillState; 94 bool deviceIdleState; 95 bool result; 96 std::string abilityName; 97 std::string bundleName; 98 } LocatorRequestStruct; 99 100 typedef struct { 101 std::string packageName; 102 std::string command; 103 bool result; 104 } CommandStruct; 105 106 typedef struct { 107 bool isEnabled; 108 int32_t userId; 109 std::string bundleName; 110 bool result; 111 } EnableAbilityStruct; 112 113 typedef struct { 114 std::string uuid; 115 bool result; 116 } NetworkRequestInfo; 117 118 typedef struct { 119 std::string* addrName; 120 int* port; 121 bool result; 122 } AgnssStruct; 123 124 typedef struct { 125 std::string bundleName; 126 bool needApproximate; 127 } ApproximatelyLocationStruct; 128 129 class HookUtils { 130 public: 131 static HOOK_MGR* GetLocationExtHookMgr(); 132 static LocationErrCode RegisterHook(LocationProcessStage stage, int prio, OhosHook hook); 133 static void UnregisterHook(LocationProcessStage stage, OhosHook hook); 134 static LocationErrCode ExecuteHook(LocationProcessStage stage, void *executionContext, 135 const HOOK_EXEC_OPTIONS *options); 136 static void ExecuteHookWhenStartLocation(std::shared_ptr<Request> request); 137 static void ExecuteHookWhenStopLocation(std::shared_ptr<Request> request); 138 static void ExecuteHookWhenGetAddressFromLocation(std::string packageName); 139 static void ExecuteHookWhenGetAddressFromLocationName(std::string packageName); 140 static void ExecuteHookWhenReportInnerInfo( 141 int32_t event, std::vector<std::string>& names, std::vector<std::string>& values); 142 static bool ExecuteHookWhenAddWorkRecord(bool stillState, bool idleState, std::string abilityName, 143 std::string bundleName); 144 static bool CheckGnssLocationValidity(const std::unique_ptr<Location>& location); 145 static bool ExecuteHookWhenCheckAppForUser(std::string packageName); 146 static bool ExecuteHookReportManagerGetCacheLocation(std::string packageName); 147 static bool ExecuteHookEnableAbility(std::string packageName, bool isEnabled, int32_t userId); 148 static bool ExecuteHookWhenPreStartLocating(std::string packageName); 149 static bool ExecuteHookWhenAddNetworkRequest(std::string uuid); 150 static bool ExecuteHookWhenRemoveNetworkRequest(std::string uuid); 151 static bool ExecuteHookWhenSetAgnssServer(std::string& addrName, int& port); 152 static bool ExecuteHookWhenSimStateChange(const std::string& data); 153 static bool ExecuteHookWhenApproximatelyLocation(std::string packageName); 154 }; 155 } // namespace Location 156 } // namespace OHOS 157 #endif // LOCATION_HOOK_UTILS_H