• 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_GEOCODE_SUPPORT
17 #include "geo_convert_skeleton.h"
18 #include "common_utils.h"
19 #include "ipc_skeleton.h"
20 #include "location_log.h"
21 #include "locationhub_ipc_interface_code.h"
22 
23 namespace OHOS {
24 namespace Location {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)25 int GeoConvertServiceStub::OnRemoteRequest(uint32_t code,
26     MessageParcel &data, MessageParcel &reply, MessageOption &option)
27 {
28     pid_t callingPid = IPCSkeleton::GetCallingPid();
29     pid_t callingUid = IPCSkeleton::GetCallingUid();
30     LBSLOGI(GEO_CONVERT, "OnRemoteRequest cmd = %{public}u, flags= %{public}d, pid= %{public}d, uid= %{public}d",
31         code, option.GetFlags(), callingPid, callingUid);
32 
33     if (data.ReadInterfaceToken() != GetDescriptor()) {
34         LBSLOGE(GEO_CONVERT, "invalid token.");
35         reply.WriteInt32(ERRCODE_SERVICE_UNAVAILABLE);
36         return ERRCODE_SERVICE_UNAVAILABLE;
37     }
38 
39     int ret = ERRCODE_SUCCESS;
40     switch (code) {
41         case static_cast<uint32_t>(GeoConvertInterfaceCode::IS_AVAILABLE): {
42             if (!CommonUtils::CheckCallingPermission(callingUid, callingPid, reply)) {
43                 return ERRCODE_PERMISSION_DENIED;
44             }
45             IsGeoConvertAvailable(reply);
46             break;
47         }
48         case static_cast<uint32_t>(GeoConvertInterfaceCode::GET_FROM_COORDINATE): {
49             if (!CommonUtils::CheckCallingPermission(callingUid, callingPid, reply)) {
50                 return ERRCODE_PERMISSION_DENIED;
51             }
52             GetAddressByCoordinate(data, reply);
53             break;
54         }
55         case static_cast<uint32_t>(GeoConvertInterfaceCode::GET_FROM_LOCATION_NAME_BY_BOUNDARY): {
56             if (!CommonUtils::CheckCallingPermission(callingUid, callingPid, reply)) {
57                 return ERRCODE_PERMISSION_DENIED;
58             }
59             GetAddressByLocationName(data, reply);
60             break;
61         }
62         case static_cast<uint32_t>(GeoConvertInterfaceCode::ENABLE_REVERSE_GEOCODE_MOCK): {
63             if (!CommonUtils::CheckCallingPermission(callingUid, callingPid, reply)) {
64                 return ERRCODE_PERMISSION_DENIED;
65             }
66             EnableReverseGeocodingMock() ? reply.WriteInt32(ERRCODE_SUCCESS) :
67                 reply.WriteInt32(ERRCODE_REVERSE_GEOCODING_FAIL);
68             break;
69         }
70         case static_cast<uint32_t>(GeoConvertInterfaceCode::DISABLE_REVERSE_GEOCODE_MOCK): {
71             if (!CommonUtils::CheckCallingPermission(callingUid, callingPid, reply)) {
72                 return ERRCODE_PERMISSION_DENIED;
73             }
74             DisableReverseGeocodingMock() ? reply.WriteInt32(ERRCODE_SUCCESS) :
75                 reply.WriteInt32(ERRCODE_REVERSE_GEOCODING_FAIL);
76             break;
77         }
78         case static_cast<uint32_t>(GeoConvertInterfaceCode::SET_REVERSE_GEOCODE_MOCKINFO): {
79             if (!CommonUtils::CheckCallingPermission(callingUid, callingPid, reply)) {
80                 return ERRCODE_PERMISSION_DENIED;
81             }
82             std::vector<std::shared_ptr<GeocodingMockInfo>> mockInfo = ParseGeocodingMockInfos(data);
83             reply.WriteInt32(SetReverseGeocodingMockInfo(mockInfo));
84             break;
85         }
86         default:
87             ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
88     }
89     UnloadGeoConvertSystemAbility();
90     return ret;
91 }
92 
ParseGeocodingMockInfos(MessageParcel & data)93 std::vector<std::shared_ptr<GeocodingMockInfo>> GeoConvertServiceStub::ParseGeocodingMockInfos(MessageParcel &data)
94 {
95     std::vector<std::shared_ptr<GeocodingMockInfo>> mockInfo;
96     int arraySize = data.ReadInt32();
97     arraySize = arraySize > INPUT_ARRAY_LEN_MAX ? INPUT_ARRAY_LEN_MAX :
98         arraySize;
99     if (arraySize <= 0) {
100         return std::vector<std::shared_ptr<GeocodingMockInfo>>();
101     }
102     for (int i = 0; i < arraySize; i++) {
103         std::shared_ptr<GeocodingMockInfo> info = std::make_shared<GeocodingMockInfo>();
104         info->ReadFromParcel(data);
105         mockInfo.push_back(info);
106     }
107     return mockInfo;
108 }
109 } // namespace Location
110 } // namespace OHOS
111 #endif
112