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 "device_control_proxy.h" 17 18 #include "edm_log.h" 19 #include "func_code.h" 20 21 namespace OHOS { 22 namespace EDM { 23 std::shared_ptr<DeviceControlProxy> DeviceControlProxy::instance_ = nullptr; 24 std::mutex DeviceControlProxy::mutexLock_; 25 const std::u16string DESCRIPTOR = u"ohos.edm.IEnterpriseDeviceMgr"; 26 DeviceControlProxy()27DeviceControlProxy::DeviceControlProxy() {} 28 ~DeviceControlProxy()29DeviceControlProxy::~DeviceControlProxy() {} 30 GetDeviceControlProxy()31std::shared_ptr<DeviceControlProxy> DeviceControlProxy::GetDeviceControlProxy() 32 { 33 if (instance_ == nullptr) { 34 std::lock_guard<std::mutex> lock(mutexLock_); 35 if (instance_ == nullptr) { 36 std::shared_ptr<DeviceControlProxy> temp = std::make_shared<DeviceControlProxy>(); 37 instance_ = temp; 38 } 39 } 40 return instance_; 41 } 42 ResetFactory(AppExecFwk::ElementName & admin)43int32_t DeviceControlProxy::ResetFactory(AppExecFwk::ElementName &admin) 44 { 45 EDMLOGD("DeviceInfoProxy::ResetFactory"); 46 auto proxy = EnterpriseDeviceMgrProxy::GetInstance(); 47 if (proxy == nullptr) { 48 EDMLOGE("can not get EnterpriseDeviceMgrProxy"); 49 return EdmReturnErrCode::SYSTEM_ABNORMALLY; 50 } 51 MessageParcel data; 52 std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::RESET_FACTORY); 53 data.WriteInterfaceToken(DESCRIPTOR); 54 data.WriteInt32(WITHOUT_USERID); 55 data.WriteParcelable(&admin); 56 return proxy->HandleDevicePolicy(funcCode, data); 57 } 58 } // namespace EDM 59 } // namespace OHOS