• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #ifndef SERVICES_EDM_INCLUDE_EDM_IPLUGIN_H
17 #define SERVICES_EDM_INCLUDE_EDM_IPLUGIN_H
18 
19 #include <iostream>
20 #include <map>
21 #include <string>
22 #include "edm_errors.h"
23 #include "func_code.h"
24 #include "message_parcel.h"
25 
26 namespace OHOS {
27 namespace EDM {
28 constexpr int32_t DEFAULT_USER_ID = 100;
29 
30 class IPlugin {
31 public:
32     enum class PermissionType {
33         NORMAL_DEVICE_ADMIN = 0,
34         SUPER_DEVICE_ADMIN,
35         UNKNOWN,
36     };
37 
38     /*
39      * handle policy
40      *
41      * @param funcCode func code
42      * @param data Data sent from the IPC
43      * @param reply Reply return to the IPC
44      * @param policyData Policy data after processing
45      * @param isChanged Whether the data is changed
46      * @return If the operation is successful, ERR_OK is returned.
47      */
48     virtual ErrCode OnHandlePolicy(std::uint32_t funcCode, MessageParcel &data, MessageParcel &reply,
49         std::string &policyData, bool &isChanged, int32_t userId) = 0;
50 
51     /*
52      * Merge policy data
53      *
54      * @param adminName current admin name
55      * @param policyData in:Current cached policy data,out:comprehensive data of all admins currently cached.
56      * @return If ERR_OK is returned,policyData incoming and outgoing data will be saved to a file.
57      */
58     virtual ErrCode MergePolicyData(const std::string &adminName, std::string &policyData);
59     virtual void OnHandlePolicyDone(std::uint32_t funcCode, const std::string &adminName, bool isGlobalChanged,
60         int32_t userId) = 0;
61     virtual ErrCode OnAdminRemove(const std::string &adminName, const std::string &policyData, int32_t userId) = 0;
62     virtual void OnAdminRemoveDone(const std::string &adminName, const std::string &currentJsonData,
63         int32_t userId) = 0;
64     virtual ErrCode WritePolicyToParcel(const std::string &policyData, MessageParcel &reply);
65     virtual ErrCode OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply,
66         int32_t userId) = 0;
67 
68     std::uint32_t GetCode();
69     std::string GetPolicyName();
70     bool NeedSavePolicy();
71     bool IsGlobalPolicy();
72     std::string GetPermission(FuncOperateType operaType);
73     IPlugin::PermissionType GetPermissionType(FuncOperateType operaType);
74     virtual ~IPlugin();
75 
76 protected:
77     std::uint32_t policyCode_ = 0;
78     std::string policyName_;
79     std::string permission_;
80     PermissionType permissionType_ = PermissionType::UNKNOWN;
81     std::map<FuncOperateType, std::pair<std::string, IPlugin::PermissionType>> permissionMap_;
82     bool needSave_ = true;
83     bool isGlobal_ = true;
84 };
85 } // namespace EDM
86 } // namespace OHOS
87 
88 #endif // SERVICES_EDM_INCLUDE_EDM_IPLUGIN_H
89