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 #include "ipc_skeleton.h"
18 #include "common_utils.h"
19
20 namespace OHOS {
21 namespace Location {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)22 int PassiveAbilityStub::OnRemoteRequest(uint32_t code,
23 MessageParcel &data, MessageParcel &reply, MessageOption &option)
24 {
25 pid_t lastCallingPid = IPCSkeleton::GetCallingPid();
26 pid_t lastCallinguid = IPCSkeleton::GetCallingUid();
27 LBSLOGI(PASSIVE, "OnRemoteRequest cmd = %{public}u, flags= %{public}d, pid= %{public}d, uid= %{public}d",
28 code, option.GetFlags(), lastCallingPid, lastCallinguid);
29 if (lastCallinguid > SYSTEM_UID) {
30 LBSLOGE(PASSIVE, "this remote request is not allowed");
31 return EXCEPTION;
32 }
33 if (data.ReadInterfaceToken() != GetDescriptor()) {
34 LBSLOGE(PASSIVE, "invalid token.");
35 return EXCEPTION;
36 }
37
38 int ret = 0;
39 switch (code) {
40 case SEND_LOCATION_REQUEST: {
41 int64_t interval = data.ReadInt64();
42 std::unique_ptr<WorkRecord> workrecord = WorkRecord::Unmarshalling(data);
43 if (workrecord != nullptr) {
44 SendLocationRequest((uint64_t)interval, *workrecord);
45 }
46 break;
47 }
48 case GET_CACHED_LOCATION: {
49 std::unique_ptr<Location> location = GetCachedLocation();
50 if (location != nullptr) {
51 location->Marshalling(reply);
52 }
53 break;
54 }
55 case SET_ENABLE: {
56 SetEnable(data.ReadBool());
57 break;
58 }
59 default:
60 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
61 }
62 return ret;
63 }
64 } // namespace Location
65 } // namespace OHOS
66