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 }; 38 39 struct AbilityTransitionInfo : public Parcelable { 40 std::string bundleName_; 41 std::string abilityName_; 42 uint32_t mode_ = 0; 43 std::vector<AppExecFwk::SupportWindowMode> windowModes_; 44 sptr<IRemoteObject> abilityToken_ = nullptr; 45 uint64_t displayId_ = 0; 46 bool isShowWhenLocked_ = false; 47 bool isRecent_ = false; 48 double maxWindowRatio_; 49 double minWindowRatio_; 50 uint32_t maxWindowWidth_; 51 uint32_t minWindowWidth_; 52 uint32_t maxWindowHeight_; 53 uint32_t minWindowHeight_; 54 int32_t missionId_; 55 TransitionReason reason_ = TransitionReason::ABILITY_TRANSITION; 56 MarshallingAbilityTransitionInfo57 virtual bool Marshalling(Parcel& parcel) const override 58 { 59 if (!parcel.WriteString(bundleName_)) { 60 return false; 61 } 62 63 if (!parcel.WriteString(abilityName_)) { 64 return false; 65 } 66 67 if (!parcel.WriteUint32(mode_)) { 68 return false; 69 } 70 71 if (!WriteAbilityToken(parcel)) { 72 return false; 73 } 74 75 if (!(parcel.WriteUint64(displayId_) && parcel.WriteBool(isShowWhenLocked_) && parcel.WriteBool(isRecent_))) { 76 return false; 77 } 78 79 auto size = windowModes_.size(); 80 if (size > 0 && size <= WINDOW_MODE_MAX_SIZE) { 81 if (!parcel.WriteUint32(static_cast<uint32_t>(size))) { 82 return false; 83 } 84 for (decltype(size) i = 0; i < size; i++) { 85 if (!parcel.WriteUint32(static_cast<uint32_t>(windowModes_[i]))) { 86 return false; 87 } 88 } 89 } else { 90 if (!parcel.WriteUint32(0)) { 91 return false; 92 } 93 } 94 95 if (!WriteWindowInfo(parcel)) { 96 return false; 97 } 98 99 if (!parcel.WriteInt32(missionId_)) { 100 return false; 101 } 102 103 if (!parcel.WriteUint32(static_cast<uint32_t>(reason_))) { 104 return false; 105 } 106 return true; 107 } 108 WriteAbilityTokenAbilityTransitionInfo109 bool WriteAbilityToken(Parcel& parcel) const 110 { 111 if (!abilityToken_) { 112 if (!parcel.WriteBool(false)) { 113 return false; 114 } 115 } else { 116 if (!parcel.WriteBool(true)) { 117 return false; 118 } 119 if (!parcel.WriteObject(abilityToken_)) { 120 return false; 121 } 122 } 123 124 return true; 125 } 126 WriteWindowInfoAbilityTransitionInfo127 bool WriteWindowInfo(Parcel& parcel) const 128 { 129 return (parcel.WriteDouble(maxWindowRatio_) && parcel.WriteDouble(minWindowRatio_) && 130 parcel.WriteUint32(maxWindowWidth_) && parcel.WriteUint32(minWindowWidth_) && 131 parcel.WriteUint32(maxWindowHeight_) && parcel.WriteUint32(minWindowHeight_)); 132 } 133 UnmarshallingAbilityTransitionInfo134 static AbilityTransitionInfo* Unmarshalling(Parcel& parcel) 135 { 136 AbilityTransitionInfo* info = new AbilityTransitionInfo(); 137 info->bundleName_ = parcel.ReadString(); 138 info->abilityName_ = parcel.ReadString(); 139 info->mode_ = parcel.ReadUint32(); 140 if (parcel.ReadBool()) { 141 info->abilityToken_ = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 142 } 143 info->displayId_ = parcel.ReadUint64(); 144 info->isShowWhenLocked_ = parcel.ReadBool(); 145 info->isRecent_ = parcel.ReadBool(); 146 auto size = parcel.ReadUint32(); 147 if (size > 0 && size <= WINDOW_MODE_MAX_SIZE) { 148 for (decltype(size) i = 0; i < size; i++) { 149 info->windowModes_.push_back(static_cast<AppExecFwk::SupportWindowMode>(parcel.ReadUint32())); 150 } 151 } 152 info->maxWindowRatio_ = parcel.ReadDouble(); 153 info->minWindowRatio_ = parcel.ReadDouble(); 154 info->maxWindowWidth_ = parcel.ReadUint32(); 155 info->minWindowWidth_ = parcel.ReadUint32(); 156 info->maxWindowHeight_ = parcel.ReadUint32(); 157 info->minWindowHeight_ = parcel.ReadUint32(); 158 info->missionId_ = parcel.ReadInt32(); 159 info->reason_ = static_cast<TransitionReason>(parcel.ReadUint32()); 160 return info; 161 } 162 }; 163 } // namespace AAFwk 164 } // namespace OHOS 165 #endif 166 #endif // OHOS_ABILITY_RUNTIME_WINDOW_INFO_H 167