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 moduleArkTSMode = parcel.ReadString();
34 compressNativeLibs = parcel.ReadBool();
35 int32_t nativeLibraryFileNamesSize;
36 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, nativeLibraryFileNamesSize);
37 CONTAINER_SECURITY_VERIFY(parcel, nativeLibraryFileNamesSize, &nativeLibraryFileNames);
38 for (int32_t i = 0; i < nativeLibraryFileNamesSize; ++i) {
39 nativeLibraryFileNames.emplace_back(Str16ToStr8(parcel.ReadString16()));
40 }
41 return true;
42 }
43
Marshalling(Parcel & parcel) const44 bool BaseSharedBundleInfo::Marshalling(Parcel &parcel) const
45 {
46 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
47 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
48 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, versionCode);
49 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(nativeLibraryPath));
50 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(hapPath));
51 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, moduleArkTSMode);
52 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, compressNativeLibs);
53 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, nativeLibraryFileNames.size());
54 for (auto &fileName : nativeLibraryFileNames) {
55 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(fileName));
56 }
57 return true;
58 }
59
Unmarshalling(Parcel & parcel)60 BaseSharedBundleInfo *BaseSharedBundleInfo::Unmarshalling(Parcel &parcel)
61 {
62 BaseSharedBundleInfo *info = new (std::nothrow) BaseSharedBundleInfo();
63 if (info && !info->ReadFromParcel(parcel)) {
64 APP_LOGW("read from parcel failed");
65 delete info;
66 info = nullptr;
67 }
68 return info;
69 }
70 } // AppExecFwk
71 } // OHOS