1 /*
2  * Copyright (c) 2022 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/snapshot_converter.h"
17 
18 #include "dtbschedmgr_log.h"
19 
20 namespace OHOS {
21 namespace DistributedSchedule {
22 namespace {
23 const std::string TAG = "SnapshotConverter";
24 constexpr int32_t DMS_VERSION = 200;
25 }
26 
ConvertToSnapshot(AAFwk::MissionSnapshot & missionSnapshot,Snapshot & snapshot)27 int32_t SnapshotConverter::ConvertToSnapshot(AAFwk::MissionSnapshot& missionSnapshot, Snapshot& snapshot)
28 {
29     snapshot.version_ = DMS_VERSION;
30     snapshot.orientation_ = 0;
31     std::unique_ptr<Rect> contentInsets = std::make_unique<Rect>(0, 0, 0, 0);
32     snapshot.rect_ = std::move(contentInsets);
33     snapshot.reducedResolution_ = true;
34     snapshot.scale_ = 0.0;
35     snapshot.isRealSnapshot_ = true;
36     snapshot.windowingMode_ = 0;
37     snapshot.systemUiVisibility_ = 0;
38     snapshot.isTranslucent_ = true;
39     std::unique_ptr<Rect> windowBounds = std::make_unique<Rect>(0, 0, 0, 0);
40     snapshot.windowBounds_ = std::move(windowBounds);
41     std::u16string appLabel;
42     snapshot.appLabel_ = appLabel;
43     std::u16string abilityLabel;
44     snapshot.abilityLabel_ = abilityLabel;
45     std::vector<uint8_t> icon;
46     snapshot.icon_ = icon;
47     std::u16string secAppLabel;
48     snapshot.secAppLabel_ = secAppLabel;
49     std::u16string secAbilityLabel;
50     snapshot.secAbilityLabel_ = secAbilityLabel;
51     std::vector<uint8_t> secIcon;
52     snapshot.secIcon_ = secIcon;
53     std::u16string sourceDeviceTips;
54     snapshot.sourceDeviceTips_ = sourceDeviceTips;
55     snapshot.pixelMap_ = missionSnapshot.snapshot;
56     return ERR_OK;
57 }
58 
ConvertToSnapshot(AAFwk::MissionSnapshot & missionSnapshot,std::unique_ptr<Snapshot> & snapshot)59 int32_t SnapshotConverter::ConvertToSnapshot(AAFwk::MissionSnapshot& missionSnapshot,
60     std::unique_ptr<Snapshot>& snapshot)
61 {
62     if (snapshot == nullptr) {
63         return INVALID_PARAMETERS_ERR;
64     }
65     snapshot->version_ = DMS_VERSION;
66     snapshot->orientation_ = 0;
67     std::unique_ptr<Rect> contentInsets = std::make_unique<Rect>(0, 0, 0, 0);
68     snapshot->rect_ = std::move(contentInsets);
69     snapshot->reducedResolution_ = true;
70     snapshot->scale_ = 0.0;
71     snapshot->isRealSnapshot_ = true;
72     snapshot->windowingMode_ = 0;
73     snapshot->systemUiVisibility_ = 0;
74     snapshot->isTranslucent_ = true;
75     std::unique_ptr<Rect> windowBounds = std::make_unique<Rect>(0, 0, 0, 0);
76     snapshot->windowBounds_ = std::move(windowBounds);
77     std::u16string appLabel;
78     snapshot->appLabel_ = appLabel;
79     std::u16string abilityLabel;
80     snapshot->abilityLabel_ = abilityLabel;
81     std::vector<uint8_t> icon;
82     snapshot->icon_ = icon;
83     std::u16string secAppLabel;
84     snapshot->secAppLabel_ = secAppLabel;
85     std::u16string secAbilityLabel;
86     snapshot->secAbilityLabel_ = secAbilityLabel;
87     std::vector<uint8_t> secIcon;
88     snapshot->secIcon_ = secIcon;
89     std::u16string sourceDeviceTips;
90     snapshot->sourceDeviceTips_ = sourceDeviceTips;
91     snapshot->pixelMap_ = missionSnapshot.snapshot;
92     return ERR_OK;
93 }
94 
ConvertToMissionSnapshot(Snapshot & snapshot,std::unique_ptr<AAFwk::MissionSnapshot> & missionSnapshot)95 int32_t SnapshotConverter::ConvertToMissionSnapshot(Snapshot& snapshot,
96     std::unique_ptr<AAFwk::MissionSnapshot>& missionSnapshot)
97 {
98     if (missionSnapshot != nullptr) {
99         missionSnapshot->snapshot = snapshot.pixelMap_;
100     }
101     return ERR_OK;
102 }
103 } // namespace DistributedSchedule
104 } // namespace OHOS
105