1 /*
2  * Copyright (c) 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 "preinstalled_application_info.h"
17 
18 #include <cerrno>
19 #include <cstring>
20 #include <fcntl.h>
21 #include <unistd.h>
22 
23 #include "json_util.h"
24 #include "nlohmann/json.hpp"
25 #include "parcel_macro.h"
26 #include "string_ex.h"
27 
28 namespace OHOS {
29 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)30 bool PreinstalledApplicationInfo::ReadFromParcel(Parcel &parcel)
31 {
32     bundleName = Str16ToStr8(parcel.ReadString16());
33     moduleName = Str16ToStr8(parcel.ReadString16());
34     labelId = parcel.ReadUint32();
35     iconId = parcel.ReadUint32();
36     return true;
37 }
38 
Unmarshalling(Parcel & parcel)39 PreinstalledApplicationInfo *PreinstalledApplicationInfo::Unmarshalling(Parcel &parcel)
40 {
41     PreinstalledApplicationInfo *info = new (std::nothrow) PreinstalledApplicationInfo();
42     if (info == nullptr) {
43         APP_LOGE("Info is null");
44         return nullptr;
45     }
46     if (info && !info->ReadFromParcel(parcel)) {
47         APP_LOGW("Read from parcel failed");
48         delete info;
49         info = nullptr;
50     }
51     return info;
52 }
53 
Marshalling(Parcel & parcel) const54 bool PreinstalledApplicationInfo::Marshalling(Parcel &parcel) const
55 {
56     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
57     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
58     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, labelId);
59     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, iconId);
60     return true;
61 }
62 }  // namespace AppExecFwk
63 }  // namespace OHOS
64