• 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 #include "passive_ability_proxy.h"
17 
18 #include "message_parcel.h"
19 #include "message_option.h"
20 
21 #include "location_log.h"
22 #include "subability_common.h"
23 
24 namespace OHOS {
25 namespace Location {
PassiveAbilityProxy(const sptr<IRemoteObject> & impl)26 PassiveAbilityProxy::PassiveAbilityProxy(const sptr<IRemoteObject> &impl)
27     : IRemoteProxy<IPassiveAbility>(impl)
28 {
29 }
30 
SendLocationRequest(WorkRecord & workrecord)31 LocationErrCode PassiveAbilityProxy::SendLocationRequest(WorkRecord &workrecord)
32 {
33     MessageParcel data;
34     MessageParcel reply;
35     MessageOption option;
36     if (!data.WriteInterfaceToken(GetDescriptor())) {
37         LBSLOGE(PASSIVE, "write interfaceToken fail!");
38         return ERRCODE_SERVICE_UNAVAILABLE;
39     }
40     workrecord.Marshalling(data);
41     int error = Remote()->SendRequest(ISubAbility::SEND_LOCATION_REQUEST, data, reply, option);
42     LBSLOGD(PASSIVE, "%{public}s Transact Error = %{public}d", __func__, error);
43     return LocationErrCode(reply.ReadInt32());
44 }
45 
SetEnable(bool state)46 LocationErrCode PassiveAbilityProxy::SetEnable(bool state)
47 {
48     MessageParcel data;
49     if (!data.WriteInterfaceToken(GetDescriptor())) {
50         LBSLOGE(PASSIVE, "write interfaceToken fail!");
51         return ERRCODE_SERVICE_UNAVAILABLE;
52     }
53     data.WriteBool(state);
54 
55     MessageParcel reply;
56     MessageOption option;
57     int error = Remote()->SendRequest(ISubAbility::SET_ENABLE, data, reply, option);
58     LBSLOGD(PASSIVE, "%{public}s Transact Error = %{public}d", __func__, error);
59     return LocationErrCode(reply.ReadInt32());
60 }
61 
EnableMock()62 LocationErrCode PassiveAbilityProxy::EnableMock()
63 {
64     MessageParcel data;
65     MessageParcel reply;
66     MessageOption option;
67     sptr<IRemoteObject> remote = Remote();
68     if (remote == nullptr) {
69         LBSLOGE(PASSIVE, "EnableLocationMock remote is null");
70         return ERRCODE_SERVICE_UNAVAILABLE;
71     }
72     if (!data.WriteInterfaceToken(GetDescriptor())) {
73         LBSLOGE(PASSIVE, "write interfaceToken fail!");
74         return ERRCODE_SERVICE_UNAVAILABLE;
75     }
76     int error = remote->SendRequest(ISubAbility::ENABLE_LOCATION_MOCK, data, reply, option);
77     LBSLOGD(PASSIVE, "%{public}s Transact Error = %{public}d", __func__, error);
78     return LocationErrCode(reply.ReadInt32());
79 }
80 
DisableMock()81 LocationErrCode PassiveAbilityProxy::DisableMock()
82 {
83     MessageParcel data;
84     MessageParcel reply;
85     MessageOption option;
86     sptr<IRemoteObject> remote = Remote();
87     if (remote == nullptr) {
88         LBSLOGE(PASSIVE, "DisableLocationMock remote is null");
89         return ERRCODE_SERVICE_UNAVAILABLE;
90     }
91     if (!data.WriteInterfaceToken(GetDescriptor())) {
92         LBSLOGE(PASSIVE, "write interfaceToken fail!");
93         return ERRCODE_SERVICE_UNAVAILABLE;
94     }
95     int error = remote->SendRequest(ISubAbility::DISABLE_LOCATION_MOCK, data, reply, option);
96     LBSLOGD(PASSIVE, "%{public}s Transact Error = %{public}d", __func__, error);
97     return LocationErrCode(reply.ReadInt32());
98 }
99 
SetMocked(const int timeInterval,const std::vector<std::shared_ptr<Location>> & location)100 LocationErrCode PassiveAbilityProxy::SetMocked(
101     const int timeInterval, const std::vector<std::shared_ptr<Location>> &location)
102 {
103     MessageParcel data;
104     MessageParcel reply;
105     MessageOption option;
106     sptr<IRemoteObject> remote = Remote();
107     if (remote == nullptr) {
108         LBSLOGE(PASSIVE, "SetMockedLocations remote is null");
109         return ERRCODE_SERVICE_UNAVAILABLE;
110     }
111     if (!data.WriteInterfaceToken(GetDescriptor())) {
112         LBSLOGE(PASSIVE, "write interfaceToken fail!");
113         return ERRCODE_SERVICE_UNAVAILABLE;
114     }
115     data.WriteInt32(timeInterval);
116     int locationSize = static_cast<int>(location.size());
117     data.WriteInt32(locationSize);
118     for (int i = 0; i < locationSize; i++) {
119         location.at(i)->Marshalling(data);
120     }
121     int error = remote->SendRequest(ISubAbility::SET_MOCKED_LOCATIONS, data, reply, option);
122     LBSLOGD(PASSIVE, "%{public}s Transact Error = %{public}d", __func__, error);
123     return LocationErrCode(reply.ReadInt32());
124 }
125 } // namespace Location
126 } // namespace OHOS