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 #include "edm_permission.h"
17 #include "string_ex.h"
18
19 namespace OHOS {
20 namespace EDM {
EdmPermission()21 EdmPermission::EdmPermission() {}
~EdmPermission()22 EdmPermission::~EdmPermission() {}
23
EdmPermission(const std::string & name,AdminType type)24 EdmPermission::EdmPermission(const std::string &name, AdminType type)
25 : permissionName_(name), adminType_(type)
26 {}
27
getPermissionName() const28 const std::string &EdmPermission::getPermissionName() const
29 {
30 return permissionName_;
31 }
32
setPermissionName(const std::string & permissionName)33 void EdmPermission::setPermissionName(const std::string &permissionName)
34 {
35 EdmPermission::permissionName_ = permissionName;
36 }
37
getAdminType() const38 AdminType EdmPermission::getAdminType() const
39 {
40 return adminType_;
41 }
42
setAdminType(AdminType adminType)43 void EdmPermission::setAdminType(AdminType adminType)
44 {
45 EdmPermission::adminType_ = adminType;
46 }
47
operator ==(const EdmPermission & permission) const48 bool EdmPermission::operator == (const EdmPermission &permission) const
49 {
50 return (permissionName_ == permission.getPermissionName() && adminType_ == permission.getAdminType());
51 }
52
ReadFromParcel(MessageParcel & parcel)53 bool EdmPermission::ReadFromParcel(MessageParcel &parcel)
54 {
55 permissionName_ = parcel.ReadString();
56 int32_t type = parcel.ReadInt32();
57 if (type == static_cast<int32_t>(AdminType::NORMAL) || type == static_cast<int32_t>(AdminType::ENT)) {
58 adminType_ = static_cast<AdminType>(type);
59 return true;
60 }
61 return false;
62 }
63
Marshalling(MessageParcel & parcel) const64 bool EdmPermission::Marshalling(MessageParcel &parcel) const
65 {
66 parcel.WriteString(permissionName_);
67 parcel.WriteInt32(static_cast<int32_t>(adminType_));
68 return true;
69 }
70
Unmarshalling(MessageParcel & parcel,EdmPermission & edmPermission)71 bool EdmPermission::Unmarshalling(MessageParcel &parcel, EdmPermission &edmPermission)
72 {
73 return edmPermission.ReadFromParcel(parcel);
74 }
75 } // namespace EDM
76 } // namespace OHOS