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
19 using namespace std;
20 namespace OHOS {
21 namespace Rosen {
22 namespace {
23 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSessionConverter" };
24 }
25
ConvertToMissionInfos(std::vector<sptr<SceneSession>> & sceneSessionInfos,std::vector<AAFwk::MissionInfo> & missionInfos)26 WSError SceneSessionConverter::ConvertToMissionInfos(std::vector<sptr<SceneSession>>& sceneSessionInfos,
27 std::vector<AAFwk::MissionInfo>& missionInfos)
28 {
29 if (sceneSessionInfos.empty()) {
30 return WSError::WS_OK;
31 }
32 for (auto iter = sceneSessionInfos.begin(); iter != sceneSessionInfos.end(); iter++) {
33 AAFwk::MissionInfo missionInfo;
34 missionInfo.id = (*iter)->GetPersistentId();
35 missionInfo.runningState = (*iter)->IsSessionValid() ? 0 : -1;
36 missionInfo.lockedState = ((*iter)->GetSessionInfo()).lockedState;
37 if ((*iter)->GetSessionInfo().abilityInfo != nullptr) {
38 missionInfo.label = ((*iter)->GetSessionInfo().abilityInfo)->label;
39 missionInfo.iconPath = ((*iter)->GetSessionInfo().abilityInfo)->iconPath;
40 missionInfo.continuable = ((*iter)->GetSessionInfo().abilityInfo)->continuable;
41 missionInfo.unclearable = ((*iter)->GetSessionInfo().abilityInfo)->unclearableMission;
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->IsSessionValid() ? 0 : -1;
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 missionInfo.unclearable = (sceneSession->GetSessionInfo().abilityInfo)->unclearableMission;
72 } else {
73 WLOGFE("abilityInfo in SceneSession is nullptr, id: %{public}d", sceneSession->GetPersistentId());
74 }
75 if ((sceneSession->GetSessionInfo()).want != nullptr) {
76 missionInfo.want = *((sceneSession->GetSessionInfo()).want);
77 } else {
78 WLOGFE("want in SceneSession is nullptr, id: %{public}d", sceneSession->GetPersistentId());
79 }
80 missionInfo.time = (sceneSession->GetSessionInfo()).time;
81 missionInfo.continueState = (AAFwk::ContinueState) (AAFwk::ContinueState::CONTINUESTATE_UNKNOWN
82 + ((sceneSession->GetSessionInfo()).continueState - Rosen::ContinueState::CONTINUESTATE_UNKNOWN));
83 return WSError::WS_OK;
84 }
85 }
86 }
87