Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [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 static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Michal Karpinski | 2927b54 | 2019-04-16 14:02:46 +0100 | [diff] [blame] | 20 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 21 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
| 22 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
| 23 | |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 24 | import static org.junit.Assert.assertEquals; |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 25 | import static org.junit.Assert.assertFalse; |
| 26 | import static org.junit.Assert.assertTrue; |
| 27 | |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 28 | import android.app.WindowConfiguration; |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 29 | import android.platform.test.annotations.Presubmit; |
| 30 | |
| 31 | import androidx.test.filters.SmallTest; |
| 32 | |
| 33 | import org.junit.Test; |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 34 | import org.junit.runner.RunWith; |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Tests for RootWindowContainer. |
| 38 | * |
| 39 | * Build/Install/Run: |
| 40 | * atest WmTests:RootWindowContainerTests |
| 41 | */ |
| 42 | @SmallTest |
| 43 | @Presubmit |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 44 | @RunWith(WindowTestRunner.class) |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 45 | public class RootWindowContainerTests extends WindowTestsBase { |
| 46 | |
| 47 | private static final int FAKE_CALLING_UID = 667; |
| 48 | |
| 49 | @Test |
Michal Karpinski | 2927b54 | 2019-04-16 14:02:46 +0100 | [diff] [blame] | 50 | public void testIsAnyNonToastWindowVisibleForUid_oneToastOneAppStartOneNonToastBothVisible() { |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 51 | final WindowState toastyToast = createWindow(null, TYPE_TOAST, "toast", FAKE_CALLING_UID); |
| 52 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app", FAKE_CALLING_UID); |
Michal Karpinski | 2927b54 | 2019-04-16 14:02:46 +0100 | [diff] [blame] | 53 | final WindowState appStart = createWindow(null, TYPE_APPLICATION_STARTING, "appStarting", |
| 54 | FAKE_CALLING_UID); |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 55 | toastyToast.mHasSurface = true; |
| 56 | app.mHasSurface = true; |
Michal Karpinski | 2927b54 | 2019-04-16 14:02:46 +0100 | [diff] [blame] | 57 | appStart.mHasSurface = true; |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 58 | |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 59 | assertTrue(toastyToast.isVisibleNow()); |
| 60 | assertTrue(app.isVisibleNow()); |
Michal Karpinski | 2927b54 | 2019-04-16 14:02:46 +0100 | [diff] [blame] | 61 | assertTrue(appStart.isVisibleNow()); |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 62 | assertTrue(mWm.mRoot.isAnyNonToastWindowVisibleForUid(FAKE_CALLING_UID)); |
| 63 | } |
| 64 | |
| 65 | @Test |
| 66 | public void testIsAnyNonToastWindowVisibleForUid_onlyToastVisible() { |
| 67 | final WindowState toastyToast = createWindow(null, TYPE_TOAST, "toast", FAKE_CALLING_UID); |
| 68 | toastyToast.mHasSurface = true; |
| 69 | |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 70 | assertTrue(toastyToast.isVisibleNow()); |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 71 | assertFalse(mWm.mRoot.isAnyNonToastWindowVisibleForUid(FAKE_CALLING_UID)); |
| 72 | } |
| 73 | |
| 74 | @Test |
Michal Karpinski | 2927b54 | 2019-04-16 14:02:46 +0100 | [diff] [blame] | 75 | public void testIsAnyNonToastWindowVisibleForUid_onlyAppStartingVisible() { |
| 76 | final WindowState appStart = createWindow(null, TYPE_APPLICATION_STARTING, "appStarting", |
| 77 | FAKE_CALLING_UID); |
| 78 | appStart.mHasSurface = true; |
| 79 | |
| 80 | assertTrue(appStart.isVisibleNow()); |
| 81 | assertFalse(mWm.mRoot.isAnyNonToastWindowVisibleForUid(FAKE_CALLING_UID)); |
| 82 | } |
| 83 | |
| 84 | @Test |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 85 | public void testIsAnyNonToastWindowVisibleForUid_aFewNonToastButNoneVisible() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 86 | final WindowState statusBar = |
| 87 | createWindow(null, TYPE_STATUS_BAR, "statusBar", FAKE_CALLING_UID); |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 88 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app", FAKE_CALLING_UID); |
| 89 | |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 90 | assertFalse(statusBar.isVisibleNow()); |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 91 | assertFalse(app.isVisibleNow()); |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 92 | assertFalse(mWm.mRoot.isAnyNonToastWindowVisibleForUid(FAKE_CALLING_UID)); |
| 93 | } |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 94 | |
| 95 | @Test |
| 96 | public void testUpdateDefaultDisplayWindowingModeOnSettingsRetrieved() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 97 | assertEquals(WindowConfiguration.WINDOWING_MODE_FULLSCREEN, |
| 98 | mWm.getDefaultDisplayContentLocked().getWindowingMode()); |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 99 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 100 | mWm.mIsPc = true; |
| 101 | mWm.mAtmService.mSupportsFreeformWindowManagement = true; |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 102 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 103 | mWm.mRoot.onSettingsRetrieved(); |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 104 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 105 | assertEquals(WindowConfiguration.WINDOWING_MODE_FREEFORM, |
| 106 | mWm.getDefaultDisplayContentLocked().getWindowingMode()); |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 107 | } |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 108 | } |
| 109 | |