• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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 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     std::unique_ptr<AppExecFwk::ElementName> hostElement(parcel.ReadParcelable<AppExecFwk::ElementName>());
41     if (hostElement == nullptr) {
42         TAG_LOGE(AAFwkTag::ABILITYMGR, "get hostElement failed");
43         delete info;
44         return nullptr;
45     }
46     info->hostElementName = *hostElement;
47     return info;
48 }
49 
Marshalling(Parcel & parcel) const50 bool UIExtensionSessionInfo::Marshalling(Parcel &parcel) const
51 {
52     if (!parcel.WriteInt32(persistentId)) {
53         TAG_LOGE(AAFwkTag::ABILITYMGR, "write persistentId failed");
54         return false;
55     }
56 
57     if (!parcel.WriteUint32(hostWindowId)) {
58         TAG_LOGE(AAFwkTag::ABILITYMGR, "write hostWindowId failed");
59         return false;
60     }
61 
62     if (!parcel.WriteUint32(static_cast<uint32_t>(uiExtensionUsage))) {
63         TAG_LOGE(AAFwkTag::ABILITYMGR, "write uiExtensionUsage failed");
64         return false;
65     }
66 
67     if (!parcel.WriteParcelable(&elementName)) {
68         TAG_LOGE(AAFwkTag::ABILITYMGR, "write elementName failed");
69         return false;
70     }
71 
72     if (!parcel.WriteInt32(static_cast<int32_t>(extensionAbilityType))) {
73         TAG_LOGE(AAFwkTag::ABILITYMGR, "write extensionAbilityType failed");
74         return false;
75     }
76 
77     if (!parcel.WriteParcelable(&hostElementName)) {
78         TAG_LOGE(AAFwkTag::ABILITYMGR, "write hostElementName failed");
79         return false;
80     }
81 
82     return true;
83 }
84 } // namespace AbilityRuntime
85 } // namespace OHOS
86