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 "disallow_modify_datetime_plugin.h"
17
18 #include "edm_constants.h"
19 #include "edm_ipc_interface_code.h"
20 #include "plugin_manager.h"
21
22 namespace OHOS {
23 namespace EDM {
24 const bool REGISTER_RESULT = PluginManager::GetInstance()->AddPlugin(DisallModifyDateTimePlugin::GetPlugin());
25
InitPlugin(std::shared_ptr<IPluginTemplate<DisallModifyDateTimePlugin,bool>> ptr)26 void DisallModifyDateTimePlugin::InitPlugin(std::shared_ptr<IPluginTemplate<DisallModifyDateTimePlugin, bool>> ptr)
27 {
28 EDMLOGI("DisallowModifyDateTimePlugin InitPlugin...");
29 std::map<std::string, std::map<IPlugin::PermissionType, std::string>> tagPermissions;
30 std::map<IPlugin::PermissionType, std::string> typePermissionsForTag11;
31 std::map<IPlugin::PermissionType, std::string> typePermissionsForTag12;
32 typePermissionsForTag11.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN,
33 "ohos.permission.ENTERPRISE_SET_DATETIME");
34 typePermissionsForTag12.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN,
35 "ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS");
36 tagPermissions.emplace(EdmConstants::PERMISSION_TAG_VERSION_11, typePermissionsForTag11);
37 tagPermissions.emplace(EdmConstants::PERMISSION_TAG_VERSION_12, typePermissionsForTag12);
38
39 IPlugin::PolicyPermissionConfig config = IPlugin::PolicyPermissionConfig(tagPermissions, IPlugin::ApiType::PUBLIC);
40 ptr->InitAttribute(EdmInterfaceCode::DISALLOW_MODIFY_DATETIME, "disallow_modify_datetime", config, true);
41 ptr->SetSerializer(BoolSerializer::GetInstance());
42 ptr->SetOnHandlePolicyListener(&DisallModifyDateTimePlugin::OnSetPolicy, FuncOperateType::SET);
43 }
44
OnSetPolicy(bool & data)45 ErrCode DisallModifyDateTimePlugin::OnSetPolicy(bool &data)
46 {
47 return ERR_OK;
48 }
49
OnGetPolicy(std::string & policyData,MessageParcel & data,MessageParcel & reply,int32_t userId)50 ErrCode DisallModifyDateTimePlugin::OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply,
51 int32_t userId)
52 {
53 bool disallow = false;
54 pluginInstance_->serializer_->Deserialize(policyData, disallow);
55 reply.WriteInt32(ERR_OK);
56 reply.WriteBool(disallow);
57 return ERR_OK;
58 }
59 } // namespace EDM
60 } // namespace OHOS
61