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 instance key.");
121 return false;
122 }
123
124 if (!parcel.WriteBool(isAllowedNWebPreload_)) {
125 TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write isAllowedNWebPreload.");
126 return false;
127 }
128
129 if (!parcel.WriteString(preloadModuleName_)) {
130 TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write preloadModuleName.");
131 return false;
132 }
133
134 if (!parcel.WriteBool(isDebugFromLocal_)) {
135 TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write isDebugFromLocal");
136 return false;
137 }
138 return true;
139 }
140
ReadFromParcel(Parcel & parcel)141 bool AppLaunchData::ReadFromParcel(Parcel &parcel)
142 {
143 std::unique_ptr<ApplicationInfo> applicationInfoRead(parcel.ReadParcelable<ApplicationInfo>());
144 if (!applicationInfoRead) {
145 TAG_LOGE(AAFwkTag::APPMGR, "failed, applicationInfoRead is nullptr");
146 return false;
147 }
148 applicationInfo_ = *applicationInfoRead;
149
150 std::unique_ptr<Profile> profileRead(parcel.ReadParcelable<Profile>());
151 if (!profileRead) {
152 TAG_LOGE(AAFwkTag::APPMGR, "failed, profileRead is nullptr");
153 return false;
154 }
155 profile_ = *profileRead;
156
157 std::unique_ptr<ProcessInfo> processInfoRead(parcel.ReadParcelable<ProcessInfo>());
158 if (!processInfoRead) {
159 TAG_LOGE(AAFwkTag::APPMGR, "failed, processInfoRead is nullptr");
160 return false;
161 }
162 processInfo_ = *processInfoRead;
163
164 recordId_ = parcel.ReadInt32();
165 uId_ = parcel.ReadInt32();
166 appIndex_ = parcel.ReadInt32();
167
168 bool valid = parcel.ReadBool();
169 if (valid) {
170 userTestRecord_ = std::shared_ptr<UserTestRecord>(parcel.ReadParcelable<UserTestRecord>());
171 if (!userTestRecord_) {
172 TAG_LOGE(AAFwkTag::APPMGR, "failed, userTestRecord is nullptr");
173 return false;
174 }
175 }
176
177 debugApp_ = parcel.ReadBool();
178 perfCmd_ = parcel.ReadString();
179 jitEnabled_ = parcel.ReadBool();
180 isNativeStart_ = parcel.ReadBool();
181 appRunningUniqueId_ = parcel.ReadString();
182 isMultiThread_ = parcel.ReadBool();
183 isErrorInfoEnhance_ = parcel.ReadBool();
184 instanceKey_ = parcel.ReadString();
185 isNeedPreloadModule_ = parcel.ReadBool();
186 isAllowedNWebPreload_ = parcel.ReadBool();
187 preloadModuleName_ = parcel.ReadString();
188 isDebugFromLocal_ = parcel.ReadBool();
189 return true;
190 }
191
Unmarshalling(Parcel & parcel)192 AppLaunchData *AppLaunchData::Unmarshalling(Parcel &parcel)
193 {
194 AppLaunchData *appLaunchData = new AppLaunchData();
195 if (appLaunchData && !appLaunchData->ReadFromParcel(parcel)) {
196 TAG_LOGW(AAFwkTag::APPMGR, "failed, because ReadFromParcel failed");
197 delete appLaunchData;
198 appLaunchData = nullptr;
199 }
200 return appLaunchData;
201 }
202
Marshalling(Parcel & parcel) const203 bool UserTestRecord::Marshalling(Parcel &parcel) const
204 {
205 if (!parcel.WriteParcelable(&want)) {
206 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write want");
207 return false;
208 }
209
210 auto valid = observer ? true : false;
211 if (!parcel.WriteBool(valid)) {
212 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write the flag which indicate whether observer is null");
213 return false;
214 }
215
216 if (valid) {
217 if (!(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(observer)) {
218 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write observer");
219 return false;
220 }
221 }
222
223 if (!parcel.WriteBool(isFinished)) {
224 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write isFinished");
225 return false;
226 }
227
228 if (!parcel.WriteInt32(userId)) {
229 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write userId");
230 return false;
231 }
232 return true;
233 }
234
Unmarshalling(Parcel & parcel)235 UserTestRecord *UserTestRecord::Unmarshalling(Parcel &parcel)
236 {
237 UserTestRecord *userTestRecord = new (std::nothrow) UserTestRecord();
238 if (userTestRecord && !userTestRecord->ReadFromParcel(parcel)) {
239 TAG_LOGW(AAFwkTag::APPMGR, "failed, because ReadFromParcel failed");
240 delete userTestRecord;
241 userTestRecord = nullptr;
242 }
243 return userTestRecord;
244 }
245
ReadFromParcel(Parcel & parcel)246 bool UserTestRecord::ReadFromParcel(Parcel &parcel)
247 {
248 AAFwk::Want *wantPtr = parcel.ReadParcelable<AAFwk::Want>();
249 if (wantPtr == nullptr) {
250 TAG_LOGE(AAFwkTag::APPMGR, "wantPtr is nullptr");
251 return false;
252 }
253 want = *wantPtr;
254 delete wantPtr;
255
256 auto valid = parcel.ReadBool();
257 if (valid) {
258 observer = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
259 if (!observer) {
260 TAG_LOGE(AAFwkTag::APPMGR, "observer is nullptr");
261 return false;
262 }
263 }
264
265 isFinished = parcel.ReadBool();
266 userId = parcel.ReadInt32();
267 return true;
268 }
269
SetNativeStart(bool isNativeStart)270 void AppLaunchData::SetNativeStart(bool isNativeStart)
271 {
272 isNativeStart_ = isNativeStart;
273 }
274
isNativeStart() const275 bool AppLaunchData::isNativeStart() const
276 {
277 return isNativeStart_;
278 }
279
SetIsNeedPreloadModule(bool isNeedPreloadModule)280 void AppLaunchData::SetIsNeedPreloadModule(bool isNeedPreloadModule)
281 {
282 isNeedPreloadModule_ = isNeedPreloadModule;
283 }
284
IsNeedPreloadModule() const285 bool AppLaunchData::IsNeedPreloadModule() const
286 {
287 return isNeedPreloadModule_;
288 }
289
SetNWebPreload(const bool isAllowedNWebPreload)290 void AppLaunchData::SetNWebPreload(const bool isAllowedNWebPreload)
291 {
292 isAllowedNWebPreload_ = isAllowedNWebPreload;
293 }
294
IsAllowedNWebPreload() const295 bool AppLaunchData::IsAllowedNWebPreload() const
296 {
297 return isAllowedNWebPreload_;
298 }
299
SetDebugFromLocal(bool isDebugFromLocal)300 void AppLaunchData::SetDebugFromLocal(bool isDebugFromLocal)
301 {
302 isDebugFromLocal_ = isDebugFromLocal;
303 }
304
GetDebugFromLocal() const305 bool AppLaunchData::GetDebugFromLocal() const
306 {
307 return isDebugFromLocal_;
308 }
309 } // namespace AppExecFwk
310 } // namespace OHOS
311