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 constexpr const char* TYPE_ALL = "All";
25 constexpr const char* TYPE_SO = "So";
26 constexpr const char* TYPE_AN = "An";
27 constexpr const char* TYPE_PATCH = "Patch";
28 constexpr const char* TYPE_AP = "Ap";
29 constexpr const char* TYPE_RESOURCE = "Resource";
30 constexpr const char* TYPE_RES_FILE = "ResFile";
31 constexpr const char* TYPE_HNPS_FILE = "HnpsFile";
32 constexpr const char* TYPE_OTHER = "Other";
33 const ExtractFileType ARGS_MAP_KEY[] = {
34 ExtractFileType::ALL, ExtractFileType::SO, ExtractFileType::AN, ExtractFileType::PATCH, ExtractFileType::AP,
35 ExtractFileType::RESOURCE, ExtractFileType::RES_FILE, ExtractFileType::HNPS_FILE,
36 };
37 constexpr const char* ARGS_MAP_VALUE[] = {
38 TYPE_ALL, TYPE_SO, TYPE_AN, TYPE_PATCH, TYPE_AP, TYPE_RESOURCE, TYPE_RES_FILE, TYPE_HNPS_FILE,
39 };
40
GetExtractFileTypeStrVal(const ExtractFileType & extractFileType)41 std::string GetExtractFileTypeStrVal(const ExtractFileType &extractFileType)
42 {
43 std::string typeStr = TYPE_OTHER;
44 size_t len = sizeof(ARGS_MAP_KEY) / sizeof(ARGS_MAP_KEY[0]);
45 for (size_t i = 0; i < len; i++) {
46 if (extractFileType == ARGS_MAP_KEY[i]) {
47 typeStr = ARGS_MAP_VALUE[i];
48 break;
49 }
50 }
51 return typeStr;
52 }
53 }
ReadFromParcel(Parcel & parcel)54 bool ExtractParam::ReadFromParcel(Parcel &parcel)
55 {
56 srcPath = Str16ToStr8(parcel.ReadString16());
57 targetPath = Str16ToStr8(parcel.ReadString16());
58 cpuAbi = Str16ToStr8(parcel.ReadString16());
59 extractFileType = static_cast<ExtractFileType>(parcel.ReadInt32());
60 needRemoveOld = parcel.ReadBool();
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 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, needRemoveOld);
71 return true;
72 }
73
Unmarshalling(Parcel & parcel)74 ExtractParam *ExtractParam::Unmarshalling(Parcel &parcel)
75 {
76 ExtractParam *info = new (std::nothrow) ExtractParam();
77 if (info) {
78 info->ReadFromParcel(parcel);
79 }
80 return info;
81 }
82
ToString() const83 std::string ExtractParam::ToString() const
84 {
85 return "[ srcPath :" + srcPath
86 + ", targetPath = " + targetPath
87 + ", cpuAbi = " + cpuAbi
88 + ", extractFileType = " + GetExtractFileTypeStrVal(extractFileType)
89 + ", needRemoveOld = " + (needRemoveOld ? "true" : "false") + "]";
90 }
91 } // namespace AppExecFwk
92 } // namespace OHOS
93