• 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 GetEnabledAdmin(AdminType type, std::vector<std::string> &enabledAdminList);
47     ErrCode GetEnterpriseInfo(AppExecFwk::ElementName &admin, EntInfo &entInfo);
48     ErrCode SetEnterpriseInfo(AppExecFwk::ElementName &admin, EntInfo &entInfo);
49     ErrCode HandleManagedEvent(const AppExecFwk::ElementName &admin, const std::vector<uint32_t> &events,
50         bool subscribe);
51     ErrCode IsSuperAdmin(const std::string &bundleName, bool &result);
52     ErrCode IsByodAdmin(const AppExecFwk::ElementName &admin, bool &result);
53     ErrCode IsAdminEnabled(AppExecFwk::ElementName &admin, int32_t userId, bool &result);
54     int32_t HandleDevicePolicy(int32_t policyCode, MessageParcel &data);
55     int32_t HandleDevicePolicy(int32_t policyCode, MessageParcel &data, MessageParcel &reply);
56     ErrCode AuthorizeAdmin(AppExecFwk::ElementName &admin, std::string &bundleName);
57     ErrCode GetSuperAdmin(std::string &bundleName, std::string &abilityName);
58     ErrCode SetDelegatedPolicies(AppExecFwk::ElementName &parentAdmin, std::string &bundleName,
59         std::vector<std::string> &policies);
60     ErrCode GetDelegatedPolicies(AppExecFwk::ElementName &parentAdmin, std::string &bundleOrPolicyName, uint32_t code,
61         std::vector<std::string> &result);
62     ErrCode GetAdmins(std::vector<std::shared_ptr<AAFwk::Want>> &wants);
63     ErrCode CheckAndGetAdminProvisionInfo(AppExecFwk::ElementName &admin, std::string &bundleName);
64     ErrCode ReplaceSuperAdmin(AppExecFwk::ElementName &oldAdmin, AppExecFwk::ElementName &newAdmin, bool keepPolicy);
65     ErrCode SetAdminRunningMode(AppExecFwk::ElementName &admin, uint32_t runningMode);
66     ErrCode SetDelegatedPolicies(std::string &bundleName, std::vector<std::string> &policies, int32_t userId);
67     ErrCode SetBundleInstallPolicies(std::vector<std::string> &bundles, int32_t userId, int32_t policyType);
68 
69     void GetEnabledSuperAdmin(std::string &enabledAdmin);
70     bool IsSuperAdminExist();
71     void GetEnabledAdmins(std::vector<std::string> &enabledAdminList);
72     int32_t SetPolicyDisabled(const AppExecFwk::ElementName &admin, bool isDisabled, uint32_t policyCode,
73         std::string permissionTag = WITHOUT_PERMISSION_TAG);
74     int32_t SetPolicyDisabled(MessageParcel &data, uint32_t policyCode);
75     int32_t IsPolicyDisabled(const AppExecFwk::ElementName *admin, int policyCode, bool &result,
76         std::string permissionTag = WITHOUT_PERMISSION_TAG);
77     int32_t IsPolicyDisabled(MessageParcel &data, uint32_t policyCode, bool &result);
78     bool GetPolicyValue(MessageParcel &data, uint32_t policyCode, std::string &policyData);
79     bool GetPolicyArray(AppExecFwk::ElementName *admin, int policyCode, std::vector<std::string> &policyData,
80         int32_t userId = DEFAULT_USER_ID);
81     bool GetPolicyMap(AppExecFwk::ElementName *admin, int policyCode, std::map<std::string, std::string> &policyData,
82         int32_t userId = DEFAULT_USER_ID);
83     bool GetPolicyData(AppExecFwk::ElementName *admin, int policyCode, int32_t userId, MessageParcel &reply);
84     bool GetPolicy(int policyCode, MessageParcel &data, MessageParcel &reply);
85     bool IsEdmEnabled();
86     bool IsEdmExtEnabled();
87     bool CheckDataInEdmDisabled(MessageParcel &data);
88 
89 private:
90     sptr<IRemoteObject> LoadAndGetEdmService();
91     void GetEnabledAdmins(AdminType type, std::vector<std::string> &enabledAdminList);
92 
93     static std::shared_ptr<EnterpriseDeviceMgrProxy> instance_;
94     static std::mutex mutexLock_;
95 };
96 } // namespace EDM
97 } // namespace OHOS
98 
99 #endif // INTERFACES_INNER_API_INCLUDE_ENTERPRISE_DEVICE_MGR_PROXY_H
100