1 /*
2 * Copyright (c) 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 "ui_extension_session_info.h"
17
18 #include "hilog_tag_wrapper.h"
19
20 namespace OHOS {
21 namespace AbilityRuntime {
Unmarshalling(Parcel & parcel)22 UIExtensionSessionInfo *UIExtensionSessionInfo::Unmarshalling(Parcel &parcel)
23 {
24 UIExtensionSessionInfo *info = new (std::nothrow) UIExtensionSessionInfo();
25 if (info == nullptr) {
26 TAG_LOGE(AAFwkTag::ABILITYMGR, "Create ui extension session info failed.");
27 return nullptr;
28 }
29 info->persistentId = parcel.ReadInt32();
30 info->hostWindowId = parcel.ReadUint32();
31 info->uiExtensionUsage = static_cast<AAFwk::UIExtensionUsage>(parcel.ReadUint32());
32 std::unique_ptr<AppExecFwk::ElementName> element(parcel.ReadParcelable<AppExecFwk::ElementName>());
33 if (element == nullptr) {
34 TAG_LOGE(AAFwkTag::ABILITYMGR, "get element failed");
35 delete info;
36 return nullptr;
37 }
38 info->elementName = *element;
39 info->extensionAbilityType = static_cast<AppExecFwk::ExtensionAbilityType>(parcel.ReadInt32());
40 return info;
41 }
42
Marshalling(Parcel & parcel) const43 bool UIExtensionSessionInfo::Marshalling(Parcel &parcel) const
44 {
45 if (!parcel.WriteInt32(persistentId)) {
46 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write persistent id failed.");
47 return false;
48 }
49
50 if (!parcel.WriteUint32(hostWindowId)) {
51 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write host window id failed.");
52 return false;
53 }
54
55 if (!parcel.WriteUint32(static_cast<uint32_t>(uiExtensionUsage))) {
56 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write uiExtensionUsage failed.");
57 return false;
58 }
59
60 if (!parcel.WriteParcelable(&elementName)) {
61 TAG_LOGE(AAFwkTag::ABILITYMGR, "write elementName failed");
62 return false;
63 }
64
65 if (!parcel.WriteInt32(static_cast<int32_t>(extensionAbilityType))) {
66 TAG_LOGE(AAFwkTag::ABILITYMGR, "write extensionAbilityType failed");
67 return false;
68 }
69
70 return true;
71 }
72 } // namespace AbilityRuntime
73 } // namespace OHOS
74