• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         if (abilityToken_) {
57             return parcel.WriteBool(true) && (static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(abilityToken_);
58         } else {
59             return parcel.WriteBool(false);
60         }
61     }
62 
Unmarshalling(Parcel & parcel)63     static FocusChangeInfo* Unmarshalling(Parcel &parcel)
64     {
65         auto focusChangeInfo = new FocusChangeInfo();
66         bool res = parcel.ReadInt32(focusChangeInfo->windowId_) && parcel.ReadUint64(focusChangeInfo->displayId_) &&
67             parcel.ReadInt32(focusChangeInfo->pid_) && parcel.ReadInt32(focusChangeInfo->uid_);
68         if (!res) {
69             delete focusChangeInfo;
70             return nullptr;
71         }
72         focusChangeInfo->windowType_ = static_cast<WindowType>(parcel.ReadUint32());
73         if (parcel.ReadBool()) {
74             focusChangeInfo->abilityToken_ = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
75         }
76         return focusChangeInfo;
77     }
78 
79     int32_t windowId_ = INVALID_WINDOW_ID;
80     DisplayId displayId_ = 0;
81     int32_t pid_ = -1;
82     int32_t uid_ = -1;
83     WindowType windowType_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
84     sptr<IRemoteObject> abilityToken_;
85 };
86 } // namespace OHOS::Rosen
87 #endif // OHOS_ROSEN_FOCUS_CHANGE_INFO_H