1 /*
2  * Copyright (c) 2021-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 "app_state_data.h"
17 
18 #include "hilog_tag_wrapper.h"
19 #include "ui_extension_utils.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
Marshalling(Parcel & parcel) const23 bool AppStateData::Marshalling(Parcel &parcel) const
24 {
25     return (parcel.WriteString(bundleName) && parcel.WriteInt32(uid) && parcel.WriteInt32(state)
26         && parcel.WriteInt32(pid) && parcel.WriteUint32(accessTokenId) && parcel.WriteBool(isFocused)
27         && parcel.WriteInt32(static_cast<int32_t>(extensionType)) && parcel.WriteInt32Vector(renderPids)
28         && parcel.WriteString(callerBundleName) && parcel.WriteBool(isSplitScreenMode)
29         && parcel.WriteBool(isFloatingWindowMode) && parcel.WriteInt32(appIndex) && parcel.WriteBool(isPreloadModule));
30 }
31 
ReadFromParcel(Parcel & parcel)32 bool AppStateData::ReadFromParcel(Parcel &parcel)
33 {
34     bundleName = parcel.ReadString();
35     uid = parcel.ReadInt32();
36     state = parcel.ReadInt32();
37     pid = parcel.ReadInt32();
38     accessTokenId = parcel.ReadUint32();
39     isFocused = parcel.ReadBool();
40     extensionType = static_cast<ExtensionAbilityType>(parcel.ReadInt32());
41     parcel.ReadInt32Vector(&renderPids);
42     callerBundleName = parcel.ReadString();
43     isSplitScreenMode = parcel.ReadBool();
44     isFloatingWindowMode = parcel.ReadBool();
45     appIndex = parcel.ReadInt32();
46     isPreloadModule = parcel.ReadBool();
47 
48     return true;
49 }
50 
Unmarshalling(Parcel & parcel)51 AppStateData *AppStateData::Unmarshalling(Parcel &parcel)
52 {
53     AppStateData *appStateData = new (std::nothrow) AppStateData();
54     if (appStateData && !appStateData->ReadFromParcel(parcel)) {
55         TAG_LOGW(AAFwkTag::APPMGR, "appStateData failed, because ReadFromParcel failed");
56         delete appStateData;
57         appStateData = nullptr;
58     }
59     return appStateData;
60 }
61 
IsUIExtension(const AppExecFwk::ExtensionAbilityType type)62 bool AppStateData::IsUIExtension(const AppExecFwk::ExtensionAbilityType type)
63 {
64     return AAFwk::UIExtensionUtils::IsUIExtension(type);
65 }
66 }  // namespace AppExecFwk
67 }  // namespace OHOS
68