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_uninstall_bundles_plugin.h"
17
18 #include "array_string_serializer.h"
19 #include "edm_ipc_interface_code.h"
20 #include "iplugin_manager.h"
21
22 namespace OHOS {
23 namespace EDM {
24 const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(DisallowedUninstallBundlesPlugin::GetPlugin());
25
InitPlugin(std::shared_ptr<IPluginTemplate<DisallowedUninstallBundlesPlugin,std::vector<std::string>>> ptr)26 void DisallowedUninstallBundlesPlugin::InitPlugin(
27 std::shared_ptr<IPluginTemplate<DisallowedUninstallBundlesPlugin, std::vector<std::string>>> ptr)
28 {
29 EDMLOGD("DisallowedUninstallBundlesPlugin InitPlugin...");
30 ptr->InitAttribute(EdmInterfaceCode::DISALLOWED_UNINSTALL_BUNDLES, "disallowed_uninstall_bundles",
31 "ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY", IPlugin::PermissionType::SUPER_DEVICE_ADMIN, true);
32 ptr->SetSerializer(ArrayStringSerializer::GetInstance());
33 ptr->SetOnHandlePolicyListener(&DisallowedUninstallBundlesPlugin::OnSetPolicy, FuncOperateType::SET);
34 ptr->SetOnHandlePolicyListener(&DisallowedUninstallBundlesPlugin::OnRemovePolicy, FuncOperateType::REMOVE);
35 ptr->SetOnAdminRemoveDoneListener(&DisallowedUninstallBundlesPlugin::OnAdminRemoveDone);
36 SetAppInstallControlRuleType(AppExecFwk::AppInstallControlRuleType::DISALLOWED_UNINSTALL);
37 }
38
OnGetPolicy(std::string & policyData,MessageParcel & data,MessageParcel & reply,int32_t userId)39 ErrCode DisallowedUninstallBundlesPlugin::OnGetPolicy(std::string &policyData, MessageParcel &data,
40 MessageParcel &reply, int32_t userId)
41 {
42 EDMLOGI("DisallowedUninstallBundlesPlugin OnGetPolicy policyData : %{public}s, userId : %{public}d",
43 policyData.c_str(), userId);
44 return GetBundlePolicy(policyData, data, reply, userId);
45 }
46 } // namespace EDM
47 } // namespace OHOS
48