• 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 "fold_common_utils.h"
17 
18 #include "hiview_logger.h"
19 #include "usage_event_common.h"
20 #include "window_manager.h"
21 
22 namespace OHOS {
23 namespace HiviewDFX {
24 namespace FoldCommonUtils {
25 DEFINE_LOG_TAG("FoldCommonUtils");
26 namespace {
GetMultiWindowMode(int32_t mode)27 int32_t GetMultiWindowMode(int32_t mode)
28 {
29     switch (mode) {
30         case 100: // 100-SPLIT_PRIMARY
31             return MultiWindowMode::WINDOW_MODE_SPLIT_PRIMARY;
32         case 101: // 101-SPLIT_SECONDARY
33             return MultiWindowMode::WINDOW_MODE_SPLIT_SECONDARY;
34         case 102: // 102-FLOATING
35             return MultiWindowMode::WINDOW_MODE_FLOATING;
36         default:
37             return -1;
38     }
39 }
40 }
41 
GetFocusedAppAndWindowInfos(std::pair<std::string,bool> & focusedAppPair,std::unordered_map<std::string,int32_t> & multiWindowInfos)42 void GetFocusedAppAndWindowInfos(std::pair<std::string, bool>& focusedAppPair,
43     std::unordered_map<std::string, int32_t>& multiWindowInfos)
44 {
45     focusedAppPair = std::pair<std::string, bool>("", false);
46     multiWindowInfos.clear();
47     Rosen::WindowInfoOption windowInfoOption;
48     windowInfoOption.windowInfoFilterOption = Rosen::WindowInfoFilterOption::FOREGROUND;
49     std::vector<sptr<Rosen::WindowInfo>> winInfos;
50     Rosen::WMError ret = Rosen::WindowManager::GetInstance().ListWindowInfo(windowInfoOption, winInfos);
51     if (ret != Rosen::WMError::WM_OK) {
52         HIVIEW_LOGI("get windowInfos failed, ret=%{public}d", ret);
53         return;
54     }
55     for (auto winInfo : winInfos) {
56         if (winInfo == nullptr) {
57             continue;
58         }
59         int32_t windowType = static_cast<int32_t>(winInfo->windowMetaInfo.windowType);
60         int32_t windowMode = GetMultiWindowMode(static_cast<int32_t>(winInfo->windowMetaInfo.windowMode));
61         if (winInfo->windowMetaInfo.isFocused) {
62             focusedAppPair = std::make_pair(winInfo->windowMetaInfo.bundleName, (windowType < SYSTEM_WINDOW_BASE));
63         }
64         if (windowType < SYSTEM_WINDOW_BASE && windowMode > 0) {
65             multiWindowInfos[winInfo->windowMetaInfo.bundleName] = windowMode;
66             if (winInfo->windowMetaInfo.isMidScene) {
67                 multiWindowInfos[winInfo->windowMetaInfo.bundleName] = MultiWindowMode::WINDOW_MODE_MIDSCENE;
68             }
69         }
70     }
71 }
72 } // namespace FoldCommonUtils
73 } // namespace HiviewDFX
74 } // namespace OHOS