• 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 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 
37 class EnterpriseDeviceMgrProxy {
38 public:
39     static std::shared_ptr<EnterpriseDeviceMgrProxy> GetInstance();
40     static void DestroyInstance();
41 
42     ErrCode EnableAdmin(AppExecFwk::ElementName &admin, EntInfo &entInfo, AdminType type, int32_t userId);
43     ErrCode DisableAdmin(AppExecFwk::ElementName &admin, int32_t userId);
44     ErrCode DisableSuperAdmin(const std::string &bundleName);
45     ErrCode GetEnabledAdmin(AdminType type, std::vector<std::string> &enabledAdminList);
46     ErrCode GetEnterpriseInfo(AppExecFwk::ElementName &admin, EntInfo &entInfo);
47     ErrCode SetEnterpriseInfo(AppExecFwk::ElementName &admin, EntInfo &entInfo);
48     ErrCode HandleManagedEvent(const AppExecFwk::ElementName &admin, const std::vector<uint32_t> &events,
49         bool subscribe);
50     ErrCode IsSuperAdmin(const std::string &bundleName, bool &result);
51     ErrCode IsAdminEnabled(AppExecFwk::ElementName &admin, int32_t userId, bool &result);
52     int32_t HandleDevicePolicy(int32_t policyCode, MessageParcel &data);
53     int32_t HandleDevicePolicy(int32_t policyCode, MessageParcel &data, MessageParcel &reply);
54     ErrCode AuthorizeAdmin(const AppExecFwk::ElementName &admin, const std::string &bundleName);
55 
56     void GetEnabledSuperAdmin(std::string &enabledAdmin);
57     bool IsSuperAdminExist();
58     void GetEnabledAdmins(std::vector<std::string> &enabledAdminList);
59     int32_t SetPolicyDisabled(const AppExecFwk::ElementName &admin, bool isDisabled, uint32_t policyCode);
60     int32_t IsPolicyDisabled(const AppExecFwk::ElementName *admin, int policyCode, bool &result);
61     bool GetPolicyValue(AppExecFwk::ElementName *admin, int policyCode, std::string &policyData,
62         int32_t userId = DEFAULT_USER_ID);
63     bool GetPolicyArray(AppExecFwk::ElementName *admin, int policyCode, std::vector<std::string> &policyData,
64         int32_t userId = DEFAULT_USER_ID);
65     bool GetPolicyMap(AppExecFwk::ElementName *admin, int policyCode, std::map<std::string, std::string> &policyData,
66         int32_t userId = DEFAULT_USER_ID);
67     bool GetPolicyData(AppExecFwk::ElementName *admin, int policyCode, int32_t userId, MessageParcel &reply);
68     bool GetPolicy(int policyCode, MessageParcel &data, MessageParcel &reply);
69     bool IsEdmEnabled();
70 
71 private:
72     sptr<IRemoteObject> LoadAndGetEdmService();
73     void GetEnabledAdmins(AdminType type, std::vector<std::string> &enabledAdminList);
74 
75     static std::shared_ptr<EnterpriseDeviceMgrProxy> instance_;
76     static std::mutex mutexLock_;
77 };
78 } // namespace EDM
79 } // namespace OHOS
80 
81 #endif // INTERFACES_INNER_API_INCLUDE_ENTERPRISE_DEVICE_MGR_PROXY_H
82