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_define.h"
17
18 #include "nlohmann/json.hpp"
19 #include "string_ex.h"
20
21 #include "app_log_wrapper.h"
22 #include "parcel_macro.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)26 bool PermissionDef::ReadFromParcel(Parcel &parcel)
27 {
28 permissionName = Str16ToStr8(parcel.ReadString16());
29 bundleName = Str16ToStr8(parcel.ReadString16());
30 label = Str16ToStr8(parcel.ReadString16());
31 description = Str16ToStr8(parcel.ReadString16());
32 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, availableLevel);
33 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, provisionEnable);
34 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, distributedSceneEnable);
35 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isKernelEffect);
36 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, hasValue);
37 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, grantMode);
38 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, labelId);
39 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, descriptionId);
40 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, availableType);
41 return true;
42 }
43
Unmarshalling(Parcel & parcel)44 PermissionDef *PermissionDef::Unmarshalling(Parcel &parcel)
45 {
46 PermissionDef *info = new (std::nothrow) PermissionDef();
47 if (info && !info->ReadFromParcel(parcel)) {
48 APP_LOGW("read from parcel failed");
49 delete info;
50 info = nullptr;
51 }
52 return info;
53 }
54
Marshalling(Parcel & parcel) const55 bool PermissionDef::Marshalling(Parcel &parcel) const
56 {
57 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(permissionName));
58 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
59 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(label));
60 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(description));
61 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, availableLevel);
62 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, provisionEnable);
63 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, distributedSceneEnable);
64 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isKernelEffect);
65 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, hasValue);
66 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, grantMode);
67 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, labelId);
68 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, descriptionId);
69 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, availableType);
70 return true;
71 }
72 } // namespace AppExecFwk
73 } // namespace OHOS
74