• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 "aot/aot_args.h"
17 
18 #include "parcel_macro.h"
19 #include "string_ex.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
23 namespace {
24 constexpr uint16_t MAX_HSP_VECTOR_SIZE = 10000;
25 }
ReadFromParcel(Parcel & parcel)26 bool HspInfo::ReadFromParcel(Parcel &parcel)
27 {
28     std::u16string bundleNameVal;
29     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, bundleNameVal);
30     bundleName = Str16ToStr8(bundleNameVal);
31     std::u16string moduleNameVal;
32     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, moduleNameVal);
33     moduleName = Str16ToStr8(moduleNameVal);
34     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, versionCode);
35     std::u16string hapPathVal;
36     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, hapPathVal);
37     hapPath = Str16ToStr8(hapPathVal);
38     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, offset);
39     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, length);
40     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, moduleArkTSMode);
41     return true;
42 }
43 
Marshalling(Parcel & parcel) const44 bool HspInfo::Marshalling(Parcel &parcel) const
45 {
46     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
47     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
48     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, versionCode);
49     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(hapPath));
50     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, offset);
51     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, length);
52     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, moduleArkTSMode);
53     return true;
54 }
55 
Unmarshalling(Parcel & parcel)56 HspInfo *HspInfo::Unmarshalling(Parcel &parcel)
57 {
58     HspInfo *hspInfo = new (std::nothrow) HspInfo();
59     if (hspInfo && !hspInfo->ReadFromParcel(parcel)) {
60         APP_LOGE("read HspInfo from parcel failed");
61         delete hspInfo;
62         hspInfo = nullptr;
63     }
64     return hspInfo;
65 }
66 
ToString() const67 std::string HspInfo::ToString() const
68 {
69     return "[ bundleName = " +  bundleName
70             + ", moduleName = " + moduleName
71             + ", versionCode = " + std::to_string(versionCode)
72             + ", hapPath = " + hapPath
73             + ", offset = " + std::to_string(offset)
74             + ", length = " + std::to_string(length)
75             + ", moduleArkTSMode = " + moduleArkTSMode + "]";
76 }
77 
ReadFromParcel(Parcel & parcel)78 bool AOTArgs::ReadFromParcel(Parcel &parcel)
79 {
80     std::u16string bundleNameVal;
81     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, bundleNameVal);
82     bundleName = Str16ToStr8(bundleNameVal);
83     std::u16string moduleNameVal;
84     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, moduleNameVal);
85     moduleName = Str16ToStr8(moduleNameVal);
86     std::u16string compileModeVal;
87     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, compileModeVal);
88     compileMode = Str16ToStr8(compileModeVal);
89     std::u16string hapPathVal;
90     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, hapPathVal);
91     hapPath = Str16ToStr8(hapPathVal);
92     std::u16string coreLibPathVal;
93     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, coreLibPathVal);
94     coreLibPath = Str16ToStr8(coreLibPathVal);
95     std::u16string outputPathVal;
96     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, outputPathVal);
97     outputPath = Str16ToStr8(outputPathVal);
98     std::u16string arkProfilePathVal;
99     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, arkProfilePathVal);
100     arkProfilePath = Str16ToStr8(arkProfilePathVal);
101     std::u16string anFileNameVal;
102     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, anFileNameVal);
103     anFileName = Str16ToStr8(anFileNameVal);
104     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, offset);
105     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, length);
106     uint32_t hspVectorSize = 0;
107     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, hspVectorSize);
108     hspVectorSize = std::min(hspVectorSize, uint32_t(MAX_HSP_VECTOR_SIZE));
109     for (uint32_t i = 0; i < hspVectorSize; ++i) {
110         std::unique_ptr<HspInfo> hspInfoPtr(parcel.ReadParcelable<HspInfo>());
111         if (!hspInfoPtr) {
112             APP_LOGE("read HspInfo failed");
113             return false;
114         }
115         hspVector.emplace_back(*hspInfoPtr);
116     }
117     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, bundleUid);
118     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, bundleGid);
119     std::u16string appIdentifilerVal;
120     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, appIdentifilerVal);
121     appIdentifier = Str16ToStr8(appIdentifilerVal);
122     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, isEncryptedBundle);
123     std::u16string optBCRangeVal;
124     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, optBCRangeVal);
125     optBCRangeList = Str16ToStr8(optBCRangeVal);
126     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, isScreenOff);
127     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, isEnableBaselinePgo);
128     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, moduleArkTSMode);
129     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isSysComp);
130     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, sysCompPath);
131     return true;
132 }
133 
Marshalling(Parcel & parcel) const134 bool AOTArgs::Marshalling(Parcel &parcel) const
135 {
136     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
137     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
138     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(compileMode));
139     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(hapPath));
140     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(coreLibPath));
141     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(outputPath));
142     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(arkProfilePath));
143     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(anFileName));
144     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, offset);
145     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, length);
146     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, hspVector.size());
147     for (const auto &hspInfo : hspVector) {
148         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &hspInfo);
149     }
150     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, bundleUid);
151     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, bundleGid);
152     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appIdentifier));
153     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, isEncryptedBundle);
154     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(optBCRangeList));
155     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, isScreenOff);
156     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, isEnableBaselinePgo);
157     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, moduleArkTSMode);
158     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isSysComp);
159     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, sysCompPath);
160     return true;
161 }
162 
Unmarshalling(Parcel & parcel)163 AOTArgs *AOTArgs::Unmarshalling(Parcel &parcel)
164 {
165     AOTArgs *aotArgs = new (std::nothrow) AOTArgs();
166     if (aotArgs && !aotArgs->ReadFromParcel(parcel)) {
167         APP_LOGE("read AOTArgs from parcel failed");
168         delete aotArgs;
169         aotArgs = nullptr;
170     }
171     return aotArgs;
172 }
173 
ToString() const174 std::string AOTArgs::ToString() const
175 {
176     std::string ret = "[ bundleName = " +  bundleName
177         + ", moduleName = " + moduleName
178         + ", compileMode = " + compileMode
179         + ", hapPath = " + hapPath
180         + ", coreLibPath = " + coreLibPath
181         + ", outputPath = " + outputPath
182         + ", arkProfilePath = " + arkProfilePath
183         + ", anFileName = " + anFileName
184         + ", offset = " + std::to_string(offset)
185         + ", length = " + std::to_string(length)
186         + ", bundleUid = " + std::to_string(bundleUid)
187         + ", bundleGid = " + std::to_string(bundleGid)
188         + ", appIdentifier = " + appIdentifier
189         + ", isEncryptedBundle = " + std::to_string(isEncryptedBundle)
190         + ", optBCRangeList = " + optBCRangeList
191         + ", isScreenOff = " + std::to_string(isScreenOff)
192         + ", isEnableBaselinePgo = " + std::to_string(isEnableBaselinePgo)
193         + ", moduleArkTSMode = " + moduleArkTSMode
194         + ", isSysComp = " + (isSysComp ? "true" : "false")
195         + ", sysCompPath = " + sysCompPath + "]";
196     ret.append(" hspVector = ");
197     for (const auto &hspInfo : hspVector) {
198         ret.append(hspInfo.ToString());
199     }
200     return ret;
201 }
202 }  // namespace AppExecFwk
203 }  // namespace OHOS
204