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_power_long_press_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 #include "edm_sys_manager.h"
23 #include "edm_data_ability_utils.h"
24
25 namespace OHOS {
26 namespace EDM {
27 const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(DisallowPowerLongPressPlugin::GetPlugin());
28
InitPlugin(std::shared_ptr<IPluginTemplate<DisallowPowerLongPressPlugin,bool>> ptr)29 void DisallowPowerLongPressPlugin::InitPlugin(std::shared_ptr<IPluginTemplate<DisallowPowerLongPressPlugin, bool>> ptr)
30 {
31 EDMLOGI("DisallowPowerLongPressPlugin InitPlugin...");
32 std::map<IPlugin::PermissionType, std::string> typePermissions;
33 typePermissions.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN,
34 EdmPermission::PERMISSION_ENTERPRISE_SET_USER_RESTRICTION);
35 IPlugin::PolicyPermissionConfig config = IPlugin::PolicyPermissionConfig(typePermissions,
36 IPlugin::ApiType::PUBLIC);
37 ptr->InitAttribute(EdmInterfaceCode::DISALLOW_POWER_LONG_PRESS, PolicyName::POLICY_DISALLOW_POWER_LONG_PRESS,
38 config, true);
39 ptr->SetSerializer(BoolSerializer::GetInstance());
40 ptr->SetOnHandlePolicyListener(&DisallowPowerLongPressPlugin::OnSetPolicy, FuncOperateType::SET);
41 ptr->SetOnAdminRemoveListener(&DisallowPowerLongPressPlugin::OnAdminRemove);
42 persistParam_ = "persist.edm.disable_power_key_shutdown";
43 }
44
SetOtherModulePolicy(bool data,int32_t userId)45 ErrCode DisallowPowerLongPressPlugin::SetOtherModulePolicy(bool data, int32_t userId)
46 {
47 EDMLOGI("DisallowPowerLongPressPlugin SetOtherModulePolicy...");
48 return EdmDataAbilityUtils::UpdateSettingsData("settings.power.block_long_press", data ? "1" : "0");
49 }
50
RemoveOtherModulePolicy(int32_t userId)51 ErrCode DisallowPowerLongPressPlugin::RemoveOtherModulePolicy(int32_t userId)
52 {
53 EDMLOGI("DisallowPowerLongPressPlugin RemoveOtherModulePolicy...");
54 return EdmDataAbilityUtils::UpdateSettingsData("settings.power.block_long_press", "0");
55 }
56 } // namespace EDM
57 } // namespace OHOS