1 /* 2 * Copyright (C) 2016 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.IBinder; 20 21 import java.util.HashMap; 22 23 /** 24 * Class that allows the owner/creator of a {@link WindowContainer} to communicate directly with the 25 * container and make changes. 26 * Note that public calls (mostly in sub-classes) into this class are assumed to be originating from 27 * outside the window manager so the window manager lock is held and appropriate permissions are 28 * checked before calls are allowed to proceed. 29 * 30 * Test class: {@link WindowContainerControllerTests} 31 */ 32 class WindowContainerController<E extends WindowContainer, I extends WindowContainerListener> { 33 34 final WindowManagerService mService; 35 final RootWindowContainer mRoot; 36 final WindowHashMap mWindowMap; 37 38 // The window container this controller owns. 39 E mContainer; 40 // Interface for communicating changes back to the owner. 41 final I mListener; 42 43 WindowContainerController(I listener, WindowManagerService service) { 44 mListener = listener; 45 mService = service; 46 mRoot = mService != null ? mService.mRoot : null; 47 mWindowMap = mService != null ? mService.mWindowMap : null; 48 } 49 50 void setContainer(E container) { 51 if (mContainer != null && container != null) { 52 throw new IllegalArgumentException("Can't set container=" + container 53 + " for controller=" + this + " Already set to=" + mContainer); 54 } 55 mContainer = container; 56 } 57 58 void removeContainer() { 59 // TODO: See if most uses cases should support removeIfPossible here. 60 //mContainer.removeIfPossible(); 61 if (mContainer != null) { 62 mContainer.setController(null); 63 mContainer = null; 64 } 65 } 66 67 boolean checkCallingPermission(String permission, String func) { 68 return mService.checkCallingPermission(permission, func); 69 } 70 } 71