• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "continuous_task_callback_info.h"
17 #include "accesstoken_log.h"
18 #include "string_ex.h"
19 
20 namespace OHOS {
21 namespace Security {
22 namespace AccessToken {
23 namespace {
24 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
25     LOG_CORE, SECURITY_DOMAIN_PRIVACY, "ContinuousTaskCallbackInfo"
26 };
27 } // namespace
Marshalling(Parcel & parcel) const28 bool ContinuousTaskCallbackInfo::Marshalling(Parcel &parcel) const
29 {
30     if (!parcel.WriteUint32(typeId_)) {
31         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint32 failed.");
32         return false;
33     }
34 
35     if (!parcel.WriteInt32(creatorUid_)) {
36         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed.");
37         return false;
38     }
39 
40     if (!parcel.WriteInt32(creatorPid_)) {
41         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed.");
42         return false;
43     }
44 
45     if (!parcel.WriteBool(isFromWebview_)) {
46         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteBool failed.");
47         return false;
48     }
49 
50     std::u16string u16AbilityName = Str8ToStr16(abilityName_);
51     if (!parcel.WriteString16(u16AbilityName)) {
52         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteString16 failed.");
53         return false;
54     }
55 
56     if (!parcel.WriteBool(isBatchApi_)) {
57         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteBool failed.");
58         return false;
59     }
60 
61     if (!parcel.WriteUInt32Vector(typeIds_)) {
62         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUInt32Vector failed.");
63         return false;
64     }
65 
66     if (!parcel.WriteInt32(abilityId_)) {
67         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed.");
68         return false;
69     }
70 
71     if (!parcel.WriteUint64(tokenId_)) {
72         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteUint64 failed.");
73         return false;
74     }
75     return true;
76 }
77 
Unmarshalling(Parcel & parcel)78 ContinuousTaskCallbackInfo *ContinuousTaskCallbackInfo::Unmarshalling(Parcel &parcel)
79 {
80     auto object = new (std::nothrow) ContinuousTaskCallbackInfo();
81     if ((object != nullptr) && !object->ReadFromParcel(parcel)) {
82         delete object;
83         object = nullptr;
84     }
85 
86     return object;
87 }
88 
ReadFromParcel(Parcel & parcel)89 bool ContinuousTaskCallbackInfo::ReadFromParcel(Parcel &parcel)
90 {
91     if (!parcel.ReadUint32(typeId_)) {
92         ACCESSTOKEN_LOG_ERROR(LABEL, "ReadUint32 failed.");
93         return false;
94     }
95 
96     if (!parcel.ReadInt32(creatorUid_)) {
97         ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed.");
98         return false;
99     }
100 
101     int32_t pid;
102     if (!parcel.ReadInt32(pid)) {
103         ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed.");
104         return false;
105     }
106     creatorPid_ = static_cast<pid_t>(pid);
107 
108     if (!parcel.ReadBool(isFromWebview_)) {
109         ACCESSTOKEN_LOG_ERROR(LABEL, "ReadBool failed.");
110         return false;
111     }
112 
113     std::u16string u16AbilityName;
114     if (!parcel.ReadString16(u16AbilityName)) {
115         ACCESSTOKEN_LOG_ERROR(LABEL, "ReadString16 failed.");
116         return false;
117     }
118     abilityName_ = Str16ToStr8(u16AbilityName);
119 
120     if (!parcel.ReadBool(isBatchApi_)) {
121         ACCESSTOKEN_LOG_ERROR(LABEL, "ReadBool failed.");
122         return false;
123     }
124 
125     if (!parcel.ReadUInt32Vector(&typeIds_)) {
126         ACCESSTOKEN_LOG_ERROR(LABEL, "ReadUInt32Vector failed.");
127         return false;
128     }
129 
130     if (!parcel.ReadInt32(abilityId_)) {
131         ACCESSTOKEN_LOG_ERROR(LABEL, "ReadInt32 failed.");
132         return false;
133     }
134 
135     if (!parcel.ReadUint64(tokenId_)) {
136         ACCESSTOKEN_LOG_ERROR(LABEL, "ReadUint64 failed.");
137         return false;
138     }
139     return true;
140 }
141 
GetFullTokenId() const142 uint64_t ContinuousTaskCallbackInfo::GetFullTokenId() const
143 {
144     return tokenId_;
145 }
146 } // namespace AccessToken
147 } // namespace Security
148 } // namespace OHOS
149