• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_used_request_parcel.h"
17 #include "parcel_utils.h"
18 
19 namespace OHOS {
20 namespace Security {
21 namespace AccessToken {
Marshalling(Parcel & out) const22 bool PermissionUsedRequestParcel::Marshalling(Parcel& out) const
23 {
24     RETURN_IF_FALSE(out.WriteUint32(this->request.tokenId));
25     RETURN_IF_FALSE(out.WriteBool(this->request.isRemote));
26     RETURN_IF_FALSE(out.WriteString(this->request.deviceId));
27     RETURN_IF_FALSE(out.WriteString(this->request.bundleName));
28 
29     RETURN_IF_FALSE(out.WriteUint32(this->request.permissionList.size()));
30     for (const auto& perm : this->request.permissionList) {
31         RETURN_IF_FALSE(out.WriteString(perm));
32     }
33     RETURN_IF_FALSE(out.WriteInt64(this->request.beginTimeMillis));
34     RETURN_IF_FALSE(out.WriteInt64(this->request.endTimeMillis));
35     RETURN_IF_FALSE(out.WriteInt32(this->request.flag));
36     return true;
37 }
38 
Unmarshalling(Parcel & in)39 PermissionUsedRequestParcel* PermissionUsedRequestParcel::Unmarshalling(Parcel& in)
40 {
41     auto* requestParcel = new (std::nothrow) PermissionUsedRequestParcel();
42     if (requestParcel == nullptr) {
43         return nullptr;
44     }
45 
46     RELEASE_IF_FALSE(in.ReadUint32(requestParcel->request.tokenId), requestParcel);
47     RELEASE_IF_FALSE(in.ReadBool (requestParcel->request.isRemote), requestParcel);
48     RELEASE_IF_FALSE(in.ReadString(requestParcel->request.deviceId), requestParcel);
49     RELEASE_IF_FALSE(in.ReadString(requestParcel->request.bundleName), requestParcel);
50 
51     uint32_t permSize = 0;
52     RELEASE_IF_FALSE(in.ReadUint32(permSize), requestParcel);
53     RELEASE_IF_FALSE(permSize <= MAX_PERMLIST_SIZE, requestParcel);
54     for (uint32_t i = 0; i < permSize; i++) {
55         std::string perm;
56         RELEASE_IF_FALSE(in.ReadString(perm), requestParcel);
57         requestParcel->request.permissionList.emplace_back(perm);
58     }
59     RELEASE_IF_FALSE(in.ReadInt64(requestParcel->request.beginTimeMillis), requestParcel);
60     RELEASE_IF_FALSE(in.ReadInt64(requestParcel->request.endTimeMillis), requestParcel);
61     int32_t flag;
62     RELEASE_IF_FALSE(in.ReadInt32(flag), requestParcel);
63     requestParcel->request.flag = static_cast<PermissionUsageFlagEnum>(flag);
64     return requestParcel;
65 }
66 } // namespace AccessToken
67 } // namespace Security
68 } // namespace OHOS
69