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_bluetooth_plugin.h"
17
18 #include "bluetooth_def.h"
19 #include "bluetooth_errorcode.h"
20 #include "bluetooth_host.h"
21 #include "bool_serializer.h"
22 #include "edm_constants.h"
23 #include "edm_ipc_interface_code.h"
24 #include "parameters.h"
25 #include "iplugin_manager.h"
26
27 namespace OHOS {
28 namespace EDM {
29 const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(DisableBluetoothPlugin::GetPlugin());
30
InitPlugin(std::shared_ptr<IPluginTemplate<DisableBluetoothPlugin,bool>> ptr)31 void DisableBluetoothPlugin::InitPlugin(std::shared_ptr<IPluginTemplate<DisableBluetoothPlugin, bool>> ptr)
32 {
33 EDMLOGI("DisableBluetoothPlugin InitPlugin...");
34 std::map<std::string, std::map<IPlugin::PermissionType, std::string>> tagPermissions;
35 std::map<IPlugin::PermissionType, std::string> typePermissionsForTag11;
36 std::map<IPlugin::PermissionType, std::string> typePermissionsForTag12;
37 typePermissionsForTag11.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN,
38 EdmPermission::PERMISSION_ENTERPRISE_MANAGE_BLUETOOTH);
39 typePermissionsForTag12.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN,
40 EdmPermission::PERMISSION_ENTERPRISE_MANAGE_RESTRICTIONS);
41 typePermissionsForTag12.emplace(IPlugin::PermissionType::BYOD_DEVICE_ADMIN,
42 EdmPermission::PERMISSION_PERSONAL_MANAGE_RESTRICTIONS);
43 tagPermissions.emplace(EdmConstants::PERMISSION_TAG_VERSION_11, typePermissionsForTag11);
44 tagPermissions.emplace(EdmConstants::PERMISSION_TAG_VERSION_12, typePermissionsForTag12);
45 IPlugin::PolicyPermissionConfig config = IPlugin::PolicyPermissionConfig(tagPermissions, IPlugin::ApiType::PUBLIC);
46 ptr->InitAttribute(EdmInterfaceCode::DISABLE_BLUETOOTH, PolicyName::POLICY_DISABLED_BLUETOOTH, config, true);
47 ptr->SetSerializer(BoolSerializer::GetInstance());
48 ptr->SetOnHandlePolicyListener(&DisableBluetoothPlugin::OnSetPolicy, FuncOperateType::SET);
49 ptr->SetOnAdminRemoveListener(&DisableBluetoothPlugin::OnAdminRemove);
50 persistParam_ = "persist.edm.prohibit_bluetooth";
51 }
52
SetOtherModulePolicy(bool data,int32_t userId)53 ErrCode DisableBluetoothPlugin::SetOtherModulePolicy(bool data, int32_t userId)
54 {
55 if (data && Bluetooth::BluetoothHost::GetDefaultHost().IsBrEnabled() &&
56 Bluetooth::BluetoothHost::GetDefaultHost().DisableBt() != Bluetooth::BT_NO_ERROR) {
57 EDMLOGW("DisableBluetoothPlugin close bluetooth failed.");
58 return EdmReturnErrCode::SYSTEM_ABNORMALLY;
59 }
60 return ERR_OK;
61 }
62 } // namespace EDM
63 } // namespace OHOS
64