15c735df2Sopenharmony_ci/*
25c735df2Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd.
35c735df2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
45c735df2Sopenharmony_ci * you may not use this file except in compliance with the License.
55c735df2Sopenharmony_ci * You may obtain a copy of the License at
65c735df2Sopenharmony_ci *
75c735df2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
85c735df2Sopenharmony_ci *
95c735df2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
105c735df2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
115c735df2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125c735df2Sopenharmony_ci * See the License for the specific language governing permissions and
135c735df2Sopenharmony_ci * limitations under the License.
145c735df2Sopenharmony_ci */
155c735df2Sopenharmony_ci
165c735df2Sopenharmony_ci#ifndef LOCATION_HOOK_UTILS_H
175c735df2Sopenharmony_ci#define LOCATION_HOOK_UTILS_H
185c735df2Sopenharmony_ci
195c735df2Sopenharmony_ci#include "hookmgr.h"
205c735df2Sopenharmony_ci#include "constant_definition.h"
215c735df2Sopenharmony_ci#include "request.h"
225c735df2Sopenharmony_ci#include "location.h"
235c735df2Sopenharmony_ci
245c735df2Sopenharmony_cinamespace OHOS {
255c735df2Sopenharmony_cinamespace Location {
265c735df2Sopenharmony_cienum class LocationProcessStage {
275c735df2Sopenharmony_ci    LOCATOR_SA_START_LOCATING = 0,
285c735df2Sopenharmony_ci    LOCATOR_SA_REQUEST_PROCESS,
295c735df2Sopenharmony_ci    GNSS_SA_REQUEST_PROCESS,
305c735df2Sopenharmony_ci    NETWORK_SA_REQUEST_PROCESS,
315c735df2Sopenharmony_ci    GNSS_SA_LOCATION_REPORT_PROCESS,
325c735df2Sopenharmony_ci    NETWORK_SA_LOCATION_REPORT_PROCESS,
335c735df2Sopenharmony_ci    LOCATOR_SA_LOCATION_REPORT_PROCESS,
345c735df2Sopenharmony_ci    START_GNSS_PROCESS,
355c735df2Sopenharmony_ci    STOP_GNSS_PROCESS,
365c735df2Sopenharmony_ci    CHECK_GNSS_LOCATION_VALIDITY,
375c735df2Sopenharmony_ci    MOCK_LOCATION_PROCESS,
385c735df2Sopenharmony_ci    FENCE_REQUEST_PROCESS,
395c735df2Sopenharmony_ci    REQUEST_MANAGER_HANDLE_STOP,
405c735df2Sopenharmony_ci    LOCATOR_SA_GET_ADDRESSES_FROM_LOCATION_PROCESS,
415c735df2Sopenharmony_ci    LOCATOR_SA_GET_ADDRESSES_FROM_LOCATIONNAME_PROCESS,
425c735df2Sopenharmony_ci    WRITE_DFX_INNER_EVENT_PROCESS,
435c735df2Sopenharmony_ci    ADD_REQUEST_TO_WORK_RECORD,
445c735df2Sopenharmony_ci    LOCATOR_SA_LOCATION_PERMISSION_CHECK,
455c735df2Sopenharmony_ci    LOCATOR_SA_COMMAND_PROCESS,
465c735df2Sopenharmony_ci    LOCATOR_SA_LOCATION_CACHE_TIME_CHECK,
475c735df2Sopenharmony_ci};
485c735df2Sopenharmony_ci
495c735df2Sopenharmony_citypedef struct {
505c735df2Sopenharmony_ci    Location location;
515c735df2Sopenharmony_ci    Request request;
525c735df2Sopenharmony_ci    std::string abilityName;
535c735df2Sopenharmony_ci    int retCode;
545c735df2Sopenharmony_ci} LocationSupplicantInfo;
555c735df2Sopenharmony_ci
565c735df2Sopenharmony_citypedef struct {
575c735df2Sopenharmony_ci    Location location;
585c735df2Sopenharmony_ci    bool result;
595c735df2Sopenharmony_ci} GnssLocationValidStruct;
605c735df2Sopenharmony_ci
615c735df2Sopenharmony_citypedef struct {
625c735df2Sopenharmony_ci    bool enableMock;
635c735df2Sopenharmony_ci} MockLocationStruct;
645c735df2Sopenharmony_ci
655c735df2Sopenharmony_citypedef struct {
665c735df2Sopenharmony_ci    int32_t eventId;
675c735df2Sopenharmony_ci    std::vector<std::string> names;
685c735df2Sopenharmony_ci    std::vector<std::string> values;
695c735df2Sopenharmony_ci} DfxInnerInfo;
705c735df2Sopenharmony_ci
715c735df2Sopenharmony_citypedef struct {
725c735df2Sopenharmony_ci    bool deviceStillState;
735c735df2Sopenharmony_ci    bool deviceIdleState;
745c735df2Sopenharmony_ci    bool result;
755c735df2Sopenharmony_ci    std::string abilityName;
765c735df2Sopenharmony_ci    std::string bundleName;
775c735df2Sopenharmony_ci} LocatorRequestStruct;
785c735df2Sopenharmony_ci
795c735df2Sopenharmony_citypedef struct {
805c735df2Sopenharmony_ci    std::string packageName;
815c735df2Sopenharmony_ci    std::string command;
825c735df2Sopenharmony_ci    bool result;
835c735df2Sopenharmony_ci} CommandStruct;
845c735df2Sopenharmony_ci
855c735df2Sopenharmony_ciclass HookUtils {
865c735df2Sopenharmony_cipublic:
875c735df2Sopenharmony_ci    static HOOK_MGR* GetLocationExtHookMgr();
885c735df2Sopenharmony_ci    static LocationErrCode RegisterHook(LocationProcessStage stage, int prio, OhosHook hook);
895c735df2Sopenharmony_ci    static void UnregisterHook(LocationProcessStage stage, OhosHook hook);
905c735df2Sopenharmony_ci    static LocationErrCode ExecuteHook(LocationProcessStage stage, void *executionContext,
915c735df2Sopenharmony_ci        const HOOK_EXEC_OPTIONS *options);
925c735df2Sopenharmony_ci    static void ExecuteHookWhenStartLocation(std::shared_ptr<Request> request);
935c735df2Sopenharmony_ci    static void ExecuteHookWhenStopLocation(std::shared_ptr<Request> request);
945c735df2Sopenharmony_ci    static void ExecuteHookWhenGetAddressFromLocation(std::string packageName);
955c735df2Sopenharmony_ci    static void ExecuteHookWhenGetAddressFromLocationName(std::string packageName);
965c735df2Sopenharmony_ci    static void ExecuteHookWhenReportInnerInfo(
975c735df2Sopenharmony_ci        int32_t event, std::vector<std::string>& names, std::vector<std::string>& values);
985c735df2Sopenharmony_ci    static bool ExecuteHookWhenAddWorkRecord(bool stillState, bool idleState, std::string abilityName,
995c735df2Sopenharmony_ci        std::string bundleName);
1005c735df2Sopenharmony_ci    static bool CheckGnssLocationValidity(const std::unique_ptr<Location>& location);
1015c735df2Sopenharmony_ci    static bool ExecuteHookWhenCheckAppForUser(std::string packageName);
1025c735df2Sopenharmony_ci    static bool ExecuteHookWhenCheckAppForCacheTime(std::string packageName);
1035c735df2Sopenharmony_ci};
1045c735df2Sopenharmony_ci} // namespace Location
1055c735df2Sopenharmony_ci} // namespace OHOS
1065c735df2Sopenharmony_ci#endif // LOCATION_HOOK_UTILS_H