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 #ifndef OHOS_MEMORY_MEMMGR_WINDOW_VISIBILITY_OBSERVER_H 17 #define OHOS_MEMORY_MEMMGR_WINDOW_VISIBILITY_OBSERVER_H 18 19 #include <sys/types.h> 20 #include <map> 21 #include <mutex> 22 #include <set> 23 24 #include "event_handler.h" 25 #include "iremote_object.h" 26 #include "i_mem_mgr.h" 27 #include "mem_mgr_window_info.h" 28 #include "reclaim_priority_manager.h" 29 #include "single_instance.h" 30 31 namespace OHOS { 32 namespace Memory { 33 struct ProcessWindowVisibilityInfo { 34 bool visible; 35 int uid; 36 std::set<uint32_t> visibleWindowIds; 37 }; 38 39 typedef struct ProcessWindowVisibilityInfo ProcessWindowVisibilityInfo; 40 41 class WindowVisibilityObserver { 42 DECLARE_SINGLE_INSTANCE_BASE(WindowVisibilityObserver); 43 public: 44 void UpdateWindowVisibilityPriority(const std::vector<sptr<MemMgrWindowInfo>> &memMgrWindowInfo); 45 void OnProcessDied(int pid); 46 47 private: 48 WindowVisibilityObserver(); 49 ~WindowVisibilityObserver(); 50 std::shared_ptr<AppExecFwk::EventHandler> handler_; 51 std::function<void()> timerFunc_; 52 std::map<int32_t, ProcessWindowVisibilityInfo> windowVisibleMap_; 53 std::mutex mutex_ {}; 54 55 void SetTimer(); 56 void CheckMapSize(int type); 57 void UpdatePriorityForVisible(std::map<int32_t, ProcessWindowVisibilityInfo> &windowVisibleMap_); 58 void UpdateWindowVisibilityPriorityInner(const std::vector<sptr<MemMgrWindowInfo>> &MemMgrWindowInfo); 59 }; 60 } // namespace Memory 61 } // namespace OHOS 62 #endif // OHOS_MEMORY_MEMMGR_WINDOW_VISIBILITY_H 63