• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "notify_update_packages_plugin.h"
17 
18 #include "securec.h"
19 
20 #include "edm_ipc_interface_code.h"
21 #include "iplugin_manager.h"
22 #include "upgrade_package_info_serializer.h"
23 
24 namespace OHOS {
25 namespace EDM {
26 const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(NotifyUpdatePackagesPlugin::GetPlugin());
27 
InitPlugin(std::shared_ptr<IPluginTemplate<NotifyUpdatePackagesPlugin,UpgradePackageInfo>> ptr)28 void NotifyUpdatePackagesPlugin::InitPlugin(std::shared_ptr<IPluginTemplate<NotifyUpdatePackagesPlugin,
29     UpgradePackageInfo>> ptr)
30 {
31     EDMLOGI("NotifyUpdatePackagesPlugin InitPlugin...");
32     ptr->InitAttribute(EdmInterfaceCode::NOTIFY_UPGRADE_PACKAGES, PolicyName::POLICY_NOTIFY_UPGRADE_PACKAGES,
33         EdmPermission::PERMISSION_ENTERPRISE_MANAGE_SYSTEM, IPlugin::PermissionType::SUPER_DEVICE_ADMIN, false);
34     ptr->SetSerializer(UpgradePackageInfoSerializer::GetInstance());
35     ptr->SetOnHandlePolicyListener(&NotifyUpdatePackagesPlugin::OnSetPolicy, FuncOperateType::SET);
36 }
37 
OnSetPolicy(UpgradePackageInfo & policy)38 ErrCode NotifyUpdatePackagesPlugin::OnSetPolicy(UpgradePackageInfo &policy)
39 {
40     UpdatePolicyUtils::ClosePackagesFileHandle(policy.packages);
41     if (policy.authInfoSize > EdmConstants::AUTH_INFO_MAX_SIZE) {
42         EDMLOGE("NotifyUpdatePackagesPlugin::OnSetPolicy authInfoSize error.");
43         return EdmReturnErrCode::PARAM_ERROR;
44     }
45     if (memset_s(policy.authInfo, policy.authInfoSize, 0, policy.authInfoSize) != EOK) {
46         EDMLOGE("NotifyUpdatePackagesPlugin::OnSetPolicy memset_s fail.");
47     }
48     return EdmReturnErrCode::INTERFACE_UNSUPPORTED;
49 }
50 
OnGetPolicy(std::string & policyData,MessageParcel & data,MessageParcel & reply,int32_t userId)51 ErrCode NotifyUpdatePackagesPlugin::OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply,
52     int32_t userId)
53 {
54     return EdmReturnErrCode::INTERFACE_UNSUPPORTED;
55 }
56 } // namespace EDM
57 } // namespace OHOS
58