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_skeleton.h"
17
18 #include "ipc_object_stub.h"
19 #include "ipc_skeleton.h"
20 #include "message_option.h"
21 #include "message_parcel.h"
22
23 #include "common_utils.h"
24 #include "location.h"
25 #include "location_log.h"
26 #include "work_record.h"
27
28 namespace OHOS {
29 namespace Location {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int PassiveAbilityStub::OnRemoteRequest(uint32_t code,
31 MessageParcel &data, MessageParcel &reply, MessageOption &option)
32 {
33 pid_t callingPid = IPCSkeleton::GetCallingPid();
34 pid_t callingUid = IPCSkeleton::GetCallingUid();
35 LBSLOGI(PASSIVE, "OnRemoteRequest cmd = %{public}u, flags= %{public}d, pid= %{public}d, uid= %{public}d",
36 code, option.GetFlags(), callingPid, callingUid);
37
38 if (data.ReadInterfaceToken() != GetDescriptor()) {
39 LBSLOGE(PASSIVE, "invalid token.");
40 reply.WriteInt32(ERRCODE_SERVICE_UNAVAILABLE);
41 return ERRCODE_SERVICE_UNAVAILABLE;
42 }
43
44 int ret = ERRCODE_SUCCESS;
45 switch (code) {
46 case SEND_LOCATION_REQUEST: {
47 if (!CommonUtils::CheckCallingPermission(callingUid, callingPid, reply)) {
48 return ERRCODE_PERMISSION_DENIED;
49 }
50 std::unique_ptr<WorkRecord> workrecord = WorkRecord::Unmarshalling(data);
51 reply.WriteInt32(SendLocationRequest(*workrecord));
52 break;
53 }
54 case SET_ENABLE: {
55 if (!CommonUtils::CheckCallingPermission(callingUid, callingPid, reply)) {
56 return ERRCODE_PERMISSION_DENIED;
57 }
58 reply.WriteInt32(SetEnable(data.ReadBool()));
59 break;
60 }
61 case ENABLE_LOCATION_MOCK: {
62 if (!CommonUtils::CheckCallingPermission(callingUid, callingPid, reply)) {
63 return ERRCODE_PERMISSION_DENIED;
64 }
65 reply.WriteInt32(EnableMock());
66 break;
67 }
68 case DISABLE_LOCATION_MOCK: {
69 if (!CommonUtils::CheckCallingPermission(callingUid, callingPid, reply)) {
70 return ERRCODE_PERMISSION_DENIED;
71 }
72 reply.WriteInt32(DisableMock());
73 break;
74 }
75 case SET_MOCKED_LOCATIONS: {
76 if (!CommonUtils::CheckCallingPermission(callingUid, callingPid, reply)) {
77 return ERRCODE_PERMISSION_DENIED;
78 }
79 SendMessage(code, data, reply);
80 break;
81 }
82 default:
83 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
84 }
85 return ret;
86 }
87 } // namespace Location
88 } // namespace OHOS
89