• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #ifndef INTERFACES_INNER_API_INCLUDE_ENTERPRISE_DEVICE_MGR_PROXY_H
17 #define INTERFACES_INNER_API_INCLUDE_ENTERPRISE_DEVICE_MGR_PROXY_H
18 
19 #include <message_parcel.h>
20 
21 #include <map>
22 #include <memory>
23 #include <mutex>
24 #include <string>
25 #include <vector>
26 
27 #include "ienterprise_device_mgr.h"
28 
29 namespace OHOS {
30 namespace EDM {
31 constexpr int32_t DEFAULT_USER_ID = 100;
32 constexpr int32_t HAS_ADMIN = 0;
33 constexpr int32_t WITHOUT_ADMIN = 1;
34 constexpr int32_t WITHOUT_USERID = 0;
35 constexpr int32_t HAS_USERID = 1;
36 constexpr const char *WITHOUT_PERMISSION_TAG = "";
37 
38 class EnterpriseDeviceMgrProxy {
39 public:
40     static std::shared_ptr<EnterpriseDeviceMgrProxy> GetInstance();
41     static void DestroyInstance();
42 
43     ErrCode EnableAdmin(AppExecFwk::ElementName &admin, EntInfo &entInfo, AdminType type, int32_t userId);
44     ErrCode DisableAdmin(AppExecFwk::ElementName &admin, int32_t userId);
45     ErrCode DisableSuperAdmin(const std::string &bundleName);
46     ErrCode DisableSuperAdmin(MessageParcel &data);
47     ErrCode GetEnabledAdmin(AdminType type, std::vector<std::string> &enabledAdminList);
48     ErrCode GetEnterpriseInfo(AppExecFwk::ElementName &admin, EntInfo &entInfo);
49     ErrCode SetEnterpriseInfo(MessageParcel &data);
50     ErrCode HandleManagedEvent(const AppExecFwk::ElementName &admin, const std::vector<uint32_t> &events,
51         bool subscribe);
52     ErrCode HandleManagedEvent(MessageParcel &data, bool subscribe);
53     ErrCode IsSuperAdmin(MessageParcel &data, bool &result);
54     ErrCode IsAdminEnabled(AppExecFwk::ElementName &admin, int32_t userId, bool &result);
55     int32_t HandleDevicePolicy(int32_t policyCode, MessageParcel &data);
56     int32_t HandleDevicePolicy(int32_t policyCode, MessageParcel &data, MessageParcel &reply);
57     ErrCode AuthorizeAdmin(MessageParcel &data);
58     ErrCode GetSuperAdmin(std::string &bundleName, std::string &abilityName);
59     ErrCode SetDelegatedPolicies(MessageParcel &data);
60     ErrCode GetDelegatedPolicies(MessageParcel &data, uint32_t code, std::vector<std::string> &result);
61     ErrCode GetAdmins(MessageParcel &data, std::vector<std::shared_ptr<AAFwk::Want>> &wants);
62     ErrCode CheckAndGetAdminProvisionInfo(AppExecFwk::ElementName &admin, std::string &bundleName);
63     ErrCode ReplaceSuperAdmin(AppExecFwk::ElementName &oldAdmin, AppExecFwk::ElementName &newAdmin, bool keepPolicy);
64 
65     void GetEnabledSuperAdmin(std::string &enabledAdmin);
66     bool IsSuperAdminExist();
67     void GetEnabledAdmins(std::vector<std::string> &enabledAdminList);
68     int32_t SetPolicyDisabled(const AppExecFwk::ElementName &admin, bool isDisabled, uint32_t policyCode,
69         std::string permissionTag = WITHOUT_PERMISSION_TAG);
70     int32_t SetPolicyDisabled(MessageParcel &data, uint32_t policyCode);
71     int32_t IsPolicyDisabled(const AppExecFwk::ElementName *admin, int policyCode, bool &result,
72         std::string permissionTag = WITHOUT_PERMISSION_TAG);
73     int32_t IsPolicyDisabled(MessageParcel &data, uint32_t policyCode, bool &result);
74     bool GetPolicyValue(MessageParcel &data, uint32_t policyCode, std::string &policyData);
75     bool GetPolicyArray(AppExecFwk::ElementName *admin, int policyCode, std::vector<std::string> &policyData,
76         int32_t userId = DEFAULT_USER_ID);
77     bool GetPolicyMap(AppExecFwk::ElementName *admin, int policyCode, std::map<std::string, std::string> &policyData,
78         int32_t userId = DEFAULT_USER_ID);
79     bool GetPolicyData(AppExecFwk::ElementName *admin, int policyCode, int32_t userId, MessageParcel &reply);
80     bool GetPolicy(int policyCode, MessageParcel &data, MessageParcel &reply);
81     bool IsEdmEnabled();
82     bool CheckDataInEdmDisabled(MessageParcel &data);
83 
84 private:
85     sptr<IRemoteObject> LoadAndGetEdmService();
86     void GetEnabledAdmins(AdminType type, std::vector<std::string> &enabledAdminList);
87 
88     static std::shared_ptr<EnterpriseDeviceMgrProxy> instance_;
89     static std::mutex mutexLock_;
90 };
91 } // namespace EDM
92 } // namespace OHOS
93 
94 #endif // INTERFACES_INNER_API_INCLUDE_ENTERPRISE_DEVICE_MGR_PROXY_H
95