1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.wm; 18 19 import com.android.internal.os.BackgroundThread; 20 import com.android.server.wm.WindowManagerInternal.TaskSystemBarsListener; 21 22 import java.util.HashSet; 23 import java.util.concurrent.Executor; 24 25 /** 26 * Manages dispatch of task system bar changes to interested listeners. All invocations must be 27 * performed while the {@link WindowManagerService#getWindowManagerLock() Window Manager Lock} is 28 * held. 29 */ 30 final class TaskSystemBarsListenerController { 31 32 private final HashSet<TaskSystemBarsListener> mListeners = new HashSet<>(); 33 private final Executor mBackgroundExecutor; 34 TaskSystemBarsListenerController()35 TaskSystemBarsListenerController() { 36 this.mBackgroundExecutor = BackgroundThread.getExecutor(); 37 } 38 registerListener(TaskSystemBarsListener listener)39 void registerListener(TaskSystemBarsListener listener) { 40 mListeners.add(listener); 41 } 42 unregisterListener(TaskSystemBarsListener listener)43 void unregisterListener(TaskSystemBarsListener listener) { 44 mListeners.remove(listener); 45 } 46 dispatchTransientSystemBarVisibilityChanged( int taskId, boolean visible, boolean wereRevealedFromSwipeOnSystemBar)47 void dispatchTransientSystemBarVisibilityChanged( 48 int taskId, 49 boolean visible, 50 boolean wereRevealedFromSwipeOnSystemBar) { 51 HashSet<TaskSystemBarsListener> localListeners; 52 localListeners = new HashSet<>(mListeners); 53 54 mBackgroundExecutor.execute(() -> { 55 for (TaskSystemBarsListener listener : localListeners) { 56 listener.onTransientSystemBarsVisibilityChanged( 57 taskId, 58 visible, 59 wereRevealedFromSwipeOnSystemBar); 60 } 61 }); 62 } 63 } 64