1 /* 2 * Copyright (c) 2023 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_ROSEN_FOCUS_CHANGE_INFO_H 17 #define OHOS_ROSEN_FOCUS_CHANGE_INFO_H 18 19 #include <cstdint> 20 #include <parcel.h> 21 #include <iremote_object.h> 22 23 #include "wm_common.h" 24 25 namespace OHOS::Rosen { 26 class FocusChangeInfo : public Parcelable { 27 public: 28 /** 29 * @brief Default construct of FocusChangeInfo 30 */ 31 FocusChangeInfo() = default; 32 33 /** 34 * @brief Construct of FocusChangeInfo 35 */ FocusChangeInfo(uint32_t winId,DisplayId displayId,int32_t pid,int32_t uid,WindowType type,const sptr<IRemoteObject> & abilityToken)36 FocusChangeInfo(uint32_t winId, DisplayId displayId, int32_t pid, int32_t uid, WindowType type, 37 const sptr<IRemoteObject>& abilityToken): windowId_(winId), displayId_(displayId), pid_(pid), uid_(uid), 38 windowType_(type), abilityToken_(abilityToken) {}; 39 40 /** 41 * @brief Deconstruct of FocusChangeInfo 42 */ 43 ~FocusChangeInfo() = default; 44 45 /** 46 * @brief Marshalling FocusChangeInfo. 47 * 48 * @param parcel Package of FocusChangeInfo. 49 * @return True means marshall FocusChangeInfo success, false means marshall failed. 50 */ Marshalling(Parcel & parcel)51 virtual bool Marshalling(Parcel& parcel) const 52 { 53 bool ret = parcel.WriteInt32(windowId_) && parcel.WriteUint64(displayId_) && 54 parcel.WriteInt32(pid_) && parcel.WriteInt32(uid_) && 55 parcel.WriteUint32(static_cast<uint32_t>(windowType_)); 56 if (!ret) { 57 return false; 58 } 59 60 if (abilityToken_) { 61 return parcel.WriteBool(true) && (static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(abilityToken_); 62 } else { 63 return parcel.WriteBool(false); 64 } 65 } 66 Unmarshalling(Parcel & parcel)67 static FocusChangeInfo* Unmarshalling(Parcel& parcel) 68 { 69 auto focusChangeInfo = new FocusChangeInfo(); 70 bool res = parcel.ReadInt32(focusChangeInfo->windowId_) && parcel.ReadUint64(focusChangeInfo->displayId_) && 71 parcel.ReadInt32(focusChangeInfo->pid_) && parcel.ReadInt32(focusChangeInfo->uid_); 72 if (!res) { 73 delete focusChangeInfo; 74 return nullptr; 75 } 76 focusChangeInfo->windowType_ = static_cast<WindowType>(parcel.ReadUint32()); 77 if (parcel.ReadBool()) { 78 focusChangeInfo->abilityToken_ = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 79 } 80 return focusChangeInfo; 81 } 82 83 int32_t windowId_ = INVALID_WINDOW_ID; 84 DisplayId displayId_ = 0; 85 int32_t pid_ = -1; 86 int32_t uid_ = -1; 87 WindowType windowType_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW; 88 sptr<IRemoteObject> abilityToken_; 89 }; 90 } // namespace OHOS::Rosen 91 #endif // OHOS_ROSEN_FOCUS_CHANGE_INFO_H