• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 LOCATOR_SKELETON_H
17 #define LOCATOR_SKELETON_H
18 
19 #include <map>
20 #include <string>
21 
22 #include "iremote_object.h"
23 #include "iremote_stub.h"
24 #include "message_option.h"
25 #include "message_parcel.h"
26 
27 #include "app_identity.h"
28 #include "i_locator.h"
29 
30 namespace OHOS {
31 namespace Location {
32 class LocatorAbilityStub : public IRemoteStub<ILocator> {
33 public:
34     using LocatorMsgHandle = int (LocatorAbilityStub::*)(
35         MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
36     using LocatorMsgHandleMap = std::map<int, LocatorMsgHandle>;
37 
38     LocatorAbilityStub();
39     virtual ~LocatorAbilityStub() = default;
40     void InitLocatorHandleMap();
41     int32_t OnRemoteRequest(uint32_t code,
42         MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
43     int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
44 
45 private:
46     int PreGetSwitchState(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
47     int PreRegisterSwitchCallback(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
48     int PreUnregisterSwitchCallback(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
49     int PreStartLocating(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
50     int PreStopLocating(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
51     int PreGetCacheLocation(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
52     int PreEnableAbility(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
53     int PreUpdateSaAbility(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
54 #ifdef FEATURE_GEOCODE_SUPPORT
55     int PreIsGeoConvertAvailable(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
56     int PreGetAddressByCoordinate(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
57     int PreGetAddressByLocationName(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
58     int PreEnableReverseGeocodingMock(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
59     int PreDisableReverseGeocodingMock(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
60     int PreSetReverseGeocodingMockInfo(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
61 #endif
62 #ifdef FEATURE_GNSS_SUPPORT
63     int PreRegisterGnssStatusCallback(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
64     int PreUnregisterGnssStatusCallback(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
65     int PreRegisterNmeaMessageCallback(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
66     int PreUnregisterNmeaMessageCallback(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
67     int PreRegisterNmeaMessageCallbackV9(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
68     int PreUnregisterNmeaMessageCallbackV9(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
69     int PreStartCacheLocating(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
70     int PreStopCacheLocating(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
71     int PreGetCachedGnssLocationsSize(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
72     int PreFlushCachedGnssLocations(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
73     int PreSendCommand(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
74     int PreAddFence(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
75     int PreRemoveFence(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
76 #endif
77     int PreIsLocationPrivacyConfirmed(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
78     int PreSetLocationPrivacyConfirmStatus(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
79     int PreEnableLocationMock(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
80     int PreDisableLocationMock(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
81     int PreSetMockedLocations(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
82     int PreProxyUidForFreeze(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
83     int PreResetAllProxy(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
84     int PreReportLocation(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
85     int PreRegisterLocatingRequiredDataCallback(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
86     int PreUnregisterLocatingRequiredDataCallback(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
87 
88 private:
89     LocatorMsgHandleMap locatorHandleMap_;
90     bool CheckLocationPermission(MessageParcel &reply, AppIdentity &identity);
91     bool CheckSettingsPermission(MessageParcel &reply, AppIdentity &identity);
92     bool CheckPreciseLocationPermissions(MessageParcel &reply, AppIdentity &identity);
93     bool CheckLocationSwitchState(MessageParcel &reply);
94     static void SaDumpInfo(std::string& result);
95     bool UnloadLocatorSa();
96 };
97 
98 class LocatorCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
99 public:
100     void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
101     LocatorCallbackDeathRecipient();
102     ~LocatorCallbackDeathRecipient() override;
103 };
104 
105 class SwitchCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
106 public:
107     void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
108     SwitchCallbackDeathRecipient();
109     ~SwitchCallbackDeathRecipient() override;
110 };
111 
112 } // namespace Location
113 } // namespace OHOS
114 #endif // LOCATOR_SKELETON_H
115