• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef OHOS_ABILITY_RUNTIME_WINDOW_INFO_H
17 #define OHOS_ABILITY_RUNTIME_WINDOW_INFO_H
18 
19 #ifdef SUPPORT_GRAPHICS
20 #include <typeinfo>
21 
22 #include "ability_info.h"
23 #include "iremote_object.h"
24 #include "parcel.h"
25 
26 namespace OHOS {
27 namespace AAFwk {
28 namespace {
29     constexpr int32_t WINDOW_MODE_MAX_SIZE = 4;
30 }
31 
32 enum class TransitionReason : uint32_t {
33     MINIMIZE = 0,
34     CLOSE,
35     ABILITY_TRANSITION,
36     BACK_TRANSITION,
37     CLOSE_BUTTON,
38     BACKGROUND_TRANSITION,
39 };
40 
41 struct AbilityTransitionInfo : public Parcelable {
42     bool isShowWhenLocked_ = false;
43     bool isRecent_ = false;
44     uint32_t mode_ = 0;
45     uint32_t maxWindowWidth_;
46     uint32_t minWindowWidth_;
47     uint32_t maxWindowHeight_;
48     uint32_t minWindowHeight_;
49     uint32_t apiCompatibleVersion_ = 0;
50     int32_t missionId_;
51     TransitionReason reason_ = TransitionReason::ABILITY_TRANSITION;
52     uint64_t displayId_ = 0;
53     double maxWindowRatio_;
54     double minWindowRatio_;
55     sptr<IRemoteObject> abilityToken_ = nullptr;
56     std::string bundleName_;
57     std::string abilityName_;
58     std::vector<AppExecFwk::SupportWindowMode> windowModes_;
59 
60     AppExecFwk::DisplayOrientation orientation_ = AppExecFwk::DisplayOrientation::UNSPECIFIED;
61 
MarshallingAbilityTransitionInfo62     virtual bool Marshalling(Parcel& parcel) const override
63     {
64         if (!parcel.WriteString(bundleName_)) {
65             return false;
66         }
67 
68         if (!parcel.WriteString(abilityName_)) {
69             return false;
70         }
71 
72         if (!parcel.WriteUint32(mode_)) {
73             return false;
74         }
75 
76         if (!WriteAbilityToken(parcel)) {
77             return false;
78         }
79 
80         if (!(parcel.WriteUint64(displayId_) && parcel.WriteBool(isShowWhenLocked_) && parcel.WriteBool(isRecent_))) {
81             return false;
82         }
83 
84         auto size = windowModes_.size();
85         if (size > 0 && size <= WINDOW_MODE_MAX_SIZE) {
86             if (!parcel.WriteUint32(static_cast<uint32_t>(size))) {
87                 return false;
88             }
89             for (decltype(size) i = 0; i < size; i++) {
90                 if (!parcel.WriteUint32(static_cast<uint32_t>(windowModes_[i]))) {
91                     return false;
92                 }
93             }
94         } else {
95             if (!parcel.WriteUint32(0)) {
96                 return false;
97             }
98         }
99 
100         if (!WriteWindowInfo(parcel)) {
101             return false;
102         }
103 
104         if (!parcel.WriteInt32(missionId_)) {
105             return false;
106         }
107 
108         if (!parcel.WriteUint32(static_cast<uint32_t>(reason_))) {
109             return false;
110         }
111 
112         if (!parcel.WriteUint32(static_cast<uint32_t>(orientation_))) {
113             return false;
114         }
115 
116         if (!parcel.WriteUint32(static_cast<uint32_t>(apiCompatibleVersion_))) {
117             return false;
118         }
119         return true;
120     }
121 
WriteAbilityTokenAbilityTransitionInfo122     bool WriteAbilityToken(Parcel& parcel) const
123     {
124         if (!abilityToken_) {
125             if (!parcel.WriteBool(false)) {
126                 return false;
127             }
128         } else {
129             if (!parcel.WriteBool(true)) {
130                 return false;
131             }
132             if (!parcel.WriteRemoteObject(abilityToken_)) {
133                 return false;
134             }
135         }
136 
137         return true;
138     }
139 
WriteWindowInfoAbilityTransitionInfo140     bool WriteWindowInfo(Parcel& parcel) const
141     {
142         return (parcel.WriteDouble(maxWindowRatio_) && parcel.WriteDouble(minWindowRatio_) &&
143             parcel.WriteUint32(maxWindowWidth_) && parcel.WriteUint32(minWindowWidth_) &&
144             parcel.WriteUint32(maxWindowHeight_) && parcel.WriteUint32(minWindowHeight_));
145     }
146 
UnmarshallingAbilityTransitionInfo147     static AbilityTransitionInfo* Unmarshalling(Parcel& parcel)
148     {
149         AbilityTransitionInfo* info = new AbilityTransitionInfo();
150         info->bundleName_ = parcel.ReadString();
151         info->abilityName_ = parcel.ReadString();
152         info->mode_ = parcel.ReadUint32();
153         if (parcel.ReadBool()) {
154             info->abilityToken_ = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
155         }
156         info->displayId_ = parcel.ReadUint64();
157         info->isShowWhenLocked_ = parcel.ReadBool();
158         info->isRecent_ = parcel.ReadBool();
159         auto size = parcel.ReadUint32();
160         if (size > 0 && size <= WINDOW_MODE_MAX_SIZE) {
161             for (decltype(size) i = 0; i < size; i++) {
162                 info->windowModes_.push_back(static_cast<AppExecFwk::SupportWindowMode>(parcel.ReadUint32()));
163             }
164         }
165         info->maxWindowRatio_ = parcel.ReadDouble();
166         info->minWindowRatio_ = parcel.ReadDouble();
167         info->maxWindowWidth_ = parcel.ReadUint32();
168         info->minWindowWidth_ = parcel.ReadUint32();
169         info->maxWindowHeight_ = parcel.ReadUint32();
170         info->minWindowHeight_ = parcel.ReadUint32();
171         info->missionId_ = parcel.ReadInt32();
172         info->reason_ = static_cast<TransitionReason>(parcel.ReadUint32());
173         info->orientation_ = static_cast<AppExecFwk::DisplayOrientation>(parcel.ReadUint32());
174         info->apiCompatibleVersion_ = parcel.ReadUint32();
175         return info;
176     }
177 };
178 } // namespace AAFwk
179 } // namespace OHOS
180 #endif
181 #endif // OHOS_ABILITY_RUNTIME_WINDOW_INFO_H
182