1 /*
2  * Copyright (c) 2023 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 "base_shared_bundle_info.h"
17 
18 #include "app_log_wrapper.h"
19 #include "json_util.h"
20 #include "nlohmann/json.hpp"
21 #include "parcel_macro.h"
22 #include "string_ex.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)26 bool BaseSharedBundleInfo::ReadFromParcel(Parcel &parcel)
27 {
28     bundleName = Str16ToStr8(parcel.ReadString16());
29     moduleName = Str16ToStr8(parcel.ReadString16());
30     versionCode = parcel.ReadUint32();
31     nativeLibraryPath = Str16ToStr8(parcel.ReadString16());
32     hapPath = Str16ToStr8(parcel.ReadString16());
33     compressNativeLibs = parcel.ReadBool();
34     int32_t nativeLibraryFileNamesSize;
35     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, nativeLibraryFileNamesSize);
36     CONTAINER_SECURITY_VERIFY(parcel, nativeLibraryFileNamesSize, &nativeLibraryFileNames);
37     for (int32_t i = 0; i < nativeLibraryFileNamesSize; ++i) {
38         nativeLibraryFileNames.emplace_back(Str16ToStr8(parcel.ReadString16()));
39     }
40     return true;
41 }
42 
Marshalling(Parcel & parcel) const43 bool BaseSharedBundleInfo::Marshalling(Parcel &parcel) const
44 {
45     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
46     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
47     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, versionCode);
48     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(nativeLibraryPath));
49     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(hapPath));
50     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, compressNativeLibs);
51     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, nativeLibraryFileNames.size());
52     for (auto &fileName : nativeLibraryFileNames) {
53         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(fileName));
54     }
55     return true;
56 }
57 
Unmarshalling(Parcel & parcel)58 BaseSharedBundleInfo *BaseSharedBundleInfo::Unmarshalling(Parcel &parcel)
59 {
60     BaseSharedBundleInfo *info = new (std::nothrow) BaseSharedBundleInfo();
61     if (info && !info->ReadFromParcel(parcel)) {
62         APP_LOGW("read from parcel failed");
63         delete info;
64         info = nullptr;
65     }
66     return info;
67 }
68 } // AppExecFwk
69 } // OHOS