• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_manager_proxy.h"
17 #include "edm_log.h"
18 #include "func_code.h"
19 
20 namespace OHOS {
21 namespace EDM {
22 std::shared_ptr<LocationManagerProxy> LocationManagerProxy::instance_ = nullptr;
23 std::once_flag LocationManagerProxy::flag_;
24 const std::u16string DESCRIPTOR = u"ohos.edm.IEnterpriseDeviceMgr";
25 
GetLocationManagerProxy()26 std::shared_ptr<LocationManagerProxy> LocationManagerProxy::GetLocationManagerProxy()
27 {
28     std::call_once(flag_, []() {
29         if (instance_ == nullptr) {
30             instance_ = std::make_shared<LocationManagerProxy>();
31         }
32     });
33     return instance_;
34 }
35 
SetLocationPolicy(MessageParcel & data)36 int32_t LocationManagerProxy::SetLocationPolicy(MessageParcel &data)
37 {
38     EDMLOGD("LocationManagerProxy::SetLocationPolicy");
39     MessageParcel reply;
40     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::LOCATION_POLICY);
41     return EnterpriseDeviceMgrProxy::GetInstance()->HandleDevicePolicy(funcCode, data);
42 }
43 
GetLocationPolicy(const AppExecFwk::ElementName * admin,LocationPolicy & locationPolicy)44 int32_t LocationManagerProxy::GetLocationPolicy(const AppExecFwk::ElementName *admin, LocationPolicy &locationPolicy)
45 {
46     EDMLOGD("LocationManagerProxy::GetLocationPolicy");
47     MessageParcel data;
48     MessageParcel reply;
49     data.WriteInterfaceToken(DESCRIPTOR);
50     data.WriteInt32(WITHOUT_USERID);
51     data.WriteString(WITHOUT_PERMISSION_TAG);
52     if (admin != nullptr) {
53         data.WriteInt32(HAS_ADMIN);
54         data.WriteParcelable(admin);
55     } else {
56         if (!EnterpriseDeviceMgrProxy::GetInstance()->IsEdmEnabled()) {
57             locationPolicy = LocationPolicy::DEFAULT_LOCATION_SERVICE;
58             return ERR_OK;
59         }
60         data.WriteInt32(WITHOUT_ADMIN);
61     }
62     EnterpriseDeviceMgrProxy::GetInstance()->GetPolicy(EdmInterfaceCode::LOCATION_POLICY, data, reply);
63     int32_t ret = ERR_INVALID_VALUE;
64     bool blRes = reply.ReadInt32(ret) && (ret == ERR_OK);
65     if (!blRes) {
66         EDMLOGE("EnterpriseDeviceMgrProxy:GetPolicy fail. %{public}d", ret);
67         return ret;
68     }
69     locationPolicy = (LocationPolicy)reply.ReadInt32();
70     return ERR_OK;
71 }
72 } // namespace EDM
73 } // namespace OHOS