• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2024 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 "location_policy_query.h"
17 
18 #include "edm_log.h"
19 #include "location_policy.h"
20 #include "parameters.h"
21 
22 namespace OHOS {
23 namespace EDM {
24 const std::string PARAM_EDM_LOCATION_POLICY = "persist.edm.location_policy";
GetPolicyName()25 std::string LocationPolicyQuery::GetPolicyName()
26 {
27     return PolicyName::POLICY_LOCATION_POLICY;
28 }
29 
GetPermission(IPlugin::PermissionType,const std::string & permissionTag)30 std::string LocationPolicyQuery::GetPermission(IPlugin::PermissionType, const std::string &permissionTag)
31 {
32     return EdmPermission::PERMISSION_ENTERPRISE_MANAGE_LOCATION;
33 }
34 
QueryPolicy(std::string & policyData,MessageParcel & data,MessageParcel & reply,int32_t userId)35 ErrCode LocationPolicyQuery::QueryPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply,
36     int32_t userId)
37 {
38     EDMLOGI("LocationPolicyQuery OnGetPolicy");
39     std::string res = system::GetParameter(PARAM_EDM_LOCATION_POLICY, "");
40     EDMLOGI("LocationPolicyQuery OnGetPolicy res = %{public}s", res.c_str());
41     if (res == "none") {
42         reply.WriteInt32(ERR_OK);
43         reply.WriteInt32(static_cast<int32_t>(LocationPolicy::DEFAULT_LOCATION_SERVICE));
44     } else if (res == "disallow") {
45         reply.WriteInt32(ERR_OK);
46         reply.WriteInt32(static_cast<int32_t>(LocationPolicy::DISALLOW_LOCATION_SERVICE));
47     } else if (res == "force_open") {
48         reply.WriteInt32(ERR_OK);
49         reply.WriteInt32(static_cast<int32_t>(LocationPolicy::FORCE_OPEN_LOCATION_SERVICE));
50     } else {
51         EDMLOGD("LocationPolicyQuery get location policy illegal. Value = %{public}s.", res.c_str());
52         reply.WriteInt32(EdmReturnErrCode::SYSTEM_ABNORMALLY);
53         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
54     }
55     return ERR_OK;
56 }
57 } // namespace EDM
58 } // namespace OHOS