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 IsAdminEnabled(AppExecFwk::ElementName &admin, int32_t userId, bool &result); 53 int32_t HandleDevicePolicy(int32_t policyCode, MessageParcel &data); 54 int32_t HandleDevicePolicy(int32_t policyCode, MessageParcel &data, MessageParcel &reply); 55 ErrCode AuthorizeAdmin(const AppExecFwk::ElementName &admin, const std::string &bundleName); 56 ErrCode GetSuperAdmin(std::string &bundleName, std::string &abilityName); 57 ErrCode SetDelegatedPolicies(const AppExecFwk::ElementName &admin, const std::string &bundleName, 58 const std::vector<std::string> &policies); 59 ErrCode GetDelegatedPolicies(const AppExecFwk::ElementName &admin, const std::string &bundleNameOrPolicyName, 60 uint32_t code, std::vector<std::string> &result); 61 62 void GetEnabledSuperAdmin(std::string &enabledAdmin); 63 bool IsSuperAdminExist(); 64 void GetEnabledAdmins(std::vector<std::string> &enabledAdminList); 65 int32_t SetPolicyDisabled(const AppExecFwk::ElementName &admin, bool isDisabled, uint32_t policyCode, 66 std::string permissionTag = WITHOUT_PERMISSION_TAG); 67 int32_t IsPolicyDisabled(const AppExecFwk::ElementName *admin, int policyCode, bool &result, 68 std::string permissionTag = WITHOUT_PERMISSION_TAG); 69 bool GetPolicyValue(AppExecFwk::ElementName *admin, int policyCode, std::string &policyData, 70 int32_t userId = DEFAULT_USER_ID); 71 bool GetPolicyArray(AppExecFwk::ElementName *admin, int policyCode, std::vector<std::string> &policyData, 72 int32_t userId = DEFAULT_USER_ID); 73 bool GetPolicyMap(AppExecFwk::ElementName *admin, int policyCode, std::map<std::string, std::string> &policyData, 74 int32_t userId = DEFAULT_USER_ID); 75 bool GetPolicyData(AppExecFwk::ElementName *admin, int policyCode, int32_t userId, MessageParcel &reply); 76 bool GetPolicy(int policyCode, MessageParcel &data, MessageParcel &reply); 77 bool IsEdmEnabled(); 78 79 private: 80 sptr<IRemoteObject> LoadAndGetEdmService(); 81 void GetEnabledAdmins(AdminType type, std::vector<std::string> &enabledAdminList); 82 83 static std::shared_ptr<EnterpriseDeviceMgrProxy> instance_; 84 static std::mutex mutexLock_; 85 }; 86 } // namespace EDM 87 } // namespace OHOS 88 89 #endif // INTERFACES_INNER_API_INCLUDE_ENTERPRISE_DEVICE_MGR_PROXY_H 90