• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 true;
37 }
38 
Unmarshalling(Parcel & in)39 PermissionDefParcel* PermissionDefParcel::Unmarshalling(Parcel& in)
40 {
41     auto* permissionDefParcel = new (std::nothrow) PermissionDefParcel();
42     if (permissionDefParcel == nullptr) {
43         return nullptr;
44     }
45 
46     permissionDefParcel->permissionDef.permissionName = in.ReadString();
47     permissionDefParcel->permissionDef.bundleName = in.ReadString();
48     RELEASE_IF_FALSE(in.ReadInt32(permissionDefParcel->permissionDef.grantMode), permissionDefParcel);
49 
50     int level;
51     RELEASE_IF_FALSE(in.ReadInt32(level), permissionDefParcel);
52     permissionDefParcel->permissionDef.availableLevel = ATokenAplEnum(level);
53 
54     RELEASE_IF_FALSE(in.ReadBool(permissionDefParcel->permissionDef.provisionEnable), permissionDefParcel);
55     RELEASE_IF_FALSE(in.ReadBool(permissionDefParcel->permissionDef.distributedSceneEnable), permissionDefParcel);
56     permissionDefParcel->permissionDef.label = in.ReadString();
57     RELEASE_IF_FALSE(in.ReadInt32(permissionDefParcel->permissionDef.labelId), permissionDefParcel);
58     permissionDefParcel->permissionDef.description = in.ReadString();
59     RELEASE_IF_FALSE(in.ReadInt32(permissionDefParcel->permissionDef.descriptionId), permissionDefParcel);
60     return permissionDefParcel;
61 }
62 } // namespace AccessToken
63 } // namespace Security
64 } // namespace OHOS
65