• 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 "disallowed_airplane_mode_plugin.h"
17 
18 #include "bool_serializer.h"
19 #include "edm_ipc_interface_code.h"
20 #include "iplugin_manager.h"
21 #include "net_conn_client.h"
22 #include "parameters.h"
23 
24 namespace OHOS {
25 namespace EDM {
26 const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(DisallowedAirplaneModePlugin::GetPlugin());
27 
InitPlugin(std::shared_ptr<IPluginTemplate<DisallowedAirplaneModePlugin,bool>> ptr)28 void DisallowedAirplaneModePlugin::InitPlugin(std::shared_ptr<IPluginTemplate<DisallowedAirplaneModePlugin, bool>> ptr)
29 {
30     EDMLOGI("DisallowedAirplaneModePlugin InitPlugin...");
31     std::map<IPlugin::PermissionType, std::string> typePermissions;
32     typePermissions.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN,
33         EdmPermission::PERMISSION_ENTERPRISE_MANAGE_NETWORK);
34     IPlugin::PolicyPermissionConfig config = IPlugin::PolicyPermissionConfig(typePermissions, IPlugin::ApiType::PUBLIC);
35     ptr->InitAttribute(EdmInterfaceCode::DISALLOWED_AIRPLANE_MODE,
36         PolicyName::POLICY_DISALLOWED_AIRPLANE_MODE, config, true);
37     ptr->SetSerializer(BoolSerializer::GetInstance());
38     ptr->SetOnHandlePolicyListener(&DisallowedAirplaneModePlugin::OnSetPolicy, FuncOperateType::SET);
39     ptr->SetOnAdminRemoveListener(&DisallowedAirplaneModePlugin::OnAdminRemove);
40     persistParam_ = "persist.edm.airplane_mode_disable";
41 }
42 
SetOtherModulePolicy(bool data,int32_t userId)43 ErrCode DisallowedAirplaneModePlugin::SetOtherModulePolicy(bool data, int32_t userId)
44 {
45     EDMLOGI("DisallowedAirplaneModePlugin OnSetPolicy disallow = %{public}d", data);
46     if (data) {
47         int32_t ret = NetManagerStandard::NetConnClient::GetInstance().SetAirplaneMode(false);
48         EDMLOGI("DisallowedAirplaneModePlugin OnSetPolicy SetAirplaneMode = %{public}d", ret);
49     }
50     return ERR_OK;
51 }
52 } // namespace EDM
53 } // namespace OHOS
54