1 /* 2 * Copyright (c) 2021 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 #ifndef OHOS_ABILITY_RUNTIME_APP_LAUNCH_DATA_H 17 #define OHOS_ABILITY_RUNTIME_APP_LAUNCH_DATA_H 18 19 #include <string> 20 21 #include "iremote_object.h" 22 #include "parcel.h" 23 24 #include "application_info.h" 25 #include "process_info.h" 26 #include "profile.h" 27 #include "want.h" 28 29 namespace OHOS { 30 namespace AppExecFwk { 31 struct UserTestRecord : public Parcelable { 32 AAFwk::Want want; 33 sptr<IRemoteObject> observer; 34 bool isFinished; 35 int32_t userId; UserTestRecordUserTestRecord36 UserTestRecord() : observer(nullptr), isFinished(false), userId(-1) 37 {} 38 39 bool ReadFromParcel(Parcel &parcel); 40 virtual bool Marshalling(Parcel &parcel) const override; 41 static UserTestRecord *Unmarshalling(Parcel &parcel); 42 }; 43 44 class AppLaunchData : public Parcelable { 45 public: 46 /** 47 * @brief setting information for the application. 48 * 49 * @param ApplicationInfo&, the current application info. 50 */ 51 void SetApplicationInfo(const ApplicationInfo &info); 52 53 /** 54 * @brief Setting information for the profile. 55 * 56 * @param Profile&, the current profile. 57 */ 58 void SetProfile(const Profile &profile); 59 60 /** 61 * @brief Setting information for the process. 62 * 63 * @param Profile&, the current process info. 64 */ 65 void SetProcessInfo(const ProcessInfo &info); 66 67 /** 68 * @brief Setting id for app record. 69 * 70 * @param int32_t, the current app record id. 71 */ 72 void SetRecordId(const int32_t recordId); 73 74 /** 75 * @brief Setting id for User. 76 * 77 * @param int32_t, the current app User. 78 */ 79 void SetUId(const int32_t uId); 80 81 /** 82 * @brief set user test info. 83 * 84 * @param UserTestRecord, user test info. 85 */ 86 void SetUserTestInfo(const std::shared_ptr<UserTestRecord> &record); 87 88 void SetAppIndex(const int32_t appIndex); 89 90 /** 91 * @brief Obtains the info of the application. 92 * 93 * @return Returns the current application info. 94 */ GetApplicationInfo()95 inline const ApplicationInfo &GetApplicationInfo() const 96 { 97 return applicationInfo_; 98 } 99 100 /** 101 * @brief Obtains the profile. 102 * 103 * @return Returns the current profile. 104 */ GetProfile()105 inline const Profile &GetProfile() const 106 { 107 return profile_; 108 } 109 110 /** 111 * @brief Obtains the info of the process. 112 * 113 * @return Returns the current process info. 114 */ GetProcessInfo()115 inline const ProcessInfo &GetProcessInfo() const 116 { 117 return processInfo_; 118 } 119 120 /** 121 * @brief Obtains the id of the app record. 122 * 123 * @return Returns the current appRecord id. 124 */ GetRecordId()125 inline int32_t GetRecordId() const 126 { 127 return recordId_; 128 } 129 130 /** 131 * @brief Obtains the id of the User. 132 * 133 * @return Returns the current User id. 134 */ GetUId()135 inline int32_t GetUId() const 136 { 137 return uId_; 138 } 139 140 /** 141 * @brief get user test info. 142 * 143 * @return Returns user test info. 144 */ GetUserTestInfo()145 inline std::shared_ptr<UserTestRecord> GetUserTestInfo() const 146 { 147 return userTestRecord_; 148 } 149 GetAppIndex()150 inline int32_t GetAppIndex() const 151 { 152 return appIndex_; 153 } 154 SetDebugApp(bool debugApp)155 inline void SetDebugApp(bool debugApp) 156 { 157 debugApp_ = debugApp; 158 } 159 GetDebugApp()160 inline bool GetDebugApp() const 161 { 162 return debugApp_; 163 } 164 SetPerfCmd(const std::string & perfCmd)165 inline void SetPerfCmd(const std::string &perfCmd) 166 { 167 perfCmd_ = perfCmd; 168 } 169 GetPerfCmd()170 inline std::string GetPerfCmd() const 171 { 172 return perfCmd_; 173 } 174 SetMultiThread(const bool multiThread)175 inline void SetMultiThread(const bool multiThread) 176 { 177 isMultiThread_ = multiThread; 178 } 179 GetMultiThread()180 inline bool GetMultiThread() const 181 { 182 return isMultiThread_; 183 } 184 SetErrorInfoEnhance(const bool errorInfoEnhance)185 inline void SetErrorInfoEnhance(const bool errorInfoEnhance) 186 { 187 isErrorInfoEnhance_ = errorInfoEnhance; 188 } 189 GetErrorInfoEnhance()190 inline bool GetErrorInfoEnhance() const 191 { 192 return isErrorInfoEnhance_; 193 } 194 SetJITEnabled(const bool jitEnabled)195 inline void SetJITEnabled(const bool jitEnabled) 196 { 197 jitEnabled_ = jitEnabled; 198 } 199 IsJITEnabled()200 inline bool IsJITEnabled() const 201 { 202 return jitEnabled_; 203 } 204 GetAppRunningUniqueId()205 inline std::string GetAppRunningUniqueId() const 206 { 207 return appRunningUniqueId_; 208 } 209 SetAppRunningUniqueId(const std::string & appRunningUniqueId)210 inline void SetAppRunningUniqueId(const std::string &appRunningUniqueId) 211 { 212 appRunningUniqueId_ = appRunningUniqueId; 213 } 214 GetPreloadModuleName()215 inline std::string GetPreloadModuleName() const 216 { 217 return preloadModuleName_; 218 } 219 SetPreloadModuleName(const std::string & moduleName)220 inline void SetPreloadModuleName(const std::string& moduleName) 221 { 222 preloadModuleName_ = moduleName; 223 } 224 GetInstanceKey()225 inline std::string GetInstanceKey() const 226 { 227 return instanceKey_; 228 } 229 SetInstanceKey(const std::string & instanceKey)230 inline void SetInstanceKey(const std::string& instanceKey) 231 { 232 instanceKey_ = instanceKey; 233 } 234 235 /** 236 * @brief read this Sequenceable object from a Parcel. 237 * 238 * @param inParcel Indicates the Parcel object into which the Sequenceable object has been marshaled. 239 * @return Returns true if read successed; returns false otherwise. 240 */ 241 bool ReadFromParcel(Parcel &parcel); 242 243 /** 244 * @brief Marshals this Sequenceable object into a Parcel. 245 * 246 * @param outParcel Indicates the Parcel object to which the Sequenceable object will be marshaled. 247 */ 248 virtual bool Marshalling(Parcel &parcel) const override; 249 250 /** 251 * @brief to solve cyclomatic of Marshalling 252 * 253 * @param outParcel Indicates the Parcel object to which the Sequenceable object will be marshaled. 254 */ 255 bool MarshallingExtend(Parcel &parcel) const; 256 257 /** 258 * @brief Unmarshals this Sequenceable object from a Parcel. 259 * 260 * @param inParcel Indicates the Parcel object into which the Sequenceable object has been marshaled. 261 */ 262 static AppLaunchData *Unmarshalling(Parcel &parcel); 263 /** 264 * @brief Setting is aa start with native. 265 * 266 * @param isNativeStart, is aa start with native. 267 */ 268 void SetNativeStart(bool isNativeStart); 269 /** 270 * @brief Obtains is native start. 271 * 272 * @return Returns is native start. 273 */ 274 bool isNativeStart() const; 275 276 /** 277 * @brief Setting is need preload module. 278 * 279 * @param isNeedPreloadModule, is need preload module. 280 */ 281 void SetIsNeedPreloadModule(bool isNeedPreloadModule); 282 /** 283 * @brief Obtains is need preload module.. 284 * 285 * @return Returns is need preload module.. 286 */ 287 bool IsNeedPreloadModule() const; 288 289 /** 290 * @brief Setting if allow nweb preload. 291 * 292 * @param isAllowedNWebPreload, if allow nweb preload. 293 */ 294 void SetNWebPreload(const bool isAllowedNWebPreload); 295 /** 296 * @brief Get if allow nweb preload. 297 * 298 * @return Returns if allow nweb preload. 299 */ 300 bool IsAllowedNWebPreload() const; 301 302 /** 303 * @brief Setting debug mode. 304 * 305 * @param ideDebugMode, false:old debug, true:local debug. 306 */ 307 void SetDebugFromLocal(bool isDebugFromLocal); 308 /** 309 * @brief Get debug mode. 310 * 311 * @return Returns debug mode. 312 */ 313 bool GetDebugFromLocal() const; 314 315 private: 316 bool debugApp_ = false; 317 bool jitEnabled_ = false; 318 bool isNativeStart_ = false; 319 bool isMultiThread_ = false; 320 bool isErrorInfoEnhance_ = false; 321 bool isNeedPreloadModule_ = false; 322 bool isAllowedNWebPreload_ = false; 323 int32_t recordId_ = 0; 324 int32_t uId_ = 0; 325 int32_t appIndex_ = 0; 326 std::shared_ptr<UserTestRecord> userTestRecord_ = nullptr; 327 ApplicationInfo applicationInfo_; 328 Profile profile_; 329 ProcessInfo processInfo_; 330 std::string perfCmd_; 331 std::string appRunningUniqueId_; 332 std::string instanceKey_; 333 std::string preloadModuleName_; 334 bool isDebugFromLocal_; 335 }; 336 } // namespace AppExecFwk 337 } // namespace OHOS 338 #endif // OHOS_ABILITY_RUNTIME_INTERFACES_INNERKITS_APPEXECFWK_CORE_APPMGR_INCLUDE_APP_LAUNCH_DATA_H 339