• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "disable_hdc_plugin.h"
17 
18 #include "bool_serializer.h"
19 #include "edm_constants.h"
20 #include "edm_ipc_interface_code.h"
21 #include "parameters.h"
22 #include "iplugin_manager.h"
23 
24 namespace OHOS {
25 namespace EDM {
26 const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(DisableHdcPlugin::GetPlugin());
27 const std::string PERSIST_HDC_CONTROL = "persist.hdc.control";
28 
InitPlugin(std::shared_ptr<IPluginTemplate<DisableHdcPlugin,bool>> ptr)29 void DisableHdcPlugin::InitPlugin(std::shared_ptr<IPluginTemplate<DisableHdcPlugin, bool>> ptr)
30 {
31     EDMLOGI("DisableHdcPlugin InitPlugin...");
32     std::map<std::string, std::map<IPlugin::PermissionType, std::string>> tagPermissions;
33     std::map<IPlugin::PermissionType, std::string> typePermissionsForTag11;
34     std::map<IPlugin::PermissionType, std::string> typePermissionsForTag12;
35     typePermissionsForTag11.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN,
36         EdmPermission::PERMISSION_ENTERPRISE_RESTRICT_POLICY);
37     typePermissionsForTag12.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN,
38         EdmPermission::PERMISSION_ENTERPRISE_MANAGE_RESTRICTIONS);
39     typePermissionsForTag12.emplace(IPlugin::PermissionType::BYOD_DEVICE_ADMIN,
40         EdmPermission::PERMISSION_PERSONAL_MANAGE_RESTRICTIONS);
41     tagPermissions.emplace(EdmConstants::PERMISSION_TAG_VERSION_11, typePermissionsForTag11);
42     tagPermissions.emplace(EdmConstants::PERMISSION_TAG_VERSION_12, typePermissionsForTag12);
43 
44     IPlugin::PolicyPermissionConfig config = IPlugin::PolicyPermissionConfig(tagPermissions, IPlugin::ApiType::PUBLIC);
45     ptr->InitAttribute(EdmInterfaceCode::DISABLED_HDC, PolicyName::POLICY_DISABLED_HDC, config, true);
46     ptr->SetSerializer(BoolSerializer::GetInstance());
47     ptr->SetOnHandlePolicyListener(&DisableHdcPlugin::OnSetPolicy, FuncOperateType::SET);
48     ptr->SetOnAdminRemoveListener(&DisableHdcPlugin::OnAdminRemove);
49 }
50 
SetOtherModulePolicy(bool data,int32_t userId)51 ErrCode DisableHdcPlugin::SetOtherModulePolicy(bool data, int32_t userId)
52 {
53     std::string newPara = data ? "false" : "true";
54     if (!system::SetParameter(PERSIST_HDC_CONTROL, newPara)) {
55         EDMLOGE("DisableHdcPlugin set param failed.");
56         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
57     }
58     return ERR_OK;
59 }
60 
RemoveOtherModulePolicy(int32_t userId)61 ErrCode DisableHdcPlugin::RemoveOtherModulePolicy(int32_t userId)
62 {
63     if (!system::SetParameter(PERSIST_HDC_CONTROL, "true")) {
64         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
65     }
66     return ERR_OK;
67 }
68 } // namespace EDM
69 } // namespace OHOS
70