• 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 "network_ability_skeleton.h"
17 
18 #include "ipc_skeleton.h"
19 
20 #include "common_utils.h"
21 
22 namespace OHOS {
23 namespace Location {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)24 int NetworkAbilityStub::OnRemoteRequest(uint32_t code,
25     MessageParcel &data, MessageParcel &reply, MessageOption &option)
26 {
27     pid_t lastCallingPid = IPCSkeleton::GetCallingPid();
28     pid_t lastCallinguid = IPCSkeleton::GetCallingUid();
29     LBSLOGI(NETWORK, "OnRemoteRequest cmd = %{public}u, flags= %{public}d, pid= %{public}d, uid= %{public}d",
30         code, option.GetFlags(), lastCallingPid, lastCallinguid);
31     if (lastCallinguid > SYSTEM_UID) {
32         LBSLOGE(NETWORK, "this remote request is not allowed");
33         return EXCEPTION;
34     }
35     if (data.ReadInterfaceToken() != GetDescriptor()) {
36         LBSLOGE(NETWORK, "invalid token.");
37         return EXCEPTION;
38     }
39 
40     int ret = 0;
41     switch (code) {
42         case SEND_LOCATION_REQUEST: {
43             int64_t interval = data.ReadInt64();
44             std::unique_ptr<WorkRecord> workrecord = WorkRecord::Unmarshalling(data);
45             SendLocationRequest((uint64_t)interval, *workrecord);
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         case SELF_REQUEST: {
60             SelfRequest(data.ReadBool());
61             break;
62         }
63         default:
64             ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
65     }
66     return ret;
67 }
68 } // namespace Location
69 } // namespace OHOS