1 /*
2 * Copyright (c) 2025 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_vpn_plugin.h"
17
18 #include "bool_serializer.h"
19 #include "edm_constants.h"
20 #include "edm_ipc_interface_code.h"
21 #include "iplugin_manager.h"
22
23 #include "networkvpn_client.h"
24
25 namespace OHOS {
26 namespace EDM {
27 const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(DisallowVPNPlugin::GetPlugin());
28
InitPlugin(std::shared_ptr<IPluginTemplate<DisallowVPNPlugin,bool>> ptr)29 void DisallowVPNPlugin::InitPlugin(std::shared_ptr<IPluginTemplate<DisallowVPNPlugin, bool>> ptr)
30 {
31 EDMLOGI("DisallowVPNPlugin InitPlugin...");
32 std::map<IPlugin::PermissionType, std::string> typePermissions;
33 typePermissions.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN,
34 EdmPermission::PERMISSION_ENTERPRISE_MANAGE_RESTRICTIONS);
35 IPlugin::PolicyPermissionConfig config = IPlugin::PolicyPermissionConfig(typePermissions,
36 IPlugin::ApiType::PUBLIC);
37 ptr->InitAttribute(EdmInterfaceCode::DISALLOW_VPN, PolicyName::POLICY_DISALLOW_VPN,
38 config, true);
39 ptr->SetSerializer(BoolSerializer::GetInstance());
40 ptr->SetOnHandlePolicyListener(&DisallowVPNPlugin::OnSetPolicy, FuncOperateType::SET);
41 ptr->SetOnAdminRemoveListener(&DisallowVPNPlugin::OnAdminRemove);
42 persistParam_ = "persist.edm.vpn_disable";
43 }
44
SetOtherModulePolicy(bool data,int32_t userId)45 ErrCode DisallowVPNPlugin::SetOtherModulePolicy(bool data, int32_t userId)
46 {
47 EDMLOGI("DisallowVPNPlugin SetOtherModulePolicy...");
48 if (data) {
49 return NetManagerStandard::NetworkVpnClient::GetInstance().DestroyVpn() == 0 ? ERR_OK :
50 EdmReturnErrCode::SYSTEM_ABNORMALLY;
51 }
52 return ERR_OK;
53 }
54 } // namespace EDM
55 } // namespace OHOS