• 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 "continuous_task_callback_info.h"
17 
18 #include "string_ex.h"
19 
20 #include "continuous_task_log.h"
21 
22 namespace OHOS {
23 namespace BackgroundTaskMgr {
ContinuousTaskCallbackInfo()24 ContinuousTaskCallbackInfo::ContinuousTaskCallbackInfo() {}
25 
ContinuousTaskCallbackInfo(uint32_t typeId,int32_t creatorUid,pid_t creatorPid,std::string abilityName)26 ContinuousTaskCallbackInfo::ContinuousTaskCallbackInfo(uint32_t typeId, int32_t creatorUid,
27     pid_t creatorPid, std::string abilityName)
28     : typeId_(typeId), creatorUid_(creatorUid), creatorPid_(creatorPid), abilityName_(abilityName) {}
29 
GetTypeId() const30 uint32_t ContinuousTaskCallbackInfo::GetTypeId() const
31 {
32     return typeId_;
33 }
34 
GetCreatorUid() const35 int32_t ContinuousTaskCallbackInfo::GetCreatorUid() const
36 {
37     return creatorUid_;
38 }
39 
GetCreatorPid() const40 pid_t ContinuousTaskCallbackInfo::GetCreatorPid() const
41 {
42     return creatorPid_;
43 }
44 
GetAbilityName() const45 std::string ContinuousTaskCallbackInfo::GetAbilityName() const
46 {
47     return abilityName_;
48 }
49 
Marshalling(Parcel & parcel) const50 bool ContinuousTaskCallbackInfo::Marshalling(Parcel &parcel) const
51 {
52     if (!parcel.WriteUint32(typeId_)) {
53         BGTASK_LOGE("Failed to write typeId");
54         return false;
55     }
56 
57     if (!parcel.WriteInt32(creatorUid_)) {
58         BGTASK_LOGE("Failed to write creator uid");
59         return false;
60     }
61 
62     if (!parcel.WriteInt32(creatorPid_)) {
63         BGTASK_LOGE("Failed to write creator pid");
64         return false;
65     }
66 
67     std::u16string u16AbilityName = Str8ToStr16(abilityName_);
68     if (!parcel.WriteString16(u16AbilityName)) {
69         BGTASK_LOGE("Failed to write ability name");
70         return false;
71     }
72     return true;
73 }
74 
Unmarshalling(Parcel & parcel)75 ContinuousTaskCallbackInfo *ContinuousTaskCallbackInfo::Unmarshalling(Parcel &parcel)
76 {
77     auto object = new (std::nothrow) ContinuousTaskCallbackInfo();
78     if ((object != nullptr) && !object->ReadFromParcel(parcel)) {
79         delete object;
80         object = nullptr;
81     }
82 
83     return object;
84 }
85 
ReadFromParcel(Parcel & parcel)86 bool ContinuousTaskCallbackInfo::ReadFromParcel(Parcel &parcel)
87 {
88     typeId_ = parcel.ReadUint32();
89 
90     creatorUid_ = static_cast<int32_t>(parcel.ReadInt32());
91     creatorPid_ = static_cast<pid_t>(parcel.ReadInt32());
92 
93     std::u16string u16AbilityName;
94     if (!parcel.ReadString16(u16AbilityName)) {
95         BGTASK_LOGE("Failed to read creator ability name");
96         return false;
97     }
98     abilityName_ = Str16ToStr8(u16AbilityName);
99     return true;
100 }
101 }  // namespace BackgroundTaskMgr
102 }  // namespace OHOS