Evan Rosky | 69cace4 | 2019-09-20 16:28:13 -0700 | [diff] [blame] | 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.server.wm; |
| 18 | |
Evan Rosky | 8220708 | 2019-10-08 17:28:29 -0700 | [diff] [blame] | 19 | import android.content.res.Configuration; |
Evan Rosky | 69cace4 | 2019-09-20 16:28:13 -0700 | [diff] [blame] | 20 | import android.os.RemoteCallbackList; |
| 21 | import android.os.RemoteException; |
| 22 | import android.view.IDisplayWindowListener; |
| 23 | |
| 24 | /** |
| 25 | * Manages dispatch of relevant hierarchy changes to interested listeners. Listeners are assumed |
| 26 | * to be remote. |
| 27 | */ |
| 28 | class 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 { |
| 42 | for (int i = 0; i < mService.mAtmService.mRootActivityContainer.getChildCount(); |
| 43 | ++i) { |
| 44 | ActivityDisplay d = mService.mAtmService.mRootActivityContainer.getChildAt(i); |
| 45 | listener.onDisplayAdded(d.mDisplayId); |
| 46 | } |
| 47 | } catch (RemoteException e) { } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | void unregisterListener(IDisplayWindowListener listener) { |
| 52 | mDisplayListeners.unregister(listener); |
| 53 | } |
| 54 | |
| 55 | void dispatchDisplayAdded(ActivityDisplay display) { |
| 56 | 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 | |
Evan Rosky | 8220708 | 2019-10-08 17:28:29 -0700 | [diff] [blame] | 66 | void dispatchDisplayChanged(ActivityDisplay display, Configuration newConfig) { |
| 67 | // 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( |
| 81 | display.mDisplayId, newConfig); |
| 82 | } catch (RemoteException e) { |
| 83 | } |
| 84 | } |
| 85 | mDisplayListeners.finishBroadcast(); |
| 86 | } |
| 87 | |
Evan Rosky | 69cace4 | 2019-09-20 16:28:13 -0700 | [diff] [blame] | 88 | void dispatchDisplayRemoved(ActivityDisplay display) { |
| 89 | 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 | } |
| 98 | } |