1 /* 2 * Copyright (c) 2023 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 return DoMarshallingFive(parcel); 46 } 47 DoMarshallingOne(Parcel & parcel) const48bool SessionInfo::DoMarshallingOne(Parcel& parcel) const 49 { 50 if (sessionToken) { 51 if (!parcel.WriteBool(true) || 52 !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(sessionToken)) { 53 ABILITYBASE_LOGE("Write session token failed"); 54 return false; 55 } 56 } else { 57 if (!parcel.WriteBool(false)) { 58 return false; 59 } 60 } 61 62 if (callerSession) { 63 if (!parcel.WriteBool(true) || 64 !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(callerSession)) { 65 ABILITYBASE_LOGE("Write caller session failed"); 66 return false; 67 } 68 } else { 69 if (!parcel.WriteBool(false)) { 70 return false; 71 } 72 } 73 74 if (callerToken) { 75 if (!parcel.WriteBool(true) || 76 !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(callerToken)) { 77 ABILITYBASE_LOGE("Write caller token failed"); 78 return false; 79 } 80 } else { 81 if (!parcel.WriteBool(false)) { 82 return false; 83 } 84 } 85 86 if (parentToken) { 87 if (!parcel.WriteBool(true) || 88 !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(parentToken)) { 89 ABILITYBASE_LOGE("Write parent token failed"); 90 return false; 91 } 92 } else { 93 if (!parcel.WriteBool(false)) { 94 return false; 95 } 96 } 97 return true; 98 } 99 DoMarshallingTwo(Parcel & parcel) const100bool SessionInfo::DoMarshallingTwo(Parcel& parcel) const 101 { 102 if (!parcel.WriteString(identityToken)) { 103 ABILITYBASE_LOGE("Write identityToken failed"); 104 return false; 105 } 106 if (!parcel.WriteUint32(parentWindowType)) { 107 ABILITYBASE_LOGE("Write parent window type failed."); 108 return false; 109 } 110 return true; 111 } 112 DoMarshallingThree(Parcel & parcel) const113bool SessionInfo::DoMarshallingThree(Parcel& parcel) const 114 { 115 if (!parcel.WriteInt32(persistentId)) { 116 ABILITYBASE_LOGE("Write persistent id failed"); 117 return false; 118 } 119 120 if (!parcel.WriteUint32(hostWindowId)) { 121 ABILITYBASE_LOGE("Write host window id failed"); 122 return false; 123 } 124 125 if (!parcel.WriteInt32(realHostWindowId)) { 126 ABILITYBASE_LOGE("Write real host window id failed"); 127 return false; 128 } 129 130 if (!parcel.WriteUint32(static_cast<uint32_t>(state))) { 131 ABILITYBASE_LOGE("Write state failed"); 132 return false; 133 } 134 135 if (!parcel.WriteInt32(resultCode)) { 136 ABILITYBASE_LOGE("Write resultCode failed"); 137 return false; 138 } 139 140 if (!parcel.WriteInt32(requestCode)) { 141 ABILITYBASE_LOGE("Write requestCode failed"); 142 return false; 143 } 144 145 if (!parcel.WriteString(errorReason)) { 146 ABILITYBASE_LOGE("Write errorReason failed"); 147 return false; 148 } 149 150 if (!parcel.WriteInt32(errorCode)) { 151 ABILITYBASE_LOGE("Write errorCode failed"); 152 return false; 153 } 154 155 if (!parcel.WriteInt64(uiAbilityId)) { 156 ABILITYBASE_LOGE("Write uiAbilityId failed"); 157 return false; 158 } 159 160 if (!parcel.WriteParcelable(startSetting.get())) { 161 ABILITYBASE_LOGE("Write startSetting failed"); 162 return false; 163 } 164 165 if (!parcel.WriteParcelable(processOptions.get())) { 166 ABILITYBASE_LOGE("Write processOptions failed"); 167 return false; 168 } 169 return true; 170 } 171 DoMarshallingFour(Parcel & parcel) const172bool SessionInfo::DoMarshallingFour(Parcel& parcel) const 173 { 174 if (!parcel.WriteBool(isNewWant)) { 175 ABILITYBASE_LOGE("Write isNewWant failed"); 176 return false; 177 } 178 179 if (!parcel.WriteBool(isClearSession)) { 180 ABILITYBASE_LOGE("Write isClearSession failed"); 181 return false; 182 } 183 184 if (!parcel.WriteUint32(callingTokenId)) { 185 ABILITYBASE_LOGE("Write callingTokenId failed"); 186 return false; 187 } 188 189 if (!parcel.WriteBool(reuse)) { 190 ABILITYBASE_LOGE("Write reuse failed"); 191 return false; 192 } 193 194 if (!parcel.WriteBool(canStartAbilityFromBackground)) { 195 ABILITYBASE_LOGE("Write canStartAbilityFromBackground failed."); 196 return false; 197 } 198 199 if (!parcel.WriteInt32(collaboratorType)) { 200 ABILITYBASE_LOGE("Write collaboratorType failed"); 201 return false; 202 } 203 204 if (!parcel.WriteString(sessionName)) { 205 ABILITYBASE_LOGE("Write sessionName failed"); 206 return false; 207 } 208 209 if (!parcel.WriteUint64(uiExtensionComponentId)) { 210 ABILITYBASE_LOGE("Write uiExtensionComponentId failed"); 211 return false; 212 } 213 214 if (!parcel.WriteBool(isAsyncModalBinding)) { 215 ABILITYBASE_LOGE("Write isAsyncModalBinding failed"); 216 return false; 217 } 218 219 if (!parcel.WriteUint32(static_cast<uint32_t>(uiExtensionUsage))) { 220 ABILITYBASE_LOGE("Write uiExtensionUsage failed"); 221 return false; 222 } 223 224 if (!parcel.WriteBool(isAtomicService)) { 225 ABILITYBASE_LOGE("Write isAtomicService failed"); 226 return false; 227 } 228 229 return true; 230 } 231 DoMarshallingFive(Parcel & parcel) const232bool SessionInfo::DoMarshallingFive(Parcel& parcel) const 233 { 234 if (!parcel.WriteBool(isBackTransition)) { 235 ABILITYBASE_LOGE("Write isBackTransition failed."); 236 return false; 237 } 238 239 if (!parcel.WriteBool(needClearInNotShowRecent)) { 240 ABILITYBASE_LOGE("Write needClearInNotShowRecent failed"); 241 return false; 242 } 243 244 if (!parcel.WriteBool(isFromIcon)) { 245 ABILITYBASE_LOGE("Write isFromIcon failed"); 246 return false; 247 } 248 249 if (!parcel.WriteParcelable(&want)) { 250 ABILITYBASE_LOGE("Write want failed"); 251 return false; 252 } 253 254 if (!parcel.WriteParcelable(startWindowOption.get())) { 255 ABILITYBASE_LOGE("Write startWindowOption failed"); 256 return false; 257 } 258 259 parcel.WriteInt32(supportWindowModes.size()); 260 for (auto windowMode : supportWindowModes) { 261 parcel.WriteInt32(static_cast<int32_t>(windowMode)); 262 } 263 return true; 264 } 265 Unmarshalling(Parcel & parcel)266SessionInfo* SessionInfo::Unmarshalling(Parcel& parcel) 267 { 268 SessionInfo* info = new SessionInfo(); 269 if (parcel.ReadBool()) { 270 info->sessionToken = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 271 } 272 273 if (parcel.ReadBool()) { 274 info->callerSession = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 275 } 276 277 if (parcel.ReadBool()) { 278 info->callerToken = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 279 } 280 281 if (parcel.ReadBool()) { 282 info->parentToken = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 283 } 284 285 info->identityToken = parcel.ReadString(); 286 info->parentWindowType = parcel.ReadUint32(); 287 info->persistentId = parcel.ReadInt32(); 288 info->hostWindowId = parcel.ReadUint32(); 289 info->realHostWindowId = parcel.ReadInt32(); 290 info->state = static_cast<CallToState>(parcel.ReadUint32()); 291 info->resultCode = parcel.ReadInt32(); 292 info->requestCode = parcel.ReadInt32(); 293 info->errorReason = parcel.ReadString(); 294 info->errorCode = parcel.ReadInt32(); 295 info->uiAbilityId = parcel.ReadInt64(); 296 info->startSetting.reset(parcel.ReadParcelable<AbilityStartSetting>()); 297 info->processOptions.reset(parcel.ReadParcelable<ProcessOptions>()); 298 info->isNewWant = parcel.ReadBool(); 299 info->isClearSession = parcel.ReadBool(); 300 info->callingTokenId = parcel.ReadUint32(); 301 info->reuse = parcel.ReadBool(); 302 info->canStartAbilityFromBackground = parcel.ReadBool(); 303 info->collaboratorType = parcel.ReadInt32(); 304 info->sessionName = parcel.ReadString(); 305 info->uiExtensionComponentId = parcel.ReadUint64(); 306 info->isAsyncModalBinding = parcel.ReadBool(); 307 info->uiExtensionUsage = static_cast<UIExtensionUsage>(parcel.ReadUint32()); 308 info->isAtomicService = parcel.ReadBool(); 309 info->isBackTransition = parcel.ReadBool(); 310 info->needClearInNotShowRecent = parcel.ReadBool(); 311 info->isFromIcon = parcel.ReadBool(); 312 313 std::unique_ptr<Want> want(parcel.ReadParcelable<Want>()); 314 if (want != nullptr) { 315 info->want = *want; 316 } 317 info->startWindowOption.reset(parcel.ReadParcelable<StartWindowOption>()); 318 auto size = parcel.ReadInt32(); 319 if (size <= MAX_SUPPOPRT_WINDOW_MODES_SIZE) { 320 for (int i = 0; i < size; i++) { 321 info->supportWindowModes.emplace_back(AppExecFwk::SupportWindowMode(parcel.ReadInt32())); 322 } 323 } 324 return info; 325 } 326 } // namespace AAFwk 327 } // namespace OHOS 328