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 | |
| 19 | import android.os.RemoteCallbackList; |
| 20 | import android.os.RemoteException; |
| 21 | import android.view.IDisplayWindowListener; |
| 22 | |
| 23 | /** |
| 24 | * Manages dispatch of relevant hierarchy changes to interested listeners. Listeners are assumed |
| 25 | * to be remote. |
| 26 | */ |
| 27 | class DisplayWindowListenerController { |
| 28 | RemoteCallbackList<IDisplayWindowListener> mDisplayListeners = new RemoteCallbackList<>(); |
| 29 | |
| 30 | // private final ArrayList<DisplayContainerListener> mDisplayListeners = new ArrayList<>(); |
| 31 | private final WindowManagerService mService; |
| 32 | |
| 33 | DisplayWindowListenerController(WindowManagerService service) { |
| 34 | mService = service; |
| 35 | } |
| 36 | |
| 37 | void registerListener(IDisplayWindowListener listener) { |
| 38 | synchronized (mService.mGlobalLock) { |
| 39 | mDisplayListeners.register(listener); |
| 40 | try { |
| 41 | for (int i = 0; i < mService.mAtmService.mRootActivityContainer.getChildCount(); |
| 42 | ++i) { |
| 43 | ActivityDisplay d = mService.mAtmService.mRootActivityContainer.getChildAt(i); |
| 44 | listener.onDisplayAdded(d.mDisplayId); |
| 45 | } |
| 46 | } catch (RemoteException e) { } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void unregisterListener(IDisplayWindowListener listener) { |
| 51 | mDisplayListeners.unregister(listener); |
| 52 | } |
| 53 | |
| 54 | void dispatchDisplayAdded(ActivityDisplay display) { |
| 55 | int count = mDisplayListeners.beginBroadcast(); |
| 56 | for (int i = 0; i < count; ++i) { |
| 57 | try { |
| 58 | mDisplayListeners.getBroadcastItem(i).onDisplayAdded(display.mDisplayId); |
| 59 | } catch (RemoteException e) { |
| 60 | } |
| 61 | } |
| 62 | mDisplayListeners.finishBroadcast(); |
| 63 | } |
| 64 | |
| 65 | void dispatchDisplayRemoved(ActivityDisplay display) { |
| 66 | int count = mDisplayListeners.beginBroadcast(); |
| 67 | for (int i = 0; i < count; ++i) { |
| 68 | try { |
| 69 | mDisplayListeners.getBroadcastItem(i).onDisplayRemoved(display.mDisplayId); |
| 70 | } catch (RemoteException e) { |
| 71 | } |
| 72 | } |
| 73 | mDisplayListeners.finishBroadcast(); |
| 74 | } |
| 75 | } |