• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "mission/distributed_mission_info.h"
17 
18 #include "adapter/adapter_constant.h"
19 #include "dtbschedmgr_log.h"
20 #include "parcel_helper.h"
21 #include "string_ex.h"
22 
23 namespace OHOS {
24 namespace DistributedSchedule {
25 using namespace Constants::Adapter;
26 namespace {
27 const std::string TAG = "DstbMissionInfo";
28 }
29 
ReadFromParcel(Parcel & parcel)30 bool DstbMissionInfo::ReadFromParcel(Parcel& parcel)
31 {
32     id = parcel.ReadInt32();
33     runingState = parcel.ReadInt32();
34     userId = parcel.ReadInt32();
35     missionStackId = parcel.ReadInt32();
36     if (!parcel.ReadInt32Vector(&combinedMissionIds)) {
37         return false;
38     }
39     windowMode = parcel.ReadInt32();
40     boundsLeft = parcel.ReadInt32();
41     boundsTop = parcel.ReadInt32();
42     boundsRight = parcel.ReadInt32();
43     boundsBottom = parcel.ReadInt32();
44     baseWant.reset(parcel.ReadParcelable<AAFwk::Want>());
45     topAbility.reset(parcel.ReadParcelable<AppExecFwk::ElementName>());
46     baseAbility.reset(parcel.ReadParcelable<AppExecFwk::ElementName>());
47     reservedAbility.reset(parcel.ReadParcelable<AppExecFwk::ElementName>());
48     lastMissionActiveTime = parcel.ReadInt64();
49     displayId = parcel.ReadInt32();
50     label = Str16ToStr8(parcel.ReadString16());
51     size = parcel.ReadInt32();
52     iconPath = Str16ToStr8(parcel.ReadString16());
53     continuable = parcel.ReadInt32();
54     windowType = parcel.ReadInt32();
55     lockedState = parcel.ReadBool();
56     missionType = parcel.ReadInt32();
57     windowTypeMode = parcel.ReadInt32();
58 
59     return true;
60 }
61 
Unmarshalling(Parcel & parcel)62 DstbMissionInfo* DstbMissionInfo::Unmarshalling(Parcel& parcel)
63 {
64     DstbMissionInfo* info = new DstbMissionInfo();
65     if (info && !info->ReadFromParcel(parcel)) {
66         HILOGE("read from parcel failed!");
67         delete info;
68         info = nullptr;
69     }
70     return info;
71 }
72 
Marshalling(Parcel & parcel) const73 bool DstbMissionInfo::Marshalling(Parcel& parcel) const
74 {
75     PARCEL_WRITE_HELPER_RET(parcel, Int32, id, false);
76     PARCEL_WRITE_HELPER_RET(parcel, Int32, runingState, false);
77     PARCEL_WRITE_HELPER_RET(parcel, Int32, userId, false);
78     PARCEL_WRITE_HELPER_RET(parcel, Int32, missionStackId, false);
79     PARCEL_WRITE_HELPER_RET(parcel, Int32Vector, combinedMissionIds, false);
80     PARCEL_WRITE_HELPER_RET(parcel, Int32, windowMode, false);
81     PARCEL_WRITE_HELPER_RET(parcel, Int32, boundsLeft, false);
82     PARCEL_WRITE_HELPER_RET(parcel, Int32, boundsTop, false);
83     PARCEL_WRITE_HELPER_RET(parcel, Int32, boundsRight, false);
84     PARCEL_WRITE_HELPER_RET(parcel, Int32, boundsBottom, false);
85     PARCEL_WRITE_HELPER_RET(parcel, Parcelable, baseWant.get(), false);
86     PARCEL_WRITE_HELPER_RET(parcel, Parcelable, topAbility.get(), false);
87     PARCEL_WRITE_HELPER_RET(parcel, Parcelable, baseAbility.get(), false);
88     PARCEL_WRITE_HELPER_RET(parcel, Parcelable, reservedAbility.get(), false);
89     PARCEL_WRITE_HELPER_RET(parcel, Int64, lastMissionActiveTime, false);
90     PARCEL_WRITE_HELPER_RET(parcel, Int32, displayId, false);
91     PARCEL_WRITE_HELPER_RET(parcel, String16, Str8ToStr16(label), false);
92     PARCEL_WRITE_HELPER_RET(parcel, Int32, size, false);
93     PARCEL_WRITE_HELPER_RET(parcel, String16, Str8ToStr16(iconPath), false);
94     PARCEL_WRITE_HELPER_RET(parcel, Int32, continuable, false);
95     PARCEL_WRITE_HELPER_RET(parcel, Int32, windowType, false);
96     PARCEL_WRITE_HELPER_RET(parcel, Bool, lockedState, false);
97     PARCEL_WRITE_HELPER_RET(parcel, Int32, missionType, false);
98     PARCEL_WRITE_HELPER_RET(parcel, Int32, windowTypeMode, false);
99 
100     return true;
101 }
102 
ReadDstbMissionInfosFromParcel(Parcel & parcel,std::vector<DstbMissionInfo> & missionInfos)103 bool DstbMissionInfo::ReadDstbMissionInfosFromParcel(Parcel& parcel,
104     std::vector<DstbMissionInfo>& missionInfos)
105 {
106     int32_t empty = parcel.ReadInt32();
107     if (empty == VALUE_OBJECT) {
108         int32_t len = parcel.ReadInt32();
109         HILOGD("ReadDstbMissionInfosFromParcel::readLength is:%{public}d", len);
110         if (len < 0) {
111             return false;
112         }
113         size_t size = static_cast<size_t>(len);
114         if ((size > parcel.GetReadableBytes()) || (missionInfos.max_size() < size)) {
115             HILOGE("Failed to read DstbMissionInfo vector, size = %{public}zu", size);
116             return false;
117         }
118         missionInfos.clear();
119         for (size_t i = 0; i < size; i++) {
120             DstbMissionInfo *ptr = parcel.ReadParcelable<DstbMissionInfo>();
121             if (ptr == nullptr) {
122                 return false;
123             }
124             HILOGD("read DstbMissionInfo is:%{public}s", ptr->ToString().c_str());
125             missionInfos.emplace_back(*ptr);
126             delete ptr;
127         }
128     }
129 
130     HILOGI("read ReadDstbMissionInfosFromParcel end. info size is:%{public}zu", missionInfos.size());
131     return true;
132 }
133 
WriteDstbMissionInfosToParcel(Parcel & parcel,const std::vector<DstbMissionInfo> & missionInfos)134 bool DstbMissionInfo::WriteDstbMissionInfosToParcel(Parcel& parcel,
135     const std::vector<DstbMissionInfo>& missionInfos)
136 {
137     size_t size = missionInfos.size();
138     if (size == 0) {
139         PARCEL_WRITE_HELPER_RET(parcel, Int32, VALUE_NULL, false);
140         return true;
141     }
142 
143     PARCEL_WRITE_HELPER_RET(parcel, Int32, VALUE_OBJECT, false);
144     PARCEL_WRITE_HELPER_RET(parcel, Int32, size, false);
145     for (auto& info : missionInfos) {
146         PARCEL_WRITE_HELPER_RET(parcel, Parcelable, &info, false);
147     }
148     return true;
149 }
150 
ToString() const151 std::string DstbMissionInfo::ToString() const
152 {
153     std::string str = "id: " + std::to_string(id);
154     str += " runingState: " + std::to_string(runingState);
155     str += " userId: " + std::to_string(userId);
156     str += " missionStackId: " + std::to_string(missionStackId);
157     str += " windowMode: " + std::to_string(windowMode);
158     str += " boundsLeft: " + std::to_string(boundsLeft);
159     str += " boundsTop: " + std::to_string(boundsTop);
160     str += " boundsRight: " + std::to_string(boundsRight);
161     str += " boundsBottom: " + std::to_string(boundsBottom);
162     if (baseWant == nullptr) {
163         str += " baseWant: nullptr";
164     } else {
165         str += " baseWant: " + baseWant->GetBundle();
166     }
167     if (topAbility == nullptr) {
168         str += " topAbility: nullptr";
169     } else {
170         str += " topAbility: " + topAbility->GetBundleName();
171     }
172     if (baseAbility == nullptr) {
173         str += " baseAbility: nullptr";
174     } else {
175         str += " baseAbility: " + baseAbility->GetBundleName();
176     }
177     if (reservedAbility == nullptr) {
178         str += " reservedAbility: nullptr";
179     } else {
180         str += " reservedAbility: " + reservedAbility->GetBundleName();
181     }
182     str += " lastMissionActiveTime: " + std::to_string(lastMissionActiveTime);
183     str += " displayId: " + std::to_string(displayId);
184     str += " label: " + label;
185     str += " size: " + std::to_string(size);
186     str += " iconPath: " + iconPath;
187     str += " continuable: " + std::to_string(continuable);
188     str += " windowType: " + std::to_string(windowType);
189     str += " lockedState: ";
190     str += lockedState ? "true" : "false";
191     str += " missionType: " + std::to_string(missionType);
192     str += " windowTypeMode: " + std::to_string(windowTypeMode);
193     return str;
194 }
195 } // namespace DistributedSchedule
196 } // namespace OHOS