• 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 #include "datetime_manager_proxy.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<DatetimeManagerProxy> DatetimeManagerProxy::instance_ = nullptr;
24 std::mutex DatetimeManagerProxy::mutexLock_;
25 const std::u16string DESCRIPTOR = u"ohos.edm.IEnterpriseDeviceMgr";
26 
DatetimeManagerProxy()27 DatetimeManagerProxy::DatetimeManagerProxy() {}
28 
~DatetimeManagerProxy()29 DatetimeManagerProxy::~DatetimeManagerProxy() {}
30 
GetDatetimeManagerProxy()31 std::shared_ptr<DatetimeManagerProxy> DatetimeManagerProxy::GetDatetimeManagerProxy()
32 {
33     if (instance_ == nullptr) {
34         std::lock_guard<std::mutex> lock(mutexLock_);
35         if (instance_ == nullptr) {
36             std::shared_ptr<DatetimeManagerProxy> temp = std::make_shared<DatetimeManagerProxy>();
37             instance_ = temp;
38         }
39     }
40     return instance_;
41 }
42 
SetDateTime(AppExecFwk::ElementName & admin,int64_t time)43 int32_t DatetimeManagerProxy::SetDateTime(AppExecFwk::ElementName &admin, int64_t time)
44 {
45     EDMLOGD("DatetimeManagerProxy::SetDateTime");
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, SET_DATETIME);
53     data.WriteInterfaceToken(DESCRIPTOR);
54     data.WriteParcelable(&admin);
55     data.WriteInt64(time);
56     return proxy->HandleDevicePolicy(funcCode, data);
57 }
58 } // namespace EDM
59 } // namespace OHOS
60