• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <vector>
17 
18 #include "hilog_wrapper.h"
19 #include "wallpaper_picture_info_by_parcel.h"
20 
21 namespace OHOS::WallpaperMgrService {
22 constexpr int32_t VECTOR_MAX_SIZE = 6;
WallpaperPictureInfoByParcel()23 WallpaperPictureInfoByParcel::WallpaperPictureInfoByParcel()
24 {
25 }
26 
Marshalling(Parcel & parcel) const27 bool WallpaperPictureInfoByParcel::Marshalling(Parcel &parcel) const
28 {
29     bool status = true;
30     status &= parcel.WriteInt32(wallpaperPictureInfo_.size());
31     for (const auto &wallpaperInfo : wallpaperPictureInfo_) {
32         status &= parcel.WriteInt32(static_cast<int32_t>(wallpaperInfo.foldState));
33         status &= parcel.WriteInt32(static_cast<int32_t>(wallpaperInfo.rotateState));
34         status &= parcel.WriteInt32(wallpaperInfo.fd);
35         status &= parcel.WriteInt64(wallpaperInfo.length);
36     }
37     return status;
38 }
39 
Unmarshalling(Parcel & parcel)40 WallpaperPictureInfoByParcel *WallpaperPictureInfoByParcel::Unmarshalling(Parcel &parcel)
41 {
42     WallpaperPictureInfoByParcel *obj = new (std::nothrow) WallpaperPictureInfoByParcel();
43     if (obj == nullptr) {
44         HILOG_ERROR("obj is nullptr");
45         return nullptr;
46     }
47     int32_t vectorSize = parcel.ReadInt32();
48     if (vectorSize > VECTOR_MAX_SIZE) {
49         HILOG_ERROR("More than maxNum 6 of wallpaper pictures, size:%{public}d", vectorSize);
50         delete obj;
51         return nullptr;
52     }
53     for (int32_t i = 0; i < vectorSize; i++) {
54         WallpaperPictureInfo wallpaperInfo;
55         int32_t foldStateVale = parcel.ReadInt32();
56         int32_t rotateStateVale = parcel.ReadInt32();
57         if (foldStateVale == static_cast<int32_t>(FoldState::NORMAL)) {
58             wallpaperInfo.foldState = NORMAL;
59         } else if (foldStateVale == static_cast<int32_t>(FoldState::UNFOLD_1)) {
60             wallpaperInfo.foldState = UNFOLD_1;
61         } else if (foldStateVale == static_cast<int32_t>(FoldState::UNFOLD_2)) {
62             wallpaperInfo.foldState = UNFOLD_2;
63         }
64         if (rotateStateVale == static_cast<int32_t>(RotateState::PORT)) {
65             wallpaperInfo.rotateState = PORT;
66         } else if (rotateStateVale == static_cast<int32_t>(RotateState::LAND)) {
67             wallpaperInfo.rotateState = LAND;
68         }
69         wallpaperInfo.fd = parcel.ReadInt32();
70         wallpaperInfo.length = parcel.ReadInt64();
71         obj->wallpaperPictureInfo_.push_back(wallpaperInfo);
72     }
73     return obj;
74 }
75 
76 } // namespace OHOS::WallpaperMgrService