• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 "app_launch_data.h"
17 
18 #include "hilog_tag_wrapper.h"
19 
20 namespace OHOS {
21 namespace AppExecFwk {
SetApplicationInfo(const ApplicationInfo & info)22 void AppLaunchData::SetApplicationInfo(const ApplicationInfo &info)
23 {
24     applicationInfo_ = info;
25 }
26 
SetProfile(const Profile & profile)27 void AppLaunchData::SetProfile(const Profile &profile)
28 {
29     profile_ = profile;
30 }
31 
SetProcessInfo(const ProcessInfo & info)32 void AppLaunchData::SetProcessInfo(const ProcessInfo &info)
33 {
34     processInfo_ = info;
35 }
36 
SetRecordId(const int32_t recordId)37 void AppLaunchData::SetRecordId(const int32_t recordId)
38 {
39     recordId_ = recordId;
40 }
41 
SetUId(const int32_t uId)42 void AppLaunchData::SetUId(const int32_t uId)
43 {
44     uId_ = uId;
45 }
46 
SetAppIndex(const int32_t appIndex)47 void AppLaunchData::SetAppIndex(const int32_t appIndex)
48 {
49     appIndex_ = appIndex;
50 }
51 
SetUserTestInfo(const std::shared_ptr<UserTestRecord> & record)52 void AppLaunchData::SetUserTestInfo(const std::shared_ptr<UserTestRecord> &record)
53 {
54     userTestRecord_ = record;
55 }
56 
Marshalling(Parcel & parcel) const57 bool AppLaunchData::Marshalling(Parcel &parcel) const
58 {
59     if (!parcel.WriteParcelable(&applicationInfo_) ||
60         !parcel.WriteParcelable(&profile_) || !parcel.WriteParcelable(&processInfo_)) {
61         return false;
62     }
63     if (!parcel.WriteInt32(recordId_) ||
64         !parcel.WriteInt32(uId_) || !parcel.WriteInt32(appIndex_)) {
65         return false;
66     }
67 
68     bool valid = userTestRecord_ ? true : false;
69     if (!parcel.WriteBool(valid)) {
70         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write the flag which indicate whether userTestRecord_ is null");
71         return false;
72     }
73     if (valid) {
74         if (!parcel.WriteParcelable(userTestRecord_.get())) {
75             TAG_LOGE(AAFwkTag::APPMGR, "Failed to write userTestRecord_");
76             return false;
77         }
78     }
79 
80     if (!parcel.WriteBool(debugApp_)) {
81         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write debug flag.");
82         return false;
83     }
84 
85     if (!parcel.WriteString(perfCmd_)) {
86         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write perf cmd.");
87         return false;
88     }
89 
90     if (!parcel.WriteBool(jitEnabled_) || !parcel.WriteBool(isNativeStart_)) {
91         return false;
92     }
93 
94     if (!parcel.WriteString(appRunningUniqueId_)) {
95         TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write app running unique id.");
96         return false;
97     }
98 
99     return MarshallingExtend(parcel);
100 }
101 
MarshallingExtend(Parcel & parcel) const102 bool AppLaunchData::MarshallingExtend(Parcel &parcel) const
103 {
104     if (!parcel.WriteBool(isMultiThread_)) {
105         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write is multi thread flag.");
106         return false;
107     }
108 
109     if (!parcel.WriteBool(isErrorInfoEnhance_)) {
110         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write is error info enhance flag.");
111         return false;
112     }
113 
114     if (!parcel.WriteString(instanceKey_)) {
115         TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write instance key.");
116         return false;
117     }
118 
119     if (!parcel.WriteBool(isNeedPreloadModule_)) {
120         TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write is need preload module.");
121         return false;
122     }
123 
124     if (!parcel.WriteInt32(static_cast<int32_t>(appPreloadMode_))) {
125         TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write app preload mode");
126         return false;
127     }
128 
129     if (!parcel.WriteBool(isAllowedNWebPreload_)) {
130         TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write isAllowedNWebPreload.");
131         return false;
132     }
133 
134     if (!parcel.WriteString(preloadModuleName_)) {
135         TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write preloadModuleName.");
136         return false;
137     }
138 
139     if (!parcel.WriteBool(isDebugFromLocal_)) {
140         TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write isDebugFromLocal");
141         return false;
142     }
143     bool hasStartupTaskData = startupTaskData_ ? true : false;
144     if (!parcel.WriteBool(hasStartupTaskData)) {
145         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write the hasStartupTaskData");
146         return false;
147     }
148     if (hasStartupTaskData && !parcel.WriteParcelable(startupTaskData_.get())) {
149         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write startupTaskData");
150         return false;
151     }
152     return true;
153 }
154 
ReadFromParcel(Parcel & parcel)155 bool AppLaunchData::ReadFromParcel(Parcel &parcel)
156 {
157     std::unique_ptr<ApplicationInfo> applicationInfoRead(parcel.ReadParcelable<ApplicationInfo>());
158     if (!applicationInfoRead) {
159         TAG_LOGE(AAFwkTag::APPMGR, "failed, applicationInfoRead is nullptr");
160         return false;
161     }
162     applicationInfo_ = *applicationInfoRead;
163     std::unique_ptr<Profile> profileRead(parcel.ReadParcelable<Profile>());
164     if (!profileRead) {
165         TAG_LOGE(AAFwkTag::APPMGR, "failed, profileRead is nullptr");
166         return false;
167     }
168     profile_ = *profileRead;
169 
170     std::unique_ptr<ProcessInfo> processInfoRead(parcel.ReadParcelable<ProcessInfo>());
171     if (!processInfoRead) {
172         TAG_LOGE(AAFwkTag::APPMGR, "failed, processInfoRead is nullptr");
173         return false;
174     }
175     processInfo_ = *processInfoRead;
176     recordId_ = parcel.ReadInt32();
177     uId_ = parcel.ReadInt32();
178     appIndex_ = parcel.ReadInt32();
179 
180     bool valid = parcel.ReadBool();
181     if (valid) {
182         userTestRecord_ = std::shared_ptr<UserTestRecord>(parcel.ReadParcelable<UserTestRecord>());
183         if (!userTestRecord_) {
184             TAG_LOGE(AAFwkTag::APPMGR, "failed, userTestRecord is nullptr");
185             return false;
186         }
187     }
188 
189     debugApp_ = parcel.ReadBool();
190     perfCmd_ = parcel.ReadString();
191     jitEnabled_ = parcel.ReadBool();
192     isNativeStart_ = parcel.ReadBool();
193     appRunningUniqueId_ = parcel.ReadString();
194     isMultiThread_ = parcel.ReadBool();
195     isErrorInfoEnhance_ = parcel.ReadBool();
196     instanceKey_ = parcel.ReadString();
197     isNeedPreloadModule_ = parcel.ReadBool();
198     appPreloadMode_ = static_cast<PreloadMode>(parcel.ReadInt32());
199     isAllowedNWebPreload_ = parcel.ReadBool();
200     preloadModuleName_ = parcel.ReadString();
201     isDebugFromLocal_ = parcel.ReadBool();
202     if (!ReadStartupTaskDataFromParcel(parcel)) {
203         return false;
204     }
205     return true;
206 }
207 
Unmarshalling(Parcel & parcel)208 AppLaunchData *AppLaunchData::Unmarshalling(Parcel &parcel)
209 {
210     AppLaunchData *appLaunchData = new AppLaunchData();
211     if (appLaunchData && !appLaunchData->ReadFromParcel(parcel)) {
212         TAG_LOGW(AAFwkTag::APPMGR, "failed, because ReadFromParcel failed");
213         delete appLaunchData;
214         appLaunchData = nullptr;
215     }
216     return appLaunchData;
217 }
218 
ReadStartupTaskDataFromParcel(Parcel & parcel)219 bool AppLaunchData::ReadStartupTaskDataFromParcel(Parcel &parcel)
220 {
221     bool hasStartupTaskData = parcel.ReadBool();
222     if (!hasStartupTaskData) {
223         return true;
224     }
225     startupTaskData_ = std::shared_ptr<StartupTaskData>(parcel.ReadParcelable<StartupTaskData>());
226     if (!startupTaskData_) {
227         TAG_LOGE(AAFwkTag::APPMGR, "failed, startupTaskData_ is nullptr");
228         return false;
229     }
230     return true;
231 }
232 
Marshalling(Parcel & parcel) const233 bool UserTestRecord::Marshalling(Parcel &parcel) const
234 {
235     if (!parcel.WriteParcelable(&want)) {
236         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write want");
237         return false;
238     }
239 
240     auto valid = observer ? true : false;
241     if (!parcel.WriteBool(valid)) {
242         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write the flag which indicate whether observer is null");
243         return false;
244     }
245 
246     if (valid) {
247         if (!(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(observer)) {
248             TAG_LOGE(AAFwkTag::APPMGR, "Failed to write observer");
249             return false;
250         }
251     }
252 
253     if (!parcel.WriteBool(isFinished)) {
254         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write isFinished");
255         return false;
256     }
257 
258     if (!parcel.WriteInt32(userId)) {
259         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write userId");
260         return false;
261     }
262     return true;
263 }
264 
Unmarshalling(Parcel & parcel)265 UserTestRecord *UserTestRecord::Unmarshalling(Parcel &parcel)
266 {
267     UserTestRecord *userTestRecord = new (std::nothrow) UserTestRecord();
268     if (userTestRecord && !userTestRecord->ReadFromParcel(parcel)) {
269         TAG_LOGW(AAFwkTag::APPMGR, "failed, because ReadFromParcel failed");
270         delete userTestRecord;
271         userTestRecord = nullptr;
272     }
273     return userTestRecord;
274 }
275 
ReadFromParcel(Parcel & parcel)276 bool UserTestRecord::ReadFromParcel(Parcel &parcel)
277 {
278     AAFwk::Want *wantPtr = parcel.ReadParcelable<AAFwk::Want>();
279     if (wantPtr == nullptr) {
280         TAG_LOGE(AAFwkTag::APPMGR, "wantPtr is nullptr");
281         return false;
282     }
283     want = *wantPtr;
284     delete wantPtr;
285 
286     auto valid = parcel.ReadBool();
287     if (valid) {
288         observer = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
289         if (!observer) {
290             TAG_LOGE(AAFwkTag::APPMGR, "observer is nullptr");
291             return false;
292         }
293     }
294 
295     isFinished = parcel.ReadBool();
296     userId = parcel.ReadInt32();
297     return true;
298 }
299 
SetNativeStart(bool isNativeStart)300 void AppLaunchData::SetNativeStart(bool isNativeStart)
301 {
302     isNativeStart_ = isNativeStart;
303 }
304 
isNativeStart() const305 bool AppLaunchData::isNativeStart() const
306 {
307     return isNativeStart_;
308 }
309 
SetIsNeedPreloadModule(bool isNeedPreloadModule)310 void AppLaunchData::SetIsNeedPreloadModule(bool isNeedPreloadModule)
311 {
312     isNeedPreloadModule_ = isNeedPreloadModule;
313 }
314 
IsNeedPreloadModule() const315 bool AppLaunchData::IsNeedPreloadModule() const
316 {
317     return isNeedPreloadModule_;
318 }
319 
SetAppPreloadMode(PreloadMode preloadMode)320 void AppLaunchData::SetAppPreloadMode(PreloadMode preloadMode)
321 {
322     appPreloadMode_ = preloadMode;
323 }
324 
GetAppPreloadMode() const325 PreloadMode AppLaunchData::GetAppPreloadMode() const
326 {
327     return appPreloadMode_;
328 }
329 
SetNWebPreload(const bool isAllowedNWebPreload)330 void AppLaunchData::SetNWebPreload(const bool isAllowedNWebPreload)
331 {
332     isAllowedNWebPreload_ = isAllowedNWebPreload;
333 }
334 
IsAllowedNWebPreload() const335 bool AppLaunchData::IsAllowedNWebPreload() const
336 {
337     return isAllowedNWebPreload_;
338 }
339 
SetDebugFromLocal(bool isDebugFromLocal)340 void AppLaunchData::SetDebugFromLocal(bool isDebugFromLocal)
341 {
342     isDebugFromLocal_ = isDebugFromLocal;
343 }
344 
GetDebugFromLocal() const345 bool AppLaunchData::GetDebugFromLocal() const
346 {
347     return isDebugFromLocal_;
348 }
349 
Marshalling(Parcel & parcel) const350 bool StartupTaskData::Marshalling(Parcel &parcel) const
351 {
352     if (!parcel.WriteString(action)) {
353         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write action");
354         return false;
355     }
356     if (!parcel.WriteString(insightIntentName)) {
357         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write insightIntentName");
358         return false;
359     }
360     if (!parcel.WriteString(uri)) {
361         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write uri");
362         return false;
363     }
364     return true;
365 }
366 
Unmarshalling(Parcel & parcel)367 StartupTaskData *StartupTaskData::Unmarshalling(Parcel &parcel)
368 {
369     StartupTaskData *data = new (std::nothrow) StartupTaskData();
370     if (data && !data->ReadFromParcel(parcel)) {
371         TAG_LOGW(AAFwkTag::APPMGR, "ReadFromParcel failed");
372         delete data;
373         data = nullptr;
374     }
375     return data;
376 }
377 
ReadFromParcel(Parcel & parcel)378 bool StartupTaskData::ReadFromParcel(Parcel &parcel)
379 {
380     action = parcel.ReadString();
381     insightIntentName = parcel.ReadString();
382     uri = parcel.ReadString();
383     return true;
384 }
385 }  // namespace AppExecFwk
386 }  // namespace OHOS
387