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
24namespace OHOS {
25namespace Location {
26enum 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    LOCATOR_SA_LOCATION_PERMISSION_CHECK,
45    LOCATOR_SA_COMMAND_PROCESS,
46    LOCATOR_SA_LOCATION_CACHE_TIME_CHECK,
47};
48
49typedef struct {
50    Location location;
51    Request request;
52    std::string abilityName;
53    int retCode;
54} LocationSupplicantInfo;
55
56typedef struct {
57    Location location;
58    bool result;
59} GnssLocationValidStruct;
60
61typedef struct {
62    bool enableMock;
63} MockLocationStruct;
64
65typedef struct {
66    int32_t eventId;
67    std::vector<std::string> names;
68    std::vector<std::string> values;
69} DfxInnerInfo;
70
71typedef struct {
72    bool deviceStillState;
73    bool deviceIdleState;
74    bool result;
75    std::string abilityName;
76    std::string bundleName;
77} LocatorRequestStruct;
78
79typedef struct {
80    std::string packageName;
81    std::string command;
82    bool result;
83} CommandStruct;
84
85class HookUtils {
86public:
87    static HOOK_MGR* GetLocationExtHookMgr();
88    static LocationErrCode RegisterHook(LocationProcessStage stage, int prio, OhosHook hook);
89    static void UnregisterHook(LocationProcessStage stage, OhosHook hook);
90    static LocationErrCode ExecuteHook(LocationProcessStage stage, void *executionContext,
91        const HOOK_EXEC_OPTIONS *options);
92    static void ExecuteHookWhenStartLocation(std::shared_ptr<Request> request);
93    static void ExecuteHookWhenStopLocation(std::shared_ptr<Request> request);
94    static void ExecuteHookWhenGetAddressFromLocation(std::string packageName);
95    static void ExecuteHookWhenGetAddressFromLocationName(std::string packageName);
96    static void ExecuteHookWhenReportInnerInfo(
97        int32_t event, std::vector<std::string>& names, std::vector<std::string>& values);
98    static bool ExecuteHookWhenAddWorkRecord(bool stillState, bool idleState, std::string abilityName,
99        std::string bundleName);
100    static bool CheckGnssLocationValidity(const std::unique_ptr<Location>& location);
101    static bool ExecuteHookWhenCheckAppForUser(std::string packageName);
102    static bool ExecuteHookWhenCheckAppForCacheTime(std::string packageName);
103};
104} // namespace Location
105} // namespace OHOS
106#endif // LOCATION_HOOK_UTILS_H