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 #include "locating_required_data.h" 24 25 namespace OHOS { 26 namespace Location { 27 enum class LocationProcessStage { 28 LOCATOR_SA_START_LOCATING = 0, 29 LOCATOR_SA_REQUEST_PROCESS, 30 GNSS_SA_REQUEST_PROCESS, 31 LOCATION_REPORT_PROCESS, 32 GNSS_SA_LOCATION_REPORT_PROCESS, 33 NETWORK_SA_LOCATION_REPORT_PROCESS, 34 LOCATOR_SA_LOCATION_REPORT_PROCESS, 35 START_GNSS_PROCESS, 36 STOP_GNSS_PROCESS, 37 CHECK_GNSS_LOCATION_VALIDITY, 38 MOCK_LOCATION_PROCESS, 39 FENCE_REQUEST_PROCESS, 40 REQUEST_MANAGER_HANDLE_STOP, 41 LOCATOR_SA_GET_ADDRESSES_FROM_LOCATION_PROCESS, 42 LOCATOR_SA_GET_ADDRESSES_FROM_LOCATIONNAME_PROCESS, 43 WRITE_DFX_INNER_EVENT_PROCESS, 44 ADD_REQUEST_TO_WORK_RECORD, 45 LOCATOR_SA_LOCATION_PERMISSION_CHECK, 46 LOCATOR_SA_COMMAND_PROCESS, 47 REPORT_MANAGER_GET_CACHE_LOCATION_PROCESS, 48 ENABLE_ABILITY_PROCESS, 49 PRE_START_LOCATING_PROCESS, 50 NETWORK_SA_ADD_REQUEST_PROCESS, 51 NETWORK_SA_REMOVE_REQUEST_PROCESS, 52 GNSS_REQUEST_RECORD_PROCESS, 53 FUSION_REPORT_PROCESS, 54 GNSS_STATUS_REPORT_PROCESS, 55 SET_AGNSS_SERVER_PROCESS, 56 SIM_STATE_CHANGED_PROCESS, 57 APPROXIMATELY_LOCATION_PROCESS, 58 START_SCAN_BLUETOOTH_DEVICE_PROCESS, 59 REPORT_BLUETOOTH_SCAN_RESULT_PROCESS, 60 WIFI_SCAN_STATE_CHANGE, 61 CUST_CONFIG_POLICY_CHANGE_PROCESS, 62 IS_APP_BACKGROUND_PROCESS, 63 LOCATOR_SA_SYNC_SWITCH_STATUS, 64 REPORT_BEACON_FENCE_OPERATE_RESULT_PROCESS, 65 REMOVE_BEACON_FENCE_BY_CALLBACK_PROCESS, 66 BEACON_FENCE_TRANSITION_STATUS_CHANGE_PROCESS, 67 }; 68 69 typedef struct { 70 std::vector<std::shared_ptr<LocatingRequiredData>> result; 71 } WifiScanResult; 72 73 typedef struct { 74 Location location; 75 Request request; 76 std::string abilityName; 77 int retCode; 78 } LocationSupplicantInfo; 79 80 typedef struct { 81 Location location; 82 Location lastFuseLocation; 83 Location resultLocation; 84 } LocationFusionInfo; 85 86 typedef struct { 87 std::vector<float> cn0; 88 int64_t availableTimeStamp; 89 } GnssStatusInfo; 90 91 typedef struct { 92 Location location; 93 bool result; 94 } GnssLocationValidStruct; 95 96 typedef struct { 97 bool enableMock; 98 } MockLocationStruct; 99 100 typedef struct { 101 int32_t eventId; 102 std::vector<std::string> names; 103 std::vector<std::string> values; 104 } DfxInnerInfo; 105 106 typedef struct { 107 bool deviceStillState; 108 bool deviceIdleState; 109 bool result; 110 int nlpRequestType; 111 int cacheTime; 112 std::string abilityName; 113 std::string bundleName; 114 } LocatorRequestStruct; 115 116 typedef struct { 117 std::string packageName; 118 std::string command; 119 bool result; 120 } CommandStruct; 121 122 typedef struct { 123 bool isEnabled; 124 int32_t userId; 125 std::string bundleName; 126 bool result; 127 } EnableAbilityStruct; 128 129 typedef struct { 130 std::string uuid; 131 bool result; 132 } NetworkRequestInfo; 133 134 typedef struct { 135 std::string* addrName; 136 int* port; 137 bool result; 138 } AgnssStruct; 139 140 typedef struct { 141 std::string packageName; 142 std::string type; 143 bool result; 144 } ScanStruct; 145 146 typedef struct { 147 bool locationEnable; 148 } LocationStatusStruct; 149 150 typedef struct { 151 std::string fenceId; 152 int transitionEvent; 153 std::string fenceExtensionAbilityName; 154 std::string packageName; 155 bool result; 156 } BeaconFenceStruct; 157 158 class HookUtils { 159 public: 160 static HOOK_MGR* GetLocationExtHookMgr(); 161 static LocationErrCode RegisterHook(LocationProcessStage stage, int prio, OhosHook hook); 162 static void UnregisterHook(LocationProcessStage stage, OhosHook hook); 163 static LocationErrCode ExecuteHook(LocationProcessStage stage, void *executionContext, 164 const HOOK_EXEC_OPTIONS *options); 165 static void ExecuteHookWhenStartLocation(std::shared_ptr<Request> request); 166 static void ExecuteHookWhenStopLocation(std::shared_ptr<Request> request); 167 static void ExecuteHookWhenGetAddressFromLocation(std::string packageName); 168 static void ExecuteHookWhenGetAddressFromLocationName(std::string packageName); 169 static void ExecuteHookWhenReportInnerInfo( 170 int32_t event, std::vector<std::string>& names, std::vector<std::string>& values); 171 static bool ExecuteHookWhenAddWorkRecord(bool stillState, bool idleState, std::string abilityName, 172 std::string bundleName); 173 static bool CheckGnssLocationValidity(const std::unique_ptr<Location>& location); 174 static bool ExecuteHookWhenCheckAppForUser(std::string packageName); 175 static int ExecuteHookReportManagerGetCacheLocation(std::string packageName, int nlpRequestType); 176 static bool ExecuteHookEnableAbility(std::string packageName, bool isEnabled, int32_t userId); 177 static bool ExecuteHookWhenPreStartLocating(std::string packageName); 178 static bool ExecuteHookWhenAddNetworkRequest(std::string uuid); 179 static bool ExecuteHookWhenRemoveNetworkRequest(std::string uuid); 180 static bool ExecuteHookWhenSetAgnssServer(std::string& addrName, int& port); 181 static bool ExecuteHookWhenSimStateChange(const std::string& data); 182 static bool ExecuteHookWhenReportBluetoothScanResult(const std::string& packageName, const std::string& type); 183 static bool ExecuteHookWhenStartScanBluetoothDevice(const std::string& packageName, const std::string& type); 184 static void ExecuteHookWhenWifiScanStateChanged( 185 const std::vector<std::shared_ptr<LocatingRequiredData>>& result); 186 static bool ExecuteHookWhenCustConfigPolicyChange(); 187 static bool ExecuteHookWhenCheckIsAppBackground(const std::string& packageName); 188 static bool ExecuteHookWhenSyncSwitchStates(int status); 189 static bool ExecuteHookWhenReportBeaconFenceOperateResult(const std::string& fenceId, int transitionEvent, 190 const std::string& fenceExtensionAbilityName, const std::string& packageName); 191 static bool ExecuteHookWhenRemoveBeaconFenceByCallback(const std::string& packageName); 192 static bool ExecuteHookWhenBeaconFenceTransitionStatusChange(const std::string& packageName); 193 }; 194 } // namespace Location 195 } // namespace OHOS 196 #endif // LOCATION_HOOK_UTILS_H