1 /* 2 * Copyright (c) 2023-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 "form_instance.h" 17 #include "fms_log_wrapper.h" 18 #include "message_parcel.h" 19 #include "string_ex.h" 20 21 namespace OHOS { 22 namespace AppExecFwk { ReadFromParcel(Parcel & parcel)23bool FormInstance::ReadFromParcel(Parcel &parcel) 24 { 25 formId = parcel.ReadInt64(); 26 formHostName = Str16ToStr8(parcel.ReadString16()); 27 formVisiblity = static_cast<FormVisibilityType>(parcel.ReadInt32()); 28 specification = parcel.ReadInt32(); 29 bundleName = Str16ToStr8(parcel.ReadString16()); 30 moduleName = Str16ToStr8(parcel.ReadString16()); 31 abilityName = Str16ToStr8(parcel.ReadString16()); 32 formName = Str16ToStr8(parcel.ReadString16()); 33 formUsageState = static_cast<FormUsageState>(parcel.ReadInt32()); 34 description = Str16ToStr8(parcel.ReadString16()); 35 return true; 36 } 37 Marshalling(Parcel & parcel) const38bool FormInstance::Marshalling(Parcel &parcel) const 39 { 40 // write formId 41 if (!parcel.WriteInt64(formId)) { 42 return false; 43 } 44 45 // write formHostName 46 if (!parcel.WriteString16(Str8ToStr16(formHostName))) { 47 return false; 48 } 49 50 // write formVisiblity 51 if (!parcel.WriteInt32(static_cast<int32_t>(formVisiblity))) { 52 return false; 53 } 54 55 // write specification 56 if (!parcel.WriteInt32(specification)) { 57 return false; 58 } 59 60 // write bundleName 61 if (!parcel.WriteString16(Str8ToStr16(bundleName))) { 62 return false; 63 } 64 65 // write moduleName 66 if (!parcel.WriteString16(Str8ToStr16(moduleName))) { 67 return false; 68 } 69 70 // write abilityName 71 if (!parcel.WriteString16(Str8ToStr16(abilityName))) { 72 return false; 73 } 74 75 // write formName 76 if (!parcel.WriteString16(Str8ToStr16(formName))) { 77 return false; 78 } 79 80 // write formUsageState 81 if (!parcel.WriteInt32(static_cast<int32_t>(formUsageState))) { 82 return false; 83 } 84 85 // write description 86 if (!parcel.WriteString16(Str8ToStr16(description))) { 87 return false; 88 } 89 return true; 90 } 91 Unmarshalling(Parcel & parcel)92FormInstance* FormInstance::Unmarshalling(Parcel &parcel) 93 { 94 std::unique_ptr<FormInstance> object = std::make_unique<FormInstance>(); 95 if (object && !object->ReadFromParcel(parcel)) { 96 object = nullptr; 97 return nullptr; 98 } 99 return object.release(); 100 } 101 } // namespace AppExecFwk 102 } // namespace OHOS 103