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