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 #include "scene_session_converter.h"
17 #include "ability_info.h"
18 #include "window_manager_hilog.h"
19
20 using namespace std;
21 namespace OHOS {
22 namespace Rosen {
23 namespace {
24 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSessionConverter" };
25 }
26
ConvertToMissionInfos(std::vector<sptr<SceneSession>> & sceneSessionInfos,std::vector<AAFwk::MissionInfo> & missionInfos)27 WSError SceneSessionConverter::ConvertToMissionInfos(std::vector<sptr<SceneSession>>& sceneSessionInfos,
28 std::vector<AAFwk::MissionInfo>& missionInfos)
29 {
30 if (sceneSessionInfos.empty()) {
31 return WSError::WS_OK;
32 }
33 for (auto iter = sceneSessionInfos.begin(); iter != sceneSessionInfos.end(); iter++) {
34 AAFwk::MissionInfo missionInfo;
35 missionInfo.id = (*iter)->GetPersistentId();
36 missionInfo.runningState = (*iter)->IsActive();
37 missionInfo.lockedState = ((*iter)->GetSessionInfo()).lockedState;
38 if ((*iter)->GetSessionInfo().abilityInfo != nullptr) {
39 missionInfo.label = ((*iter)->GetSessionInfo().abilityInfo)->label;
40 missionInfo.iconPath = ((*iter)->GetSessionInfo().abilityInfo)->iconPath;
41 missionInfo.continuable = ((*iter)->GetSessionInfo().abilityInfo)->continuable;
42 } else {
43 WLOGFE("abilityInfo in SceneSession is nullptr, id: %{public}d", (*iter)->GetPersistentId());
44 }
45 if (((*iter)->GetSessionInfo()).want != nullptr) {
46 missionInfo.want = *(((*iter)->GetSessionInfo()).want);
47 } else {
48 WLOGFE("want in SceneSession is nullptr, id: %{public}d", (*iter)->GetPersistentId());
49 }
50 missionInfo.time = ((*iter)->GetSessionInfo()).time;
51 missionInfo.continueState = (AAFwk::ContinueState)(AAFwk::ContinueState::CONTINUESTATE_UNKNOWN
52 + (((*iter)->GetSessionInfo()).continueState - Rosen::ContinueState::CONTINUESTATE_UNKNOWN));
53 missionInfos.push_back(std::move(missionInfo));
54 }
55 return WSError::WS_OK;
56 }
57
ConvertToMissionInfo(sptr<SceneSession> & sceneSession,AAFwk::MissionInfo & missionInfo)58 WSError SceneSessionConverter::ConvertToMissionInfo(sptr<SceneSession>& sceneSession,
59 AAFwk::MissionInfo& missionInfo)
60 {
61 if (sceneSession == nullptr) {
62 return WSError::WS_OK;
63 }
64 missionInfo.id = sceneSession->GetPersistentId();
65 missionInfo.runningState = sceneSession->IsActive();
66 missionInfo.lockedState = (sceneSession->GetSessionInfo()).lockedState;
67 if (sceneSession->GetSessionInfo().abilityInfo != nullptr) {
68 missionInfo.label = (sceneSession->GetSessionInfo().abilityInfo)->label;
69 missionInfo.iconPath = (sceneSession->GetSessionInfo().abilityInfo)->iconPath;
70 missionInfo.continuable = (sceneSession->GetSessionInfo().abilityInfo)->continuable;
71 } else {
72 WLOGFE("abilityInfo in SceneSession is nullptr, id: %{public}d", sceneSession->GetPersistentId());
73 }
74 if ((sceneSession->GetSessionInfo()).want != nullptr) {
75 missionInfo.want = *((sceneSession->GetSessionInfo()).want);
76 } else {
77 WLOGFE("want in SceneSession is nullptr, id: %{public}d", sceneSession->GetPersistentId());
78 }
79 missionInfo.time = (sceneSession->GetSessionInfo()).time;
80 missionInfo.continueState = (AAFwk::ContinueState) (AAFwk::ContinueState::CONTINUESTATE_UNKNOWN
81 + ((sceneSession->GetSessionInfo()).continueState - Rosen::ContinueState::CONTINUESTATE_UNKNOWN));
82 return WSError::WS_OK;
83 }
84 }
85 }
86