blob: eb23fafb47f042494ed4486b95d2ba33c4347cb1 [file] [log] [blame]
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001/*
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
17package com.android.server.wm;
18
Wale Ogunwale034a8ec2017-09-02 17:14:40 -070019import android.content.res.Configuration;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080020
21/**
22 * Class that allows the owner/creator of a {@link WindowContainer} to communicate directly with the
23 * container and make changes.
24 * Note that public calls (mostly in sub-classes) into this class are assumed to be originating from
25 * outside the window manager so the window manager lock is held and appropriate permissions are
26 * checked before calls are allowed to proceed.
27 *
28 * Test class: {@link WindowContainerControllerTests}
29 */
Wale Ogunwale034a8ec2017-09-02 17:14:40 -070030class WindowContainerController<E extends WindowContainer, I extends WindowContainerListener>
31 implements ConfigurationContainerListener {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080032
33 final WindowManagerService mService;
34 final RootWindowContainer mRoot;
Jorim Jaggi36db1272017-03-28 00:43:31 +020035 final WindowHashMap mWindowMap;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080036
37 // The window container this controller owns.
38 E mContainer;
39 // Interface for communicating changes back to the owner.
40 final I mListener;
41
42 WindowContainerController(I listener, WindowManagerService service) {
43 mListener = listener;
44 mService = service;
45 mRoot = mService != null ? mService.mRoot : null;
46 mWindowMap = mService != null ? mService.mWindowMap : null;
47 }
48
49 void setContainer(E container) {
50 if (mContainer != null && container != null) {
51 throw new IllegalArgumentException("Can't set container=" + container
52 + " for controller=" + this + " Already set to=" + mContainer);
53 }
54 mContainer = container;
Wale Ogunwale034a8ec2017-09-02 17:14:40 -070055 if (mContainer != null && mListener != null) {
56 mListener.registerConfigurationChangeListener(this);
57 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080058 }
59
60 void removeContainer() {
61 // TODO: See if most uses cases should support removeIfPossible here.
62 //mContainer.removeIfPossible();
Wale Ogunwale034a8ec2017-09-02 17:14:40 -070063 if (mContainer == null) {
64 return;
65 }
66
67 mContainer.setController(null);
68 mContainer = null;
69 if (mListener != null) {
70 mListener.unregisterConfigurationChangeListener(this);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080071 }
72 }
73
Wale Ogunwale034a8ec2017-09-02 17:14:40 -070074 @Override
75 public void onOverrideConfigurationChanged(Configuration overrideConfiguration) {
76 synchronized (mWindowMap) {
77 if (mContainer == null) {
78 return;
79 }
80 mContainer.onOverrideConfigurationChanged(overrideConfiguration);
81 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080082 }
83}