• 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.WriteBool(isAllowedNWebPreload_)) {
115         TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write isAllowedNWebPreload.");
116         return false;
117     }
118 
119     return true;
120 }
121 
ReadFromParcel(Parcel & parcel)122 bool AppLaunchData::ReadFromParcel(Parcel &parcel)
123 {
124     std::unique_ptr<ApplicationInfo> applicationInfoRead(parcel.ReadParcelable<ApplicationInfo>());
125     if (!applicationInfoRead) {
126         TAG_LOGE(AAFwkTag::APPMGR, "failed, applicationInfoRead is nullptr");
127         return false;
128     }
129     applicationInfo_ = *applicationInfoRead;
130 
131     std::unique_ptr<Profile> profileRead(parcel.ReadParcelable<Profile>());
132     if (!profileRead) {
133         TAG_LOGE(AAFwkTag::APPMGR, "failed, profileRead is nullptr");
134         return false;
135     }
136     profile_ = *profileRead;
137 
138     std::unique_ptr<ProcessInfo> processInfoRead(parcel.ReadParcelable<ProcessInfo>());
139     if (!processInfoRead) {
140         TAG_LOGE(AAFwkTag::APPMGR, "failed, processInfoRead is nullptr");
141         return false;
142     }
143     processInfo_ = *processInfoRead;
144 
145     recordId_ = parcel.ReadInt32();
146     uId_ = parcel.ReadInt32();
147     appIndex_ = parcel.ReadInt32();
148 
149     bool valid = parcel.ReadBool();
150     if (valid) {
151         userTestRecord_ = std::shared_ptr<UserTestRecord>(parcel.ReadParcelable<UserTestRecord>());
152         if (!userTestRecord_) {
153             TAG_LOGE(AAFwkTag::APPMGR, "failed, userTestRecord is nullptr");
154             return false;
155         }
156     }
157 
158     debugApp_ = parcel.ReadBool();
159     perfCmd_ = parcel.ReadString();
160     jitEnabled_ = parcel.ReadBool();
161     isNativeStart_ = parcel.ReadBool();
162     appRunningUniqueId_ = parcel.ReadString();
163     isMultiThread_ = parcel.ReadBool();
164     isErrorInfoEnhance_ = parcel.ReadBool();
165     isAllowedNWebPreload_ = parcel.ReadBool();
166     return true;
167 }
168 
Unmarshalling(Parcel & parcel)169 AppLaunchData *AppLaunchData::Unmarshalling(Parcel &parcel)
170 {
171     AppLaunchData *appLaunchData = new AppLaunchData();
172     if (appLaunchData && !appLaunchData->ReadFromParcel(parcel)) {
173         TAG_LOGW(AAFwkTag::APPMGR, "failed, because ReadFromParcel failed");
174         delete appLaunchData;
175         appLaunchData = nullptr;
176     }
177     return appLaunchData;
178 }
179 
Marshalling(Parcel & parcel) const180 bool UserTestRecord::Marshalling(Parcel &parcel) const
181 {
182     if (!parcel.WriteParcelable(&want)) {
183         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write want");
184         return false;
185     }
186 
187     auto valid = observer ? true : false;
188     if (!parcel.WriteBool(valid)) {
189         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write the flag which indicate whether observer is null");
190         return false;
191     }
192 
193     if (valid) {
194         if (!(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(observer)) {
195             TAG_LOGE(AAFwkTag::APPMGR, "Failed to write observer");
196             return false;
197         }
198     }
199 
200     if (!parcel.WriteBool(isFinished)) {
201         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write isFinished");
202         return false;
203     }
204 
205     if (!parcel.WriteInt32(userId)) {
206         TAG_LOGE(AAFwkTag::APPMGR, "Failed to write userId");
207         return false;
208     }
209     return true;
210 }
211 
Unmarshalling(Parcel & parcel)212 UserTestRecord *UserTestRecord::Unmarshalling(Parcel &parcel)
213 {
214     UserTestRecord *userTestRecord = new (std::nothrow) UserTestRecord();
215     if (userTestRecord && !userTestRecord->ReadFromParcel(parcel)) {
216         TAG_LOGW(AAFwkTag::APPMGR, "failed, because ReadFromParcel failed");
217         delete userTestRecord;
218         userTestRecord = nullptr;
219     }
220     return userTestRecord;
221 }
222 
ReadFromParcel(Parcel & parcel)223 bool UserTestRecord::ReadFromParcel(Parcel &parcel)
224 {
225     AAFwk::Want *wantPtr = parcel.ReadParcelable<AAFwk::Want>();
226     if (wantPtr == nullptr) {
227         TAG_LOGE(AAFwkTag::APPMGR, "wantPtr is nullptr");
228         return ERR_INVALID_VALUE;
229     }
230     want = *wantPtr;
231     delete wantPtr;
232 
233     auto valid = parcel.ReadBool();
234     if (valid) {
235         observer = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
236         if (!observer) {
237             TAG_LOGE(AAFwkTag::APPMGR, "observer is nullptr");
238             return false;
239         }
240     }
241 
242     isFinished = parcel.ReadBool();
243     userId = parcel.ReadInt32();
244     return true;
245 }
246 
SetNativeStart(bool isNativeStart)247 void AppLaunchData::SetNativeStart(bool isNativeStart)
248 {
249     isNativeStart_ = isNativeStart;
250 }
251 
isNativeStart() const252 bool AppLaunchData::isNativeStart() const
253 {
254     return isNativeStart_;
255 }
256 
SetNWebPreload(const bool isAllowedNWebPreload)257 void AppLaunchData::SetNWebPreload(const bool isAllowedNWebPreload)
258 {
259     isAllowedNWebPreload_ = isAllowedNWebPreload;
260 }
261 
IsAllowedNWebPreload() const262 bool AppLaunchData::IsAllowedNWebPreload() const
263 {
264     return isAllowedNWebPreload_;
265 }
266 }  // namespace AppExecFwk
267 }  // namespace OHOS
268