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