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_tethering_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 "plugin_manager.h"
23 
24 namespace OHOS {
25 namespace EDM {
26 const bool REGISTER_RESULT = PluginManager::GetInstance()->AddPlugin(DisallowedTetheringPlugin::GetPlugin());
27 const std::string PERSIST_TETHERING_CONTROL = "persist.edm.tethering_disallowed";
28 
InitPlugin(std::shared_ptr<IPluginTemplate<DisallowedTetheringPlugin, bool>> ptr)29 void DisallowedTetheringPlugin::InitPlugin(std::shared_ptr<IPluginTemplate<DisallowedTetheringPlugin, bool>> ptr)
30 {
31     EDMLOGI("DisallowedTetheringPlugin InitPlugin...");
32     ptr->InitAttribute(EdmInterfaceCode::DISALLOWED_TETHERING, "disallowed_tethering",
33         "ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS", IPlugin::PermissionType::SUPER_DEVICE_ADMIN, false);
34     ptr->SetSerializer(BoolSerializer::GetInstance());
35     ptr->SetOnHandlePolicyListener(&DisallowedTetheringPlugin::OnSetPolicy, FuncOperateType::SET);
36 }
37 
OnSetPolicy(bool &data)38 ErrCode DisallowedTetheringPlugin::OnSetPolicy(bool &data)
39 {
40     EDMLOGI("DisallowedTetheringPlugin OnSetPolicy %{public}d", data);
41     std::string value = data ? "true" : "false";
42     return system::SetParameter(PERSIST_TETHERING_CONTROL, value) ? ERR_OK : EdmReturnErrCode::SYSTEM_ABNORMALLY;
43 }
44 
OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply, int32_t userId)45 ErrCode DisallowedTetheringPlugin::OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply,
46     int32_t userId)
47 {
48     bool ret = system::GetBoolParameter(PERSIST_TETHERING_CONTROL, true);
49     reply.WriteInt32(ERR_OK);
50     reply.WriteBool(ret);
51     return ERR_OK;
52 }
53 } // namespace EDM
54 } // namespace OHOS
55