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_param.h" 17 #include "continuous_task_log.h" 18 19 namespace OHOS { 20 namespace BackgroundTaskMgr { ReadFromParcel(Parcel & parcel)21bool ContinuousTaskParam::ReadFromParcel(Parcel &parcel) 22 { 23 if (!parcel.ReadBool(isNewApi_)) { 24 BGTASK_LOGE("Failed to read the flag which indicate whether is called from newApi"); 25 return false; 26 } 27 28 if (!parcel.ReadUint32(bgModeId_)) { 29 BGTASK_LOGE("Failed to read request background mode info"); 30 return false; 31 } 32 bool valid = parcel.ReadBool(); 33 if (valid) { 34 wantAgent_ = std::shared_ptr<AbilityRuntime::WantAgent::WantAgent>( 35 parcel.ReadParcelable<AbilityRuntime::WantAgent::WantAgent>()); 36 if (!wantAgent_) { 37 BGTASK_LOGE("Failed to read wantAgent"); 38 return false; 39 } 40 } 41 42 if (!parcel.ReadString(abilityName_)) { 43 BGTASK_LOGE("Failed to read ability name"); 44 return false; 45 } 46 valid = parcel.ReadBool(); 47 if (valid) { 48 abilityToken_ = parcel.ReadObject<IRemoteObject>(); 49 if (!abilityToken_) { 50 BGTASK_LOGE("Failed to read ablityToken"); 51 return false; 52 } 53 } 54 55 return true; 56 } 57 Unmarshalling(Parcel & parcel)58ContinuousTaskParam *ContinuousTaskParam::Unmarshalling(Parcel &parcel) 59 { 60 ContinuousTaskParam *param = new (std::nothrow) ContinuousTaskParam(); 61 if (param && !param->ReadFromParcel(parcel)) { 62 BGTASK_LOGE("read from parcel failed"); 63 delete param; 64 param = nullptr; 65 } 66 return param; 67 } 68 Marshalling(Parcel & parcel) const69bool ContinuousTaskParam::Marshalling(Parcel &parcel) const 70 { 71 if (!parcel.WriteBool(isNewApi_)) { 72 BGTASK_LOGE("Failed to write the flag which indicate whether is called from newApi"); 73 return false; 74 } 75 76 if (!parcel.WriteUint32(bgModeId_)) { 77 BGTASK_LOGE("Failed to write request background mode info"); 78 return false; 79 } 80 bool valid = wantAgent_ != nullptr; 81 if (!parcel.WriteBool(valid)) { 82 BGTASK_LOGE("Failed to write the flag which indicate whether wantAgent is null"); 83 return false; 84 } 85 if (valid) { 86 if (!parcel.WriteParcelable(wantAgent_.get())) { 87 BGTASK_LOGE("Failed to write wantAgent"); 88 return false; 89 } 90 } 91 92 if (!parcel.WriteString(abilityName_)) { 93 BGTASK_LOGE("Failed to write abilityName"); 94 return false; 95 } 96 97 valid = abilityToken_ != nullptr; 98 if (!parcel.WriteBool(valid)) { 99 BGTASK_LOGE("Failed to write the flag which indicate whether ability token is null"); 100 return false; 101 } 102 if (valid) { 103 if (!parcel.WriteObject(abilityToken_)) { 104 BGTASK_LOGE("parcel ability token failed"); 105 return false; 106 } 107 } 108 return true; 109 } 110 } 111 }