blob: b627b33c036ed762f101cf664b0f9accdba27271 [file] [log] [blame]
Evan Rosky69cace42019-09-20 16:28:13 -07001/*
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
17package com.android.server.wm;
18
Evan Rosky82207082019-10-08 17:28:29 -070019import android.content.res.Configuration;
Evan Rosky69cace42019-09-20 16:28:13 -070020import android.os.RemoteCallbackList;
21import android.os.RemoteException;
22import android.view.IDisplayWindowListener;
23
24/**
25 * Manages dispatch of relevant hierarchy changes to interested listeners. Listeners are assumed
26 * to be remote.
27 */
28class DisplayWindowListenerController {
29 RemoteCallbackList<IDisplayWindowListener> mDisplayListeners = new RemoteCallbackList<>();
30
31// private final ArrayList<DisplayContainerListener> mDisplayListeners = new ArrayList<>();
32 private final WindowManagerService mService;
33
34 DisplayWindowListenerController(WindowManagerService service) {
35 mService = service;
36 }
37
38 void registerListener(IDisplayWindowListener listener) {
39 synchronized (mService.mGlobalLock) {
40 mDisplayListeners.register(listener);
41 try {
Louis Chang149d5c82019-12-30 09:47:39 +080042 for (int i = 0; i < mService.mAtmService.mRootWindowContainer.getChildCount();
Evan Rosky69cace42019-09-20 16:28:13 -070043 ++i) {
Louis Chang149d5c82019-12-30 09:47:39 +080044 DisplayContent d = mService.mAtmService.mRootWindowContainer.getChildAt(i);
Evan Rosky69cace42019-09-20 16:28:13 -070045 listener.onDisplayAdded(d.mDisplayId);
46 }
47 } catch (RemoteException e) { }
48 }
49 }
50
51 void unregisterListener(IDisplayWindowListener listener) {
52 mDisplayListeners.unregister(listener);
53 }
54
Louis Chang677921f2019-12-06 16:44:24 +080055 void dispatchDisplayAdded(DisplayContent display) {
Evan Rosky69cace42019-09-20 16:28:13 -070056 int count = mDisplayListeners.beginBroadcast();
57 for (int i = 0; i < count; ++i) {
58 try {
59 mDisplayListeners.getBroadcastItem(i).onDisplayAdded(display.mDisplayId);
60 } catch (RemoteException e) {
61 }
62 }
63 mDisplayListeners.finishBroadcast();
64 }
65
Louis Chang2453d062019-11-19 22:30:48 +080066 void dispatchDisplayChanged(DisplayContent display, Configuration newConfig) {
Evan Rosky82207082019-10-08 17:28:29 -070067 // Only report changed if this has actually been added to the hierarchy already.
68 boolean isInHierarchy = false;
69 for (int i = 0; i < display.getParent().getChildCount(); ++i) {
70 if (display.getParent().getChildAt(i) == display) {
71 isInHierarchy = true;
72 }
73 }
74 if (!isInHierarchy) {
75 return;
76 }
77 int count = mDisplayListeners.beginBroadcast();
78 for (int i = 0; i < count; ++i) {
79 try {
80 mDisplayListeners.getBroadcastItem(i).onDisplayConfigurationChanged(
Louis Chang2453d062019-11-19 22:30:48 +080081 display.getDisplayId(), newConfig);
Evan Rosky82207082019-10-08 17:28:29 -070082 } catch (RemoteException e) {
83 }
84 }
85 mDisplayListeners.finishBroadcast();
86 }
87
Louis Chang677921f2019-12-06 16:44:24 +080088 void dispatchDisplayRemoved(DisplayContent display) {
Evan Rosky69cace42019-09-20 16:28:13 -070089 int count = mDisplayListeners.beginBroadcast();
90 for (int i = 0; i < count; ++i) {
91 try {
92 mDisplayListeners.getBroadcastItem(i).onDisplayRemoved(display.mDisplayId);
93 } catch (RemoteException e) {
94 }
95 }
96 mDisplayListeners.finishBroadcast();
97 }
Hongwei Wangf4e4bab2020-05-19 11:28:32 -070098
99 void dispatchFixedRotationStarted(DisplayContent display, int newRotation) {
100 int count = mDisplayListeners.beginBroadcast();
101 for (int i = 0; i < count; ++i) {
102 try {
103 mDisplayListeners.getBroadcastItem(i).onFixedRotationStarted(
104 display.mDisplayId, newRotation);
105 } catch (RemoteException e) {
106 }
107 }
108 mDisplayListeners.finishBroadcast();
109 }
110
111 void dispatchFixedRotationFinished(DisplayContent display) {
112 int count = mDisplayListeners.beginBroadcast();
113 for (int i = 0; i < count; ++i) {
114 try {
115 mDisplayListeners.getBroadcastItem(i).onFixedRotationFinished(display.mDisplayId);
116 } catch (RemoteException e) {
117 }
118 }
119 mDisplayListeners.finishBroadcast();
120 }
Evan Rosky69cace42019-09-20 16:28:13 -0700121}