• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 android.server.wm;
18 
19 import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
20 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
21 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
22 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
23 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
24 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
25 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
26 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
27 import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
28 import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
29 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
30 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
31 import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
32 import static android.view.WindowManager.LayoutParams.TYPE_PHONE;
33 import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
34 import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
35 import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR;
36 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
37 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
38 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
39 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
40 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
41 import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
42 import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
43 
44 import android.content.Context;
45 import android.platform.test.annotations.Presubmit;
46 import android.view.Display;
47 
48 import org.junit.Test;
49 
50 /**
51  * Tests that verify the behavior of window context policy
52  *
53  * Build/Install/Run:
54  *     atest CtsWindowManagerDeviceTestCases:WindowContextPolicyTests
55  */
56 @Presubmit
57 public class WindowContextPolicyTests extends WindowContextTestBase {
58 
59     @Test(expected = UnsupportedOperationException.class)
testCreateWindowContextWithNoDisplayContext()60     public void testCreateWindowContextWithNoDisplayContext() {
61         mContext.createWindowContext(TYPE_APPLICATION_OVERLAY, null);
62     }
63 
64     @Test(expected = IllegalArgumentException.class)
testWindowContextWithNullDisplay()65     public void testWindowContextWithNullDisplay() {
66         final Context displayContext = createDisplayContext(Display.DEFAULT_DISPLAY);
67         displayContext.createWindowContext(null /* display */, TYPE_APPLICATION_OVERLAY,
68                 null /* options */);
69     }
70 
71     @Test
testWindowContextWithDisplayOnNonUiContext()72     public void testWindowContextWithDisplayOnNonUiContext() {
73         createAllowSystemAlertWindowAppOpSession();
74         final Display display = mDm.getDisplay(Display.DEFAULT_DISPLAY);
75         mContext.createWindowContext(display, TYPE_APPLICATION_OVERLAY, null /* options */);
76     }
77 
78     @Test
testCreateMultipleWindowContextsWithoutView()79     public void testCreateMultipleWindowContextsWithoutView() {
80         final WindowManagerState.DisplayContent display = createManagedVirtualDisplaySession()
81                 .setSimulateDisplay(true).createDisplay();
82         for (int i = 0; i < 10; i++) {
83             createWindowContext(display.mId);
84         }
85     }
86 
87     @Test
testWindowContextWithAllPublicTypes()88     public void testWindowContextWithAllPublicTypes() {
89         final WindowManagerState.DisplayContent display = createManagedVirtualDisplaySession()
90                 .setSimulateDisplay(true).createDisplay();
91 
92         final int[] allPublicWindowTypes = new int[] {
93                 TYPE_BASE_APPLICATION, TYPE_APPLICATION, TYPE_APPLICATION_STARTING,
94                 TYPE_DRAWN_APPLICATION, TYPE_APPLICATION_PANEL, TYPE_APPLICATION_MEDIA,
95                 TYPE_APPLICATION_SUB_PANEL, TYPE_APPLICATION_ATTACHED_DIALOG,
96                 TYPE_STATUS_BAR, TYPE_SEARCH_BAR, TYPE_PHONE, TYPE_SYSTEM_ALERT,
97                 TYPE_TOAST, TYPE_SYSTEM_OVERLAY, TYPE_PRIORITY_PHONE,
98                 TYPE_SYSTEM_DIALOG, TYPE_KEYGUARD_DIALOG, TYPE_SYSTEM_ERROR, TYPE_INPUT_METHOD,
99                 TYPE_INPUT_METHOD_DIALOG, TYPE_WALLPAPER, TYPE_PRIVATE_PRESENTATION,
100                 TYPE_ACCESSIBILITY_OVERLAY, TYPE_APPLICATION_OVERLAY
101         };
102 
103         for (int windowType : allPublicWindowTypes) {
104             createWindowContext(display.mId, windowType);
105         }
106     }
107 }
108