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 "continuous_task_callback_info.h"
17 #include "continuous_task_log.h"
18
19 namespace OHOS {
20 namespace BackgroundTaskMgr {
ContinuousTaskCallbackInfo()21 ContinuousTaskCallbackInfo::ContinuousTaskCallbackInfo() {}
22
ContinuousTaskCallbackInfo(int32_t typeId,int32_t creatorUid,pid_t creatorPid,std::string abilityName)23 ContinuousTaskCallbackInfo::ContinuousTaskCallbackInfo(int32_t typeId, int32_t creatorUid,
24 pid_t creatorPid, std::string abilityName)
25 : typeId_(typeId), creatorUid_(creatorUid), creatorPid_(creatorPid), abilityName_(abilityName) {}
26
GetTypeId() const27 int32_t ContinuousTaskCallbackInfo::GetTypeId() const
28 {
29 return typeId_;
30 }
31
GetCreatorUid() const32 int32_t ContinuousTaskCallbackInfo::GetCreatorUid() const
33 {
34 return creatorUid_;
35 }
36
GetCreatorPid() const37 pid_t ContinuousTaskCallbackInfo::GetCreatorPid() const
38 {
39 return creatorPid_;
40 }
41
GetAbilityName() const42 std::string ContinuousTaskCallbackInfo::GetAbilityName() const
43 {
44 return abilityName_;
45 }
46
Marshalling(Parcel & parcel) const47 bool ContinuousTaskCallbackInfo::Marshalling(Parcel &parcel) const
48 {
49 if (!parcel.WriteInt32(typeId_)) {
50 BGTASK_LOGE("Failed to write typeId");
51 return false;
52 }
53
54 if (!parcel.WriteInt32(creatorUid_)) {
55 BGTASK_LOGE("Failed to write creator uid");
56 return false;
57 }
58
59 if (!parcel.WriteInt32(creatorPid_)) {
60 BGTASK_LOGE("Failed to write creator pid");
61 return false;
62 }
63
64 if (!parcel.WriteString(abilityName_)) {
65 BGTASK_LOGE("Failed to write ability name");
66 return false;
67 }
68 return true;
69 }
70
Unmarshalling(Parcel & parcel)71 ContinuousTaskCallbackInfo *ContinuousTaskCallbackInfo::Unmarshalling(Parcel &parcel)
72 {
73 auto object = new (std::nothrow) ContinuousTaskCallbackInfo();
74 if ((object != nullptr) && !object->ReadFromParcel(parcel)) {
75 delete object;
76 object = nullptr;
77 }
78
79 return object;
80 }
81
ReadFromParcel(Parcel & parcel)82 bool ContinuousTaskCallbackInfo::ReadFromParcel(Parcel &parcel)
83 {
84 typeId_ = parcel.ReadInt32();
85
86 creatorUid_ = static_cast<int32_t>(parcel.ReadInt32());
87 creatorPid_ = static_cast<pid_t>(parcel.ReadInt32());
88
89 if (!parcel.ReadString(abilityName_)) {
90 BGTASK_LOGE("Failed to read creator ability name");
91 return false;
92 }
93 return true;
94 }
95 }
96 }