• 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 "snapshot_skip_plugin.h"
17 
18 #include "mock_session_manager_service_interface.h"
19 
20 #include "array_string_serializer.h"
21 #include "edm_ipc_interface_code.h"
22 #include "edm_sys_manager.h"
23 #include "iplugin_manager.h"
24 #include "system_ability_definition.h"
25 
26 namespace OHOS {
27 namespace EDM {
28 const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(SnapshotSkipPlugin::GetPlugin());
29 
InitPlugin(std::shared_ptr<IPluginTemplate<SnapshotSkipPlugin,std::vector<std::string>>> ptr)30 void SnapshotSkipPlugin::InitPlugin(std::shared_ptr<IPluginTemplate<SnapshotSkipPlugin, std::vector<std::string>>> ptr)
31 {
32     EDMLOGI("SnapshotSkipPlugin InitPlugin...");
33     ptr->InitAttribute(EdmInterfaceCode::SNAPSHOT_SKIP, "snapshot_skip",
34         EdmPermission::PERMISSION_ENTERPRISE_MANAGE_RESTRICTIONS, IPlugin::PermissionType::SUPER_DEVICE_ADMIN, true);
35     ptr->SetSerializer(ArrayStringSerializer::GetInstance());
36     ptr->SetOnHandlePolicyListener(&SnapshotSkipPlugin::OnSetPolicy, FuncOperateType::SET);
37     ptr->SetOnHandlePolicyListener(&SnapshotSkipPlugin::OnRemovePolicy, FuncOperateType::REMOVE);
38 }
39 
OnSetPolicy(std::vector<std::string> & data,std::vector<std::string> & currentData,std::vector<std::string> & mergeData,int32_t userId)40 ErrCode SnapshotSkipPlugin::OnSetPolicy(std::vector<std::string> &data,
41     std::vector<std::string> &currentData, std::vector<std::string> &mergeData, int32_t userId)
42 {
43     EDMLOGD("SnapshotSkipPlugin OnSetPolicy");
44     if (data.empty()) {
45         EDMLOGW("SnapshotSkipPlugin OnSetPolicy data is empty.");
46         return ERR_OK;
47     }
48     if (data.size() > EdmConstants::DISALLOW_LIST_FOR_ACCOUNT_MAX_SIZE) {
49         EDMLOGE("SnapshotSkipPlugin OnSetPolicy input data is too large.");
50         return EdmReturnErrCode::PARAM_ERROR;
51     }
52     auto afterHandle = ArrayStringSerializer::GetInstance()->SetUnionPolicyData(currentData, data);
53     auto afterMerge = ArrayStringSerializer::GetInstance()->SetUnionPolicyData(mergeData, afterHandle);
54     if (afterMerge.size() > EdmConstants::DISALLOW_LIST_FOR_ACCOUNT_MAX_SIZE) {
55         EDMLOGE("SnapshotSkipPlugin OnSetPolicy merge data is too large.");
56         return EdmReturnErrCode::PARAM_ERROR;
57     }
58 
59     int32_t ret = SetSnapshotSkipByUserIdAndBundleNameList(userId, afterMerge);
60     if (FAILED(ret)) {
61         EDMLOGE("SnapshotSkipPlugin SetSnapshotSkipByUserIdAndBundleNameList failed %{public}d", ret);
62         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
63     }
64     currentData = afterHandle;
65     mergeData = afterMerge;
66     return ERR_OK;
67 }
68 
OnRemovePolicy(std::vector<std::string> & data,std::vector<std::string> & currentData,std::vector<std::string> & mergeData,int32_t userId)69 ErrCode SnapshotSkipPlugin::OnRemovePolicy(std::vector<std::string> &data, std::vector<std::string> &currentData,
70     std::vector<std::string> &mergeData, int32_t userId)
71 {
72     if (data.empty()) {
73         EDMLOGW("SnapshotSkipPlugin OnRemovePolicy data is empty.");
74         return ERR_OK;
75     }
76     if (data.size() > EdmConstants::DISALLOW_LIST_FOR_ACCOUNT_MAX_SIZE) {
77         EDMLOGE("SnapshotSkipPlugin OnRemovePolicy input data is too large.");
78         return EdmReturnErrCode::PARAM_ERROR;
79     }
80     auto afterHandle = ArrayStringSerializer::GetInstance()->SetDifferencePolicyData(data, currentData);
81     auto afterMerge = ArrayStringSerializer::GetInstance()->SetUnionPolicyData(mergeData, currentData);
82 
83     int32_t ret = SetSnapshotSkipByUserIdAndBundleNameList(userId, afterMerge);
84     if (FAILED(ret)) {
85         EDMLOGE("SnapshotSkipPlugin SetSnapshotSkipByUserIdAndBundleNameList failed %{public}d", ret);
86         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
87     }
88     currentData = afterHandle;
89     mergeData = afterMerge;
90     return ERR_OK;
91 }
92 
SetSnapshotSkipByUserIdAndBundleNameList(int32_t userId,const std::vector<std::string> & mergeData)93 int32_t SnapshotSkipPlugin::SetSnapshotSkipByUserIdAndBundleNameList(int32_t userId,
94     const std::vector<std::string> &mergeData)
95 {
96     auto remoteObject = EdmSysManager::GetRemoteObjectOfSystemAbility(WINDOW_MANAGER_SERVICE_ID);
97     if (remoteObject == nullptr) {
98         EDMLOGE("SetSnapshotSkipByUserIdAndBundleNameList wms obj get fial");
99         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
100     }
101     auto mockSessionManagerServiceProxy = iface_cast<OHOS::Rosen::IMockSessionManagerInterface>(remoteObject);
102     if (mockSessionManagerServiceProxy == nullptr) {
103         EDMLOGE("SetSnapshotSkipByUserIdAndBundleNameList wms obj cast fial");
104         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
105     }
106     return mockSessionManagerServiceProxy->SetSnapshotSkipByUserIdAndBundleNames(userId, mergeData);
107 }
108 
OnAdminRemove(const std::string & adminName,std::vector<std::string> & data,std::vector<std::string> & mergeData,int32_t userId)109 ErrCode SnapshotSkipPlugin::OnAdminRemove(const std::string &adminName, std::vector<std::string> &data,
110     std::vector<std::string> &mergeData, int32_t userId)
111 {
112     int32_t ret = SetSnapshotSkipByUserIdAndBundleNameList(userId, mergeData);
113     if (FAILED(ret)) {
114         EDMLOGE("SnapshotSkipPlugin OnAdminRemove failed %{public}d", ret);
115         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
116     }
117     return ERR_OK;
118 }
119 } // namespace EDM
120 } // namespace OHOS
121