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 "enhance_execute_strategy.h"
17 
18 #include "edm_log.h"
19 #include "plugin_manager.h"
20 
21 namespace OHOS {
22 namespace EDM {
OnGetExecute(std::uint32_t funcCode,std::string & policyData,MessageParcel & data,MessageParcel & reply,int32_t userId)23 ErrCode EnhanceExecuteStrategy::OnGetExecute(std::uint32_t funcCode, std::string &policyData, MessageParcel &data,
24     MessageParcel &reply, int32_t userId)
25 {
26     auto plugin = PluginManager::GetInstance()->GetPluginByFuncCode(funcCode);
27     if (plugin != nullptr) {
28         EDMLOGD("EnhanceExecuteStrategy::OnGetExecute plugin %{public}d execute enhance strategy.", plugin->GetCode());
29         ErrCode ret = plugin->OnGetPolicy(policyData, data, reply, userId);
30         if (FAILED(ret) && ret != EdmReturnErrCode::INTERFACE_UNSUPPORTED) {
31             return ret;
32         }
33         auto extensionPlugin = plugin->GetExtensionPlugin();
34         if (extensionPlugin != nullptr && extensionPlugin->GetPluginType() == IPlugin::PluginType::EXTENSION) {
35             EDMLOGD("EnhanceExecuteStrategy::OnGetExecute extensionPlugin %{public}d start execute.",
36                 extensionPlugin->GetCode());
37             ret = extensionPlugin->OnGetPolicy(policyData, data, reply, userId);
38         }
39         return ret;
40     }
41     EDMLOGE("EnhanceExecuteStrategy::OnGetExecute plugin %{public}d is not exist.", funcCode);
42     return ERR_EDM_GET_POLICY_FAILED;
43 }
44 
OnSetExecute(std::uint32_t funcCode,MessageParcel & data,MessageParcel & reply,HandlePolicyData & policyData,int32_t userId)45 ErrCode EnhanceExecuteStrategy::OnSetExecute(std::uint32_t funcCode, MessageParcel &data, MessageParcel &reply,
46     HandlePolicyData &policyData, int32_t userId)
47 {
48     auto plugin = PluginManager::GetInstance()->GetPluginByFuncCode(funcCode);
49     if (plugin != nullptr) {
50         EDMLOGD("EnhanceExecuteStrategy::OnSetExecute plugin %{public}d execute enhance strategy.", plugin->GetCode());
51         ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, policyData, userId);
52         if (FAILED(ret) && ret != EdmReturnErrCode::INTERFACE_UNSUPPORTED) {
53             return ret;
54         }
55         auto extensionPlugin = plugin->GetExtensionPlugin();
56         if (extensionPlugin != nullptr && extensionPlugin->GetPluginType() == IPlugin::PluginType::EXTENSION) {
57             EDMLOGD("EnhanceExecuteStrategy::OnSetExecute extensionPlugin %{public}d start execute.",
58                 extensionPlugin->GetCode());
59             ret = extensionPlugin->OnHandlePolicy(funcCode, data, reply, policyData, userId);
60         }
61         return ret;
62     }
63     EDMLOGE("EnhanceExecuteStrategy::OnSetExecute plugin %{public}d is not exist.", funcCode);
64     return ERR_EDM_HANDLE_POLICY_FAILED;
65 }
66 } // namespace EDM
67 } // namespace OHOS
68