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 import android.view.View; 48 import android.view.WindowManager; 49 50 import org.junit.Test; 51 52 /** 53 * Tests that verify the behavior of window context policy 54 * 55 * Build/Install/Run: 56 * atest CtsWindowManagerDeviceTestCases:WindowContextPolicyTests 57 */ 58 @Presubmit 59 public class WindowContextPolicyTests extends WindowContextTestBase { 60 61 @Test(expected = UnsupportedOperationException.class) testCreateWindowContextWithNoDisplayContext()62 public void testCreateWindowContextWithNoDisplayContext() { 63 mContext.createWindowContext(TYPE_APPLICATION_OVERLAY, null); 64 } 65 66 @Test(expected = IllegalArgumentException.class) testWindowContextWithNullDisplay()67 public void testWindowContextWithNullDisplay() { 68 final Context displayContext = createDisplayContext(Display.DEFAULT_DISPLAY); 69 displayContext.createWindowContext(null /* display */, TYPE_APPLICATION_OVERLAY, 70 null /* options */); 71 } 72 73 @Test testWindowContextWithDisplayOnNonUiContext()74 public void testWindowContextWithDisplayOnNonUiContext() { 75 createAllowSystemAlertWindowAppOpSession(); 76 final Display display = mDm.getDisplay(Display.DEFAULT_DISPLAY); 77 mContext.createWindowContext(display, TYPE_APPLICATION_OVERLAY, null /* options */); 78 } 79 80 @Test testCreateMultipleWindowContextsWithoutView()81 public void testCreateMultipleWindowContextsWithoutView() { 82 final WindowManagerState.DisplayContent display = createManagedVirtualDisplaySession() 83 .setSimulateDisplay(true).createDisplay(); 84 for (int i = 0; i < 10; i++) { 85 createWindowContext(display.mId); 86 } 87 } 88 89 @Test testWindowContextWithAllPublicTypes()90 public void testWindowContextWithAllPublicTypes() { 91 final WindowManagerState.DisplayContent display = createManagedVirtualDisplaySession() 92 .setSimulateDisplay(true).createDisplay(); 93 94 final int[] allPublicWindowTypes = new int[] { 95 TYPE_BASE_APPLICATION, TYPE_APPLICATION, TYPE_APPLICATION_STARTING, 96 TYPE_DRAWN_APPLICATION, TYPE_APPLICATION_PANEL, TYPE_APPLICATION_MEDIA, 97 TYPE_APPLICATION_SUB_PANEL, TYPE_APPLICATION_ATTACHED_DIALOG, 98 TYPE_STATUS_BAR, TYPE_SEARCH_BAR, TYPE_PHONE, TYPE_SYSTEM_ALERT, 99 TYPE_TOAST, TYPE_SYSTEM_OVERLAY, TYPE_PRIORITY_PHONE, 100 TYPE_SYSTEM_DIALOG, TYPE_KEYGUARD_DIALOG, TYPE_SYSTEM_ERROR, TYPE_INPUT_METHOD, 101 TYPE_INPUT_METHOD_DIALOG, TYPE_WALLPAPER, TYPE_PRIVATE_PRESENTATION, 102 TYPE_ACCESSIBILITY_OVERLAY, TYPE_APPLICATION_OVERLAY 103 }; 104 105 for (int windowType : allPublicWindowTypes) { 106 createWindowContext(display.mId, windowType); 107 } 108 } 109 110 @Test(expected = IllegalArgumentException.class) testWindowContextAddMismatchedWindowType()111 public void testWindowContextAddMismatchedWindowType() { 112 final WindowManagerState.DisplayContent display = createManagedVirtualDisplaySession() 113 .setSimulateDisplay(true).createDisplay(); 114 final Context windowContext = createWindowContext(display.mId); 115 windowContext.getSystemService(WindowManager.class) 116 .addView(new View(windowContext), new WindowManager.LayoutParams(TYPE_PHONE)); 117 } 118 } 119