1 /*
2  * Copyright (c) 2022-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 "quick_fix_info.h"
17 
18 #include "hilog_tag_wrapper.h"
19 
20 namespace OHOS {
21 namespace AAFwk {
ReadFromParcel(Parcel & parcel)22 bool ApplicationQuickFixInfo::ReadFromParcel(Parcel &parcel)
23 {
24     bundleName = parcel.ReadString();
25     bundleVersionCode = parcel.ReadUint32();
26     bundleVersionName = parcel.ReadString();
27     std::unique_ptr<AppExecFwk::AppqfInfo> qfInfo(parcel.ReadParcelable<AppExecFwk::AppqfInfo>());
28     if (qfInfo == nullptr) {
29         TAG_LOGE(AAFwkTag::QUICKFIX, "ReadParcelable<AppqfInfo> failed");
30         return false;
31     }
32     appqfInfo = *qfInfo;
33     return true;
34 }
35 
Marshalling(Parcel & parcel) const36 bool ApplicationQuickFixInfo::Marshalling(Parcel &parcel) const
37 {
38     if (!parcel.WriteString(bundleName)) {
39         TAG_LOGE(AAFwkTag::QUICKFIX, "Write bundleName failed");
40         return false;
41     }
42     if (!parcel.WriteUint32(bundleVersionCode)) {
43         TAG_LOGE(AAFwkTag::QUICKFIX, "Write bundleVersionCode failed");
44         return false;
45     }
46     if (!parcel.WriteString(bundleVersionName)) {
47         TAG_LOGE(AAFwkTag::QUICKFIX, "Write bundleVersionName failed");
48         return false;
49     }
50     if (!parcel.WriteParcelable(&appqfInfo)) {
51         TAG_LOGE(AAFwkTag::QUICKFIX, "Write appQfInfo failed");
52         return false;
53     }
54     return true;
55 }
56 
Unmarshalling(Parcel & parcel)57 ApplicationQuickFixInfo *ApplicationQuickFixInfo::Unmarshalling(Parcel &parcel)
58 {
59     ApplicationQuickFixInfo *info = new (std::nothrow) ApplicationQuickFixInfo();
60     if (info == nullptr) {
61         TAG_LOGE(AAFwkTag::QUICKFIX, "Create failed");
62         return nullptr;
63     }
64 
65     if (!info->ReadFromParcel(parcel)) {
66         TAG_LOGE(AAFwkTag::QUICKFIX, "Read from parcel failed");
67         delete info;
68         return nullptr;
69     }
70 
71     return info;
72 }
73 } // namespace AAFwk
74 } // namespace OHOS