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