1 /*
2  * Copyright (C) 2019 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.systemui.shared.system;
18 
19 import android.content.pm.ParceledListSlice;
20 import android.graphics.Rect;
21 import android.os.RemoteException;
22 import android.view.IPinnedStackController;
23 import android.view.IPinnedStackListener;
24 
25 import java.util.ArrayList;
26 import java.util.List;
27 
28 /**
29  * PinnedStackListener that simply forwards all calls to each listener added via
30  * {@link #addListener}. This is necessary since calling
31  * {@link com.android.server.wm.WindowManagerService#registerPinnedStackListener} replaces any
32  * previously set listener.
33  */
34 public class PinnedStackListenerForwarder extends IPinnedStackListener.Stub {
35     private List<IPinnedStackListener> mListeners = new ArrayList<>();
36 
37     /** Adds a listener to receive updates from the WindowManagerService. */
addListener(IPinnedStackListener listener)38     public void addListener(IPinnedStackListener listener) {
39         mListeners.add(listener);
40     }
41 
42     /** Removes a listener so it will no longer receive updates from the WindowManagerService. */
removeListener(IPinnedStackListener listener)43     public void removeListener(IPinnedStackListener listener) {
44         mListeners.remove(listener);
45     }
46 
47     @Override
onListenerRegistered(IPinnedStackController controller)48     public void onListenerRegistered(IPinnedStackController controller) throws RemoteException {
49         for (IPinnedStackListener listener : mListeners) {
50             listener.onListenerRegistered(controller);
51         }
52     }
53 
54     @Override
onMovementBoundsChanged(Rect insetBounds, Rect normalBounds, Rect animatingBounds, boolean fromImeAdjustment, boolean fromShelfAdjustment, int displayRotation)55     public void onMovementBoundsChanged(Rect insetBounds, Rect normalBounds, Rect animatingBounds,
56             boolean fromImeAdjustment, boolean fromShelfAdjustment, int displayRotation)
57             throws RemoteException {
58         for (IPinnedStackListener listener : mListeners) {
59             listener.onMovementBoundsChanged(
60                     insetBounds, normalBounds, animatingBounds,
61                     fromImeAdjustment, fromShelfAdjustment, displayRotation);
62         }
63     }
64 
65     @Override
onImeVisibilityChanged(boolean imeVisible, int imeHeight)66     public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) throws RemoteException {
67         for (IPinnedStackListener listener : mListeners) {
68             listener.onImeVisibilityChanged(imeVisible, imeHeight);
69         }
70     }
71 
72     @Override
onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight)73     public void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight)
74             throws RemoteException {
75         for (IPinnedStackListener listener : mListeners) {
76             listener.onShelfVisibilityChanged(shelfVisible, shelfHeight);
77         }
78     }
79 
80     @Override
onMinimizedStateChanged(boolean isMinimized)81     public void onMinimizedStateChanged(boolean isMinimized) throws RemoteException {
82         for (IPinnedStackListener listener : mListeners) {
83             listener.onMinimizedStateChanged(isMinimized);
84         }
85     }
86 
87     @Override
onActionsChanged(ParceledListSlice actions)88     public void onActionsChanged(ParceledListSlice actions) throws RemoteException {
89         for (IPinnedStackListener listener : mListeners) {
90             listener.onActionsChanged(actions);
91         }
92     }
93 }
94