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()24ContinuousTaskCallbackInfo::ContinuousTaskCallbackInfo() {} 25 GetTypeId() const26uint32_t ContinuousTaskCallbackInfo::GetTypeId() const 27 { 28 return typeId_; 29 } 30 GetCreatorUid() const31int32_t ContinuousTaskCallbackInfo::GetCreatorUid() const 32 { 33 return creatorUid_; 34 } 35 GetCreatorPid() const36pid_t ContinuousTaskCallbackInfo::GetCreatorPid() const 37 { 38 return creatorPid_; 39 } 40 GetAbilityName() const41std::string ContinuousTaskCallbackInfo::GetAbilityName() const 42 { 43 return abilityName_; 44 } 45 IsFromWebview() const46bool ContinuousTaskCallbackInfo::IsFromWebview() const 47 { 48 return isFromWebview_; 49 } 50 Marshalling(Parcel & parcel) const51bool ContinuousTaskCallbackInfo::Marshalling(Parcel &parcel) const 52 { 53 if (!parcel.WriteUint32(typeId_)) { 54 BGTASK_LOGE("Failed to write typeId"); 55 return false; 56 } 57 58 if (!parcel.WriteInt32(creatorUid_)) { 59 BGTASK_LOGE("Failed to write creator uid"); 60 return false; 61 } 62 63 if (!parcel.WriteInt32(creatorPid_)) { 64 BGTASK_LOGE("Failed to write creator pid"); 65 return false; 66 } 67 68 if (!parcel.WriteBool(isFromWebview_)) { 69 BGTASK_LOGE("Failed to write the flag which indicates from webview"); 70 return false; 71 } 72 73 std::u16string u16AbilityName = Str8ToStr16(abilityName_); 74 if (!parcel.WriteString16(u16AbilityName)) { 75 BGTASK_LOGE("Failed to write ability name"); 76 return false; 77 } 78 return true; 79 } 80 Unmarshalling(Parcel & parcel)81ContinuousTaskCallbackInfo *ContinuousTaskCallbackInfo::Unmarshalling(Parcel &parcel) 82 { 83 auto object = new (std::nothrow) ContinuousTaskCallbackInfo(); 84 if ((object != nullptr) && !object->ReadFromParcel(parcel)) { 85 delete object; 86 object = nullptr; 87 } 88 89 return object; 90 } 91 ReadFromParcel(Parcel & parcel)92bool ContinuousTaskCallbackInfo::ReadFromParcel(Parcel &parcel) 93 { 94 typeId_ = parcel.ReadUint32(); 95 96 creatorUid_ = static_cast<int32_t>(parcel.ReadInt32()); 97 creatorPid_ = static_cast<pid_t>(parcel.ReadInt32()); 98 99 if (!parcel.ReadBool(isFromWebview_)) { 100 BGTASK_LOGE("Failed to read the flag which indicates from webview"); 101 return false; 102 } 103 104 std::u16string u16AbilityName; 105 if (!parcel.ReadString16(u16AbilityName)) { 106 BGTASK_LOGE("Failed to read creator ability name"); 107 return false; 108 } 109 abilityName_ = Str16ToStr8(u16AbilityName); 110 return true; 111 } 112 } // namespace BackgroundTaskMgr 113 } // namespace OHOS