1 /* 2 * Copyright (c) 2023-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 "session_info.h" 17 18 #include "ability_base_log_wrapper.h" 19 #include "ability_start_setting.h" 20 #include "process_options.h" 21 #include "start_window_option.h" 22 23 namespace OHOS { 24 namespace AAFwk { 25 constexpr int MAX_SUPPOPRT_WINDOW_MODES_SIZE = 10; 26 Marshalling(Parcel & parcel) const27bool SessionInfo::Marshalling(Parcel& parcel) const 28 { 29 if (!DoMarshallingOne(parcel)) { 30 return false; 31 } 32 33 if (!DoMarshallingTwo(parcel)) { 34 return false; 35 } 36 37 if (!DoMarshallingThree(parcel)) { 38 return false; 39 } 40 41 if (!DoMarshallingFour(parcel)) { 42 return false; 43 } 44 45 if (!DoMarshallingFive(parcel)) { 46 return false; 47 } 48 49 return DoMarshallingSix(parcel); 50 } 51 DoMarshallingOne(Parcel & parcel) const52bool SessionInfo::DoMarshallingOne(Parcel& parcel) const 53 { 54 if (sessionToken) { 55 if (!parcel.WriteBool(true) || 56 !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(sessionToken)) { 57 ABILITYBASE_LOGE("Write session token failed"); 58 return false; 59 } 60 } else { 61 if (!parcel.WriteBool(false)) { 62 return false; 63 } 64 } 65 66 if (callerSession) { 67 if (!parcel.WriteBool(true) || 68 !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(callerSession)) { 69 ABILITYBASE_LOGE("Write caller session failed"); 70 return false; 71 } 72 } else { 73 if (!parcel.WriteBool(false)) { 74 return false; 75 } 76 } 77 78 if (callerToken) { 79 if (!parcel.WriteBool(true) || 80 !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(callerToken)) { 81 ABILITYBASE_LOGE("Write caller token failed"); 82 return false; 83 } 84 } else { 85 if (!parcel.WriteBool(false)) { 86 return false; 87 } 88 } 89 90 if (parentToken) { 91 if (!parcel.WriteBool(true) || 92 !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(parentToken)) { 93 ABILITYBASE_LOGE("Write parent token failed"); 94 return false; 95 } 96 } else { 97 if (!parcel.WriteBool(false)) { 98 return false; 99 } 100 } 101 return true; 102 } 103 DoMarshallingTwo(Parcel & parcel) const104bool SessionInfo::DoMarshallingTwo(Parcel& parcel) const 105 { 106 if (!parcel.WriteString(identityToken)) { 107 ABILITYBASE_LOGE("Write identityToken failed"); 108 return false; 109 } 110 111 if (!parcel.WriteUint32(parentWindowType)) { 112 ABILITYBASE_LOGE("Write parent window type failed."); 113 return false; 114 } 115 116 return true; 117 } 118 DoMarshallingThree(Parcel & parcel) const119bool SessionInfo::DoMarshallingThree(Parcel& parcel) const 120 { 121 if (!parcel.WriteInt32(persistentId)) { 122 ABILITYBASE_LOGE("Write persistent id failed"); 123 return false; 124 } 125 126 if (!parcel.WriteUint32(hostWindowId)) { 127 ABILITYBASE_LOGE("Write host window id failed"); 128 return false; 129 } 130 131 if (!parcel.WriteUint32(realHostWindowId)) { 132 ABILITYBASE_LOGE("Write real host window id failed."); 133 return false; 134 } 135 136 if (!parcel.WriteUint32(static_cast<uint32_t>(state))) { 137 ABILITYBASE_LOGE("Write state failed"); 138 return false; 139 } 140 141 if (!parcel.WriteInt32(resultCode)) { 142 ABILITYBASE_LOGE("Write resultCode failed"); 143 return false; 144 } 145 146 if (!parcel.WriteInt32(requestCode)) { 147 ABILITYBASE_LOGE("Write requestCode failed"); 148 return false; 149 } 150 151 if (!parcel.WriteString(errorReason)) { 152 ABILITYBASE_LOGE("Write errorReason failed"); 153 return false; 154 } 155 156 if (!parcel.WriteInt32(errorCode)) { 157 ABILITYBASE_LOGE("Write errorCode failed"); 158 return false; 159 } 160 161 if (!parcel.WriteInt64(uiAbilityId)) { 162 ABILITYBASE_LOGE("Write uiAbilityId failed"); 163 return false; 164 } 165 166 if (!parcel.WriteParcelable(startSetting.get())) { 167 ABILITYBASE_LOGE("Write startSetting failed"); 168 return false; 169 } 170 171 if (!parcel.WriteParcelable(processOptions.get())) { 172 ABILITYBASE_LOGE("Write processOptions failed"); 173 return false; 174 } 175 return true; 176 } 177 DoMarshallingFour(Parcel & parcel) const178bool SessionInfo::DoMarshallingFour(Parcel& parcel) const 179 { 180 if (!parcel.WriteBool(isNewWant)) { 181 ABILITYBASE_LOGE("Write isNewWant failed"); 182 return false; 183 } 184 185 if (!parcel.WriteBool(isClearSession)) { 186 ABILITYBASE_LOGE("Write isClearSession failed"); 187 return false; 188 } 189 190 if (!parcel.WriteUint32(callingTokenId)) { 191 ABILITYBASE_LOGE("Write callingTokenId failed"); 192 return false; 193 } 194 195 if (!parcel.WriteBool(reuse)) { 196 ABILITYBASE_LOGE("Write reuse failed"); 197 return false; 198 } 199 200 if (!parcel.WriteBool(canStartAbilityFromBackground)) { 201 ABILITYBASE_LOGE("Write canStartAbilityFromBackground failed."); 202 return false; 203 } 204 205 if (!parcel.WriteInt32(collaboratorType)) { 206 ABILITYBASE_LOGE("Write collaboratorType failed"); 207 return false; 208 } 209 210 if (!parcel.WriteString(sessionName)) { 211 ABILITYBASE_LOGE("Write sessionName failed"); 212 return false; 213 } 214 215 if (!parcel.WriteUint64(uiExtensionComponentId)) { 216 ABILITYBASE_LOGE("Write uiExtensionComponentId failed"); 217 return false; 218 } 219 220 if (!parcel.WriteBool(isAsyncModalBinding)) { 221 ABILITYBASE_LOGE("Write isAsyncModalBinding failed"); 222 return false; 223 } 224 225 if (!parcel.WriteUint32(static_cast<uint32_t>(uiExtensionUsage))) { 226 ABILITYBASE_LOGE("Write uiExtensionUsage failed"); 227 return false; 228 } 229 230 if (!parcel.WriteBool(isAtomicService)) { 231 ABILITYBASE_LOGE("Write isAtomicService failed"); 232 return false; 233 } 234 235 return true; 236 } 237 DoMarshallingFive(Parcel & parcel) const238bool SessionInfo::DoMarshallingFive(Parcel& parcel) const 239 { 240 if (!parcel.WriteBool(isBackTransition)) { 241 ABILITYBASE_LOGE("Write isBackTransition failed."); 242 return false; 243 } 244 245 if (!parcel.WriteBool(isSkipErms)) { 246 ABILITYBASE_LOGE("Write isSkipErms failed."); 247 return false; 248 } 249 250 if (!parcel.WriteUint64(displayId)) { 251 ABILITYBASE_LOGE("Write displayId failed."); 252 return false; 253 } 254 255 if (!parcel.WriteFloat(density)) { 256 ABILITYBASE_LOGE("Write density failed."); 257 return false; 258 } 259 260 if (!parcel.WriteInt32(orientation)) { 261 ABILITYBASE_LOGE("Write orientation failed."); 262 return false; 263 } 264 265 if (!parcel.WriteBool(needClearInNotShowRecent)) { 266 ABILITYBASE_LOGE("Write needClearInNotShowRecent failed"); 267 return false; 268 } 269 270 if (!parcel.WriteString(instanceKey)) { 271 ABILITYBASE_LOGE("Write instanceKey failed"); 272 return false; 273 } 274 275 if (!parcel.WriteBool(isFromIcon)) { 276 ABILITYBASE_LOGE("Write isFromIcon failed"); 277 return false; 278 } 279 280 if (!parcel.WriteInt32(requestId)) { 281 ABILITYBASE_LOGE("Write requestId failed"); 282 return false; 283 } 284 return true; 285 } 286 DoMarshallingSix(Parcel & parcel) const287bool SessionInfo::DoMarshallingSix(Parcel& parcel) const 288 { 289 if (!parcel.WriteInt32(isDensityFollowHost)) { 290 ABILITYBASE_LOGE("Write isDensityFollowHost failed"); 291 return false; 292 } 293 294 if (!parcel.WriteString(specifiedFlag)) { 295 ABILITYBASE_LOGE("Write specifiedFlag failed"); 296 return false; 297 } 298 299 if (!parcel.WriteParcelable(&want)) { 300 ABILITYBASE_LOGE("Write want failed"); 301 return false; 302 } 303 304 if (!parcel.WriteParcelable(startWindowOption.get())) { 305 ABILITYBASE_LOGE("Write startWindowOption failed"); 306 return false; 307 } 308 309 parcel.WriteInt32(supportWindowModes.size()); 310 for (auto windowMode : supportWindowModes) { 311 parcel.WriteInt32(static_cast<int32_t>(windowMode)); 312 } 313 return true; 314 } 315 Unmarshalling(Parcel & parcel)316SessionInfo* SessionInfo::Unmarshalling(Parcel& parcel) 317 { 318 SessionInfo* info = new (std::nothrow) SessionInfo(); 319 if (info == nullptr) { 320 ABILITYBASE_LOGE("new SessionInfo failed"); 321 return nullptr; 322 } 323 if (parcel.ReadBool()) { 324 info->sessionToken = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 325 } 326 327 if (parcel.ReadBool()) { 328 info->callerSession = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 329 } 330 331 if (parcel.ReadBool()) { 332 info->callerToken = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 333 } 334 335 if (parcel.ReadBool()) { 336 info->parentToken = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 337 } 338 return ReadParcelOne(info, parcel); 339 } 340 ReadParcelOne(SessionInfo * info,Parcel & parcel)341SessionInfo* SessionInfo::ReadParcelOne(SessionInfo* info, Parcel& parcel) 342 { 343 info->identityToken = parcel.ReadString(); 344 info->parentWindowType = parcel.ReadUint32(); 345 info->persistentId = parcel.ReadInt32(); 346 info->hostWindowId = parcel.ReadUint32(); 347 info->realHostWindowId = parcel.ReadInt32(); 348 info->state = static_cast<CallToState>(parcel.ReadUint32()); 349 info->resultCode = parcel.ReadInt32(); 350 info->requestCode = parcel.ReadInt32(); 351 info->errorReason = parcel.ReadString(); 352 info->errorCode = parcel.ReadInt32(); 353 info->uiAbilityId = parcel.ReadInt64(); 354 info->startSetting.reset(parcel.ReadParcelable<AbilityStartSetting>()); 355 info->processOptions.reset(parcel.ReadParcelable<ProcessOptions>()); 356 info->isNewWant = parcel.ReadBool(); 357 info->isClearSession = parcel.ReadBool(); 358 info->callingTokenId = parcel.ReadUint32(); 359 info->reuse = parcel.ReadBool(); 360 info->canStartAbilityFromBackground = parcel.ReadBool(); 361 info->collaboratorType = parcel.ReadInt32(); 362 info->sessionName = parcel.ReadString(); 363 info->uiExtensionComponentId = parcel.ReadUint64(); 364 info->isAsyncModalBinding = parcel.ReadBool(); 365 info->uiExtensionUsage = static_cast<UIExtensionUsage>(parcel.ReadUint32()); 366 info->isAtomicService = parcel.ReadBool(); 367 info->isBackTransition = parcel.ReadBool(); 368 info->isSkipErms = parcel.ReadBool(); 369 info->displayId = parcel.ReadUint64(); 370 info->density = parcel.ReadFloat(); 371 info->orientation = parcel.ReadInt32(); 372 info->needClearInNotShowRecent = parcel.ReadBool(); 373 info->instanceKey = parcel.ReadString(); 374 info->isFromIcon = parcel.ReadBool(); 375 info->requestId = parcel.ReadInt32(); 376 info->isDensityFollowHost = parcel.ReadBool(); 377 info->specifiedFlag = parcel.ReadString(); 378 379 std::unique_ptr<Want> want(parcel.ReadParcelable<Want>()); 380 if (want != nullptr) { 381 info->want = *want; 382 } 383 info->startWindowOption.reset(parcel.ReadParcelable<StartWindowOption>()); 384 auto size = parcel.ReadInt32(); 385 if (size <= MAX_SUPPOPRT_WINDOW_MODES_SIZE) { 386 for (int i = 0; i < size; i++) { 387 info->supportWindowModes.emplace_back(AppExecFwk::SupportWindowMode(parcel.ReadInt32())); 388 } 389 } 390 return info; 391 } 392 } // namespace AAFwk 393 } // namespace OHOS 394