1 /*
2 * Copyright (c) 2022-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 "datetime_manager_proxy.h"
17
18 #include "edm_log.h"
19 #include "func_code.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 MessageParcel data;
47 std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_DATETIME);
48 data.WriteInterfaceToken(DESCRIPTOR);
49 data.WriteInt32(WITHOUT_USERID);
50 data.WriteParcelable(&admin);
51 data.WriteInt64(time);
52 return EnterpriseDeviceMgrProxy::GetInstance()->HandleDevicePolicy(funcCode, data);
53 }
54
DisallowModifyDateTime(AppExecFwk::ElementName & admin,bool disallow)55 int32_t DatetimeManagerProxy::DisallowModifyDateTime(AppExecFwk::ElementName &admin, bool disallow)
56 {
57 EDMLOGD("DatetimeManagerProxy::DisallowModifyDateTime");
58 return EnterpriseDeviceMgrProxy::GetInstance()->SetPolicyDisabled(admin, disallow,
59 EdmInterfaceCode::DISALLOW_MODIFY_DATETIME);
60 }
61
IsModifyDateTimeDisallowed(AppExecFwk::ElementName * admin,bool & result)62 int32_t DatetimeManagerProxy::IsModifyDateTimeDisallowed(AppExecFwk::ElementName *admin, bool &result)
63 {
64 EDMLOGD("DatetimeManagerProxy::IsModifyDateTimeDisallowed");
65 return EnterpriseDeviceMgrProxy::GetInstance()->IsPolicyDisabled(admin, EdmInterfaceCode::DISALLOW_MODIFY_DATETIME,
66 result);
67 }
68 } // namespace EDM
69 } // namespace OHOS
70