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 #include "admin.h"
17
18 #include "edm_log.h"
19 #include "ent_info.h"
20 #include "string_ex.h"
21
22 namespace OHOS {
23 namespace EDM {
Admin(const Admin & other)24 Admin::Admin(const Admin& other)
25 {
26 adminInfo_.packageName_ = other.adminInfo_.packageName_;
27 adminInfo_.className_ = other.adminInfo_.className_;
28 adminInfo_.entInfo_ = other.adminInfo_.entInfo_;
29 adminInfo_.permission_ = other.adminInfo_.permission_;
30 adminInfo_.managedEvents_ = other.adminInfo_.managedEvents_;
31 adminInfo_.parentAdminName_ = other.adminInfo_.parentAdminName_;
32 adminInfo_.accessiblePolicies_ = other.adminInfo_.accessiblePolicies_;
33 adminInfo_.adminType_ = other.adminInfo_.adminType_;
34 adminInfo_.isDebug_ = other.adminInfo_.isDebug_;
35 adminInfo_.runningMode_ = other.adminInfo_.runningMode_;
36 }
37
operator =(const Admin & other)38 Admin& Admin::operator=(const Admin& other)
39 {
40 adminInfo_.packageName_ = other.adminInfo_.packageName_;
41 adminInfo_.className_ = other.adminInfo_.className_;
42 adminInfo_.entInfo_ = other.adminInfo_.entInfo_;
43 adminInfo_.permission_ = other.adminInfo_.permission_;
44 adminInfo_.managedEvents_ = other.adminInfo_.managedEvents_;
45 adminInfo_.parentAdminName_ = other.adminInfo_.parentAdminName_;
46 adminInfo_.accessiblePolicies_ = other.adminInfo_.accessiblePolicies_;
47 adminInfo_.adminType_ = other.adminInfo_.adminType_;
48 adminInfo_.isDebug_ = other.adminInfo_.isDebug_;
49 adminInfo_.runningMode_ = other.adminInfo_.runningMode_;
50 return *this;
51 }
52
Admin(const AppExecFwk::ExtensionAbilityInfo & abilityInfo,AdminType type,const EntInfo & entInfo,const std::vector<std::string> & permissions,bool isDebug)53 Admin::Admin(const AppExecFwk::ExtensionAbilityInfo &abilityInfo, AdminType type, const EntInfo &entInfo,
54 const std::vector<std::string> &permissions, bool isDebug)
55 {
56 adminInfo_.adminType_ = type;
57 adminInfo_.entInfo_ = entInfo;
58 adminInfo_.permission_ = permissions;
59 adminInfo_.packageName_ = abilityInfo.bundleName;
60 adminInfo_.className_ = abilityInfo.name;
61 adminInfo_.isDebug_ = isDebug;
62 }
63
Admin(const std::string & bundleName,AdminType type,const std::vector<std::string> & permissions)64 Admin::Admin(const std::string &bundleName, AdminType type, const std::vector<std::string> &permissions)
65 {
66 adminInfo_.packageName_ = bundleName;
67 adminInfo_.adminType_ = type;
68 adminInfo_.permission_ = permissions;
69 }
70
SetParentAdminName(const std::string & parentAdminName)71 void Admin::SetParentAdminName(const std::string &parentAdminName)
72 {
73 adminInfo_.parentAdminName_ = parentAdminName;
74 }
75
SetAccessiblePolicies(const std::vector<std::string> & accessiblePolicies)76 void Admin::SetAccessiblePolicies(const std::vector<std::string> &accessiblePolicies)
77 {
78 adminInfo_.accessiblePolicies_ = accessiblePolicies;
79 }
80
CheckPermission(const std::string & permission)81 bool Admin::CheckPermission(const std::string &permission)
82 {
83 EDMLOGD("Admin::CheckPermission");
84 return std::any_of(adminInfo_.permission_.begin(), adminInfo_.permission_.end(),
85 [&permission](const std::string &item) { return item == permission; });
86 }
87
GetAdminType() const88 AdminType Admin::GetAdminType() const
89 {
90 return adminInfo_.adminType_;
91 }
GetParentAdminName() const92 std::string Admin::GetParentAdminName() const
93 {
94 return adminInfo_.parentAdminName_;
95 }
96 } // namespace EDM
97 } // namespace OHOS