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