1 /*
2 * Copyright (c) 2021-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 "permission_def_parcel.h"
17
18 #include "access_token.h"
19 #include "parcel_utils.h"
20
21 namespace OHOS {
22 namespace Security {
23 namespace AccessToken {
Marshalling(Parcel & out) const24 bool PermissionDefParcel::Marshalling(Parcel& out) const
25 {
26 RETURN_IF_FALSE(out.WriteString(this->permissionDef.permissionName));
27 RETURN_IF_FALSE(out.WriteString(this->permissionDef.bundleName));
28 RETURN_IF_FALSE(out.WriteInt32(this->permissionDef.grantMode));
29 RETURN_IF_FALSE(out.WriteInt32(this->permissionDef.availableLevel));
30 RETURN_IF_FALSE(out.WriteBool(this->permissionDef.provisionEnable));
31 RETURN_IF_FALSE(out.WriteBool(this->permissionDef.distributedSceneEnable));
32 RETURN_IF_FALSE(out.WriteString(this->permissionDef.label));
33 RETURN_IF_FALSE(out.WriteInt32(this->permissionDef.labelId));
34 RETURN_IF_FALSE(out.WriteString(this->permissionDef.description));
35 RETURN_IF_FALSE(out.WriteInt32(this->permissionDef.descriptionId));
36 RETURN_IF_FALSE(out.WriteInt32(this->permissionDef.availableType));
37 return true;
38 }
39
Unmarshalling(Parcel & in)40 PermissionDefParcel* PermissionDefParcel::Unmarshalling(Parcel& in)
41 {
42 auto* permissionDefParcel = new (std::nothrow) PermissionDefParcel();
43 if (permissionDefParcel == nullptr) {
44 return nullptr;
45 }
46
47 permissionDefParcel->permissionDef.permissionName = in.ReadString();
48 permissionDefParcel->permissionDef.bundleName = in.ReadString();
49 RELEASE_IF_FALSE(in.ReadInt32(permissionDefParcel->permissionDef.grantMode), permissionDefParcel);
50
51 int level;
52 RELEASE_IF_FALSE(in.ReadInt32(level), permissionDefParcel);
53 permissionDefParcel->permissionDef.availableLevel = ATokenAplEnum(level);
54
55 RELEASE_IF_FALSE(in.ReadBool(permissionDefParcel->permissionDef.provisionEnable), permissionDefParcel);
56 RELEASE_IF_FALSE(in.ReadBool(permissionDefParcel->permissionDef.distributedSceneEnable), permissionDefParcel);
57 permissionDefParcel->permissionDef.label = in.ReadString();
58 RELEASE_IF_FALSE(in.ReadInt32(permissionDefParcel->permissionDef.labelId), permissionDefParcel);
59 permissionDefParcel->permissionDef.description = in.ReadString();
60 RELEASE_IF_FALSE(in.ReadInt32(permissionDefParcel->permissionDef.descriptionId), permissionDefParcel);
61 int32_t availableType;
62 RELEASE_IF_FALSE(in.ReadInt32(availableType), permissionDefParcel);
63 permissionDefParcel->permissionDef.availableType = ATokenAvailableTypeEnum(availableType);
64 return permissionDefParcel;
65 }
66 } // namespace AccessToken
67 } // namespace Security
68 } // namespace OHOS
69