• 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_RESOURCE = "Resource";
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 };
41 
GetExtractFileTypeStrVal(const ExtractFileType & extractFileType)42 std::string GetExtractFileTypeStrVal(const ExtractFileType &extractFileType)
43 {
44     std::string typeStr = TYPE_OTHER;
45     auto operatorIter = ARGS_MAP.find(extractFileType);
46     if (operatorIter != ARGS_MAP.end()) {
47         typeStr = operatorIter->second;
48     }
49 
50     return typeStr;
51 }
52 }
ReadFromParcel(Parcel & parcel)53 bool ExtractParam::ReadFromParcel(Parcel &parcel)
54 {
55     srcPath = Str16ToStr8(parcel.ReadString16());
56     targetPath = Str16ToStr8(parcel.ReadString16());
57     cpuAbi = Str16ToStr8(parcel.ReadString16());
58     extractFileType = static_cast<ExtractFileType>(parcel.ReadInt32());
59     return true;
60 }
61 
Marshalling(Parcel & parcel) const62 bool ExtractParam::Marshalling(Parcel &parcel) const
63 {
64     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcPath));
65     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(targetPath));
66     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(cpuAbi));
67     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(extractFileType));
68     return true;
69 }
70 
Unmarshalling(Parcel & parcel)71 ExtractParam *ExtractParam::Unmarshalling(Parcel &parcel)
72 {
73     ExtractParam *info = new (std::nothrow) ExtractParam();
74     if (info) {
75         info->ReadFromParcel(parcel);
76     }
77     return info;
78 }
79 
ToString() const80 std::string ExtractParam::ToString() const
81 {
82     return "[ srcPath :" +  srcPath
83             + ", targetPath = " + targetPath
84             + ", cpuAbi = " + cpuAbi
85             + ", extractFileType = " + GetExtractFileTypeStrVal(extractFileType) + "]";
86 }
87 }  // namespace AppExecFwk
88 }  // namespace OHOS
89