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