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()21EdmPermission::EdmPermission() {} ~EdmPermission()22EdmPermission::~EdmPermission() {} 23 EdmPermission(const std::string & name,AdminType type)24EdmPermission::EdmPermission(const std::string &name, AdminType type) 25 : permissionName_(name), adminType_(type) 26 {} 27 getPermissionName() const28const std::string &EdmPermission::getPermissionName() const 29 { 30 return permissionName_; 31 } 32 setPermissionName(const std::string & permissionName)33void EdmPermission::setPermissionName(const std::string &permissionName) 34 { 35 EdmPermission::permissionName_ = permissionName; 36 } 37 getAdminType() const38AdminType EdmPermission::getAdminType() const 39 { 40 return adminType_; 41 } 42 setAdminType(AdminType adminType)43void EdmPermission::setAdminType(AdminType adminType) 44 { 45 EdmPermission::adminType_ = adminType; 46 } 47 operator ==(const EdmPermission & permission) const48bool EdmPermission::operator == (const EdmPermission &permission) const 49 { 50 return (permissionName_ == permission.getPermissionName() && adminType_ == permission.getAdminType()); 51 } 52 ReadFromParcel(Parcel & parcel)53bool EdmPermission::ReadFromParcel(Parcel &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(Parcel & parcel) const64bool EdmPermission::Marshalling(Parcel &parcel) const 65 { 66 parcel.WriteString(permissionName_); 67 parcel.WriteInt32(static_cast<int32_t>(adminType_)); 68 return true; 69 } 70 Unmarshalling(Parcel & parcel)71EdmPermission *EdmPermission::Unmarshalling(Parcel &parcel) 72 { 73 auto *permission = new (std::nothrow)EdmPermission(); 74 permission->ReadFromParcel(parcel); 75 return permission; 76 } 77 } // namespace EDM 78 } // namespace OHOS