1 /*
2 * Copyright (c) 2022 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 "ipc/extract_param.h"
17
18 #include "parcel_macro.h"
19 #include "string_ex.h"
20
21 namespace OHOS {
22 namespace AppExecFwk {
23 namespace {
24 const std::string TYPE_ALL = "All";
25 const std::string TYPE_SO = "So";
26 const std::string TYPE_AN = "An";
27 const std::string TYPE_PATCH = "Patch";
28 const std::string TYPE_AP = "Ap";
29 const std::string TYPE_RESOURCE = "Resource";
30 const std::string TYPE_RES_FILE = "ResFile";
31 const std::string TYPE_HNPS_FILE = "HnpsFile";
32 const std::string TYPE_OTHER = "Other";
33 const std::unordered_map<ExtractFileType, std::string> ARGS_MAP = {
34 { ExtractFileType::ALL, TYPE_ALL },
35 { ExtractFileType::SO, TYPE_SO },
36 { ExtractFileType::AN, TYPE_AN },
37 { ExtractFileType::PATCH, TYPE_PATCH },
38 { ExtractFileType::AP, TYPE_AP },
39 { ExtractFileType::RESOURCE, TYPE_RESOURCE },
40 { ExtractFileType::RES_FILE, TYPE_RES_FILE },
41 { ExtractFileType::HNPS_FILE, TYPE_HNPS_FILE },
42 };
43
GetExtractFileTypeStrVal(const ExtractFileType & extractFileType)44 std::string GetExtractFileTypeStrVal(const ExtractFileType &extractFileType)
45 {
46 std::string typeStr = TYPE_OTHER;
47 auto operatorIter = ARGS_MAP.find(extractFileType);
48 if (operatorIter != ARGS_MAP.end()) {
49 typeStr = operatorIter->second;
50 }
51
52 return typeStr;
53 }
54 }
ReadFromParcel(Parcel & parcel)55 bool ExtractParam::ReadFromParcel(Parcel &parcel)
56 {
57 srcPath = Str16ToStr8(parcel.ReadString16());
58 targetPath = Str16ToStr8(parcel.ReadString16());
59 cpuAbi = Str16ToStr8(parcel.ReadString16());
60 extractFileType = static_cast<ExtractFileType>(parcel.ReadInt32());
61 return true;
62 }
63
Marshalling(Parcel & parcel) const64 bool ExtractParam::Marshalling(Parcel &parcel) const
65 {
66 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcPath));
67 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(targetPath));
68 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(cpuAbi));
69 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(extractFileType));
70 return true;
71 }
72
Unmarshalling(Parcel & parcel)73 ExtractParam *ExtractParam::Unmarshalling(Parcel &parcel)
74 {
75 ExtractParam *info = new (std::nothrow) ExtractParam();
76 if (info) {
77 info->ReadFromParcel(parcel);
78 }
79 return info;
80 }
81
ToString() const82 std::string ExtractParam::ToString() const
83 {
84 return "[ srcPath :" + srcPath
85 + ", targetPath = " + targetPath
86 + ", cpuAbi = " + cpuAbi
87 + ", extractFileType = " + GetExtractFileTypeStrVal(extractFileType) + "]";
88 }
89 } // namespace AppExecFwk
90 } // namespace OHOS
91