• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 EDM_ENTERPRISE_DEVICE_MGR_ABILITY_H
17 #define EDM_ENTERPRISE_DEVICE_MGR_ABILITY_H
18 
19 #include <bundle_mgr_interface.h>
20 #include <string>
21 #include "admin_manager.h"
22 #include "enterprise_device_mgr_stub.h"
23 #include "hilog/log.h"
24 #include "plugin_manager.h"
25 #include "policy_manager.h"
26 #include "system_ability.h"
27 
28 namespace OHOS {
29 namespace EDM {
30 class EnterpriseDeviceMgrAbility : public SystemAbility, public EnterpriseDeviceMgrStub {
31     DECLARE_SYSTEM_ABILITY(EnterpriseDeviceMgrAbility);
32 
33 public:
34     EnterpriseDeviceMgrAbility();
35     DISALLOW_COPY_AND_MOVE(EnterpriseDeviceMgrAbility);
36     ~EnterpriseDeviceMgrAbility();
37     static sptr<EnterpriseDeviceMgrAbility> GetInstance();
38 
39     ErrCode ActiveAdmin(AppExecFwk::ElementName &admin, EntInfo &entInfo, AdminType type,
40         int32_t userId) override;
41     ErrCode DeactiveAdmin(AppExecFwk::ElementName &admin, int32_t userId) override;
42     ErrCode DeactiveSuperAdmin(std::string &bundleName) override;
43     ErrCode HandleDevicePolicy(uint32_t code, AppExecFwk::ElementName &admin, MessageParcel &data) override;
44     ErrCode GetDevicePolicy(uint32_t code, AppExecFwk::ElementName *admin, MessageParcel &reply) override;
45     ErrCode GetActiveAdmin(AdminType type, std::vector<std::string> &activeAdminList) override;
46     ErrCode GetEnterpriseInfo(AppExecFwk::ElementName &admin, MessageParcel &reply) override;
47     ErrCode SetEnterpriseInfo(AppExecFwk::ElementName &admin, EntInfo &entInfo) override;
48     bool IsSuperAdmin(std::string &bundleName) override;
49     bool IsAdminActive(AppExecFwk::ElementName &admin) override;
50 protected:
51     void OnDump() override;
52     void OnStart() override;
53     void OnStop() override;
54 
55 private:
56     bool IsHdb();
57     ErrCode CheckPermission();
58     ErrCode CheckCallingUid(std::string &bundleName);
59     ErrCode RemoveAdminItem(std::string adminName, std::string policyName, std::string policyValue);
60     ErrCode RemoveAdmin(const std::string &adminName);
61     ErrCode GetAllPermissionsByAdmin(const std::string& bundleInfoName,
62         std::vector<std::string> &permissionList, int32_t userId);
63     ErrCode UpdateDeviceAdmin(AppExecFwk::ElementName &admin);
64     ErrCode VerifyActiveAdminCondition(AppExecFwk::ElementName &admin, AdminType type);
65     bool VerifyCallingPermission(const std::string &permissionName);
66     sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgr();
67     static std::mutex mutexLock_;
68     static sptr<EnterpriseDeviceMgrAbility> instance_;
69     std::shared_ptr<PolicyManager> policyMgr_;
70     std::shared_ptr<AdminManager> adminMgr_;
71     std::shared_ptr<PluginManager> pluginMgr_;
72     bool registerToService_ = false;
73 };
74 } // namespace EDM
75 } // namespace OHOS
76 #endif // EDM_ENTERPRISE_DEVICE_MGR_ABILITY_H