Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
Tiger Huang | d5f0b9a | 2019-10-10 10:34:57 +0200 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 23 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 24 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 25 | import static android.content.res.Configuration.UI_MODE_TYPE_CAR; |
| 26 | import static android.content.res.Configuration.UI_MODE_TYPE_MASK; |
Dominik Laskowski | 26290bb | 2020-01-15 16:09:55 -0800 | [diff] [blame] | 27 | import static android.view.Display.TYPE_INTERNAL; |
Tiger Huang | e16645a | 2020-02-25 22:24:39 +0800 | [diff] [blame] | 28 | import static android.view.InsetsState.ITYPE_BOTTOM_DISPLAY_CUTOUT; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 29 | import static android.view.InsetsState.ITYPE_BOTTOM_GESTURES; |
| 30 | import static android.view.InsetsState.ITYPE_BOTTOM_TAPPABLE_ELEMENT; |
Yuncheol Heo | 13a6eb6 | 2020-03-04 23:50:37 -0800 | [diff] [blame] | 31 | import static android.view.InsetsState.ITYPE_CAPTION_BAR; |
Tiger Huang | e16645a | 2020-02-25 22:24:39 +0800 | [diff] [blame] | 32 | import static android.view.InsetsState.ITYPE_LEFT_DISPLAY_CUTOUT; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 33 | import static android.view.InsetsState.ITYPE_LEFT_GESTURES; |
| 34 | import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; |
Tiger Huang | e16645a | 2020-02-25 22:24:39 +0800 | [diff] [blame] | 35 | import static android.view.InsetsState.ITYPE_RIGHT_DISPLAY_CUTOUT; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 36 | import static android.view.InsetsState.ITYPE_RIGHT_GESTURES; |
| 37 | import static android.view.InsetsState.ITYPE_STATUS_BAR; |
Tiger Huang | e16645a | 2020-02-25 22:24:39 +0800 | [diff] [blame] | 38 | import static android.view.InsetsState.ITYPE_TOP_DISPLAY_CUTOUT; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 39 | import static android.view.InsetsState.ITYPE_TOP_GESTURES; |
| 40 | import static android.view.InsetsState.ITYPE_TOP_TAPPABLE_ELEMENT; |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 41 | import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Jorim Jaggi | d649057 | 2019-04-16 14:57:56 +0200 | [diff] [blame] | 42 | import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 43 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 44 | import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL; |
Jorim Jaggi | 648e588 | 2019-01-24 13:24:02 +0100 | [diff] [blame] | 45 | import static android.view.ViewRootImpl.NEW_INSETS_MODE_NONE; |
Tiger Huang | e218e42 | 2020-03-06 21:36:12 +0800 | [diff] [blame] | 46 | import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 47 | import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS; |
Tiger Huang | e218e42 | 2020-03-06 21:36:12 +0800 | [diff] [blame] | 48 | import static android.view.WindowInsetsController.APPEARANCE_OPAQUE_NAVIGATION_BARS; |
| 49 | import static android.view.WindowInsetsController.APPEARANCE_OPAQUE_STATUS_BARS; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 50 | import static android.view.WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE; |
Tiger Huang | 9ff42bd | 2020-05-01 03:27:33 +0800 | [diff] [blame] | 51 | import static android.view.WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_TOUCH; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 52 | import static android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 53 | import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION; |
| 54 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 55 | import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW; |
| 56 | import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| 57 | import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
| 58 | import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN; |
| 59 | import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN; |
| 60 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR; |
| 61 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 62 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
| 63 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 64 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 65 | import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; |
| 66 | import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; |
| 67 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 68 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 69 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 70 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT; |
Arthur Hung | 2047992 | 2019-02-27 17:13:22 +0800 | [diff] [blame] | 71 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 72 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 73 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 74 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_SCREEN_DECOR; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 75 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 76 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; |
| 77 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 78 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 79 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 80 | import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; |
| 81 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 82 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER; |
| 83 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
Charles Chen | 64172bb | 2019-04-22 17:30:29 +0800 | [diff] [blame] | 84 | import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 85 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
| 86 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 87 | import static android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 88 | import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT; |
| 89 | import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
| 90 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
Heemin Seog | 2cf45dd | 2020-02-24 15:43:29 -0800 | [diff] [blame] | 91 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_ADDITIONAL; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 92 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; |
| 93 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; |
| 94 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; |
| 95 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
| 96 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; |
| 97 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Joshua Tsuji | 94d4c34 | 2020-05-04 14:00:24 -0400 | [diff] [blame] | 98 | import static android.view.WindowManager.LayoutParams.TYPE_TRUSTED_APPLICATION_OVERLAY; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 99 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; |
| 100 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING; |
| 101 | import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; |
| 102 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
| 103 | import static android.view.WindowManagerGlobal.ADD_OKAY; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 104 | import static android.view.WindowManagerPolicyConstants.ACTION_HDMI_PLUGGED; |
| 105 | import static android.view.WindowManagerPolicyConstants.EXTRA_HDMI_PLUGGED_STATE; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 106 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_BOTTOM; |
| 107 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_LEFT; |
| 108 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_RIGHT; |
| 109 | |
| 110 | import static com.android.server.policy.PhoneWindowManager.TOAST_WINDOW_TIMEOUT; |
| 111 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
| 112 | import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER; |
| 113 | import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT; |
| 114 | import static com.android.server.policy.WindowManagerPolicy.TRANSIT_HIDE; |
| 115 | import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 116 | import static com.android.server.policy.WindowManagerPolicy.TRANSIT_SHOW; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 117 | import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 118 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_SCREEN_ON; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 119 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 120 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 121 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 122 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 123 | |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 124 | import android.Manifest.permission; |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 125 | import android.annotation.NonNull; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 126 | import android.annotation.Nullable; |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 127 | import android.annotation.Px; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 128 | import android.app.ActivityManager; |
| 129 | import android.app.ActivityThread; |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 130 | import android.app.LoadedApk; |
| 131 | import android.app.ResourcesManager; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 132 | import android.app.StatusBarManager; |
| 133 | import android.content.Context; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 134 | import android.content.Intent; |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 135 | import android.content.pm.PackageManager; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 136 | import android.content.res.Resources; |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 137 | import android.graphics.Insets; |
Arthur Hung | 2047992 | 2019-02-27 17:13:22 +0800 | [diff] [blame] | 138 | import android.graphics.PixelFormat; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 139 | import android.graphics.Rect; |
Winson Chung | 3694163 | 2019-04-19 15:21:38 -0700 | [diff] [blame] | 140 | import android.graphics.Region; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 141 | import android.hardware.input.InputManager; |
| 142 | import android.hardware.power.V1_0.PowerHint; |
| 143 | import android.os.Handler; |
| 144 | import android.os.Looper; |
| 145 | import android.os.Message; |
| 146 | import android.os.SystemClock; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 147 | import android.os.SystemProperties; |
| 148 | import android.os.UserHandle; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 149 | import android.util.ArraySet; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 150 | import android.util.IntArray; |
Tarandeep Singh | e439dec | 2019-04-22 12:28:43 -0700 | [diff] [blame] | 151 | import android.util.Pair; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 152 | import android.util.PrintWriterPrinter; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 153 | import android.util.Slog; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 154 | import android.view.DisplayCutout; |
| 155 | import android.view.Gravity; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 156 | import android.view.InputChannel; |
| 157 | import android.view.InputDevice; |
| 158 | import android.view.InputEvent; |
| 159 | import android.view.InputEventReceiver; |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 160 | import android.view.InsetsFlags; |
Tiger Huang | 9ff42bd | 2020-05-01 03:27:33 +0800 | [diff] [blame] | 161 | import android.view.InsetsSource; |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 162 | import android.view.InsetsState; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 163 | import android.view.InsetsState.InternalInsetsType; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 164 | import android.view.MotionEvent; |
| 165 | import android.view.PointerIcon; |
| 166 | import android.view.Surface; |
| 167 | import android.view.View; |
Jorim Jaggi | 648e588 | 2019-01-24 13:24:02 +0100 | [diff] [blame] | 168 | import android.view.ViewRootImpl; |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 169 | import android.view.WindowInsets.Side; |
| 170 | import android.view.WindowInsets.Side.InsetsSide; |
| 171 | import android.view.WindowInsets.Type; |
| 172 | import android.view.WindowInsets.Type.InsetsType; |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 173 | import android.view.WindowInsetsController.Appearance; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 174 | import android.view.WindowManager; |
| 175 | import android.view.WindowManager.LayoutParams; |
| 176 | import android.view.WindowManagerGlobal; |
| 177 | import android.view.WindowManagerPolicyConstants; |
| 178 | import android.view.accessibility.AccessibilityManager; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 179 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 180 | import com.android.internal.R; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 181 | import com.android.internal.annotations.VisibleForTesting; |
Mehdi Alizadeh | f2b28e9 | 2019-12-05 20:13:49 -0800 | [diff] [blame] | 182 | import com.android.internal.policy.GestureNavigationSettingsObserver; |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 183 | import com.android.internal.policy.ScreenDecorationsUtils; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 184 | import com.android.internal.util.ScreenshotHelper; |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 185 | import com.android.internal.util.function.TriConsumer; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 186 | import com.android.internal.view.AppearanceRegion; |
Arthur Hung | 2047992 | 2019-02-27 17:13:22 +0800 | [diff] [blame] | 187 | import com.android.internal.widget.PointerLocationView; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 188 | import com.android.server.LocalServices; |
| 189 | import com.android.server.UiThread; |
| 190 | import com.android.server.policy.WindowManagerPolicy; |
| 191 | import com.android.server.policy.WindowManagerPolicy.InputConsumer; |
| 192 | import com.android.server.policy.WindowManagerPolicy.NavigationBarPosition; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 193 | import com.android.server.policy.WindowManagerPolicy.ScreenOnListener; |
| 194 | import com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 195 | import com.android.server.policy.WindowOrientationListener; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 196 | import com.android.server.protolog.common.ProtoLog; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 197 | import com.android.server.statusbar.StatusBarManagerInternal; |
wilsonshih | 643bf13 | 2019-02-27 12:49:19 +0800 | [diff] [blame] | 198 | import com.android.server.wallpaper.WallpaperManagerInternal; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 199 | import com.android.server.wm.utils.InsetUtils; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 200 | |
| 201 | import java.io.PrintWriter; |
| 202 | |
| 203 | /** |
| 204 | * The policy that provides the basic behaviors and states of a display to show UI. |
| 205 | */ |
| 206 | public class DisplayPolicy { |
| 207 | private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayPolicy" : TAG_WM; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 208 | private static final boolean DEBUG = false; |
| 209 | |
| 210 | private static final boolean ALTERNATE_CAR_MODE_NAV_SIZE = false; |
| 211 | |
| 212 | // The panic gesture may become active only after the keyguard is dismissed and the immersive |
| 213 | // app shows again. If that doesn't happen for 30s we drop the gesture. |
| 214 | private static final long PANIC_GESTURE_EXPIRATION = 30000; |
| 215 | |
| 216 | // Controls navigation bar opacity depending on which workspace stacks are currently |
| 217 | // visible. |
| 218 | // Nav bar is always opaque when either the freeform stack or docked stack is visible. |
| 219 | private static final int NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED = 0; |
| 220 | // Nav bar is always translucent when the freeform stack is visible, otherwise always opaque. |
| 221 | private static final int NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE = 1; |
Adrian Roos | faba406 | 2019-05-14 15:27:17 +0200 | [diff] [blame] | 222 | // Nav bar is never forced opaque. |
| 223 | private static final int NAV_BAR_FORCE_TRANSPARENT = 2; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 224 | |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 225 | /** Don't apply window animation (see {@link #selectAnimation}). */ |
| 226 | static final int ANIMATION_NONE = -1; |
| 227 | /** Use the transit animation in style resource (see {@link #selectAnimation}). */ |
| 228 | static final int ANIMATION_STYLEABLE = 0; |
| 229 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 230 | /** |
| 231 | * These are the system UI flags that, when changing, can cause the layout |
| 232 | * of the screen to change. |
| 233 | */ |
| 234 | private static final int SYSTEM_UI_CHANGING_LAYOUT = |
| 235 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 236 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 237 | | View.STATUS_BAR_TRANSLUCENT |
| 238 | | View.NAVIGATION_BAR_TRANSLUCENT |
| 239 | | View.STATUS_BAR_TRANSPARENT |
| 240 | | View.NAVIGATION_BAR_TRANSPARENT; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 241 | |
| 242 | private final WindowManagerService mService; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 243 | private final Context mContext; |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 244 | private final Context mUiContext; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 245 | private final DisplayContent mDisplayContent; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 246 | private final Object mLock; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 247 | private final Handler mHandler; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 248 | |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 249 | private Resources mCurrentUserResources; |
| 250 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 251 | private final boolean mCarDockEnablesAccelerometer; |
| 252 | private final boolean mDeskDockEnablesAccelerometer; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 253 | private final AccessibilityManager mAccessibilityManager; |
| 254 | private final ImmersiveModeConfirmation mImmersiveModeConfirmation; |
| 255 | private final ScreenshotHelper mScreenshotHelper; |
| 256 | |
| 257 | private final Object mServiceAcquireLock = new Object(); |
| 258 | private StatusBarManagerInternal mStatusBarManagerInternal; |
| 259 | |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 260 | @Px |
| 261 | private int mBottomGestureAdditionalInset; |
| 262 | @Px |
Mehdi Alizadeh | f2b28e9 | 2019-12-05 20:13:49 -0800 | [diff] [blame] | 263 | private int mLeftGestureInset; |
| 264 | @Px |
| 265 | private int mRightGestureInset; |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 266 | |
Sunny Goyal | 3841295 | 2020-04-17 11:35:37 -0700 | [diff] [blame] | 267 | private boolean mNavButtonForcedVisible; |
| 268 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 269 | StatusBarManagerInternal getStatusBarManagerInternal() { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 270 | synchronized (mServiceAcquireLock) { |
| 271 | if (mStatusBarManagerInternal == null) { |
| 272 | mStatusBarManagerInternal = |
| 273 | LocalServices.getService(StatusBarManagerInternal.class); |
| 274 | } |
| 275 | return mStatusBarManagerInternal; |
| 276 | } |
| 277 | } |
| 278 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 279 | private final SystemGesturesPointerEventListener mSystemGestures; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 280 | |
| 281 | private volatile int mLidState = LID_ABSENT; |
| 282 | private volatile int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 283 | private volatile boolean mHdmiPlugged; |
| 284 | |
Louis Chang | fc64c83 | 2018-12-04 11:38:26 +0800 | [diff] [blame] | 285 | private volatile boolean mHasStatusBar; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 286 | private volatile boolean mHasNavigationBar; |
| 287 | // Can the navigation bar ever move to the side? |
| 288 | private volatile boolean mNavigationBarCanMove; |
Winson Chung | 3694163 | 2019-04-19 15:21:38 -0700 | [diff] [blame] | 289 | private volatile boolean mNavigationBarLetsThroughTaps; |
| 290 | private volatile boolean mNavigationBarAlwaysShowOnSideGesture; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 291 | |
| 292 | // Written by vr manager thread, only read in this class. |
| 293 | private volatile boolean mPersistentVrModeEnabled; |
| 294 | |
| 295 | private volatile boolean mAwake; |
| 296 | private volatile boolean mScreenOnEarly; |
| 297 | private volatile boolean mScreenOnFully; |
| 298 | private volatile ScreenOnListener mScreenOnListener; |
| 299 | |
| 300 | private volatile boolean mKeyguardDrawComplete; |
| 301 | private volatile boolean mWindowManagerDrawComplete; |
| 302 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 303 | private final ArraySet<WindowState> mScreenDecorWindows = new ArraySet<>(); |
| 304 | private WindowState mStatusBar = null; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 305 | private WindowState mNotificationShade = null; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 306 | private final int[] mStatusBarHeightForRotation = new int[4]; |
| 307 | private WindowState mNavigationBar = null; |
| 308 | @NavigationBarPosition |
| 309 | private int mNavigationBarPosition = NAV_BAR_BOTTOM; |
| 310 | private int[] mNavigationBarHeightForRotationDefault = new int[4]; |
| 311 | private int[] mNavigationBarWidthForRotationDefault = new int[4]; |
| 312 | private int[] mNavigationBarHeightForRotationInCarMode = new int[4]; |
| 313 | private int[] mNavigationBarWidthForRotationInCarMode = new int[4]; |
| 314 | |
Matthew Ng | a7f24bc | 2019-04-09 17:06:41 -0700 | [diff] [blame] | 315 | /** See {@link #getNavigationBarFrameHeight} */ |
| 316 | private int[] mNavigationBarFrameHeightForRotationDefault = new int[4]; |
| 317 | |
HEO SEUNG | 22d3ec2 | 2019-05-30 20:28:53 +0900 | [diff] [blame] | 318 | private boolean mIsFreeformWindowOverlappingWithNavBar; |
| 319 | |
Tiger Huang | dd6db47 | 2020-02-13 21:38:46 +0800 | [diff] [blame] | 320 | private boolean mLastImmersiveMode; |
| 321 | |
Riddle Hsu | d80ae9b | 2019-03-26 00:40:35 +0800 | [diff] [blame] | 322 | private final StatusBarController mStatusBarController; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 323 | |
Riddle Hsu | d80ae9b | 2019-03-26 00:40:35 +0800 | [diff] [blame] | 324 | private final BarController mNavigationBarController; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 325 | |
| 326 | private final BarController.OnBarVisibilityChangedListener mNavBarVisibilityListener = |
| 327 | new BarController.OnBarVisibilityChangedListener() { |
| 328 | @Override |
| 329 | public void onBarVisibilityChanged(boolean visible) { |
| 330 | if (mAccessibilityManager == null) { |
| 331 | return; |
| 332 | } |
| 333 | mAccessibilityManager.notifyAccessibilityButtonVisibilityChanged(visible); |
| 334 | } |
| 335 | }; |
| 336 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 337 | // The windows we were told about in focusChanged. |
| 338 | private WindowState mFocusedWindow; |
| 339 | private WindowState mLastFocusedWindow; |
| 340 | |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 341 | // The states of decor windows from the last layout. These are used to generate another display |
| 342 | // layout in different bounds but with the same states. |
| 343 | private boolean mLastNavVisible; |
| 344 | private boolean mLastNavTranslucent; |
| 345 | private boolean mLastNavAllowedHidden; |
| 346 | private boolean mLastNotificationShadeForcesShowingNavigation; |
| 347 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 348 | int mLastSystemUiFlags; |
| 349 | // Bits that we are in the process of clearing, so we want to prevent |
| 350 | // them from being set by applications until everything has been updated |
| 351 | // to have them clear. |
| 352 | private int mResettingSystemUiFlags = 0; |
| 353 | // Bits that we are currently always keeping cleared. |
| 354 | private int mForceClearedSystemUiFlags = 0; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 355 | private int mLastAppearance; |
| 356 | private int mLastFullscreenAppearance; |
| 357 | private int mLastDockedAppearance; |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 358 | private int mLastBehavior; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 359 | private final Rect mNonDockedStackBounds = new Rect(); |
| 360 | private final Rect mDockedStackBounds = new Rect(); |
| 361 | private final Rect mLastNonDockedStackBounds = new Rect(); |
| 362 | private final Rect mLastDockedStackBounds = new Rect(); |
| 363 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 364 | // What we last reported to system UI about whether the focused window is fullscreen/immersive. |
| 365 | private boolean mLastFocusIsFullscreen = false; |
| 366 | private boolean mLastFocusIsImmersive = false; |
| 367 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 368 | // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending. |
| 369 | private long mPendingPanicGestureUptime; |
| 370 | |
| 371 | private static final Rect sTmpDisplayCutoutSafeExceptMaybeBarsRect = new Rect(); |
| 372 | private static final Rect sTmpRect = new Rect(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 373 | private static final Rect sTmpNavFrame = new Rect(); |
| 374 | private static final Rect sTmpLastParentFrame = new Rect(); |
| 375 | |
| 376 | private WindowState mTopFullscreenOpaqueWindowState; |
| 377 | private WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
| 378 | private WindowState mTopDockedOpaqueWindowState; |
| 379 | private WindowState mTopDockedOpaqueOrDimmingWindowState; |
| 380 | private boolean mTopIsFullscreen; |
| 381 | private boolean mForceStatusBar; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 382 | private int mNavBarOpacityMode = NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED; |
| 383 | private boolean mForcingShowNavBar; |
| 384 | private int mForcingShowNavBarLayer; |
| 385 | private boolean mForceShowSystemBars; |
| 386 | |
Brad Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 387 | /** |
| 388 | * Force the display of system bars regardless of other settings. |
| 389 | */ |
| 390 | private boolean mForceShowSystemBarsFromExternal; |
| 391 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 392 | private boolean mShowingDream; |
| 393 | private boolean mLastShowingDream; |
| 394 | private boolean mDreamingLockscreen; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 395 | private boolean mAllowLockscreenWhenOn; |
| 396 | |
Tiger Huang | 9ff42bd | 2020-05-01 03:27:33 +0800 | [diff] [blame] | 397 | @VisibleForTesting |
| 398 | InputConsumer mInputConsumer = null; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 399 | |
Arthur Hung | 2047992 | 2019-02-27 17:13:22 +0800 | [diff] [blame] | 400 | private PointerLocationView mPointerLocationView; |
| 401 | |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 402 | /** |
| 403 | * The area covered by system windows which belong to another display. Forwarded insets is set |
| 404 | * in case this is a virtual display, this is displayed on another display that has insets, and |
| 405 | * the bounds of this display is overlapping with the insets of the host display (e.g. IME is |
| 406 | * displayed on the host display, and it covers a part of this virtual display.) |
| 407 | * The forwarded insets is used to compute display frames of this virtual display, which will |
| 408 | * be then used to layout windows in the virtual display. |
| 409 | */ |
| 410 | @NonNull private Insets mForwardedInsets = Insets.NONE; |
| 411 | |
Ady Abraham | f3e0531 | 2019-05-13 18:04:59 -0700 | [diff] [blame] | 412 | private RefreshRatePolicy mRefreshRatePolicy; |
| 413 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 414 | // -------- PolicyHandler -------- |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 415 | private static final int MSG_REQUEST_TRANSIENT_BARS = 2; |
| 416 | private static final int MSG_DISPOSE_INPUT_CONSUMER = 3; |
Arthur Hung | 2047992 | 2019-02-27 17:13:22 +0800 | [diff] [blame] | 417 | private static final int MSG_ENABLE_POINTER_LOCATION = 4; |
| 418 | private static final int MSG_DISABLE_POINTER_LOCATION = 5; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 419 | |
| 420 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0; |
| 421 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1; |
| 422 | |
Mehdi Alizadeh | f2b28e9 | 2019-12-05 20:13:49 -0800 | [diff] [blame] | 423 | private final GestureNavigationSettingsObserver mGestureNavigationSettingsObserver; |
| 424 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 425 | private class PolicyHandler extends Handler { |
| 426 | |
| 427 | PolicyHandler(Looper looper) { |
| 428 | super(looper); |
| 429 | } |
| 430 | |
| 431 | @Override |
| 432 | public void handleMessage(Message msg) { |
| 433 | switch (msg.what) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 434 | case MSG_REQUEST_TRANSIENT_BARS: |
Tiger Huang | 82fd0ad | 2020-03-09 17:55:47 +0800 | [diff] [blame] | 435 | synchronized (mLock) { |
| 436 | WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) |
| 437 | ? mStatusBar : mNavigationBar; |
| 438 | if (targetBar != null) { |
| 439 | requestTransientBars(targetBar); |
| 440 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 441 | } |
| 442 | break; |
| 443 | case MSG_DISPOSE_INPUT_CONSUMER: |
| 444 | disposeInputConsumer((InputConsumer) msg.obj); |
| 445 | break; |
Arthur Hung | 2047992 | 2019-02-27 17:13:22 +0800 | [diff] [blame] | 446 | case MSG_ENABLE_POINTER_LOCATION: |
| 447 | enablePointerLocation(); |
| 448 | break; |
| 449 | case MSG_DISABLE_POINTER_LOCATION: |
| 450 | disablePointerLocation(); |
| 451 | break; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | DisplayPolicy(WindowManagerService service, DisplayContent displayContent) { |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 457 | mService = service; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 458 | mContext = displayContent.isDefaultDisplay ? service.mContext |
| 459 | : service.mContext.createDisplayContext(displayContent.getDisplay()); |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 460 | mUiContext = displayContent.isDefaultDisplay ? service.mAtmService.mUiContext |
| 461 | : service.mAtmService.mSystemThread |
| 462 | .createSystemUiContext(displayContent.getDisplayId()); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 463 | mDisplayContent = displayContent; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 464 | mLock = service.getWindowManagerLock(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 465 | |
Riddle Hsu | d80ae9b | 2019-03-26 00:40:35 +0800 | [diff] [blame] | 466 | final int displayId = displayContent.getDisplayId(); |
| 467 | mStatusBarController = new StatusBarController(displayId); |
| 468 | mNavigationBarController = new BarController("NavigationBar", |
| 469 | displayId, |
| 470 | View.NAVIGATION_BAR_TRANSIENT, |
| 471 | View.NAVIGATION_BAR_UNHIDE, |
| 472 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 473 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
| 474 | FLAG_TRANSLUCENT_NAVIGATION, |
| 475 | View.NAVIGATION_BAR_TRANSPARENT); |
| 476 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 477 | final Resources r = mContext.getResources(); |
| 478 | mCarDockEnablesAccelerometer = r.getBoolean(R.bool.config_carDockEnablesAccelerometer); |
| 479 | mDeskDockEnablesAccelerometer = r.getBoolean(R.bool.config_deskDockEnablesAccelerometer); |
Brad Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 480 | mForceShowSystemBarsFromExternal = r.getBoolean(R.bool.config_forceShowSystemBars); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 481 | |
| 482 | mAccessibilityManager = (AccessibilityManager) mContext.getSystemService( |
| 483 | Context.ACCESSIBILITY_SERVICE); |
| 484 | if (!displayContent.isDefaultDisplay) { |
| 485 | mAwake = true; |
| 486 | mScreenOnEarly = true; |
| 487 | mScreenOnFully = true; |
| 488 | } |
| 489 | |
| 490 | final Looper looper = UiThread.getHandler().getLooper(); |
| 491 | mHandler = new PolicyHandler(looper); |
| 492 | mSystemGestures = new SystemGesturesPointerEventListener(mContext, mHandler, |
| 493 | new SystemGesturesPointerEventListener.Callbacks() { |
| 494 | @Override |
| 495 | public void onSwipeFromTop() { |
Tiger Huang | 82fd0ad | 2020-03-09 17:55:47 +0800 | [diff] [blame] | 496 | synchronized (mLock) { |
| 497 | if (mStatusBar != null) { |
| 498 | requestTransientBars(mStatusBar); |
| 499 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
| 503 | @Override |
| 504 | public void onSwipeFromBottom() { |
Tiger Huang | 82fd0ad | 2020-03-09 17:55:47 +0800 | [diff] [blame] | 505 | synchronized (mLock) { |
| 506 | if (mNavigationBar != null |
| 507 | && mNavigationBarPosition == NAV_BAR_BOTTOM) { |
| 508 | requestTransientBars(mNavigationBar); |
| 509 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
| 513 | @Override |
| 514 | public void onSwipeFromRight() { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 515 | final Region excludedRegion = Region.obtain(); |
Jeff Chang | 3cf3e56 | 2019-06-18 11:51:25 +0800 | [diff] [blame] | 516 | synchronized (mLock) { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 517 | mDisplayContent.calculateSystemGestureExclusion( |
| 518 | excludedRegion, null /* outUnrestricted */); |
Tiger Huang | 82fd0ad | 2020-03-09 17:55:47 +0800 | [diff] [blame] | 519 | final boolean sideAllowed = mNavigationBarAlwaysShowOnSideGesture |
| 520 | || mNavigationBarPosition == NAV_BAR_RIGHT; |
| 521 | if (mNavigationBar != null && sideAllowed |
| 522 | && !mSystemGestures.currentGestureStartedInRegion( |
| 523 | excludedRegion)) { |
| 524 | requestTransientBars(mNavigationBar); |
| 525 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 526 | } |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 527 | excludedRegion.recycle(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | @Override |
| 531 | public void onSwipeFromLeft() { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 532 | final Region excludedRegion = Region.obtain(); |
Jeff Chang | 3cf3e56 | 2019-06-18 11:51:25 +0800 | [diff] [blame] | 533 | synchronized (mLock) { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 534 | mDisplayContent.calculateSystemGestureExclusion( |
| 535 | excludedRegion, null /* outUnrestricted */); |
Tiger Huang | 82fd0ad | 2020-03-09 17:55:47 +0800 | [diff] [blame] | 536 | final boolean sideAllowed = mNavigationBarAlwaysShowOnSideGesture |
| 537 | || mNavigationBarPosition == NAV_BAR_LEFT; |
| 538 | if (mNavigationBar != null && sideAllowed |
| 539 | && !mSystemGestures.currentGestureStartedInRegion( |
| 540 | excludedRegion)) { |
| 541 | requestTransientBars(mNavigationBar); |
| 542 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 543 | } |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 544 | excludedRegion.recycle(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | @Override |
| 548 | public void onFling(int duration) { |
| 549 | if (mService.mPowerManagerInternal != null) { |
| 550 | mService.mPowerManagerInternal.powerHint( |
| 551 | PowerHint.INTERACTION, duration); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | @Override |
| 556 | public void onDebug() { |
| 557 | // no-op |
| 558 | } |
| 559 | |
| 560 | private WindowOrientationListener getOrientationListener() { |
| 561 | final DisplayRotation rotation = mDisplayContent.getDisplayRotation(); |
| 562 | return rotation != null ? rotation.getOrientationListener() : null; |
| 563 | } |
| 564 | |
| 565 | @Override |
| 566 | public void onDown() { |
| 567 | final WindowOrientationListener listener = getOrientationListener(); |
| 568 | if (listener != null) { |
| 569 | listener.onTouchStart(); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | @Override |
| 574 | public void onUpOrCancel() { |
| 575 | final WindowOrientationListener listener = getOrientationListener(); |
| 576 | if (listener != null) { |
| 577 | listener.onTouchEnd(); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | @Override |
| 582 | public void onMouseHoverAtTop() { |
| 583 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 584 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 585 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS; |
| 586 | mHandler.sendMessageDelayed(msg, 500 /* delayMillis */); |
| 587 | } |
| 588 | |
| 589 | @Override |
| 590 | public void onMouseHoverAtBottom() { |
| 591 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 592 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 593 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION; |
| 594 | mHandler.sendMessageDelayed(msg, 500 /* delayMillis */); |
| 595 | } |
| 596 | |
| 597 | @Override |
| 598 | public void onMouseLeaveFromEdge() { |
| 599 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 600 | } |
| 601 | }); |
| 602 | displayContent.registerPointerEventListener(mSystemGestures); |
| 603 | displayContent.mAppTransition.registerListenerLocked( |
| 604 | mStatusBarController.getAppTransitionListener()); |
| 605 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext, looper, |
| 606 | mService.mVrModeEnabled); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 607 | |
| 608 | // TODO: Make it can take screenshot on external display |
| 609 | mScreenshotHelper = displayContent.isDefaultDisplay |
| 610 | ? new ScreenshotHelper(mContext) : null; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 611 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 612 | if (mDisplayContent.isDefaultDisplay) { |
Louis Chang | fc64c83 | 2018-12-04 11:38:26 +0800 | [diff] [blame] | 613 | mHasStatusBar = true; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 614 | mHasNavigationBar = mContext.getResources().getBoolean(R.bool.config_showNavigationBar); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 615 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 616 | // Allow a system property to override this. Used by the emulator. |
| 617 | // See also hasNavigationBar(). |
| 618 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 619 | if ("1".equals(navBarOverride)) { |
| 620 | mHasNavigationBar = false; |
| 621 | } else if ("0".equals(navBarOverride)) { |
| 622 | mHasNavigationBar = true; |
| 623 | } |
| 624 | } else { |
Louis Chang | fc64c83 | 2018-12-04 11:38:26 +0800 | [diff] [blame] | 625 | mHasStatusBar = false; |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 626 | mHasNavigationBar = mDisplayContent.supportsSystemDecorations(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 627 | } |
Ady Abraham | f3e0531 | 2019-05-13 18:04:59 -0700 | [diff] [blame] | 628 | |
| 629 | mRefreshRatePolicy = new RefreshRatePolicy(mService, |
| 630 | mDisplayContent.getDisplayInfo(), |
| 631 | mService.mHighRefreshRateBlacklist); |
Mehdi Alizadeh | f2b28e9 | 2019-12-05 20:13:49 -0800 | [diff] [blame] | 632 | |
| 633 | mGestureNavigationSettingsObserver = new GestureNavigationSettingsObserver(mHandler, |
| 634 | mContext, () -> { |
| 635 | synchronized (mLock) { |
| 636 | onConfigurationChanged(); |
| 637 | mSystemGestures.onConfigurationChanged(); |
| 638 | mDisplayContent.updateSystemGestureExclusion(); |
| 639 | } |
| 640 | }); |
| 641 | mHandler.post(mGestureNavigationSettingsObserver::register); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 642 | } |
| 643 | |
Charles Chen | 5bdd3e2 | 2018-12-18 17:51:56 +0800 | [diff] [blame] | 644 | void systemReady() { |
| 645 | mSystemGestures.systemReady(); |
Arthur Hung | 2047992 | 2019-02-27 17:13:22 +0800 | [diff] [blame] | 646 | if (mService.mPointerLocationEnabled) { |
| 647 | setPointerLocationEnabled(true); |
| 648 | } |
Charles Chen | 5bdd3e2 | 2018-12-18 17:51:56 +0800 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | private int getDisplayId() { |
| 652 | return mDisplayContent.getDisplayId(); |
| 653 | } |
| 654 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 655 | public void setHdmiPlugged(boolean plugged) { |
| 656 | setHdmiPlugged(plugged, false /* force */); |
| 657 | } |
| 658 | |
| 659 | public void setHdmiPlugged(boolean plugged, boolean force) { |
| 660 | if (force || mHdmiPlugged != plugged) { |
| 661 | mHdmiPlugged = plugged; |
| 662 | mService.updateRotation(true /* alwaysSendConfiguration */, true /* forceRelayout */); |
| 663 | final Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
| 664 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 665 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 666 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 667 | } |
| 668 | } |
| 669 | |
| 670 | boolean isHdmiPlugged() { |
| 671 | return mHdmiPlugged; |
| 672 | } |
| 673 | |
| 674 | boolean isCarDockEnablesAccelerometer() { |
| 675 | return mCarDockEnablesAccelerometer; |
| 676 | } |
| 677 | |
| 678 | boolean isDeskDockEnablesAccelerometer() { |
| 679 | return mDeskDockEnablesAccelerometer; |
| 680 | } |
| 681 | |
| 682 | public void setPersistentVrModeEnabled(boolean persistentVrModeEnabled) { |
| 683 | mPersistentVrModeEnabled = persistentVrModeEnabled; |
| 684 | } |
| 685 | |
| 686 | public boolean isPersistentVrModeEnabled() { |
| 687 | return mPersistentVrModeEnabled; |
| 688 | } |
| 689 | |
| 690 | public void setDockMode(int dockMode) { |
| 691 | mDockMode = dockMode; |
| 692 | } |
| 693 | |
| 694 | public int getDockMode() { |
| 695 | return mDockMode; |
| 696 | } |
| 697 | |
Brad Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 698 | /** |
| 699 | * @see WindowManagerService.setForceShowSystemBars |
| 700 | */ |
| 701 | void setForceShowSystemBars(boolean forceShowSystemBars) { |
| 702 | mForceShowSystemBarsFromExternal = forceShowSystemBars; |
| 703 | } |
| 704 | |
JianYang Liu | ae86b3f | 2020-04-03 20:20:35 -0700 | [diff] [blame] | 705 | boolean getForceShowSystemBars() { |
| 706 | return mForceShowSystemBarsFromExternal; |
| 707 | } |
| 708 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 709 | public boolean hasNavigationBar() { |
| 710 | return mHasNavigationBar; |
| 711 | } |
| 712 | |
Louis Chang | fc64c83 | 2018-12-04 11:38:26 +0800 | [diff] [blame] | 713 | public boolean hasStatusBar() { |
| 714 | return mHasStatusBar; |
| 715 | } |
| 716 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 717 | boolean hasSideGestures() { |
Mehdi Alizadeh | f2b28e9 | 2019-12-05 20:13:49 -0800 | [diff] [blame] | 718 | return mHasNavigationBar && (mLeftGestureInset > 0 || mRightGestureInset > 0); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 719 | } |
| 720 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 721 | public boolean navigationBarCanMove() { |
| 722 | return mNavigationBarCanMove; |
| 723 | } |
| 724 | |
| 725 | public void setLidState(int lidState) { |
| 726 | mLidState = lidState; |
| 727 | } |
| 728 | |
| 729 | public int getLidState() { |
| 730 | return mLidState; |
| 731 | } |
| 732 | |
| 733 | public void setAwake(boolean awake) { |
| 734 | mAwake = awake; |
| 735 | } |
| 736 | |
| 737 | public boolean isAwake() { |
| 738 | return mAwake; |
| 739 | } |
| 740 | |
| 741 | public boolean isScreenOnEarly() { |
| 742 | return mScreenOnEarly; |
| 743 | } |
| 744 | |
| 745 | public boolean isScreenOnFully() { |
| 746 | return mScreenOnFully; |
| 747 | } |
| 748 | |
| 749 | public boolean isKeyguardDrawComplete() { |
| 750 | return mKeyguardDrawComplete; |
| 751 | } |
| 752 | |
| 753 | public boolean isWindowManagerDrawComplete() { |
| 754 | return mWindowManagerDrawComplete; |
| 755 | } |
| 756 | |
| 757 | public ScreenOnListener getScreenOnListener() { |
| 758 | return mScreenOnListener; |
| 759 | } |
| 760 | |
| 761 | public void screenTurnedOn(ScreenOnListener screenOnListener) { |
| 762 | synchronized (mLock) { |
| 763 | mScreenOnEarly = true; |
| 764 | mScreenOnFully = false; |
| 765 | mKeyguardDrawComplete = false; |
| 766 | mWindowManagerDrawComplete = false; |
| 767 | mScreenOnListener = screenOnListener; |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | public void screenTurnedOff() { |
| 772 | synchronized (mLock) { |
| 773 | mScreenOnEarly = false; |
| 774 | mScreenOnFully = false; |
| 775 | mKeyguardDrawComplete = false; |
| 776 | mWindowManagerDrawComplete = false; |
| 777 | mScreenOnListener = null; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | /** Return false if we are not awake yet or we have already informed of this event. */ |
| 782 | public boolean finishKeyguardDrawn() { |
| 783 | synchronized (mLock) { |
| 784 | if (!mScreenOnEarly || mKeyguardDrawComplete) { |
| 785 | return false; |
| 786 | } |
| 787 | |
| 788 | mKeyguardDrawComplete = true; |
| 789 | mWindowManagerDrawComplete = false; |
| 790 | } |
| 791 | return true; |
| 792 | } |
| 793 | |
| 794 | /** Return false if screen is not turned on or we did already handle this case earlier. */ |
| 795 | public boolean finishWindowsDrawn() { |
| 796 | synchronized (mLock) { |
| 797 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
| 798 | return false; |
| 799 | } |
| 800 | |
| 801 | mWindowManagerDrawComplete = true; |
| 802 | } |
| 803 | return true; |
| 804 | } |
| 805 | |
| 806 | /** Return false if it is not ready to turn on. */ |
| 807 | public boolean finishScreenTurningOn() { |
| 808 | synchronized (mLock) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 809 | ProtoLog.d(WM_DEBUG_SCREEN_ON, |
| 810 | "finishScreenTurningOn: mAwake=%b, mScreenOnEarly=%b, " |
| 811 | + "mScreenOnFully=%b, mKeyguardDrawComplete=%b, " |
| 812 | + "mWindowManagerDrawComplete=%b", |
| 813 | mAwake, mScreenOnEarly, mScreenOnFully, mKeyguardDrawComplete, |
| 814 | mWindowManagerDrawComplete); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 815 | |
| 816 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 817 | || (mAwake && !mKeyguardDrawComplete)) { |
| 818 | return false; |
| 819 | } |
| 820 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 821 | ProtoLog.i(WM_DEBUG_SCREEN_ON, "Finished screen turning on..."); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 822 | mScreenOnListener = null; |
| 823 | mScreenOnFully = true; |
| 824 | } |
| 825 | return true; |
| 826 | } |
| 827 | |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 828 | private boolean hasStatusBarServicePermission(int pid, int uid) { |
| 829 | return mContext.checkPermission(permission.STATUS_BAR_SERVICE, pid, uid) |
| 830 | == PackageManager.PERMISSION_GRANTED; |
| 831 | } |
| 832 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 833 | /** |
| 834 | * Sanitize the layout parameters coming from a client. Allows the policy |
| 835 | * to do things like ensure that windows of a specific type can't take |
| 836 | * input focus. |
| 837 | * |
| 838 | * @param attrs The window layout parameters to be modified. These values |
| 839 | * are modified in-place. |
| 840 | */ |
| 841 | public void adjustWindowParamsLw(WindowState win, WindowManager.LayoutParams attrs, |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 842 | int callingPid, int callingUid) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 843 | |
| 844 | final boolean isScreenDecor = (attrs.privateFlags & PRIVATE_FLAG_IS_SCREEN_DECOR) != 0; |
| 845 | if (mScreenDecorWindows.contains(win)) { |
| 846 | if (!isScreenDecor) { |
| 847 | // No longer has the flag set, so remove from the set. |
| 848 | mScreenDecorWindows.remove(win); |
| 849 | } |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 850 | } else if (isScreenDecor && hasStatusBarServicePermission(callingPid, callingUid)) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 851 | mScreenDecorWindows.add(win); |
| 852 | } |
| 853 | |
| 854 | switch (attrs.type) { |
| 855 | case TYPE_SYSTEM_OVERLAY: |
| 856 | case TYPE_SECURE_SYSTEM_OVERLAY: |
| 857 | // These types of windows can't receive input events. |
| 858 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 859 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 860 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
| 861 | break; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 862 | case TYPE_WALLPAPER: |
| 863 | // Dreams and wallpapers don't have an app window token and can thus not be |
| 864 | // letterboxed. Hence always let them extend under the cutout. |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 865 | attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 866 | break; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 867 | case TYPE_NOTIFICATION_SHADE: |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 868 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 869 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 870 | // the keyguard as occluded wouldn't set these flags again. |
| 871 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 872 | if (mService.mPolicy.isKeyguardOccluded()) { |
| 873 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 874 | } |
| 875 | break; |
| 876 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 877 | case TYPE_TOAST: |
| 878 | // While apps should use the dedicated toast APIs to add such windows |
| 879 | // it possible legacy apps to add the window directly. Therefore, we |
| 880 | // make windows added directly by the app behave as a toast as much |
| 881 | // as possible in terms of timeout and animation. |
| 882 | if (attrs.hideTimeoutMilliseconds < 0 |
| 883 | || attrs.hideTimeoutMilliseconds > TOAST_WINDOW_TIMEOUT) { |
| 884 | attrs.hideTimeoutMilliseconds = TOAST_WINDOW_TIMEOUT; |
| 885 | } |
Rhed Jao | 406d3a2 | 2018-11-30 19:28:58 +0800 | [diff] [blame] | 886 | // Accessibility users may need longer timeout duration. This api compares |
| 887 | // original timeout with user's preference and return longer one. It returns |
| 888 | // original timeout if there's no preference. |
| 889 | attrs.hideTimeoutMilliseconds = mAccessibilityManager.getRecommendedTimeoutMillis( |
| 890 | (int) attrs.hideTimeoutMilliseconds, |
| 891 | AccessibilityManager.FLAG_CONTENT_TEXT); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 892 | attrs.windowAnimations = com.android.internal.R.style.Animation_Toast; |
Jeff Chang | b10fac7 | 2019-04-09 17:28:30 +0800 | [diff] [blame] | 893 | // Toast can show with below conditions when the screen is locked. |
| 894 | if (canToastShowWhenLocked(callingPid)) { |
| 895 | attrs.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
| 896 | } |
Bernardo Rufino | 974de95 | 2019-10-22 11:53:42 +0100 | [diff] [blame] | 897 | // Toasts can't be clickable |
| 898 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 899 | break; |
Jorim Jaggi | 0da8fd1 | 2020-01-10 01:23:21 +0100 | [diff] [blame] | 900 | |
| 901 | case TYPE_BASE_APPLICATION: |
| 902 | |
| 903 | // A non-translucent main app window isn't allowed to fit insets, as it would create |
| 904 | // a hole on the display! |
| 905 | if (attrs.isFullscreen() && win.mActivityRecord != null |
| 906 | && win.mActivityRecord.fillsParent() |
| 907 | && (win.mAttrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS) != 0 |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 908 | && attrs.getFitInsetsTypes() != 0) { |
Jorim Jaggi | 0da8fd1 | 2020-01-10 01:23:21 +0100 | [diff] [blame] | 909 | throw new RuntimeException("Illegal attributes: Main activity window that isn't" |
| 910 | + " translucent trying to fit insets: " |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 911 | + attrs.getFitInsetsTypes() |
Jorim Jaggi | 0da8fd1 | 2020-01-10 01:23:21 +0100 | [diff] [blame] | 912 | + " attrs=" + attrs); |
| 913 | } |
| 914 | break; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 915 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | /** |
Jeff Chang | b10fac7 | 2019-04-09 17:28:30 +0800 | [diff] [blame] | 919 | * @return {@code true} if the calling activity initiate toast and is visible with |
| 920 | * {@link WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} flag. |
| 921 | */ |
| 922 | boolean canToastShowWhenLocked(int callingPid) { |
| 923 | return mDisplayContent.forAllWindows(w -> { |
| 924 | return callingPid == w.mSession.mPid && w.isVisible() && w.canShowWhenLocked(); |
| 925 | }, true /* traverseTopToBottom */); |
| 926 | } |
| 927 | |
| 928 | /** |
Tiger Huang | 5f6cbca | 2019-07-18 19:00:01 +0800 | [diff] [blame] | 929 | * Check if a window can be added to the system. |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 930 | * |
Tiger Huang | 5f6cbca | 2019-07-18 19:00:01 +0800 | [diff] [blame] | 931 | * Currently enforces that two window types are singletons per display: |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 932 | * <ul> |
| 933 | * <li>{@link WindowManager.LayoutParams#TYPE_STATUS_BAR}</li> |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 934 | * <li>{@link WindowManager.LayoutParams#TYPE_NOTIFICATION_SHADE}</li> |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 935 | * <li>{@link WindowManager.LayoutParams#TYPE_NAVIGATION_BAR}</li> |
| 936 | * </ul> |
| 937 | * |
Tiger Huang | 5f6cbca | 2019-07-18 19:00:01 +0800 | [diff] [blame] | 938 | * @param attrs Information about the window to be added. |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 939 | * |
| 940 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 941 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
| 942 | */ |
Riddle Hsu | 1371c57 | 2020-02-13 13:41:53 +0800 | [diff] [blame] | 943 | int validateAddingWindowLw(WindowManager.LayoutParams attrs, int callingPid, int callingUid) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 944 | if ((attrs.privateFlags & PRIVATE_FLAG_IS_SCREEN_DECOR) != 0) { |
Riddle Hsu | 1371c57 | 2020-02-13 13:41:53 +0800 | [diff] [blame] | 945 | mContext.enforcePermission( |
| 946 | android.Manifest.permission.STATUS_BAR_SERVICE, callingPid, callingUid, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 947 | "DisplayPolicy"); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | switch (attrs.type) { |
| 951 | case TYPE_STATUS_BAR: |
Riddle Hsu | 1371c57 | 2020-02-13 13:41:53 +0800 | [diff] [blame] | 952 | mContext.enforcePermission( |
| 953 | android.Manifest.permission.STATUS_BAR_SERVICE, callingPid, callingUid, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 954 | "DisplayPolicy"); |
| 955 | if (mStatusBar != null) { |
| 956 | if (mStatusBar.isAlive()) { |
| 957 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 958 | } |
| 959 | } |
Tiger Huang | 5f6cbca | 2019-07-18 19:00:01 +0800 | [diff] [blame] | 960 | break; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 961 | case TYPE_NOTIFICATION_SHADE: |
Riddle Hsu | 1371c57 | 2020-02-13 13:41:53 +0800 | [diff] [blame] | 962 | mContext.enforcePermission( |
| 963 | android.Manifest.permission.STATUS_BAR_SERVICE, callingPid, callingUid, |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 964 | "DisplayPolicy"); |
| 965 | if (mNotificationShade != null) { |
| 966 | if (mNotificationShade.isAlive()) { |
| 967 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 968 | } |
| 969 | } |
| 970 | break; |
Tiger Huang | 5f6cbca | 2019-07-18 19:00:01 +0800 | [diff] [blame] | 971 | case TYPE_NAVIGATION_BAR: |
Riddle Hsu | 1371c57 | 2020-02-13 13:41:53 +0800 | [diff] [blame] | 972 | mContext.enforcePermission( |
| 973 | android.Manifest.permission.STATUS_BAR_SERVICE, callingPid, callingUid, |
Tiger Huang | 5f6cbca | 2019-07-18 19:00:01 +0800 | [diff] [blame] | 974 | "DisplayPolicy"); |
| 975 | if (mNavigationBar != null) { |
| 976 | if (mNavigationBar.isAlive()) { |
| 977 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 978 | } |
| 979 | } |
| 980 | break; |
| 981 | case TYPE_NAVIGATION_BAR_PANEL: |
Matt Casey | 27f0bdd | 2020-01-28 12:19:28 -0500 | [diff] [blame] | 982 | // Check for permission if the caller is not the recents component. |
Riddle Hsu | 1371c57 | 2020-02-13 13:41:53 +0800 | [diff] [blame] | 983 | if (!mService.mAtmInternal.isCallerRecents(callingUid)) { |
| 984 | mContext.enforcePermission( |
| 985 | android.Manifest.permission.STATUS_BAR_SERVICE, callingPid, callingUid, |
| 986 | "DisplayPolicy"); |
Matt Casey | 27f0bdd | 2020-01-28 12:19:28 -0500 | [diff] [blame] | 987 | } |
| 988 | break; |
Heemin Seog | 2cf45dd | 2020-02-24 15:43:29 -0800 | [diff] [blame] | 989 | case TYPE_STATUS_BAR_ADDITIONAL: |
Tiger Huang | 5f6cbca | 2019-07-18 19:00:01 +0800 | [diff] [blame] | 990 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 991 | case TYPE_VOICE_INTERACTION_STARTING: |
Riddle Hsu | 1371c57 | 2020-02-13 13:41:53 +0800 | [diff] [blame] | 992 | mContext.enforcePermission( |
| 993 | android.Manifest.permission.STATUS_BAR_SERVICE, callingPid, callingUid, |
Tiger Huang | 5f6cbca | 2019-07-18 19:00:01 +0800 | [diff] [blame] | 994 | "DisplayPolicy"); |
| 995 | break; |
Joshua Tsuji | 94d4c34 | 2020-05-04 14:00:24 -0400 | [diff] [blame] | 996 | case TYPE_TRUSTED_APPLICATION_OVERLAY: |
| 997 | mContext.enforcePermission( |
| 998 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW, callingPid, callingUid, |
| 999 | "DisplayPolicy"); |
| 1000 | break; |
Heemin Seog | 2cf45dd | 2020-02-24 15:43:29 -0800 | [diff] [blame] | 1001 | case TYPE_STATUS_BAR_PANEL: |
| 1002 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
Tiger Huang | 5f6cbca | 2019-07-18 19:00:01 +0800 | [diff] [blame] | 1003 | } |
Yuncheol Heo | 13a6eb6 | 2020-03-04 23:50:37 -0800 | [diff] [blame] | 1004 | |
| 1005 | if (attrs.providesInsetsTypes != null) { |
| 1006 | mContext.enforcePermission( |
| 1007 | android.Manifest.permission.STATUS_BAR_SERVICE, callingPid, callingUid, |
| 1008 | "DisplayPolicy"); |
| 1009 | enforceSingleInsetsTypeCorrespondingToWindowType(attrs.providesInsetsTypes); |
| 1010 | } |
Tiger Huang | 5f6cbca | 2019-07-18 19:00:01 +0800 | [diff] [blame] | 1011 | return ADD_OKAY; |
| 1012 | } |
| 1013 | |
| 1014 | /** |
| 1015 | * Called when a window is being added to the system. Must not throw an exception. |
| 1016 | * |
| 1017 | * @param win The window being added. |
| 1018 | * @param attrs Information about the window to be added. |
| 1019 | */ |
| 1020 | void addWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 1021 | if ((attrs.privateFlags & PRIVATE_FLAG_IS_SCREEN_DECOR) != 0) { |
| 1022 | mScreenDecorWindows.add(win); |
| 1023 | } |
| 1024 | |
| 1025 | switch (attrs.type) { |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1026 | case TYPE_NOTIFICATION_SHADE: |
| 1027 | mNotificationShade = win; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1028 | if (mDisplayContent.isDefaultDisplay) { |
| 1029 | mService.mPolicy.setKeyguardCandidateLw(win); |
| 1030 | } |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1031 | break; |
| 1032 | case TYPE_STATUS_BAR: |
| 1033 | mStatusBar = win; |
| 1034 | mStatusBarController.setWindow(win); |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 1035 | final TriConsumer<DisplayFrames, WindowState, Rect> frameProvider = |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1036 | (displayFrames, windowState, rect) -> { |
| 1037 | rect.top = 0; |
| 1038 | rect.bottom = getStatusBarHeight(displayFrames); |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 1039 | }; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1040 | mDisplayContent.setInsetProvider(ITYPE_STATUS_BAR, win, frameProvider); |
| 1041 | mDisplayContent.setInsetProvider(ITYPE_TOP_GESTURES, win, frameProvider); |
| 1042 | mDisplayContent.setInsetProvider(ITYPE_TOP_TAPPABLE_ELEMENT, win, frameProvider); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1043 | break; |
| 1044 | case TYPE_NAVIGATION_BAR: |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1045 | mNavigationBar = win; |
| 1046 | mNavigationBarController.setWindow(win); |
| 1047 | mNavigationBarController.setOnBarVisibilityChangedListener( |
| 1048 | mNavBarVisibilityListener, true); |
Jorim Jaggi | dd3d510 | 2020-01-28 12:09:03 +0100 | [diff] [blame] | 1049 | mDisplayContent.setInsetProvider(ITYPE_NAVIGATION_BAR, win, |
| 1050 | (displayFrames, windowState, inOutFrame) -> { |
| 1051 | |
| 1052 | // In Gesture Nav, navigation bar frame is larger than frame to |
| 1053 | // calculate inset. |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 1054 | if (navigationBarPosition(displayFrames.mDisplayWidth, |
| 1055 | displayFrames.mDisplayHeight, |
Sunny Goyal | 3841295 | 2020-04-17 11:35:37 -0700 | [diff] [blame] | 1056 | displayFrames.mRotation) == NAV_BAR_BOTTOM |
| 1057 | && !mNavButtonForcedVisible) { |
| 1058 | |
Jorim Jaggi | dd3d510 | 2020-01-28 12:09:03 +0100 | [diff] [blame] | 1059 | sTmpRect.set(displayFrames.mUnrestricted); |
| 1060 | sTmpRect.intersectUnchecked(displayFrames.mDisplayCutoutSafe); |
| 1061 | inOutFrame.top = sTmpRect.bottom |
| 1062 | - getNavigationBarHeight(displayFrames.mRotation, |
Sunny Goyal | 3841295 | 2020-04-17 11:35:37 -0700 | [diff] [blame] | 1063 | mDisplayContent.getConfiguration().uiMode); |
Jorim Jaggi | dd3d510 | 2020-01-28 12:09:03 +0100 | [diff] [blame] | 1064 | } |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 1065 | }, |
| 1066 | |
| 1067 | // For IME we use regular frame. |
| 1068 | (displayFrames, windowState, inOutFrame) -> |
| 1069 | inOutFrame.set(windowState.getFrameLw())); |
| 1070 | |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1071 | mDisplayContent.setInsetProvider(ITYPE_BOTTOM_GESTURES, win, |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 1072 | (displayFrames, windowState, inOutFrame) -> { |
| 1073 | inOutFrame.top -= mBottomGestureAdditionalInset; |
| 1074 | }); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1075 | mDisplayContent.setInsetProvider(ITYPE_LEFT_GESTURES, win, |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 1076 | (displayFrames, windowState, inOutFrame) -> { |
| 1077 | inOutFrame.left = 0; |
| 1078 | inOutFrame.top = 0; |
| 1079 | inOutFrame.bottom = displayFrames.mDisplayHeight; |
Mehdi Alizadeh | f2b28e9 | 2019-12-05 20:13:49 -0800 | [diff] [blame] | 1080 | inOutFrame.right = displayFrames.mUnrestricted.left + mLeftGestureInset; |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 1081 | }); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1082 | mDisplayContent.setInsetProvider(ITYPE_RIGHT_GESTURES, win, |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 1083 | (displayFrames, windowState, inOutFrame) -> { |
Mehdi Alizadeh | f2b28e9 | 2019-12-05 20:13:49 -0800 | [diff] [blame] | 1084 | inOutFrame.left = displayFrames.mUnrestricted.right |
| 1085 | - mRightGestureInset; |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 1086 | inOutFrame.top = 0; |
| 1087 | inOutFrame.bottom = displayFrames.mDisplayHeight; |
| 1088 | inOutFrame.right = displayFrames.mDisplayWidth; |
| 1089 | }); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1090 | mDisplayContent.setInsetProvider(ITYPE_BOTTOM_TAPPABLE_ELEMENT, win, |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 1091 | (displayFrames, windowState, inOutFrame) -> { |
| 1092 | if ((windowState.getAttrs().flags & FLAG_NOT_TOUCHABLE) != 0 |
| 1093 | || mNavigationBarLetsThroughTaps) { |
| 1094 | inOutFrame.setEmpty(); |
| 1095 | } |
| 1096 | }); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1097 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
| 1098 | break; |
Yuncheol Heo | 13a6eb6 | 2020-03-04 23:50:37 -0800 | [diff] [blame] | 1099 | default: |
| 1100 | if (attrs.providesInsetsTypes != null) { |
| 1101 | for (int insetsType : attrs.providesInsetsTypes) { |
| 1102 | mDisplayContent.setInsetProvider(insetsType, win, null); |
| 1103 | } |
| 1104 | } |
| 1105 | break; |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | private static void enforceSingleInsetsTypeCorrespondingToWindowType(int[] insetsTypes) { |
| 1110 | int count = 0; |
| 1111 | for (int insetsType : insetsTypes) { |
| 1112 | switch (insetsType) { |
| 1113 | case ITYPE_NAVIGATION_BAR: |
| 1114 | case ITYPE_STATUS_BAR: |
| 1115 | case ITYPE_CAPTION_BAR: |
| 1116 | if (++count > 1) { |
| 1117 | throw new IllegalArgumentException( |
| 1118 | "Multiple InsetsTypes corresponding to Window type"); |
| 1119 | } |
| 1120 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1121 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | /** |
| 1125 | * Called when a window is being removed from a window manager. Must not |
| 1126 | * throw an exception -- clean up as much as possible. |
| 1127 | * |
| 1128 | * @param win The window being removed. |
| 1129 | */ |
Tiger Huang | 5f6cbca | 2019-07-18 19:00:01 +0800 | [diff] [blame] | 1130 | void removeWindowLw(WindowState win) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1131 | if (mStatusBar == win) { |
| 1132 | mStatusBar = null; |
| 1133 | mStatusBarController.setWindow(null); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1134 | mDisplayContent.setInsetProvider(ITYPE_STATUS_BAR, null, null); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1135 | } else if (mNavigationBar == win) { |
| 1136 | mNavigationBar = null; |
| 1137 | mNavigationBarController.setWindow(null); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1138 | mDisplayContent.setInsetProvider(ITYPE_NAVIGATION_BAR, null, null); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1139 | } else if (mNotificationShade == win) { |
| 1140 | mNotificationShade = null; |
| 1141 | if (mDisplayContent.isDefaultDisplay) { |
| 1142 | mService.mPolicy.setKeyguardCandidateLw(null); |
| 1143 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1144 | } |
| 1145 | if (mLastFocusedWindow == win) { |
| 1146 | mLastFocusedWindow = null; |
| 1147 | } |
| 1148 | mScreenDecorWindows.remove(win); |
| 1149 | } |
| 1150 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1151 | private int getStatusBarHeight(DisplayFrames displayFrames) { |
| 1152 | return Math.max(mStatusBarHeightForRotation[displayFrames.mRotation], |
| 1153 | displayFrames.mDisplayCutoutSafe.top); |
| 1154 | } |
| 1155 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 1156 | WindowState getStatusBar() { |
| 1157 | return mStatusBar; |
| 1158 | } |
| 1159 | |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1160 | WindowState getNotificationShade() { |
| 1161 | return mNotificationShade; |
| 1162 | } |
| 1163 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 1164 | WindowState getNavigationBar() { |
| 1165 | return mNavigationBar; |
| 1166 | } |
| 1167 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1168 | /** |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1169 | * Control the animation to run when a window's state changes. Return a positive number to |
| 1170 | * force the animation to a specific resource ID, {@link #ANIMATION_STYLEABLE} to use the |
| 1171 | * style resource defining the animation, or {@link #ANIMATION_NONE} for no animation. |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1172 | * |
| 1173 | * @param win The window that is changing. |
| 1174 | * @param transit What is happening to the window: |
| 1175 | * {@link com.android.server.policy.WindowManagerPolicy#TRANSIT_ENTER}, |
| 1176 | * {@link com.android.server.policy.WindowManagerPolicy#TRANSIT_EXIT}, |
| 1177 | * {@link com.android.server.policy.WindowManagerPolicy#TRANSIT_SHOW}, or |
| 1178 | * {@link com.android.server.policy.WindowManagerPolicy#TRANSIT_HIDE}. |
| 1179 | * |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1180 | * @return Resource ID of the actual animation to use, or {@link #ANIMATION_NONE} for none. |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1181 | */ |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1182 | int selectAnimation(WindowState win, int transit) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1183 | if (DEBUG_ANIM) Slog.i(TAG, "selectAnimation in " + win |
| 1184 | + ": transit=" + transit); |
| 1185 | if (win == mStatusBar) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1186 | if (transit == TRANSIT_EXIT |
| 1187 | || transit == TRANSIT_HIDE) { |
| 1188 | return R.anim.dock_top_exit; |
| 1189 | } else if (transit == TRANSIT_ENTER |
| 1190 | || transit == TRANSIT_SHOW) { |
| 1191 | return R.anim.dock_top_enter; |
| 1192 | } |
| 1193 | } else if (win == mNavigationBar) { |
| 1194 | if (win.getAttrs().windowAnimations != 0) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1195 | return ANIMATION_STYLEABLE; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1196 | } |
| 1197 | // This can be on either the bottom or the right or the left. |
| 1198 | if (mNavigationBarPosition == NAV_BAR_BOTTOM) { |
| 1199 | if (transit == TRANSIT_EXIT |
| 1200 | || transit == TRANSIT_HIDE) { |
| 1201 | if (mService.mPolicy.isKeyguardShowingAndNotOccluded()) { |
| 1202 | return R.anim.dock_bottom_exit_keyguard; |
| 1203 | } else { |
| 1204 | return R.anim.dock_bottom_exit; |
| 1205 | } |
| 1206 | } else if (transit == TRANSIT_ENTER |
| 1207 | || transit == TRANSIT_SHOW) { |
| 1208 | return R.anim.dock_bottom_enter; |
| 1209 | } |
| 1210 | } else if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
| 1211 | if (transit == TRANSIT_EXIT |
| 1212 | || transit == TRANSIT_HIDE) { |
| 1213 | return R.anim.dock_right_exit; |
| 1214 | } else if (transit == TRANSIT_ENTER |
| 1215 | || transit == TRANSIT_SHOW) { |
| 1216 | return R.anim.dock_right_enter; |
| 1217 | } |
| 1218 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
| 1219 | if (transit == TRANSIT_EXIT |
| 1220 | || transit == TRANSIT_HIDE) { |
| 1221 | return R.anim.dock_left_exit; |
| 1222 | } else if (transit == TRANSIT_ENTER |
| 1223 | || transit == TRANSIT_SHOW) { |
| 1224 | return R.anim.dock_left_enter; |
| 1225 | } |
| 1226 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | if (transit == TRANSIT_PREVIEW_DONE) { |
| 1230 | if (win.hasAppShownWindows()) { |
Riddle Hsu | 3b9ac73 | 2020-02-18 16:10:29 +0800 | [diff] [blame] | 1231 | if (win.isActivityTypeHome()) { |
| 1232 | // Dismiss the starting window as soon as possible to avoid the crossfade out |
| 1233 | // with old content because home is easier to have different UI states. |
| 1234 | return ANIMATION_NONE; |
| 1235 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1236 | if (DEBUG_ANIM) Slog.i(TAG, "**** STARTING EXIT"); |
| 1237 | return R.anim.app_starting_exit; |
| 1238 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1239 | } |
| 1240 | |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1241 | return ANIMATION_STYLEABLE; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1242 | } |
| 1243 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1244 | /** |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1245 | * Called when a new system UI visibility is being reported, allowing |
| 1246 | * the policy to adjust what is actually reported. |
| 1247 | * @param visibility The raw visibility reported by the status bar. |
| 1248 | * @return The new desired visibility. |
| 1249 | */ |
| 1250 | public int adjustSystemUiVisibilityLw(int visibility) { |
| 1251 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 1252 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 1253 | |
| 1254 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 1255 | // are now clear. |
| 1256 | mResettingSystemUiFlags &= visibility; |
| 1257 | // Clear any bits in the new visibility that are currently being |
| 1258 | // force cleared, before reporting it. |
| 1259 | return visibility & ~mResettingSystemUiFlags |
| 1260 | & ~mForceClearedSystemUiFlags; |
| 1261 | } |
| 1262 | |
| 1263 | /** |
Brad Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 1264 | * @return true if the system bars are forced to stay visible |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1265 | */ |
Brad Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 1266 | public boolean areSystemBarsForcedShownLw(WindowState windowState) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1267 | return mForceShowSystemBars; |
| 1268 | } |
| 1269 | |
| 1270 | // TODO: Should probably be moved into DisplayFrames. |
| 1271 | /** |
| 1272 | * Return the layout hints for a newly added window. These values are computed on the |
| 1273 | * most recent layout, so they are not guaranteed to be correct. |
| 1274 | * |
| 1275 | * @param attrs The LayoutParams of the window. |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 1276 | * @param windowToken The token of the window. |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1277 | * @param outFrame The frame of the window. |
| 1278 | * @param outContentInsets The areas covered by system windows, expressed as positive insets. |
| 1279 | * @param outStableInsets The areas covered by stable system windows irrespective of their |
| 1280 | * current visibility. Expressed as positive insets. |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1281 | * @param outDisplayCutout The area that has been cut away from the display. |
Brad Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 1282 | * @return Whether to always consume the system bars. |
| 1283 | * See {@link #areSystemBarsForcedShownLw(WindowState)}. |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1284 | */ |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 1285 | boolean getLayoutHint(LayoutParams attrs, WindowToken windowToken, Rect outFrame, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1286 | Rect outContentInsets, Rect outStableInsets, |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1287 | DisplayCutout.ParcelableWrapper outDisplayCutout) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1288 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
| 1289 | final int pfl = attrs.privateFlags; |
| 1290 | final int requestedSysUiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 1291 | final int sysUiVis = requestedSysUiVis | getImpliedSysUiFlagsForLayout(attrs); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1292 | |
| 1293 | final boolean layoutInScreen = (fl & FLAG_LAYOUT_IN_SCREEN) != 0; |
| 1294 | final boolean layoutInScreenAndInsetDecor = layoutInScreen |
| 1295 | && (fl & FLAG_LAYOUT_INSET_DECOR) != 0; |
| 1296 | final boolean screenDecor = (pfl & PRIVATE_FLAG_IS_SCREEN_DECOR) != 0; |
| 1297 | |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 1298 | final boolean isFixedRotationTransforming = |
| 1299 | windowToken != null && windowToken.isFixedRotationTransforming(); |
| 1300 | final ActivityRecord activity = windowToken != null ? windowToken.asActivityRecord() : null; |
| 1301 | final Task task = activity != null ? activity.getTask() : null; |
| 1302 | final Rect taskBounds = isFixedRotationTransforming |
| 1303 | // Use token (activity) bounds if it is rotated because its task is not rotated. |
| 1304 | ? windowToken.getBounds() |
| 1305 | : (task != null ? task.getBounds() : null); |
| 1306 | final DisplayFrames displayFrames = isFixedRotationTransforming |
| 1307 | ? windowToken.getFixedRotationTransformDisplayFrames() |
| 1308 | : mDisplayContent.mDisplayFrames; |
| 1309 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1310 | if (layoutInScreenAndInsetDecor && !screenDecor) { |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 1311 | if ((sysUiVis & SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 1312 | || (attrs.getFitInsetsTypes() & Type.navigationBars()) == 0) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1313 | outFrame.set(displayFrames.mUnrestricted); |
| 1314 | } else { |
| 1315 | outFrame.set(displayFrames.mRestricted); |
| 1316 | } |
| 1317 | |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 1318 | final boolean isFloatingTask = task != null && task.isFloating(); |
| 1319 | final Rect sf = isFloatingTask ? null : displayFrames.mStable; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1320 | final Rect cf; |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 1321 | if (isFloatingTask) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1322 | cf = null; |
| 1323 | } else if ((sysUiVis & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 1324 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 1325 | cf = displayFrames.mStableFullscreen; |
| 1326 | } else { |
| 1327 | cf = displayFrames.mStable; |
| 1328 | } |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1329 | } else if ((fl & FLAG_FULLSCREEN) != 0) { |
| 1330 | cf = displayFrames.mUnrestricted; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1331 | } else { |
| 1332 | cf = displayFrames.mCurrent; |
| 1333 | } |
| 1334 | |
| 1335 | if (taskBounds != null) { |
| 1336 | outFrame.intersect(taskBounds); |
| 1337 | } |
| 1338 | InsetUtils.insetsBetweenFrames(outFrame, cf, outContentInsets); |
| 1339 | InsetUtils.insetsBetweenFrames(outFrame, sf, outStableInsets); |
| 1340 | outDisplayCutout.set(displayFrames.mDisplayCutout.calculateRelativeTo(outFrame) |
| 1341 | .getDisplayCutout()); |
| 1342 | return mForceShowSystemBars; |
| 1343 | } else { |
| 1344 | if (layoutInScreen) { |
| 1345 | outFrame.set(displayFrames.mUnrestricted); |
| 1346 | } else { |
| 1347 | outFrame.set(displayFrames.mStable); |
| 1348 | } |
| 1349 | if (taskBounds != null) { |
| 1350 | outFrame.intersect(taskBounds); |
| 1351 | } |
| 1352 | |
| 1353 | outContentInsets.setEmpty(); |
| 1354 | outStableInsets.setEmpty(); |
| 1355 | outDisplayCutout.set(DisplayCutout.NO_CUTOUT); |
| 1356 | return mForceShowSystemBars; |
| 1357 | } |
| 1358 | } |
| 1359 | |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 1360 | // TODO(b/118118435): remove after migration |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1361 | private static int getImpliedSysUiFlagsForLayout(LayoutParams attrs) { |
| 1362 | int impliedFlags = 0; |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 1363 | final boolean forceWindowDrawsBarBackgrounds = |
| 1364 | (attrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS) != 0 |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 1365 | && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1366 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 1367 | || forceWindowDrawsBarBackgrounds) { |
Jorim Jaggi | d649057 | 2019-04-16 14:57:56 +0200 | [diff] [blame] | 1368 | impliedFlags |= SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1369 | impliedFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 1370 | } |
| 1371 | return impliedFlags; |
| 1372 | } |
| 1373 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1374 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 1375 | @Override |
| 1376 | public void run() { |
| 1377 | synchronized (mLock) { |
| 1378 | mForceClearedSystemUiFlags &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 1379 | mDisplayContent.reevaluateStatusBarVisibility(); |
| 1380 | } |
| 1381 | } |
| 1382 | }; |
| 1383 | |
| 1384 | /** |
| 1385 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 1386 | * to determine when the nav bar should be shown and prevent applications from |
| 1387 | * receiving those touches. |
| 1388 | */ |
| 1389 | private final class HideNavInputEventReceiver extends InputEventReceiver { |
| 1390 | HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 1391 | super(inputChannel, looper); |
| 1392 | } |
| 1393 | |
| 1394 | @Override |
| 1395 | public void onInputEvent(InputEvent event) { |
| 1396 | try { |
| 1397 | if (event instanceof MotionEvent |
| 1398 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 1399 | final MotionEvent motionEvent = (MotionEvent) event; |
| 1400 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
| 1401 | // When the user taps down, we re-show the nav bar. |
| 1402 | boolean changed = false; |
| 1403 | synchronized (mLock) { |
| 1404 | if (mInputConsumer == null) { |
| 1405 | return; |
| 1406 | } |
Tiger Huang | 9ff42bd | 2020-05-01 03:27:33 +0800 | [diff] [blame] | 1407 | showNavigationBar(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1408 | // Any user activity always causes us to show the |
| 1409 | // navigation controls, if they had been hidden. |
| 1410 | // We also clear the low profile and only content |
| 1411 | // flags so that tapping on the screen will atomically |
| 1412 | // restore all currently hidden screen decorations. |
| 1413 | int newVal = mResettingSystemUiFlags |
| 1414 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 1415 | | View.SYSTEM_UI_FLAG_LOW_PROFILE |
| 1416 | | View.SYSTEM_UI_FLAG_FULLSCREEN; |
| 1417 | if (mResettingSystemUiFlags != newVal) { |
| 1418 | mResettingSystemUiFlags = newVal; |
| 1419 | changed = true; |
| 1420 | } |
| 1421 | // We don't allow the system's nav bar to be hidden |
| 1422 | // again for 1 second, to prevent applications from |
| 1423 | // spamming us and keeping it from being shown. |
| 1424 | newVal = mForceClearedSystemUiFlags |
| 1425 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 1426 | if (mForceClearedSystemUiFlags != newVal) { |
| 1427 | mForceClearedSystemUiFlags = newVal; |
| 1428 | changed = true; |
| 1429 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
| 1430 | } |
| 1431 | if (changed) { |
| 1432 | mDisplayContent.reevaluateStatusBarVisibility(); |
| 1433 | } |
| 1434 | } |
| 1435 | } |
| 1436 | } |
| 1437 | } finally { |
| 1438 | finishInputEvent(event, false /* handled */); |
| 1439 | } |
| 1440 | } |
Tiger Huang | 9ff42bd | 2020-05-01 03:27:33 +0800 | [diff] [blame] | 1441 | |
| 1442 | private void showNavigationBar() { |
| 1443 | final InsetsSourceProvider provider = mDisplayContent.getInsetsStateController() |
| 1444 | .peekSourceProvider(ITYPE_NAVIGATION_BAR); |
| 1445 | final InsetsControlTarget target = |
| 1446 | provider != null ? provider.getControlTarget() : null; |
| 1447 | if (target != null) { |
| 1448 | target.showInsets(Type.navigationBars(), false /* fromIme */); |
| 1449 | } |
| 1450 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1451 | } |
| 1452 | |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1453 | private void simulateLayoutDecorWindow(WindowState win, DisplayFrames displayFrames, |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1454 | InsetsState insetsState, WindowFrames simulatedWindowFrames, Runnable layout) { |
| 1455 | win.setSimulatedWindowFrames(simulatedWindowFrames); |
| 1456 | try { |
| 1457 | layout.run(); |
| 1458 | } finally { |
| 1459 | win.setSimulatedWindowFrames(null); |
| 1460 | } |
| 1461 | mDisplayContent.getInsetsStateController().computeSimulatedState(insetsState, win, |
| 1462 | displayFrames, simulatedWindowFrames); |
| 1463 | } |
| 1464 | |
| 1465 | /** |
| 1466 | * Computes the frames of display (its logical size, rotation and cutout should already be set) |
| 1467 | * used to layout window. The result of display frames and insets state should be the same as |
| 1468 | * using {@link #beginLayoutLw}, but this method only changes the given display frames, insets |
| 1469 | * state and some temporal states. In other words, it doesn't change the window frames used to |
| 1470 | * show on screen. |
| 1471 | */ |
| 1472 | void simulateLayoutDisplay(DisplayFrames displayFrames, InsetsState insetsState, int uiMode) { |
| 1473 | displayFrames.onBeginLayout(); |
Tiger Huang | e16645a | 2020-02-25 22:24:39 +0800 | [diff] [blame] | 1474 | updateInsetsStateForDisplayCutout(displayFrames, insetsState); |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 1475 | insetsState.setDisplayFrame(displayFrames.mUnrestricted); |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1476 | final WindowFrames simulatedWindowFrames = new WindowFrames(); |
| 1477 | if (mNavigationBar != null) { |
| 1478 | simulateLayoutDecorWindow( |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1479 | mNavigationBar, displayFrames, insetsState, simulatedWindowFrames, |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1480 | () -> layoutNavigationBar(displayFrames, uiMode, mLastNavVisible, |
| 1481 | mLastNavTranslucent, mLastNavAllowedHidden, |
| 1482 | mLastNotificationShadeForcesShowingNavigation, |
| 1483 | false /* isRealLayout */)); |
| 1484 | } |
| 1485 | if (mStatusBar != null) { |
| 1486 | simulateLayoutDecorWindow( |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1487 | mStatusBar, displayFrames, insetsState, simulatedWindowFrames, |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1488 | () -> layoutStatusBar(displayFrames, mLastSystemUiFlags, |
| 1489 | false /* isRealLayout */)); |
| 1490 | } |
| 1491 | layoutScreenDecorWindows(displayFrames, simulatedWindowFrames); |
| 1492 | postAdjustDisplayFrames(displayFrames); |
| 1493 | } |
| 1494 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1495 | /** |
| 1496 | * Called when layout of the windows is about to start. |
| 1497 | * |
| 1498 | * @param displayFrames frames of the display we are doing layout on. |
| 1499 | * @param uiMode The current uiMode in configuration. |
| 1500 | */ |
| 1501 | public void beginLayoutLw(DisplayFrames displayFrames, int uiMode) { |
| 1502 | displayFrames.onBeginLayout(); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 1503 | updateInsetsStateForDisplayCutout(displayFrames, |
| 1504 | mDisplayContent.getInsetsStateController().getRawInsetsState()); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1505 | mSystemGestures.screenWidth = displayFrames.mUnrestricted.width(); |
| 1506 | mSystemGestures.screenHeight = displayFrames.mUnrestricted.height(); |
| 1507 | |
| 1508 | // For purposes of putting out fake window up to steal focus, we will |
| 1509 | // drive nav being hidden only by whether it is requested. |
| 1510 | final int sysui = mLastSystemUiFlags; |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 1511 | final int behavior = mLastBehavior; |
Tiger Huang | 9ff42bd | 2020-05-01 03:27:33 +0800 | [diff] [blame] | 1512 | final InsetsSourceProvider provider = |
| 1513 | mDisplayContent.getInsetsStateController().peekSourceProvider(ITYPE_NAVIGATION_BAR); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 1514 | boolean navVisible = ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL |
| 1515 | ? (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
Tiger Huang | 9ff42bd | 2020-05-01 03:27:33 +0800 | [diff] [blame] | 1516 | : provider != null |
| 1517 | ? provider.isClientVisible() |
| 1518 | : InsetsState.getDefaultVisibility(ITYPE_NAVIGATION_BAR); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1519 | boolean navTranslucent = (sysui |
| 1520 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0; |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 1521 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0 |
| 1522 | || (behavior & BEHAVIOR_SHOW_BARS_BY_SWIPE) != 0; |
| 1523 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0 |
| 1524 | || (behavior & BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE) != 0; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1525 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 1526 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1527 | boolean isKeyguardShowing = isKeyguardShowing() && !isKeyguardOccluded(); |
| 1528 | boolean notificationShadeForcesShowingNavigation = |
| 1529 | !isKeyguardShowing && mNotificationShade != null |
| 1530 | && (mNotificationShade.getAttrs().privateFlags |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1531 | & PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION) != 0; |
| 1532 | |
Tiger Huang | 9ff42bd | 2020-05-01 03:27:33 +0800 | [diff] [blame] | 1533 | updateHideNavInputEventReceiver(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1534 | |
| 1535 | // For purposes of positioning and showing the nav bar, if we have decided that it can't |
| 1536 | // be hidden (because of the screen aspect ratio), then take that into account. |
| 1537 | navVisible |= !canHideNavigationBar(); |
| 1538 | |
| 1539 | boolean updateSysUiVisibility = layoutNavigationBar(displayFrames, uiMode, navVisible, |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1540 | navTranslucent, navAllowedHidden, notificationShadeForcesShowingNavigation, |
| 1541 | true /* isRealLayout */); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1542 | if (DEBUG_LAYOUT) Slog.i(TAG, "mDock rect:" + displayFrames.mDock); |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1543 | updateSysUiVisibility |= layoutStatusBar(displayFrames, sysui, true /* isRealLayout */); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1544 | if (updateSysUiVisibility) { |
| 1545 | updateSystemUiVisibilityLw(); |
| 1546 | } |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1547 | layoutScreenDecorWindows(displayFrames, null /* simulatedFrames */); |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1548 | postAdjustDisplayFrames(displayFrames); |
| 1549 | mLastNavVisible = navVisible; |
| 1550 | mLastNavTranslucent = navTranslucent; |
| 1551 | mLastNavAllowedHidden = navAllowedHidden; |
| 1552 | mLastNotificationShadeForcesShowingNavigation = notificationShadeForcesShowingNavigation; |
| 1553 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1554 | |
Tiger Huang | 9ff42bd | 2020-05-01 03:27:33 +0800 | [diff] [blame] | 1555 | void updateHideNavInputEventReceiver() { |
| 1556 | final InsetsSourceProvider provider = mDisplayContent.getInsetsStateController() |
| 1557 | .peekSourceProvider(ITYPE_NAVIGATION_BAR); |
| 1558 | final InsetsControlTarget navControlTarget = |
| 1559 | provider != null ? provider.getControlTarget() : null; |
| 1560 | final WindowState navControllingWin = |
| 1561 | navControlTarget instanceof WindowState ? (WindowState) navControlTarget : null; |
| 1562 | final InsetsState requestedState = navControllingWin != null |
| 1563 | ? navControllingWin.getRequestedInsetsState() : null; |
| 1564 | final InsetsSource navSource = requestedState != null |
| 1565 | ? requestedState.peekSource(ITYPE_NAVIGATION_BAR) : null; |
| 1566 | final boolean navVisible = navSource != null |
| 1567 | ? navSource.isVisible() : InsetsState.getDefaultVisibility(ITYPE_NAVIGATION_BAR); |
| 1568 | final boolean showBarsByTouch = navControllingWin != null |
| 1569 | && navControllingWin.mAttrs.insetsFlags.behavior == BEHAVIOR_SHOW_BARS_BY_TOUCH; |
Tiger Huang | d611a9b | 2020-03-25 17:52:17 +0800 | [diff] [blame] | 1570 | // When the navigation bar isn't visible, we put up a fake input window to catch all |
| 1571 | // touch events. This way we can detect when the user presses anywhere to bring back the |
| 1572 | // nav bar and ensure the application doesn't see the event. |
Tiger Huang | 9ff42bd | 2020-05-01 03:27:33 +0800 | [diff] [blame] | 1573 | if (navVisible || !showBarsByTouch) { |
Tiger Huang | d611a9b | 2020-03-25 17:52:17 +0800 | [diff] [blame] | 1574 | if (mInputConsumer != null) { |
| 1575 | mInputConsumer.dismiss(); |
| 1576 | mHandler.sendMessage( |
| 1577 | mHandler.obtainMessage(MSG_DISPOSE_INPUT_CONSUMER, mInputConsumer)); |
| 1578 | mInputConsumer = null; |
Tiger Huang | 9ff42bd | 2020-05-01 03:27:33 +0800 | [diff] [blame] | 1579 | Slog.v(TAG, INPUT_CONSUMER_NAVIGATION + " dismissed."); |
Tiger Huang | d611a9b | 2020-03-25 17:52:17 +0800 | [diff] [blame] | 1580 | } |
| 1581 | } else if (mInputConsumer == null && mStatusBar != null && canHideNavigationBar()) { |
| 1582 | mInputConsumer = mDisplayContent.getInputMonitor().createInputConsumer( |
| 1583 | mHandler.getLooper(), |
| 1584 | INPUT_CONSUMER_NAVIGATION, |
| 1585 | HideNavInputEventReceiver::new); |
Tiger Huang | 9ff42bd | 2020-05-01 03:27:33 +0800 | [diff] [blame] | 1586 | Slog.v(TAG, INPUT_CONSUMER_NAVIGATION + " created."); |
Tiger Huang | d611a9b | 2020-03-25 17:52:17 +0800 | [diff] [blame] | 1587 | // As long as mInputConsumer is active, hover events are not dispatched to the app |
| 1588 | // and the pointer icon is likely to become stale. Hide it to avoid confusion. |
| 1589 | InputManager.getInstance().setPointerIconType(PointerIcon.TYPE_NULL); |
| 1590 | } |
| 1591 | } |
| 1592 | |
Tiger Huang | e16645a | 2020-02-25 22:24:39 +0800 | [diff] [blame] | 1593 | private static void updateInsetsStateForDisplayCutout(DisplayFrames displayFrames, |
| 1594 | InsetsState state) { |
| 1595 | if (displayFrames.mDisplayCutout.getDisplayCutout().isEmpty()) { |
| 1596 | state.removeSource(ITYPE_LEFT_DISPLAY_CUTOUT); |
| 1597 | state.removeSource(ITYPE_TOP_DISPLAY_CUTOUT); |
| 1598 | state.removeSource(ITYPE_RIGHT_DISPLAY_CUTOUT); |
| 1599 | state.removeSource(ITYPE_BOTTOM_DISPLAY_CUTOUT); |
| 1600 | return; |
| 1601 | } |
| 1602 | final Rect u = displayFrames.mUnrestricted; |
| 1603 | final Rect s = displayFrames.mDisplayCutoutSafe; |
| 1604 | state.getSource(ITYPE_LEFT_DISPLAY_CUTOUT).setFrame(u.left, u.top, s.left, u.bottom); |
| 1605 | state.getSource(ITYPE_TOP_DISPLAY_CUTOUT).setFrame(u.left, u.top, u.right, s.top); |
| 1606 | state.getSource(ITYPE_RIGHT_DISPLAY_CUTOUT).setFrame(s.right, u.top, u.right, u.bottom); |
| 1607 | state.getSource(ITYPE_BOTTOM_DISPLAY_CUTOUT).setFrame(u.left, s.bottom, u.right, u.bottom); |
| 1608 | } |
| 1609 | |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1610 | /** Enforces the last layout policy for display frames. */ |
| 1611 | private void postAdjustDisplayFrames(DisplayFrames displayFrames) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1612 | if (displayFrames.mDisplayCutoutSafe.top > displayFrames.mUnrestricted.top) { |
| 1613 | // Make sure that the zone we're avoiding for the cutout is at least as tall as the |
| 1614 | // status bar; otherwise fullscreen apps will end up cutting halfway into the status |
| 1615 | // bar. |
| 1616 | displayFrames.mDisplayCutoutSafe.top = Math.max(displayFrames.mDisplayCutoutSafe.top, |
| 1617 | displayFrames.mStable.top); |
| 1618 | } |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 1619 | |
| 1620 | // In case this is a virtual display, and the host display has insets that overlap this |
| 1621 | // virtual display, apply the insets of the overlapped area onto the current and content |
| 1622 | // frame of this virtual display. This let us layout windows in the virtual display as |
| 1623 | // expected when the window needs to avoid overlap with the system windows. |
| 1624 | // TODO: Generalize the forwarded insets, so that we can handle system windows other than |
| 1625 | // IME. |
| 1626 | displayFrames.mCurrent.inset(mForwardedInsets); |
| 1627 | displayFrames.mContent.inset(mForwardedInsets); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1628 | } |
| 1629 | |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1630 | /** |
| 1631 | * Layout the decor windows with {@link #PRIVATE_FLAG_IS_SCREEN_DECOR}. |
| 1632 | * |
| 1633 | * @param displayFrames The display frames to be layouted. |
| 1634 | * @param simulatedFrames Non-null if the caller only needs the result of display frames (see |
| 1635 | * {@link WindowState#mSimulatedWindowFrames}). |
| 1636 | */ |
| 1637 | private void layoutScreenDecorWindows(DisplayFrames displayFrames, |
| 1638 | WindowFrames simulatedFrames) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1639 | if (mScreenDecorWindows.isEmpty()) { |
| 1640 | return; |
| 1641 | } |
| 1642 | |
| 1643 | sTmpRect.setEmpty(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1644 | final int displayId = displayFrames.mDisplayId; |
| 1645 | final Rect dockFrame = displayFrames.mDock; |
| 1646 | final int displayHeight = displayFrames.mDisplayHeight; |
| 1647 | final int displayWidth = displayFrames.mDisplayWidth; |
| 1648 | |
| 1649 | for (int i = mScreenDecorWindows.size() - 1; i >= 0; --i) { |
| 1650 | final WindowState w = mScreenDecorWindows.valueAt(i); |
| 1651 | if (w.getDisplayId() != displayId || !w.isVisibleLw()) { |
| 1652 | // Skip if not on the same display or not visible. |
| 1653 | continue; |
| 1654 | } |
| 1655 | |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1656 | final boolean isSimulatedLayout = simulatedFrames != null; |
| 1657 | if (isSimulatedLayout) { |
| 1658 | w.setSimulatedWindowFrames(simulatedFrames); |
| 1659 | } |
| 1660 | final WindowFrames windowFrames = w.getLayoutingWindowFrames(); |
| 1661 | windowFrames.setFrames(displayFrames.mUnrestricted /* parentFrame */, |
chaviw | 0d83376 | 2019-06-20 17:09:53 -0700 | [diff] [blame] | 1662 | displayFrames.mUnrestricted /* displayFrame */, |
chaviw | 0d83376 | 2019-06-20 17:09:53 -0700 | [diff] [blame] | 1663 | displayFrames.mUnrestricted /* contentFrame */, |
| 1664 | displayFrames.mUnrestricted /* visibleFrame */, sTmpRect /* decorFrame */, |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1665 | displayFrames.mUnrestricted /* stableFrame */); |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1666 | try { |
| 1667 | w.computeFrame(displayFrames); |
| 1668 | } finally { |
| 1669 | if (isSimulatedLayout) { |
| 1670 | w.setSimulatedWindowFrames(null); |
| 1671 | } |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 1672 | } |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1673 | final Rect frame = windowFrames.mFrame; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1674 | |
| 1675 | if (frame.left <= 0 && frame.top <= 0) { |
| 1676 | // Docked at left or top. |
| 1677 | if (frame.bottom >= displayHeight) { |
| 1678 | // Docked left. |
| 1679 | dockFrame.left = Math.max(frame.right, dockFrame.left); |
| 1680 | } else if (frame.right >= displayWidth) { |
| 1681 | // Docked top. |
| 1682 | dockFrame.top = Math.max(frame.bottom, dockFrame.top); |
| 1683 | } else { |
| 1684 | Slog.w(TAG, "layoutScreenDecorWindows: Ignoring decor win=" + w |
| 1685 | + " not docked on left or top of display. frame=" + frame |
| 1686 | + " displayWidth=" + displayWidth + " displayHeight=" + displayHeight); |
| 1687 | } |
| 1688 | } else if (frame.right >= displayWidth && frame.bottom >= displayHeight) { |
| 1689 | // Docked at right or bottom. |
| 1690 | if (frame.top <= 0) { |
| 1691 | // Docked right. |
| 1692 | dockFrame.right = Math.min(frame.left, dockFrame.right); |
| 1693 | } else if (frame.left <= 0) { |
| 1694 | // Docked bottom. |
| 1695 | dockFrame.bottom = Math.min(frame.top, dockFrame.bottom); |
| 1696 | } else { |
| 1697 | Slog.w(TAG, "layoutScreenDecorWindows: Ignoring decor win=" + w |
| 1698 | + " not docked on right or bottom" + " of display. frame=" + frame |
| 1699 | + " displayWidth=" + displayWidth + " displayHeight=" + displayHeight); |
| 1700 | } |
| 1701 | } else { |
| 1702 | // Screen decor windows are required to be docked on one of the sides of the screen. |
| 1703 | Slog.w(TAG, "layoutScreenDecorWindows: Ignoring decor win=" + w |
| 1704 | + " not docked on one of the sides of the display. frame=" + frame |
| 1705 | + " displayWidth=" + displayWidth + " displayHeight=" + displayHeight); |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | displayFrames.mRestricted.set(dockFrame); |
| 1710 | displayFrames.mCurrent.set(dockFrame); |
| 1711 | displayFrames.mVoiceContent.set(dockFrame); |
| 1712 | displayFrames.mSystem.set(dockFrame); |
| 1713 | displayFrames.mContent.set(dockFrame); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1714 | } |
| 1715 | |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1716 | private boolean layoutStatusBar(DisplayFrames displayFrames, int sysui, boolean isRealLayout) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1717 | // decide where the status bar goes ahead of time |
| 1718 | if (mStatusBar == null) { |
| 1719 | return false; |
| 1720 | } |
| 1721 | // apply any navigation bar insets |
| 1722 | sTmpRect.setEmpty(); |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1723 | final WindowFrames windowFrames = mStatusBar.getLayoutingWindowFrames(); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 1724 | windowFrames.setFrames(displayFrames.mUnrestricted /* parentFrame */, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1725 | displayFrames.mUnrestricted /* displayFrame */, |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1726 | displayFrames.mStable /* contentFrame */, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1727 | displayFrames.mStable /* visibleFrame */, sTmpRect /* decorFrame */, |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1728 | displayFrames.mStable /* stableFrame */); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1729 | // Let the status bar determine its size. |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1730 | mStatusBar.computeFrame(displayFrames); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 1731 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1732 | // For layout, the status bar is always at the top with our fixed height. |
| 1733 | displayFrames.mStable.top = displayFrames.mUnrestricted.top |
| 1734 | + mStatusBarHeightForRotation[displayFrames.mRotation]; |
| 1735 | // Make sure the status bar covers the entire cutout height |
| 1736 | displayFrames.mStable.top = Math.max(displayFrames.mStable.top, |
| 1737 | displayFrames.mDisplayCutoutSafe.top); |
| 1738 | |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1739 | if (isRealLayout) { |
| 1740 | // Tell the bar controller where the collapsed status bar content is. |
| 1741 | sTmpRect.set(windowFrames.mContentFrame); |
| 1742 | sTmpRect.intersect(displayFrames.mDisplayCutoutSafe); |
| 1743 | sTmpRect.top = windowFrames.mContentFrame.top; // Ignore top display cutout inset |
| 1744 | sTmpRect.bottom = displayFrames.mStable.top; // Use collapsed status bar size |
| 1745 | mStatusBarController.setContentFrame(sTmpRect); |
| 1746 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1747 | |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 1748 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0 |
| 1749 | || mDisplayContent.getInsetsPolicy().isTransient(ITYPE_STATUS_BAR); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1750 | boolean statusBarTranslucent = (sysui |
| 1751 | & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1752 | |
| 1753 | // If the status bar is hidden, we don't want to cause windows behind it to scroll. |
| 1754 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
| 1755 | // Status bar may go away, so the screen area it occupies is available to apps but just |
| 1756 | // covering them when the status bar is visible. |
| 1757 | final Rect dockFrame = displayFrames.mDock; |
| 1758 | dockFrame.top = displayFrames.mStable.top; |
| 1759 | displayFrames.mContent.set(dockFrame); |
| 1760 | displayFrames.mVoiceContent.set(dockFrame); |
| 1761 | displayFrames.mCurrent.set(dockFrame); |
| 1762 | |
| 1763 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + String.format( |
| 1764 | "dock=%s content=%s cur=%s", dockFrame.toString(), |
| 1765 | displayFrames.mContent.toString(), displayFrames.mCurrent.toString())); |
| 1766 | |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 1767 | if (!statusBarTranslucent && !mStatusBarController.wasRecentlyTranslucent() |
| 1768 | && !mStatusBar.isAnimatingLw()) { |
| 1769 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1770 | // If the opaque status bar is currently requested to be visible, and not in the |
| 1771 | // process of animating on or off, then we can tell the app that it is covered by |
| 1772 | // it. |
| 1773 | displayFrames.mSystem.top = displayFrames.mStable.top; |
| 1774 | } |
| 1775 | } |
| 1776 | return mStatusBarController.checkHiddenLw(); |
| 1777 | } |
| 1778 | |
| 1779 | private boolean layoutNavigationBar(DisplayFrames displayFrames, int uiMode, boolean navVisible, |
| 1780 | boolean navTranslucent, boolean navAllowedHidden, |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1781 | boolean statusBarForcesShowingNavigation, boolean isRealLayout) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1782 | if (mNavigationBar == null) { |
| 1783 | return false; |
| 1784 | } |
| 1785 | |
| 1786 | final Rect navigationFrame = sTmpNavFrame; |
| 1787 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
| 1788 | // Force the navigation bar to its appropriate place and size. We need to do this directly, |
| 1789 | // instead of relying on it to bubble up from the nav bar, because this needs to change |
| 1790 | // atomically with screen rotations. |
| 1791 | final int rotation = displayFrames.mRotation; |
| 1792 | final int displayHeight = displayFrames.mDisplayHeight; |
| 1793 | final int displayWidth = displayFrames.mDisplayWidth; |
| 1794 | final Rect dockFrame = displayFrames.mDock; |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1795 | final int navBarPosition = navigationBarPosition(displayWidth, displayHeight, rotation); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1796 | |
| 1797 | final Rect cutoutSafeUnrestricted = sTmpRect; |
| 1798 | cutoutSafeUnrestricted.set(displayFrames.mUnrestricted); |
| 1799 | cutoutSafeUnrestricted.intersectUnchecked(displayFrames.mDisplayCutoutSafe); |
| 1800 | |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1801 | if (navBarPosition == NAV_BAR_BOTTOM) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1802 | // It's a system nav bar or a portrait screen; nav bar goes on bottom. |
| 1803 | final int top = cutoutSafeUnrestricted.bottom |
| 1804 | - getNavigationBarHeight(rotation, uiMode); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1805 | final int topNavBar = cutoutSafeUnrestricted.bottom |
Matthew Ng | a7f24bc | 2019-04-09 17:06:41 -0700 | [diff] [blame] | 1806 | - getNavigationBarFrameHeight(rotation, uiMode); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1807 | navigationFrame.set(0, topNavBar, displayWidth, displayFrames.mUnrestricted.bottom); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1808 | displayFrames.mStable.bottom = displayFrames.mStableFullscreen.bottom = top; |
| 1809 | if (transientNavBarShowing) { |
| 1810 | mNavigationBarController.setBarShowingLw(true); |
| 1811 | } else if (navVisible) { |
| 1812 | mNavigationBarController.setBarShowingLw(true); |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1813 | dockFrame.bottom = displayFrames.mRestricted.bottom = top; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1814 | } else { |
| 1815 | // We currently want to hide the navigation UI - unless we expanded the status bar. |
| 1816 | mNavigationBarController.setBarShowingLw(statusBarForcesShowingNavigation); |
| 1817 | } |
| 1818 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 1819 | && !mNavigationBar.isAnimatingLw() |
| 1820 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 1821 | // If the opaque nav bar is currently requested to be visible and not in the process |
| 1822 | // of animating on or off, then we can tell the app that it is covered by it. |
| 1823 | displayFrames.mSystem.bottom = top; |
| 1824 | } |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1825 | } else if (navBarPosition == NAV_BAR_RIGHT) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1826 | // Landscape screen; nav bar goes to the right. |
| 1827 | final int left = cutoutSafeUnrestricted.right |
| 1828 | - getNavigationBarWidth(rotation, uiMode); |
Matthew Ng | a7f24bc | 2019-04-09 17:06:41 -0700 | [diff] [blame] | 1829 | navigationFrame.set(left, 0, displayFrames.mUnrestricted.right, displayHeight); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1830 | displayFrames.mStable.right = displayFrames.mStableFullscreen.right = left; |
| 1831 | if (transientNavBarShowing) { |
| 1832 | mNavigationBarController.setBarShowingLw(true); |
| 1833 | } else if (navVisible) { |
| 1834 | mNavigationBarController.setBarShowingLw(true); |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1835 | dockFrame.right = displayFrames.mRestricted.right = left; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1836 | } else { |
| 1837 | // We currently want to hide the navigation UI - unless we expanded the status bar. |
| 1838 | mNavigationBarController.setBarShowingLw(statusBarForcesShowingNavigation); |
| 1839 | } |
| 1840 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 1841 | && !mNavigationBar.isAnimatingLw() |
| 1842 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 1843 | // If the nav bar is currently requested to be visible, and not in the process of |
| 1844 | // animating on or off, then we can tell the app that it is covered by it. |
| 1845 | displayFrames.mSystem.right = left; |
| 1846 | } |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1847 | } else if (navBarPosition == NAV_BAR_LEFT) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1848 | // Seascape screen; nav bar goes to the left. |
| 1849 | final int right = cutoutSafeUnrestricted.left |
| 1850 | + getNavigationBarWidth(rotation, uiMode); |
Matthew Ng | a7f24bc | 2019-04-09 17:06:41 -0700 | [diff] [blame] | 1851 | navigationFrame.set(displayFrames.mUnrestricted.left, 0, right, displayHeight); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1852 | displayFrames.mStable.left = displayFrames.mStableFullscreen.left = right; |
| 1853 | if (transientNavBarShowing) { |
| 1854 | mNavigationBarController.setBarShowingLw(true); |
| 1855 | } else if (navVisible) { |
| 1856 | mNavigationBarController.setBarShowingLw(true); |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1857 | dockFrame.left = displayFrames.mRestricted.left = right; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1858 | } else { |
| 1859 | // We currently want to hide the navigation UI - unless we expanded the status bar. |
| 1860 | mNavigationBarController.setBarShowingLw(statusBarForcesShowingNavigation); |
| 1861 | } |
| 1862 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 1863 | && !mNavigationBar.isAnimatingLw() |
| 1864 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 1865 | // If the nav bar is currently requested to be visible, and not in the process of |
| 1866 | // animating on or off, then we can tell the app that it is covered by it. |
| 1867 | displayFrames.mSystem.left = right; |
| 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | // Make sure the content and current rectangles are updated to account for the restrictions |
| 1872 | // from the navigation bar. |
| 1873 | displayFrames.mCurrent.set(dockFrame); |
| 1874 | displayFrames.mVoiceContent.set(dockFrame); |
| 1875 | displayFrames.mContent.set(dockFrame); |
| 1876 | // And compute the final frame. |
| 1877 | sTmpRect.setEmpty(); |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1878 | final WindowFrames windowFrames = mNavigationBar.getLayoutingWindowFrames(); |
| 1879 | windowFrames.setFrames(navigationFrame /* parentFrame */, |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1880 | navigationFrame /* displayFrame */, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1881 | displayFrames.mDisplayCutoutSafe /* contentFrame */, |
| 1882 | navigationFrame /* visibleFrame */, sTmpRect /* decorFrame */, |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1883 | navigationFrame /* stableFrame */); |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 1884 | mNavigationBar.computeFrame(displayFrames); |
| 1885 | if (isRealLayout) { |
| 1886 | mNavigationBarPosition = navBarPosition; |
| 1887 | mNavigationBarController.setContentFrame(windowFrames.mContentFrame); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 1888 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1889 | |
| 1890 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + navigationFrame); |
| 1891 | return mNavigationBarController.checkHiddenLw(); |
| 1892 | } |
| 1893 | |
| 1894 | private void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1895 | boolean insetDecors, Rect pf, Rect df, Rect cf, Rect vf, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1896 | DisplayFrames displayFrames) { |
| 1897 | if (!win.isInputMethodTarget() && attached.isInputMethodTarget()) { |
| 1898 | // Here's a special case: if the child window is not the 'dock window' |
| 1899 | // or input method target, and the window it is attached to is below |
| 1900 | // the dock window, then the frames we computed for the window it is |
| 1901 | // attached to can not be used because the dock is effectively part |
| 1902 | // of the underlying window and the attached window is floating on top |
| 1903 | // of the whole thing. So, we ignore the attached window and explicitly |
| 1904 | // compute the frames that would be appropriate without the dock. |
| 1905 | vf.set(displayFrames.mDock); |
| 1906 | cf.set(displayFrames.mDock); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1907 | df.set(displayFrames.mDock); |
| 1908 | } else { |
Jorim Jaggi | d649057 | 2019-04-16 14:57:56 +0200 | [diff] [blame] | 1909 | |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1910 | // In case we forced the window to draw behind the navigation bar, restrict df to |
| 1911 | // DF.Restricted to simulate old compat behavior. |
Jorim Jaggi | a72b4cc | 2019-04-16 15:38:49 +0200 | [diff] [blame] | 1912 | Rect parentDisplayFrame = attached.getDisplayFrameLw(); |
Jorim Jaggi | d649057 | 2019-04-16 14:57:56 +0200 | [diff] [blame] | 1913 | final WindowManager.LayoutParams attachedAttrs = attached.mAttrs; |
| 1914 | if ((attachedAttrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS) != 0 |
| 1915 | && (attachedAttrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0 |
| 1916 | && (attachedAttrs.systemUiVisibility |
| 1917 | & SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) == 0) { |
Jorim Jaggi | a72b4cc | 2019-04-16 15:38:49 +0200 | [diff] [blame] | 1918 | parentDisplayFrame = new Rect(parentDisplayFrame); |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1919 | parentDisplayFrame.intersect(displayFrames.mRestricted); |
Jorim Jaggi | d649057 | 2019-04-16 14:57:56 +0200 | [diff] [blame] | 1920 | } |
| 1921 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1922 | // The effective display frame of the attached window depends on whether it is taking |
| 1923 | // care of insetting its content. If not, we need to use the parent's content frame so |
| 1924 | // that the entire window is positioned within that content. Otherwise we can use the |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1925 | // parent display frame and let the attached window take care of positioning its content |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1926 | // appropriately. |
| 1927 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 1928 | // Set the content frame of the attached window to the parent's decor frame |
| 1929 | // (same as content frame when IME isn't present) if specifically requested by |
| 1930 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 1931 | // Otherwise, use the overscan frame. |
| 1932 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 1933 | ? attached.getContentFrameLw() : parentDisplayFrame); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1934 | } else { |
| 1935 | // If the window is resizing, then we want to base the content frame on our attached |
| 1936 | // content frame to resize...however, things can be tricky if the attached window is |
| 1937 | // NOT in resize mode, in which case its content frame will be larger. |
| 1938 | // Ungh. So to deal with that, make sure the content frame we end up using is not |
| 1939 | // covering the IM dock. |
| 1940 | cf.set(attached.getContentFrameLw()); |
| 1941 | if (attached.isVoiceInteraction()) { |
| 1942 | cf.intersectUnchecked(displayFrames.mVoiceContent); |
| 1943 | } else if (win.isInputMethodTarget() || attached.isInputMethodTarget()) { |
| 1944 | cf.intersectUnchecked(displayFrames.mContent); |
| 1945 | } |
| 1946 | } |
Jorim Jaggi | d649057 | 2019-04-16 14:57:56 +0200 | [diff] [blame] | 1947 | df.set(insetDecors ? parentDisplayFrame : cf); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1948 | vf.set(attached.getVisibleFrameLw()); |
| 1949 | } |
| 1950 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached window should be |
| 1951 | // positioned relative to its parent or the entire screen. |
| 1952 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 ? attached.getFrameLw() : df); |
| 1953 | } |
| 1954 | |
| 1955 | private void applyStableConstraints(int sysui, int fl, Rect r, DisplayFrames displayFrames) { |
| 1956 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) == 0) { |
| 1957 | return; |
| 1958 | } |
| 1959 | // If app is requesting a stable layout, don't let the content insets go below the stable |
| 1960 | // values. |
| 1961 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 1962 | r.intersectUnchecked(displayFrames.mStableFullscreen); |
| 1963 | } else { |
| 1964 | r.intersectUnchecked(displayFrames.mStable); |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | private boolean canReceiveInput(WindowState win) { |
| 1969 | boolean notFocusable = |
| 1970 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0; |
| 1971 | boolean altFocusableIm = |
| 1972 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0; |
| 1973 | boolean notFocusableForIm = notFocusable ^ altFocusableIm; |
| 1974 | return !notFocusableForIm; |
| 1975 | } |
| 1976 | |
| 1977 | /** |
| 1978 | * Called for each window attached to the window manager as layout is proceeding. The |
| 1979 | * implementation of this function must take care of setting the window's frame, either here or |
| 1980 | * in finishLayout(). |
| 1981 | * |
| 1982 | * @param win The window being positioned. |
| 1983 | * @param attached For sub-windows, the window it is attached to; this |
| 1984 | * window will already have had layoutWindow() called on it |
| 1985 | * so you can use its Rect. Otherwise null. |
| 1986 | * @param displayFrames The display frames. |
| 1987 | */ |
| 1988 | public void layoutWindowLw(WindowState win, WindowState attached, DisplayFrames displayFrames) { |
| 1989 | // We've already done the navigation bar, status bar, and all screen decor windows. If the |
| 1990 | // status bar can receive input, we need to layout it again to accommodate for the IME |
| 1991 | // window. |
| 1992 | if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar |
| 1993 | || mScreenDecorWindows.contains(win)) { |
| 1994 | return; |
| 1995 | } |
| 1996 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1997 | |
| 1998 | final int type = attrs.type; |
| 1999 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
| 2000 | final int pfl = attrs.privateFlags; |
| 2001 | final int sim = attrs.softInputMode; |
| 2002 | final int requestedSysUiFl = PolicyControl.getSystemUiVisibility(null, attrs); |
| 2003 | final int sysUiFl = requestedSysUiFl | getImpliedSysUiFlagsForLayout(attrs); |
| 2004 | |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 2005 | displayFrames = win.getDisplayFrames(displayFrames); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2006 | final WindowFrames windowFrames = win.getWindowFrames(); |
| 2007 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2008 | sTmpLastParentFrame.set(windowFrames.mParentFrame); |
| 2009 | final Rect pf = windowFrames.mParentFrame; |
| 2010 | final Rect df = windowFrames.mDisplayFrame; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2011 | final Rect cf = windowFrames.mContentFrame; |
| 2012 | final Rect vf = windowFrames.mVisibleFrame; |
| 2013 | final Rect dcf = windowFrames.mDecorFrame; |
| 2014 | final Rect sf = windowFrames.mStableFrame; |
| 2015 | dcf.setEmpty(); |
| 2016 | windowFrames.setParentFrameWasClippedByDisplayCutout(false); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2017 | |
| 2018 | final boolean hasNavBar = hasNavigationBar() && mNavigationBar != null |
| 2019 | && mNavigationBar.isVisibleLw(); |
| 2020 | |
| 2021 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 2022 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2023 | final boolean layoutInScreen = (fl & FLAG_LAYOUT_IN_SCREEN) == FLAG_LAYOUT_IN_SCREEN; |
| 2024 | final boolean layoutInsetDecor = (fl & FLAG_LAYOUT_INSET_DECOR) == FLAG_LAYOUT_INSET_DECOR; |
| 2025 | |
| 2026 | sf.set(displayFrames.mStable); |
| 2027 | |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 2028 | if (ViewRootImpl.sNewInsetsMode == NEW_INSETS_MODE_FULL) { |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 2029 | final @InsetsType int typesToFit = attrs.getFitInsetsTypes(); |
| 2030 | final @InsetsSide int sidesToFit = attrs.getFitInsetsSides(); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 2031 | final ArraySet<Integer> types = InsetsState.toInternalType(typesToFit); |
| 2032 | final Rect dfu = displayFrames.mUnrestricted; |
| 2033 | Insets insets = Insets.of(0, 0, 0, 0); |
| 2034 | for (int i = types.size() - 1; i >= 0; i--) { |
Tiger Huang | eb5a592 | 2020-05-06 22:54:28 +0800 | [diff] [blame] | 2035 | final InsetsSource source = mDisplayContent.getInsetsPolicy() |
| 2036 | .getInsetsForDispatch(win).peekSource(types.valueAt(i)); |
| 2037 | if (source == null) { |
| 2038 | continue; |
| 2039 | } |
| 2040 | insets = Insets.max(insets, source.calculateInsets( |
| 2041 | dfu, attrs.isFitInsetsIgnoringVisibility())); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 2042 | } |
| 2043 | final int left = (sidesToFit & Side.LEFT) != 0 ? insets.left : 0; |
| 2044 | final int top = (sidesToFit & Side.TOP) != 0 ? insets.top : 0; |
| 2045 | final int right = (sidesToFit & Side.RIGHT) != 0 ? insets.right : 0; |
| 2046 | final int bottom = (sidesToFit & Side.BOTTOM) != 0 ? insets.bottom : 0; |
| 2047 | df.set(left, top, dfu.right - right, dfu.bottom - bottom); |
| 2048 | if (attached == null) { |
| 2049 | pf.set(df); |
| 2050 | vf.set(adjust != SOFT_INPUT_ADJUST_NOTHING |
| 2051 | ? displayFrames.mCurrent : displayFrames.mDock); |
| 2052 | } else { |
| 2053 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 ? attached.getFrameLw() : df); |
| 2054 | vf.set(attached.getVisibleFrameLw()); |
| 2055 | } |
| 2056 | cf.set(adjust != SOFT_INPUT_ADJUST_RESIZE |
| 2057 | ? displayFrames.mDock : displayFrames.mContent); |
| 2058 | dcf.set(displayFrames.mSystem); |
| 2059 | } else if (type == TYPE_INPUT_METHOD) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2060 | vf.set(displayFrames.mDock); |
| 2061 | cf.set(displayFrames.mDock); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2062 | df.set(displayFrames.mDock); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 2063 | pf.set(displayFrames.mDock); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2064 | // IM dock windows layout below the nav bar... |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2065 | pf.bottom = df.bottom = displayFrames.mUnrestricted.bottom; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2066 | // ...with content insets above the nav bar |
| 2067 | cf.bottom = vf.bottom = displayFrames.mStable.bottom; |
| 2068 | if (mStatusBar != null && mFocusedWindow == mStatusBar && canReceiveInput(mStatusBar)) { |
| 2069 | // The status bar forces the navigation bar while it's visible. Make sure the IME |
| 2070 | // avoids the navigation bar in that case. |
| 2071 | if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2072 | pf.right = df.right = cf.right = vf.right = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2073 | displayFrames.mStable.right; |
| 2074 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2075 | pf.left = df.left = cf.left = vf.left = displayFrames.mStable.left; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2076 | } |
| 2077 | } |
| 2078 | |
Matthew Ng | a7f24bc | 2019-04-09 17:06:41 -0700 | [diff] [blame] | 2079 | // In case the navigation bar is on the bottom, we use the frame height instead of the |
| 2080 | // regular height for the insets we send to the IME as we need some space to show |
| 2081 | // additional buttons in SystemUI when the IME is up. |
| 2082 | if (mNavigationBarPosition == NAV_BAR_BOTTOM) { |
| 2083 | final int rotation = displayFrames.mRotation; |
| 2084 | final int uimode = mService.mPolicy.getUiMode(); |
| 2085 | final int navHeightOffset = getNavigationBarFrameHeight(rotation, uimode) |
| 2086 | - getNavigationBarHeight(rotation, uimode); |
| 2087 | if (navHeightOffset > 0) { |
| 2088 | cf.bottom -= navHeightOffset; |
| 2089 | sf.bottom -= navHeightOffset; |
| 2090 | vf.bottom -= navHeightOffset; |
| 2091 | dcf.bottom -= navHeightOffset; |
| 2092 | } |
| 2093 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2094 | |
| 2095 | // IM dock windows always go to the bottom of the screen. |
| 2096 | attrs.gravity = Gravity.BOTTOM; |
| 2097 | } else if (type == TYPE_VOICE_INTERACTION) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2098 | df.set(displayFrames.mUnrestricted); |
| 2099 | pf.set(displayFrames.mUnrestricted); |
| 2100 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 2101 | cf.set(displayFrames.mDock); |
| 2102 | } else { |
| 2103 | cf.set(displayFrames.mContent); |
| 2104 | } |
| 2105 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 2106 | vf.set(displayFrames.mCurrent); |
| 2107 | } else { |
| 2108 | vf.set(cf); |
| 2109 | } |
| 2110 | } else if (type == TYPE_WALLPAPER) { |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2111 | layoutWallpaper(displayFrames, pf, df, cf); |
Jorim Jaggi | f2ce4fa | 2020-01-21 22:32:37 +0100 | [diff] [blame] | 2112 | } else if (win == mStatusBar || type == TYPE_NOTIFICATION_SHADE) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2113 | df.set(displayFrames.mUnrestricted); |
| 2114 | pf.set(displayFrames.mUnrestricted); |
| 2115 | cf.set(displayFrames.mStable); |
| 2116 | vf.set(displayFrames.mStable); |
| 2117 | |
| 2118 | if (adjust == SOFT_INPUT_ADJUST_RESIZE) { |
Tiger Huang | 7fe7f68 | 2019-10-26 01:11:23 +0800 | [diff] [blame] | 2119 | // cf.bottom should not be below the stable bottom, or the content might be obscured |
| 2120 | // by the navigation bar. |
| 2121 | if (cf.bottom > displayFrames.mContent.bottom) { |
| 2122 | cf.bottom = displayFrames.mContent.bottom; |
| 2123 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2124 | } else { |
Tiger Huang | 7fe7f68 | 2019-10-26 01:11:23 +0800 | [diff] [blame] | 2125 | if (cf.bottom > displayFrames.mDock.bottom) { |
| 2126 | cf.bottom = displayFrames.mDock.bottom; |
| 2127 | } |
| 2128 | if (vf.bottom > displayFrames.mContent.bottom) { |
| 2129 | vf.bottom = displayFrames.mContent.bottom; |
| 2130 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2131 | } |
| 2132 | } else { |
| 2133 | dcf.set(displayFrames.mSystem); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2134 | final boolean isAppWindow = |
| 2135 | type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW; |
| 2136 | final boolean topAtRest = |
| 2137 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
Jorim Jaggi | a2e648e | 2019-10-25 15:06:53 +0200 | [diff] [blame] | 2138 | if (isAppWindow && !topAtRest) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2139 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 2140 | && (fl & FLAG_FULLSCREEN) == 0 |
| 2141 | && (fl & FLAG_TRANSLUCENT_STATUS) == 0 |
| 2142 | && (fl & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0 |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 2143 | && (pfl & PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS) == 0) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2144 | // Ensure policy decor includes status bar |
| 2145 | dcf.top = displayFrames.mStable.top; |
| 2146 | } |
| 2147 | if ((fl & FLAG_TRANSLUCENT_NAVIGATION) == 0 |
| 2148 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 2149 | && (fl & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0 |
| 2150 | && (pfl & PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS) == 0) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2151 | // Ensure policy decor includes navigation bar |
| 2152 | dcf.bottom = displayFrames.mStable.bottom; |
| 2153 | dcf.right = displayFrames.mStable.right; |
| 2154 | } |
| 2155 | } |
| 2156 | |
| 2157 | if (layoutInScreen && layoutInsetDecor) { |
| 2158 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
| 2159 | + "): IN_SCREEN, INSET_DECOR"); |
| 2160 | // This is the case for a normal activity window: we want it to cover all of the |
| 2161 | // screen space, and it can take care of moving its contents to account for screen |
| 2162 | // decorations that intrude into that space. |
| 2163 | if (attached != null) { |
| 2164 | // If this window is attached to another, our display |
| 2165 | // frame is the same as the one we are attached to. |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2166 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, cf, vf, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2167 | displayFrames); |
| 2168 | } else { |
Heemin Seog | 2cf45dd | 2020-02-24 15:43:29 -0800 | [diff] [blame] | 2169 | if (type == TYPE_STATUS_BAR_ADDITIONAL || type == TYPE_STATUS_BAR_SUB_PANEL) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2170 | // Status bar panels are the only windows who can go on top of the status |
| 2171 | // bar. They are protected by the STATUS_BAR_SERVICE permission, so they |
| 2172 | // have the same privileges as the status bar itself. |
| 2173 | // |
| 2174 | // However, they should still dodge the navigation bar if it exists. |
| 2175 | |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2176 | pf.left = df.left = hasNavBar |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2177 | ? displayFrames.mDock.left : displayFrames.mUnrestricted.left; |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2178 | pf.top = df.top = displayFrames.mUnrestricted.top; |
| 2179 | pf.right = df.right = hasNavBar |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2180 | ? displayFrames.mRestricted.right |
| 2181 | : displayFrames.mUnrestricted.right; |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2182 | pf.bottom = df.bottom = hasNavBar |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2183 | ? displayFrames.mRestricted.bottom |
| 2184 | : displayFrames.mUnrestricted.bottom; |
| 2185 | |
| 2186 | if (DEBUG_LAYOUT) Slog.v(TAG, "Laying out status bar window: " + pf); |
Jorim Jaggi | d649057 | 2019-04-16 14:57:56 +0200 | [diff] [blame] | 2187 | } else if ((sysUiFl & SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2188 | && (type >= FIRST_APPLICATION_WINDOW && type <= LAST_SUB_WINDOW |
Charles Chen | 64172bb | 2019-04-22 17:30:29 +0800 | [diff] [blame] | 2189 | || type == TYPE_VOLUME_OVERLAY |
| 2190 | || type == TYPE_KEYGUARD_DIALOG)) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2191 | // Asking for layout as if the nav bar is hidden, lets the application |
| 2192 | // extend into the unrestricted overscan screen area. We only do this for |
| 2193 | // application windows and certain system windows to ensure no window that |
| 2194 | // can be above the nav bar can do this. |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2195 | df.set(displayFrames.mUnrestricted); |
| 2196 | pf.set(displayFrames.mUnrestricted); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2197 | } else { |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2198 | df.set(displayFrames.mRestricted); |
| 2199 | pf.set(displayFrames.mRestricted); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | if ((fl & FLAG_FULLSCREEN) == 0) { |
| 2203 | if (win.isVoiceInteraction()) { |
| 2204 | cf.set(displayFrames.mVoiceContent); |
| 2205 | } else { |
Jorim Jaggi | 648e588 | 2019-01-24 13:24:02 +0100 | [diff] [blame] | 2206 | // IME Insets are handled on the client for ADJUST_RESIZE in the new |
| 2207 | // insets world |
| 2208 | if (ViewRootImpl.sNewInsetsMode != NEW_INSETS_MODE_NONE |
| 2209 | || adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2210 | cf.set(displayFrames.mDock); |
| 2211 | } else { |
| 2212 | cf.set(displayFrames.mContent); |
| 2213 | } |
| 2214 | } |
| 2215 | } else { |
| 2216 | // Full screen windows are always given a layout that is as if the status |
| 2217 | // bar and other transient decors are gone. This is to avoid bad states when |
| 2218 | // moving from a window that is not hiding the status bar to one that is. |
| 2219 | cf.set(displayFrames.mRestricted); |
| 2220 | } |
| 2221 | applyStableConstraints(sysUiFl, fl, cf, displayFrames); |
Jorim Jaggi | 4e04eb2 | 2020-01-09 16:42:14 +0100 | [diff] [blame] | 2222 | if (ViewRootImpl.sNewInsetsMode == NEW_INSETS_MODE_NONE |
| 2223 | && adjust != SOFT_INPUT_ADJUST_NOTHING) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2224 | vf.set(displayFrames.mCurrent); |
| 2225 | } else { |
| 2226 | vf.set(cf); |
| 2227 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2228 | } |
| 2229 | } else if (layoutInScreen || (sysUiFl |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 2230 | & (SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
Jorim Jaggi | d649057 | 2019-04-16 14:57:56 +0200 | [diff] [blame] | 2231 | | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2232 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
| 2233 | + "): IN_SCREEN"); |
| 2234 | // A window that has requested to fill the entire screen just |
| 2235 | // gets everything, period. |
Heemin Seog | 2cf45dd | 2020-02-24 15:43:29 -0800 | [diff] [blame] | 2236 | if (type == TYPE_STATUS_BAR_ADDITIONAL || type == TYPE_STATUS_BAR_SUB_PANEL) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2237 | cf.set(displayFrames.mUnrestricted); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2238 | df.set(displayFrames.mUnrestricted); |
| 2239 | pf.set(displayFrames.mUnrestricted); |
| 2240 | if (hasNavBar) { |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2241 | pf.left = df.left = cf.left = displayFrames.mDock.left; |
| 2242 | pf.right = df.right = cf.right = displayFrames.mRestricted.right; |
| 2243 | pf.bottom = df.bottom = cf.bottom = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2244 | displayFrames.mRestricted.bottom; |
| 2245 | } |
| 2246 | if (DEBUG_LAYOUT) Slog.v(TAG, "Laying out IN_SCREEN status bar window: " + pf); |
| 2247 | } else if (type == TYPE_NAVIGATION_BAR || type == TYPE_NAVIGATION_BAR_PANEL) { |
| 2248 | // The navigation bar has Real Ultimate Power. |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2249 | df.set(displayFrames.mUnrestricted); |
| 2250 | pf.set(displayFrames.mUnrestricted); |
| 2251 | if (DEBUG_LAYOUT) Slog.v(TAG, "Laying out navigation bar window: " + pf); |
| 2252 | } else if ((type == TYPE_SECURE_SYSTEM_OVERLAY || type == TYPE_SCREENSHOT) |
| 2253 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 2254 | // Fullscreen secure system overlays get what they ask for. Screenshot region |
| 2255 | // selection overlay should also expand to full screen. |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2256 | cf.set(displayFrames.mUnrestricted); |
| 2257 | df.set(displayFrames.mUnrestricted); |
| 2258 | pf.set(displayFrames.mUnrestricted); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2259 | } else if (type == TYPE_BOOT_PROGRESS) { |
| 2260 | // Boot progress screen always covers entire display. |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2261 | cf.set(displayFrames.mUnrestricted); |
| 2262 | df.set(displayFrames.mUnrestricted); |
| 2263 | pf.set(displayFrames.mUnrestricted); |
Jorim Jaggi | d649057 | 2019-04-16 14:57:56 +0200 | [diff] [blame] | 2264 | } else if ((sysUiFl & SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 2265 | && (type == TYPE_NOTIFICATION_SHADE |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2266 | || type == TYPE_TOAST |
| 2267 | || type == TYPE_DOCK_DIVIDER |
| 2268 | || type == TYPE_VOICE_INTERACTION_STARTING |
| 2269 | || (type >= FIRST_APPLICATION_WINDOW && type <= LAST_SUB_WINDOW))) { |
| 2270 | // Asking for layout as if the nav bar is hidden, lets the |
| 2271 | // application extend into the unrestricted screen area. We |
| 2272 | // only do this for application windows (or toasts) to ensure no window that |
| 2273 | // can be above the nav bar can do this. |
| 2274 | // XXX This assumes that an app asking for this will also |
| 2275 | // ask for layout in only content. We can't currently figure out |
| 2276 | // what the screen would be if only laying out to hide the nav bar. |
| 2277 | cf.set(displayFrames.mUnrestricted); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2278 | df.set(displayFrames.mUnrestricted); |
| 2279 | pf.set(displayFrames.mUnrestricted); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 2280 | } else if ((sysUiFl & SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2281 | df.set(displayFrames.mRestricted); |
| 2282 | pf.set(displayFrames.mRestricted); |
Jorim Jaggi | 648e588 | 2019-01-24 13:24:02 +0100 | [diff] [blame] | 2283 | |
| 2284 | // IME Insets are handled on the client for ADJUST_RESIZE in the new insets |
| 2285 | // world |
| 2286 | if (ViewRootImpl.sNewInsetsMode != NEW_INSETS_MODE_NONE |
| 2287 | || adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2288 | cf.set(displayFrames.mDock); |
| 2289 | } else { |
| 2290 | cf.set(displayFrames.mContent); |
| 2291 | } |
| 2292 | } else { |
| 2293 | cf.set(displayFrames.mRestricted); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2294 | df.set(displayFrames.mRestricted); |
| 2295 | pf.set(displayFrames.mRestricted); |
| 2296 | } |
| 2297 | |
| 2298 | applyStableConstraints(sysUiFl, fl, cf, displayFrames); |
| 2299 | |
Jorim Jaggi | 4e04eb2 | 2020-01-09 16:42:14 +0100 | [diff] [blame] | 2300 | if (ViewRootImpl.sNewInsetsMode == NEW_INSETS_MODE_NONE |
| 2301 | && adjust != SOFT_INPUT_ADJUST_NOTHING) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2302 | vf.set(displayFrames.mCurrent); |
| 2303 | } else { |
| 2304 | vf.set(cf); |
| 2305 | } |
| 2306 | } else if (attached != null) { |
| 2307 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
| 2308 | + "): attached to " + attached); |
| 2309 | // A child window should be placed inside of the same visible |
| 2310 | // frame that its parent had. |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2311 | setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, cf, vf, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2312 | displayFrames); |
| 2313 | } else { |
| 2314 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
| 2315 | + "): normal window"); |
| 2316 | // Otherwise, a normal window must be placed inside the content |
| 2317 | // of all screen decorations. |
Heemin Seog | 2cf45dd | 2020-02-24 15:43:29 -0800 | [diff] [blame] | 2318 | if (type == TYPE_STATUS_BAR_ADDITIONAL) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2319 | // Status bar panels can go on |
| 2320 | // top of the status bar. They are protected by the STATUS_BAR_SERVICE |
| 2321 | // permission, so they have the same privileges as the status bar itself. |
| 2322 | cf.set(displayFrames.mRestricted); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2323 | df.set(displayFrames.mRestricted); |
| 2324 | pf.set(displayFrames.mRestricted); |
Vishnu Nair | 9ccb1d2 | 2019-03-20 16:32:44 +0000 | [diff] [blame] | 2325 | } else if (type == TYPE_TOAST || type == TYPE_SYSTEM_ALERT) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2326 | // These dialogs are stable to interim decor changes. |
| 2327 | cf.set(displayFrames.mStable); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2328 | df.set(displayFrames.mStable); |
| 2329 | pf.set(displayFrames.mStable); |
| 2330 | } else { |
| 2331 | pf.set(displayFrames.mContent); |
| 2332 | if (win.isVoiceInteraction()) { |
| 2333 | cf.set(displayFrames.mVoiceContent); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2334 | df.set(displayFrames.mVoiceContent); |
| 2335 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 2336 | cf.set(displayFrames.mDock); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2337 | df.set(displayFrames.mDock); |
| 2338 | } else { |
| 2339 | cf.set(displayFrames.mContent); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2340 | df.set(displayFrames.mContent); |
| 2341 | } |
Jorim Jaggi | 4e04eb2 | 2020-01-09 16:42:14 +0100 | [diff] [blame] | 2342 | if (ViewRootImpl.sNewInsetsMode == NEW_INSETS_MODE_NONE |
| 2343 | && adjust != SOFT_INPUT_ADJUST_NOTHING) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2344 | vf.set(displayFrames.mCurrent); |
| 2345 | } else { |
| 2346 | vf.set(cf); |
| 2347 | } |
| 2348 | } |
| 2349 | } |
| 2350 | } |
| 2351 | |
| 2352 | final int cutoutMode = attrs.layoutInDisplayCutoutMode; |
| 2353 | final boolean attachedInParent = attached != null && !layoutInScreen; |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 2354 | final boolean requestedFullscreen = (fl & FLAG_FULLSCREEN) != 0 |
| 2355 | || (requestedSysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0 |
Jorim Jaggi | 0dd0cf9 | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 2356 | || (ViewRootImpl.sNewInsetsMode == NEW_INSETS_MODE_FULL |
| 2357 | && !win.getRequestedInsetsState().getSource(ITYPE_STATUS_BAR).isVisible()); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2358 | final boolean requestedHideNavigation = |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 2359 | (requestedSysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 0dd0cf9 | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 2360 | || (ViewRootImpl.sNewInsetsMode == NEW_INSETS_MODE_FULL |
| 2361 | && !win.getRequestedInsetsState().getSource(ITYPE_NAVIGATION_BAR) |
| 2362 | .isVisible()); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2363 | |
| 2364 | // TYPE_BASE_APPLICATION windows are never considered floating here because they don't get |
| 2365 | // cropped / shifted to the displayFrame in WindowState. |
| 2366 | final boolean floatingInScreenWindow = !attrs.isFullscreen() && layoutInScreen |
| 2367 | && type != TYPE_BASE_APPLICATION; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2368 | // Ensure that windows with a DEFAULT or NEVER display cutout mode are laid out in |
| 2369 | // the cutout safe zone. |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 2370 | if (cutoutMode != LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2371 | final Rect displayCutoutSafeExceptMaybeBars = sTmpDisplayCutoutSafeExceptMaybeBarsRect; |
| 2372 | displayCutoutSafeExceptMaybeBars.set(displayFrames.mDisplayCutoutSafe); |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 2373 | if (cutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES) { |
| 2374 | if (displayFrames.mDisplayWidth < displayFrames.mDisplayHeight) { |
| 2375 | displayCutoutSafeExceptMaybeBars.top = Integer.MIN_VALUE; |
| 2376 | displayCutoutSafeExceptMaybeBars.bottom = Integer.MAX_VALUE; |
| 2377 | } else { |
| 2378 | displayCutoutSafeExceptMaybeBars.left = Integer.MIN_VALUE; |
| 2379 | displayCutoutSafeExceptMaybeBars.right = Integer.MAX_VALUE; |
| 2380 | } |
| 2381 | } |
| 2382 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2383 | if (layoutInScreen && layoutInsetDecor && !requestedFullscreen |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 2384 | && (cutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT |
| 2385 | || cutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES)) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2386 | // At the top we have the status bar, so apps that are |
| 2387 | // LAYOUT_IN_SCREEN | LAYOUT_INSET_DECOR but not FULLSCREEN |
| 2388 | // already expect that there's an inset there and we don't need to exclude |
| 2389 | // the window from that area. |
| 2390 | displayCutoutSafeExceptMaybeBars.top = Integer.MIN_VALUE; |
| 2391 | } |
| 2392 | if (layoutInScreen && layoutInsetDecor && !requestedHideNavigation |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 2393 | && (cutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT |
| 2394 | || cutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES)) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2395 | // Same for the navigation bar. |
| 2396 | switch (mNavigationBarPosition) { |
| 2397 | case NAV_BAR_BOTTOM: |
| 2398 | displayCutoutSafeExceptMaybeBars.bottom = Integer.MAX_VALUE; |
| 2399 | break; |
| 2400 | case NAV_BAR_RIGHT: |
| 2401 | displayCutoutSafeExceptMaybeBars.right = Integer.MAX_VALUE; |
| 2402 | break; |
| 2403 | case NAV_BAR_LEFT: |
| 2404 | displayCutoutSafeExceptMaybeBars.left = Integer.MIN_VALUE; |
| 2405 | break; |
| 2406 | } |
| 2407 | } |
| 2408 | if (type == TYPE_INPUT_METHOD && mNavigationBarPosition == NAV_BAR_BOTTOM) { |
| 2409 | // The IME can always extend under the bottom cutout if the navbar is there. |
| 2410 | displayCutoutSafeExceptMaybeBars.bottom = Integer.MAX_VALUE; |
| 2411 | } |
| 2412 | // Windows that are attached to a parent and laid out in said parent already avoid |
| 2413 | // the cutout according to that parent and don't need to be further constrained. |
| 2414 | // Floating IN_SCREEN windows get what they ask for and lay out in the full screen. |
| 2415 | // They will later be cropped or shifted using the displayFrame in WindowState, |
| 2416 | // which prevents overlap with the DisplayCutout. |
| 2417 | if (!attachedInParent && !floatingInScreenWindow) { |
| 2418 | sTmpRect.set(pf); |
| 2419 | pf.intersectUnchecked(displayCutoutSafeExceptMaybeBars); |
| 2420 | windowFrames.setParentFrameWasClippedByDisplayCutout(!sTmpRect.equals(pf)); |
| 2421 | } |
| 2422 | // Make sure that NO_LIMITS windows clipped to the display don't extend under the |
| 2423 | // cutout. |
| 2424 | df.intersectUnchecked(displayCutoutSafeExceptMaybeBars); |
| 2425 | } |
| 2426 | |
| 2427 | // Content should never appear in the cutout. |
| 2428 | cf.intersectUnchecked(displayFrames.mDisplayCutoutSafe); |
| 2429 | |
| 2430 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 2431 | // Also, we don't allow windows in multi-window mode to extend out of the screen. |
| 2432 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && type != TYPE_SYSTEM_ERROR |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 2433 | && !win.inMultiWindowMode()) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2434 | df.left = df.top = -10000; |
| 2435 | df.right = df.bottom = 10000; |
| 2436 | if (type != TYPE_WALLPAPER) { |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2437 | cf.left = cf.top = vf.left = vf.top = -10000; |
| 2438 | cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2439 | } |
| 2440 | } |
| 2441 | |
| 2442 | if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle() |
| 2443 | + ": sim=#" + Integer.toHexString(sim) |
| 2444 | + " attach=" + attached + " type=" + type |
| 2445 | + String.format(" flags=0x%08x", fl) |
| 2446 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2447 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
| 2448 | + " dcf=" + dcf.toShortString() |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2449 | + " sf=" + sf.toShortString()); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2450 | |
| 2451 | if (!sTmpLastParentFrame.equals(pf)) { |
| 2452 | windowFrames.setContentChanged(true); |
| 2453 | } |
| 2454 | |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 2455 | win.computeFrame(displayFrames); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2456 | // Dock windows carve out the bottom of the screen, so normal windows |
| 2457 | // can't appear underneath them. |
| 2458 | if (type == TYPE_INPUT_METHOD && win.isVisibleLw() |
| 2459 | && !win.getGivenInsetsPendingLw()) { |
| 2460 | offsetInputMethodWindowLw(win, displayFrames); |
| 2461 | } |
| 2462 | if (type == TYPE_VOICE_INTERACTION && win.isVisibleLw() |
| 2463 | && !win.getGivenInsetsPendingLw()) { |
| 2464 | offsetVoiceInputWindowLw(win, displayFrames); |
| 2465 | } |
| 2466 | } |
| 2467 | |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 2468 | private void layoutWallpaper(DisplayFrames displayFrames, Rect pf, Rect df, Rect cf) { |
| 2469 | // The wallpaper has Real Ultimate Power |
| 2470 | df.set(displayFrames.mUnrestricted); |
| 2471 | pf.set(displayFrames.mUnrestricted); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2472 | cf.set(displayFrames.mUnrestricted); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | private void offsetInputMethodWindowLw(WindowState win, DisplayFrames displayFrames) { |
Winson Chung | 913690d | 2019-11-14 16:06:01 -0800 | [diff] [blame] | 2476 | final int rotation = displayFrames.mRotation; |
| 2477 | final int navBarPosition = navigationBarPosition(displayFrames.mDisplayWidth, |
| 2478 | displayFrames.mDisplayHeight, rotation); |
| 2479 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2480 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
| 2481 | top += win.getGivenContentInsetsLw().top; |
| 2482 | displayFrames.mContent.bottom = Math.min(displayFrames.mContent.bottom, top); |
Winson Chung | 913690d | 2019-11-14 16:06:01 -0800 | [diff] [blame] | 2483 | if (navBarPosition == NAV_BAR_BOTTOM) { |
| 2484 | // Always account for the nav bar frame height on the bottom since in all navigation |
| 2485 | // modes we make room to show the dismiss-ime button, even if the IME does not report |
| 2486 | // insets (ie. when floating) |
| 2487 | final int uimode = mService.mPolicy.getUiMode(); |
| 2488 | final int navFrameHeight = getNavigationBarFrameHeight(rotation, uimode); |
| 2489 | displayFrames.mContent.bottom = Math.min(displayFrames.mContent.bottom, |
| 2490 | displayFrames.mUnrestricted.bottom - navFrameHeight); |
| 2491 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2492 | displayFrames.mVoiceContent.bottom = Math.min(displayFrames.mVoiceContent.bottom, top); |
| 2493 | top = win.getVisibleFrameLw().top; |
| 2494 | top += win.getGivenVisibleInsetsLw().top; |
| 2495 | displayFrames.mCurrent.bottom = Math.min(displayFrames.mCurrent.bottom, top); |
| 2496 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
| 2497 | + displayFrames.mDock.bottom + " mContentBottom=" |
| 2498 | + displayFrames.mContent.bottom + " mCurBottom=" + displayFrames.mCurrent.bottom); |
| 2499 | } |
| 2500 | |
| 2501 | private void offsetVoiceInputWindowLw(WindowState win, DisplayFrames displayFrames) { |
| 2502 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
| 2503 | top += win.getGivenContentInsetsLw().top; |
| 2504 | displayFrames.mVoiceContent.bottom = Math.min(displayFrames.mVoiceContent.bottom, top); |
| 2505 | } |
| 2506 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2507 | WindowState getTopFullscreenOpaqueWindow() { |
| 2508 | return mTopFullscreenOpaqueWindowState; |
| 2509 | } |
| 2510 | |
| 2511 | boolean isTopLayoutFullscreen() { |
| 2512 | return mTopIsFullscreen; |
| 2513 | } |
| 2514 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2515 | /** |
| 2516 | * Called following layout of all windows before each window has policy applied. |
| 2517 | */ |
| 2518 | public void beginPostLayoutPolicyLw() { |
| 2519 | mTopFullscreenOpaqueWindowState = null; |
| 2520 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
| 2521 | mTopDockedOpaqueWindowState = null; |
| 2522 | mTopDockedOpaqueOrDimmingWindowState = null; |
| 2523 | mForceStatusBar = false; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2524 | mForcingShowNavBar = false; |
| 2525 | mForcingShowNavBarLayer = -1; |
| 2526 | |
| 2527 | mAllowLockscreenWhenOn = false; |
| 2528 | mShowingDream = false; |
HEO SEUNG | 22d3ec2 | 2019-05-30 20:28:53 +0900 | [diff] [blame] | 2529 | mIsFreeformWindowOverlappingWithNavBar = false; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | /** |
| 2533 | * Called following layout of all window to apply policy to each window. |
| 2534 | * |
| 2535 | * @param win The window being positioned. |
| 2536 | * @param attrs The LayoutParams of the window. |
| 2537 | * @param attached For sub-windows, the window it is attached to. Otherwise null. |
| 2538 | */ |
| 2539 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs, |
| 2540 | WindowState attached, WindowState imeTarget) { |
| 2541 | final boolean affectsSystemUi = win.canAffectSystemUiFlags(); |
| 2542 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": affectsSystemUi=" + affectsSystemUi); |
| 2543 | mService.mPolicy.applyKeyguardPolicyLw(win, imeTarget); |
| 2544 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
| 2545 | if (mTopFullscreenOpaqueWindowState == null && affectsSystemUi |
| 2546 | && attrs.type == TYPE_INPUT_METHOD) { |
| 2547 | mForcingShowNavBar = true; |
| 2548 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
| 2549 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2550 | |
| 2551 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
| 2552 | && attrs.type < FIRST_SYSTEM_WINDOW; |
| 2553 | final int windowingMode = win.getWindowingMode(); |
| 2554 | final boolean inFullScreenOrSplitScreenSecondaryWindowingMode = |
| 2555 | windowingMode == WINDOWING_MODE_FULLSCREEN |
| 2556 | || windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 2557 | if (mTopFullscreenOpaqueWindowState == null && affectsSystemUi) { |
| 2558 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
| 2559 | mForceStatusBar = true; |
| 2560 | } |
Galia Peycheva | 70b5571 | 2020-03-16 18:31:34 +0100 | [diff] [blame] | 2561 | if (win.isDreamWindow()) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2562 | // If the lockscreen was showing when the dream started then wait |
| 2563 | // for the dream to draw before hiding the lockscreen. |
| 2564 | if (!mDreamingLockscreen |
| 2565 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 2566 | mShowingDream = true; |
| 2567 | appWindow = true; |
| 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | // For app windows that are not attached, we decide if all windows in the app they |
| 2572 | // represent should be hidden or if we should hide the lockscreen. For attached app |
| 2573 | // windows we defer the decision to the window it is attached to. |
| 2574 | if (appWindow && attached == null) { |
| 2575 | if (attrs.isFullscreen() && inFullScreenOrSplitScreenSecondaryWindowingMode) { |
| 2576 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 2577 | mTopFullscreenOpaqueWindowState = win; |
| 2578 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 2579 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 2580 | } |
| 2581 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
| 2582 | mAllowLockscreenWhenOn = true; |
| 2583 | } |
| 2584 | } |
| 2585 | } |
| 2586 | } |
| 2587 | |
| 2588 | // Voice interaction overrides both top fullscreen and top docked. |
Jorim Jaggi | 5015015 | 2019-03-27 23:08:58 +0100 | [diff] [blame] | 2589 | if (affectsSystemUi && attrs.type == TYPE_VOICE_INTERACTION) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2590 | if (mTopFullscreenOpaqueWindowState == null) { |
| 2591 | mTopFullscreenOpaqueWindowState = win; |
| 2592 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 2593 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 2594 | } |
| 2595 | } |
| 2596 | if (mTopDockedOpaqueWindowState == null) { |
| 2597 | mTopDockedOpaqueWindowState = win; |
| 2598 | if (mTopDockedOpaqueOrDimmingWindowState == null) { |
| 2599 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 2600 | } |
| 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | // Keep track of the window if it's dimming but not necessarily fullscreen. |
| 2605 | if (mTopFullscreenOpaqueOrDimmingWindowState == null && affectsSystemUi |
| 2606 | && win.isDimming() && inFullScreenOrSplitScreenSecondaryWindowingMode) { |
| 2607 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 2608 | } |
| 2609 | |
| 2610 | // We need to keep track of the top "fullscreen" opaque window for the docked stack |
| 2611 | // separately, because both the "real fullscreen" opaque window and the one for the docked |
| 2612 | // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR. |
| 2613 | if (mTopDockedOpaqueWindowState == null && affectsSystemUi && appWindow && attached == null |
| 2614 | && attrs.isFullscreen() && windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 2615 | mTopDockedOpaqueWindowState = win; |
| 2616 | if (mTopDockedOpaqueOrDimmingWindowState == null) { |
| 2617 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 2618 | } |
| 2619 | } |
| 2620 | |
HEO SEUNG | 22d3ec2 | 2019-05-30 20:28:53 +0900 | [diff] [blame] | 2621 | // Check if the freeform window overlaps with the navigation bar area. |
| 2622 | final WindowState navBarWin = hasNavigationBar() ? mNavigationBar : null; |
| 2623 | if (!mIsFreeformWindowOverlappingWithNavBar && win.inFreeformWindowingMode() |
| 2624 | && isOverlappingWithNavBar(win, navBarWin)) { |
| 2625 | mIsFreeformWindowOverlappingWithNavBar = true; |
| 2626 | } |
| 2627 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2628 | // Also keep track of any windows that are dimming but not necessarily fullscreen in the |
| 2629 | // docked stack. |
| 2630 | if (mTopDockedOpaqueOrDimmingWindowState == null && affectsSystemUi && win.isDimming() |
| 2631 | && windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 2632 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 2633 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | /** |
| 2637 | * Called following layout of all windows and after policy has been applied |
| 2638 | * to each window. If in this function you do |
| 2639 | * something that may have modified the animation state of another window, |
| 2640 | * be sure to return non-zero in order to perform another pass through layout. |
| 2641 | * |
| 2642 | * @return Return any bit set of |
| 2643 | * {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_LAYOUT}, |
| 2644 | * {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_CONFIG}, |
| 2645 | * {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_WALLPAPER}, or |
| 2646 | * {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_ANIM}. |
| 2647 | */ |
| 2648 | public int finishPostLayoutPolicyLw() { |
| 2649 | int changes = 0; |
| 2650 | boolean topIsFullscreen = false; |
| 2651 | |
| 2652 | // If we are not currently showing a dream then remember the current |
| 2653 | // lockscreen state. We will use this to determine whether the dream |
| 2654 | // started while the lockscreen was showing and remember this state |
| 2655 | // while the dream is showing. |
| 2656 | if (!mShowingDream) { |
| 2657 | mDreamingLockscreen = mService.mPolicy.isKeyguardShowingAndNotOccluded(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | if (mStatusBar != null) { |
| 2661 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2662 | + " top=" + mTopFullscreenOpaqueWindowState); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 2663 | final boolean forceShowStatusBar = (mStatusBar.getAttrs().privateFlags |
| 2664 | & PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR) != 0; |
| 2665 | final boolean notificationShadeForcesShowingNavigation = |
| 2666 | mNotificationShade != null |
| 2667 | && (mNotificationShade.getAttrs().privateFlags |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2668 | & PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION) != 0; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 2669 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2670 | boolean topAppHidesStatusBar = topAppHidesStatusBar(); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 2671 | if (mForceStatusBar || forceShowStatusBar) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2672 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
| 2673 | if (mStatusBarController.setBarShowingLw(true)) { |
| 2674 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 2675 | } |
| 2676 | // Maintain fullscreen layout until incoming animation is complete. |
| 2677 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 2678 | // Transient status bar is not allowed if notification shade is expecting the |
| 2679 | // navigation keys from the user. |
| 2680 | if (notificationShadeForcesShowingNavigation |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2681 | && mStatusBarController.isTransientShowing()) { |
| 2682 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 2683 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 2684 | } |
| 2685 | } else if (mTopFullscreenOpaqueWindowState != null) { |
| 2686 | topIsFullscreen = topAppHidesStatusBar; |
| 2687 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
| 2688 | // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window |
| 2689 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 2690 | // case though. |
| 2691 | if (mStatusBarController.isTransientShowing()) { |
| 2692 | if (mStatusBarController.setBarShowingLw(true)) { |
| 2693 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 2694 | } |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 2695 | } else if (topIsFullscreen && !mDisplayContent.getDefaultTaskDisplayArea() |
| 2696 | .isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2697 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
| 2698 | if (mStatusBarController.setBarShowingLw(false)) { |
| 2699 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 2700 | } else { |
| 2701 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
| 2702 | } |
| 2703 | } else { |
| 2704 | if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen"); |
| 2705 | if (mStatusBarController.setBarShowingLw(true)) { |
| 2706 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 2707 | } |
| 2708 | topAppHidesStatusBar = false; |
| 2709 | } |
| 2710 | } |
| 2711 | mStatusBarController.setTopAppHidesStatusBar(topAppHidesStatusBar); |
| 2712 | } |
| 2713 | |
| 2714 | if (mTopIsFullscreen != topIsFullscreen) { |
| 2715 | if (!topIsFullscreen) { |
| 2716 | // Force another layout when status bar becomes fully shown. |
| 2717 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 2718 | } |
| 2719 | mTopIsFullscreen = topIsFullscreen; |
| 2720 | } |
| 2721 | |
| 2722 | if ((updateSystemUiVisibilityLw() & SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
| 2723 | // If the navigation bar has been hidden or shown, we need to do another |
| 2724 | // layout pass to update that window. |
| 2725 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 2726 | } |
| 2727 | |
| 2728 | if (mShowingDream != mLastShowingDream) { |
| 2729 | mLastShowingDream = mShowingDream; |
| 2730 | mService.notifyShowingDreamChanged(); |
| 2731 | } |
| 2732 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2733 | mService.mPolicy.setAllowLockscreenWhenOn(getDisplayId(), mAllowLockscreenWhenOn); |
| 2734 | return changes; |
| 2735 | } |
| 2736 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2737 | /** |
| 2738 | * @return Whether the top app should hide the statusbar based on the top fullscreen opaque |
| 2739 | * window. |
| 2740 | */ |
| 2741 | private boolean topAppHidesStatusBar() { |
hyok.kim | 332ccfc | 2019-07-02 15:39:43 +0900 | [diff] [blame] | 2742 | if (mTopFullscreenOpaqueWindowState == null || mForceShowSystemBars) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2743 | return false; |
| 2744 | } |
| 2745 | final int fl = PolicyControl.getWindowFlags(null, |
| 2746 | mTopFullscreenOpaqueWindowState.getAttrs()); |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame] | 2747 | if (WindowManagerDebugConfig.DEBUG) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2748 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()); |
| 2749 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
| 2750 | + " lp.flags=0x" + Integer.toHexString(fl)); |
| 2751 | } |
| 2752 | return (fl & LayoutParams.FLAG_FULLSCREEN) != 0 |
| 2753 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
| 2754 | } |
| 2755 | |
| 2756 | /** |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2757 | * Called when the user is switched. |
| 2758 | */ |
| 2759 | public void switchUser() { |
| 2760 | updateCurrentUserResources(); |
| 2761 | } |
| 2762 | |
| 2763 | /** |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2764 | * Called when the resource overlays change. |
| 2765 | */ |
| 2766 | public void onOverlayChangedLw() { |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2767 | updateCurrentUserResources(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2768 | onConfigurationChanged(); |
Jeff Chang | b0a061e | 2019-03-11 11:39:54 +0800 | [diff] [blame] | 2769 | mSystemGestures.onConfigurationChanged(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | /** |
| 2773 | * Called when the configuration has changed, and it's safe to load new values from resources. |
| 2774 | */ |
| 2775 | public void onConfigurationChanged() { |
| 2776 | final DisplayRotation displayRotation = mDisplayContent.getDisplayRotation(); |
| 2777 | |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2778 | final Resources res = getCurrentUserResources(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2779 | final int portraitRotation = displayRotation.getPortraitRotation(); |
| 2780 | final int upsideDownRotation = displayRotation.getUpsideDownRotation(); |
| 2781 | final int landscapeRotation = displayRotation.getLandscapeRotation(); |
| 2782 | final int seascapeRotation = displayRotation.getSeascapeRotation(); |
Matthew Ng | a7f24bc | 2019-04-09 17:06:41 -0700 | [diff] [blame] | 2783 | final int uiMode = mService.mPolicy.getUiMode(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2784 | |
Louis Chang | fc64c83 | 2018-12-04 11:38:26 +0800 | [diff] [blame] | 2785 | if (hasStatusBar()) { |
| 2786 | mStatusBarHeightForRotation[portraitRotation] = |
| 2787 | mStatusBarHeightForRotation[upsideDownRotation] = |
| 2788 | res.getDimensionPixelSize(R.dimen.status_bar_height_portrait); |
| 2789 | mStatusBarHeightForRotation[landscapeRotation] = |
| 2790 | mStatusBarHeightForRotation[seascapeRotation] = |
| 2791 | res.getDimensionPixelSize(R.dimen.status_bar_height_landscape); |
| 2792 | } else { |
| 2793 | mStatusBarHeightForRotation[portraitRotation] = |
| 2794 | mStatusBarHeightForRotation[upsideDownRotation] = |
| 2795 | mStatusBarHeightForRotation[landscapeRotation] = |
| 2796 | mStatusBarHeightForRotation[seascapeRotation] = 0; |
| 2797 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2798 | |
| 2799 | // Height of the navigation bar when presented horizontally at bottom |
| 2800 | mNavigationBarHeightForRotationDefault[portraitRotation] = |
| 2801 | mNavigationBarHeightForRotationDefault[upsideDownRotation] = |
| 2802 | res.getDimensionPixelSize(R.dimen.navigation_bar_height); |
| 2803 | mNavigationBarHeightForRotationDefault[landscapeRotation] = |
| 2804 | mNavigationBarHeightForRotationDefault[seascapeRotation] = |
| 2805 | res.getDimensionPixelSize(R.dimen.navigation_bar_height_landscape); |
| 2806 | |
Matthew Ng | a7f24bc | 2019-04-09 17:06:41 -0700 | [diff] [blame] | 2807 | // Height of the navigation bar frame when presented horizontally at bottom |
| 2808 | mNavigationBarFrameHeightForRotationDefault[portraitRotation] = |
| 2809 | mNavigationBarFrameHeightForRotationDefault[upsideDownRotation] = |
| 2810 | res.getDimensionPixelSize(R.dimen.navigation_bar_frame_height); |
| 2811 | mNavigationBarFrameHeightForRotationDefault[landscapeRotation] = |
| 2812 | mNavigationBarFrameHeightForRotationDefault[seascapeRotation] = |
| 2813 | res.getDimensionPixelSize(R.dimen.navigation_bar_frame_height_landscape); |
| 2814 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2815 | // Width of the navigation bar when presented vertically along one side |
| 2816 | mNavigationBarWidthForRotationDefault[portraitRotation] = |
| 2817 | mNavigationBarWidthForRotationDefault[upsideDownRotation] = |
| 2818 | mNavigationBarWidthForRotationDefault[landscapeRotation] = |
| 2819 | mNavigationBarWidthForRotationDefault[seascapeRotation] = |
| 2820 | res.getDimensionPixelSize(R.dimen.navigation_bar_width); |
| 2821 | |
| 2822 | if (ALTERNATE_CAR_MODE_NAV_SIZE) { |
| 2823 | // Height of the navigation bar when presented horizontally at bottom |
| 2824 | mNavigationBarHeightForRotationInCarMode[portraitRotation] = |
| 2825 | mNavigationBarHeightForRotationInCarMode[upsideDownRotation] = |
| 2826 | res.getDimensionPixelSize(R.dimen.navigation_bar_height_car_mode); |
| 2827 | mNavigationBarHeightForRotationInCarMode[landscapeRotation] = |
| 2828 | mNavigationBarHeightForRotationInCarMode[seascapeRotation] = |
| 2829 | res.getDimensionPixelSize(R.dimen.navigation_bar_height_landscape_car_mode); |
| 2830 | |
| 2831 | // Width of the navigation bar when presented vertically along one side |
| 2832 | mNavigationBarWidthForRotationInCarMode[portraitRotation] = |
| 2833 | mNavigationBarWidthForRotationInCarMode[upsideDownRotation] = |
| 2834 | mNavigationBarWidthForRotationInCarMode[landscapeRotation] = |
| 2835 | mNavigationBarWidthForRotationInCarMode[seascapeRotation] = |
| 2836 | res.getDimensionPixelSize(R.dimen.navigation_bar_width_car_mode); |
| 2837 | } |
| 2838 | |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 2839 | mNavBarOpacityMode = res.getInteger(R.integer.config_navBarOpacityMode); |
Mehdi Alizadeh | f2b28e9 | 2019-12-05 20:13:49 -0800 | [diff] [blame] | 2840 | mLeftGestureInset = mGestureNavigationSettingsObserver.getLeftSensitivity(res); |
| 2841 | mRightGestureInset = mGestureNavigationSettingsObserver.getRightSensitivity(res); |
Sunny Goyal | 3841295 | 2020-04-17 11:35:37 -0700 | [diff] [blame] | 2842 | mNavButtonForcedVisible = |
| 2843 | mGestureNavigationSettingsObserver.areNavigationButtonForcedVisible(); |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 2844 | mNavigationBarLetsThroughTaps = res.getBoolean(R.bool.config_navBarTapThrough); |
Winson Chung | 3694163 | 2019-04-19 15:21:38 -0700 | [diff] [blame] | 2845 | mNavigationBarAlwaysShowOnSideGesture = |
| 2846 | res.getBoolean(R.bool.config_navBarAlwaysShowOnSideEdgeGesture); |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 2847 | |
Matthew Ng | a7f24bc | 2019-04-09 17:06:41 -0700 | [diff] [blame] | 2848 | // This should calculate how much above the frame we accept gestures. |
Sunny Goyal | b5e5bcb | 2019-05-22 14:28:44 -0700 | [diff] [blame] | 2849 | mBottomGestureAdditionalInset = |
Matthew Ng | a7f24bc | 2019-04-09 17:06:41 -0700 | [diff] [blame] | 2850 | res.getDimensionPixelSize(R.dimen.navigation_bar_gesture_height) |
Sunny Goyal | b5e5bcb | 2019-05-22 14:28:44 -0700 | [diff] [blame] | 2851 | - getNavigationBarFrameHeight(portraitRotation, uiMode); |
Adrian Roos | 11dfd27 | 2019-03-25 19:21:26 +0100 | [diff] [blame] | 2852 | |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 2853 | updateConfigurationAndScreenSizeDependentBehaviors(); |
| 2854 | } |
| 2855 | |
| 2856 | void updateConfigurationAndScreenSizeDependentBehaviors() { |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2857 | final Resources res = getCurrentUserResources(); |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 2858 | mNavigationBarCanMove = |
| 2859 | mDisplayContent.mBaseDisplayWidth != mDisplayContent.mBaseDisplayHeight |
| 2860 | && res.getBoolean(R.bool.config_navBarCanMove); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2861 | mDisplayContent.getDisplayRotation().updateUserDependentConfiguration(res); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2862 | } |
| 2863 | |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2864 | /** |
| 2865 | * Updates the current user's resources to pick up any changes for the current user (including |
| 2866 | * overlay paths) |
| 2867 | */ |
| 2868 | private void updateCurrentUserResources() { |
| 2869 | final int userId = mService.mAmInternal.getCurrentUserId(); |
| 2870 | final Context uiContext = getSystemUiContext(); |
Winson Chung | 203e152 | 2019-05-02 15:42:22 -0700 | [diff] [blame] | 2871 | |
| 2872 | if (userId == UserHandle.USER_SYSTEM) { |
| 2873 | // Skip the (expensive) recreation of resources for the system user below and just |
| 2874 | // use the resources from the system ui context |
| 2875 | mCurrentUserResources = uiContext.getResources(); |
| 2876 | return; |
| 2877 | } |
| 2878 | |
| 2879 | // For non-system users, ensure that the resources are loaded from the current |
| 2880 | // user's package info (see ContextImpl.createDisplayContext) |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2881 | final LoadedApk pi = ActivityThread.currentActivityThread().getPackageInfo( |
| 2882 | uiContext.getPackageName(), null, 0, userId); |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2883 | mCurrentUserResources = ResourcesManager.getInstance().getResources(null, |
| 2884 | pi.getResDir(), |
| 2885 | null /* splitResDirs */, |
| 2886 | pi.getOverlayDirs(), |
| 2887 | pi.getApplicationInfo().sharedLibraryFiles, |
| 2888 | mDisplayContent.getDisplayId(), |
| 2889 | null /* overrideConfig */, |
| 2890 | uiContext.getResources().getCompatibilityInfo(), |
Ryan Mitchell | 4579c0a | 2020-01-08 16:29:11 -0800 | [diff] [blame] | 2891 | null /* classLoader */, |
| 2892 | null /* loaders */); |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2893 | } |
| 2894 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2895 | @VisibleForTesting |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2896 | Resources getCurrentUserResources() { |
| 2897 | if (mCurrentUserResources == null) { |
| 2898 | updateCurrentUserResources(); |
| 2899 | } |
| 2900 | return mCurrentUserResources; |
| 2901 | } |
| 2902 | |
| 2903 | @VisibleForTesting |
| 2904 | Context getContext() { |
| 2905 | return mContext; |
| 2906 | } |
| 2907 | |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 2908 | Context getSystemUiContext() { |
| 2909 | return mUiContext; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | private int getNavigationBarWidth(int rotation, int uiMode) { |
| 2913 | if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) { |
| 2914 | return mNavigationBarWidthForRotationInCarMode[rotation]; |
| 2915 | } else { |
| 2916 | return mNavigationBarWidthForRotationDefault[rotation]; |
| 2917 | } |
| 2918 | } |
| 2919 | |
Charles Chen | 3dedec3 | 2019-01-24 22:19:37 +0800 | [diff] [blame] | 2920 | void notifyDisplayReady() { |
wilsonshih | 643bf13 | 2019-02-27 12:49:19 +0800 | [diff] [blame] | 2921 | mHandler.post(() -> { |
| 2922 | final int displayId = getDisplayId(); |
| 2923 | getStatusBarManagerInternal().onDisplayReady(displayId); |
Felipe Leme | 34a861a | 2019-08-05 16:00:12 -0700 | [diff] [blame] | 2924 | final WallpaperManagerInternal wpMgr = LocalServices |
| 2925 | .getService(WallpaperManagerInternal.class); |
| 2926 | if (wpMgr != null) { |
| 2927 | wpMgr.onDisplayReady(displayId); |
| 2928 | } |
wilsonshih | 643bf13 | 2019-02-27 12:49:19 +0800 | [diff] [blame] | 2929 | }); |
Charles Chen | 3dedec3 | 2019-01-24 22:19:37 +0800 | [diff] [blame] | 2930 | } |
| 2931 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2932 | /** |
| 2933 | * Return the display width available after excluding any screen |
| 2934 | * decorations that could never be removed in Honeycomb. That is, system bar or |
| 2935 | * button bar. |
| 2936 | */ |
| 2937 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2938 | DisplayCutout displayCutout) { |
| 2939 | int width = fullWidth; |
| 2940 | if (hasNavigationBar()) { |
Tiger Huang | 3d2b898 | 2019-01-29 22:56:48 +0800 | [diff] [blame] | 2941 | final int navBarPosition = navigationBarPosition(fullWidth, fullHeight, rotation); |
| 2942 | if (navBarPosition == NAV_BAR_LEFT || navBarPosition == NAV_BAR_RIGHT) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2943 | width -= getNavigationBarWidth(rotation, uiMode); |
| 2944 | } |
| 2945 | } |
| 2946 | if (displayCutout != null) { |
| 2947 | width -= displayCutout.getSafeInsetLeft() + displayCutout.getSafeInsetRight(); |
| 2948 | } |
| 2949 | return width; |
| 2950 | } |
| 2951 | |
| 2952 | private int getNavigationBarHeight(int rotation, int uiMode) { |
| 2953 | if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) { |
| 2954 | return mNavigationBarHeightForRotationInCarMode[rotation]; |
| 2955 | } else { |
| 2956 | return mNavigationBarHeightForRotationDefault[rotation]; |
| 2957 | } |
| 2958 | } |
| 2959 | |
| 2960 | /** |
Matthew Ng | a7f24bc | 2019-04-09 17:06:41 -0700 | [diff] [blame] | 2961 | * Get the Navigation Bar Frame height. This dimension is the height of the navigation bar that |
| 2962 | * is used for spacing to show additional buttons on the navigation bar (such as the ime |
| 2963 | * switcher when ime is visible) while {@link #getNavigationBarHeight} is used for the visible |
| 2964 | * height that we send to the app as content insets that can be smaller. |
| 2965 | * <p> |
| 2966 | * In car mode it will return the same height as {@link #getNavigationBarHeight} |
| 2967 | * |
| 2968 | * @param rotation specifies rotation to return dimension from |
| 2969 | * @param uiMode to determine if in car mode |
| 2970 | * @return navigation bar frame height |
| 2971 | */ |
| 2972 | private int getNavigationBarFrameHeight(int rotation, int uiMode) { |
| 2973 | if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) { |
| 2974 | return mNavigationBarHeightForRotationInCarMode[rotation]; |
| 2975 | } else { |
| 2976 | return mNavigationBarFrameHeightForRotationDefault[rotation]; |
| 2977 | } |
| 2978 | } |
| 2979 | |
| 2980 | /** |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2981 | * Return the display height available after excluding any screen |
| 2982 | * decorations that could never be removed in Honeycomb. That is, system bar or |
| 2983 | * button bar. |
| 2984 | */ |
| 2985 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2986 | DisplayCutout displayCutout) { |
| 2987 | int height = fullHeight; |
| 2988 | if (hasNavigationBar()) { |
Tiger Huang | 3d2b898 | 2019-01-29 22:56:48 +0800 | [diff] [blame] | 2989 | final int navBarPosition = navigationBarPosition(fullWidth, fullHeight, rotation); |
| 2990 | if (navBarPosition == NAV_BAR_BOTTOM) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2991 | height -= getNavigationBarHeight(rotation, uiMode); |
| 2992 | } |
| 2993 | } |
| 2994 | if (displayCutout != null) { |
| 2995 | height -= displayCutout.getSafeInsetTop() + displayCutout.getSafeInsetBottom(); |
| 2996 | } |
| 2997 | return height; |
| 2998 | } |
| 2999 | |
| 3000 | /** |
| 3001 | * Return the available screen width that we should report for the |
| 3002 | * configuration. This must be no larger than |
| 3003 | * {@link #getNonDecorDisplayWidth(int, int, int, int, DisplayCutout)}; it may be smaller |
| 3004 | * than that to account for more transient decoration like a status bar. |
| 3005 | */ |
| 3006 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 3007 | DisplayCutout displayCutout) { |
| 3008 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode, displayCutout); |
| 3009 | } |
| 3010 | |
| 3011 | /** |
| 3012 | * Return the available screen height that we should report for the |
| 3013 | * configuration. This must be no larger than |
| 3014 | * {@link #getNonDecorDisplayHeight(int, int, int, int, DisplayCutout)}; it may be smaller |
| 3015 | * than that to account for more transient decoration like a status bar. |
| 3016 | */ |
| 3017 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 3018 | DisplayCutout displayCutout) { |
| 3019 | // There is a separate status bar at the top of the display. We don't count that as part |
| 3020 | // of the fixed decor, since it can hide; however, for purposes of configurations, |
| 3021 | // we do want to exclude it since applications can't generally use that part |
| 3022 | // of the screen. |
| 3023 | int statusBarHeight = mStatusBarHeightForRotation[rotation]; |
| 3024 | if (displayCutout != null) { |
| 3025 | // If there is a cutout, it may already have accounted for some part of the status |
| 3026 | // bar height. |
| 3027 | statusBarHeight = Math.max(0, statusBarHeight - displayCutout.getSafeInsetTop()); |
| 3028 | } |
| 3029 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation, uiMode, displayCutout) |
| 3030 | - statusBarHeight; |
| 3031 | } |
| 3032 | |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 3033 | /** |
| 3034 | * Return corner radius in pixels that should be used on windows in order to cover the display. |
Dominik Laskowski | 26290bb | 2020-01-15 16:09:55 -0800 | [diff] [blame] | 3035 | * |
| 3036 | * The radius is only valid for internal displays, since the corner radius of external displays |
| 3037 | * is not known at build time when window corners are configured. |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 3038 | */ |
| 3039 | float getWindowCornerRadius() { |
Dominik Laskowski | 26290bb | 2020-01-15 16:09:55 -0800 | [diff] [blame] | 3040 | return mDisplayContent.getDisplay().getType() == TYPE_INTERNAL |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 3041 | ? ScreenDecorationsUtils.getWindowCornerRadius(mContext.getResources()) : 0f; |
| 3042 | } |
| 3043 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3044 | boolean isShowingDreamLw() { |
| 3045 | return mShowingDream; |
| 3046 | } |
| 3047 | |
| 3048 | /** |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 3049 | * Calculates the stable insets if we already have the non-decor insets. |
| 3050 | * |
| 3051 | * @param inOutInsets The known non-decor insets. It will be modified to stable insets. |
| 3052 | * @param rotation The current display rotation. |
| 3053 | */ |
| 3054 | void convertNonDecorInsetsToStableInsets(Rect inOutInsets, int rotation) { |
| 3055 | inOutInsets.top = Math.max(inOutInsets.top, mStatusBarHeightForRotation[rotation]); |
| 3056 | } |
| 3057 | |
| 3058 | /** |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3059 | * Calculates the stable insets without running a layout. |
| 3060 | * |
| 3061 | * @param displayRotation the current display rotation |
| 3062 | * @param displayWidth the current display width |
| 3063 | * @param displayHeight the current display height |
| 3064 | * @param displayCutout the current display cutout |
| 3065 | * @param outInsets the insets to return |
| 3066 | */ |
| 3067 | public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
| 3068 | DisplayCutout displayCutout, Rect outInsets) { |
| 3069 | outInsets.setEmpty(); |
| 3070 | |
| 3071 | // Navigation bar and status bar. |
| 3072 | getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, displayCutout, outInsets); |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 3073 | convertNonDecorInsetsToStableInsets(outInsets, displayRotation); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | /** |
| 3077 | * Calculates the insets for the areas that could never be removed in Honeycomb, i.e. system |
| 3078 | * bar or button bar. See {@link #getNonDecorDisplayWidth}. |
| 3079 | * |
| 3080 | * @param displayRotation the current display rotation |
| 3081 | * @param displayWidth the current display width |
| 3082 | * @param displayHeight the current display height |
| 3083 | * @param displayCutout the current display cutout |
| 3084 | * @param outInsets the insets to return |
| 3085 | */ |
| 3086 | public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
| 3087 | DisplayCutout displayCutout, Rect outInsets) { |
| 3088 | outInsets.setEmpty(); |
| 3089 | |
| 3090 | // Only navigation bar |
| 3091 | if (hasNavigationBar()) { |
| 3092 | final int uiMode = mService.mPolicy.getUiMode(); |
| 3093 | int position = navigationBarPosition(displayWidth, displayHeight, displayRotation); |
| 3094 | if (position == NAV_BAR_BOTTOM) { |
| 3095 | outInsets.bottom = getNavigationBarHeight(displayRotation, uiMode); |
| 3096 | } else if (position == NAV_BAR_RIGHT) { |
| 3097 | outInsets.right = getNavigationBarWidth(displayRotation, uiMode); |
| 3098 | } else if (position == NAV_BAR_LEFT) { |
| 3099 | outInsets.left = getNavigationBarWidth(displayRotation, uiMode); |
| 3100 | } |
| 3101 | } |
| 3102 | |
| 3103 | if (displayCutout != null) { |
| 3104 | outInsets.left += displayCutout.getSafeInsetLeft(); |
| 3105 | outInsets.top += displayCutout.getSafeInsetTop(); |
| 3106 | outInsets.right += displayCutout.getSafeInsetRight(); |
| 3107 | outInsets.bottom += displayCutout.getSafeInsetBottom(); |
| 3108 | } |
| 3109 | } |
| 3110 | |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 3111 | /** |
| 3112 | * @see IWindowManager#setForwardedInsets |
| 3113 | */ |
| 3114 | public void setForwardedInsets(@NonNull Insets forwardedInsets) { |
| 3115 | mForwardedInsets = forwardedInsets; |
| 3116 | } |
| 3117 | |
| 3118 | @NonNull |
| 3119 | public Insets getForwardedInsets() { |
| 3120 | return mForwardedInsets; |
| 3121 | } |
| 3122 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3123 | @NavigationBarPosition |
| 3124 | int navigationBarPosition(int displayWidth, int displayHeight, int displayRotation) { |
| 3125 | if (navigationBarCanMove() && displayWidth > displayHeight) { |
| 3126 | if (displayRotation == Surface.ROTATION_270) { |
| 3127 | return NAV_BAR_LEFT; |
| 3128 | } else if (displayRotation == Surface.ROTATION_90) { |
| 3129 | return NAV_BAR_RIGHT; |
| 3130 | } |
| 3131 | } |
| 3132 | return NAV_BAR_BOTTOM; |
| 3133 | } |
| 3134 | |
| 3135 | /** |
| 3136 | * @return The side of the screen where navigation bar is positioned. |
| 3137 | * @see WindowManagerPolicyConstants#NAV_BAR_LEFT |
| 3138 | * @see WindowManagerPolicyConstants#NAV_BAR_RIGHT |
| 3139 | * @see WindowManagerPolicyConstants#NAV_BAR_BOTTOM |
| 3140 | */ |
| 3141 | @NavigationBarPosition |
| 3142 | public int getNavBarPosition() { |
| 3143 | return mNavigationBarPosition; |
| 3144 | } |
| 3145 | |
| 3146 | /** |
| 3147 | * A new window has been focused. |
| 3148 | */ |
| 3149 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
| 3150 | mFocusedWindow = newFocus; |
| 3151 | mLastFocusedWindow = lastFocus; |
Issei Suzuki | 9f840c7 | 2018-12-07 15:09:30 -0800 | [diff] [blame] | 3152 | if (mDisplayContent.isDefaultDisplay) { |
| 3153 | mService.mPolicy.onDefaultDisplayFocusChangedLw(newFocus); |
| 3154 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3155 | if ((updateSystemUiVisibilityLw() & SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
| 3156 | // If the navigation bar has been hidden or shown, we need to do another |
| 3157 | // layout pass to update that window. |
| 3158 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 3159 | } |
| 3160 | return 0; |
| 3161 | } |
| 3162 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3163 | private void requestTransientBars(WindowState swipeTarget) { |
Tiger Huang | 82fd0ad | 2020-03-09 17:55:47 +0800 | [diff] [blame] | 3164 | if (!mService.mPolicy.isUserSetupComplete()) { |
| 3165 | // Swipe-up for navigation bar is disabled during setup |
| 3166 | return; |
| 3167 | } |
| 3168 | if (ViewRootImpl.sNewInsetsMode == NEW_INSETS_MODE_FULL) { |
| 3169 | if (swipeTarget == mNavigationBar |
| 3170 | && !getInsetsPolicy().isHidden(ITYPE_NAVIGATION_BAR)) { |
| 3171 | // Don't show status bar when swiping on already visible navigation bar |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3172 | return; |
| 3173 | } |
Tiger Huang | 82fd0ad | 2020-03-09 17:55:47 +0800 | [diff] [blame] | 3174 | final InsetsSourceProvider provider = swipeTarget.getControllableInsetProvider(); |
| 3175 | final InsetsControlTarget controlTarget = provider != null |
| 3176 | ? provider.getControlTarget() : null; |
Jorim Jaggi | 026ed75 | 2020-01-29 00:30:24 +0100 | [diff] [blame] | 3177 | |
Tiger Huang | 82fd0ad | 2020-03-09 17:55:47 +0800 | [diff] [blame] | 3178 | // No transient mode on lockscreen (in notification shade window). |
| 3179 | if (controlTarget == null || controlTarget == getNotificationShade()) { |
| 3180 | return; |
| 3181 | } |
| 3182 | if (controlTarget.canShowTransient()) { |
| 3183 | mDisplayContent.getInsetsPolicy().showTransient(IntArray.wrap( |
| 3184 | new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR})); |
| 3185 | } else { |
| 3186 | controlTarget.showInsets(Type.systemBars(), false); |
| 3187 | } |
| 3188 | } else { |
| 3189 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 3190 | boolean nb = mNavigationBarController.checkShowTransientBarLw() |
| 3191 | && !isNavBarEmpty(mLastSystemUiFlags); |
| 3192 | if (sb || nb) { |
| 3193 | // Don't show status bar when swiping on already visible navigation bar |
| 3194 | if (!nb && swipeTarget == mNavigationBar) { |
| 3195 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3196 | return; |
| 3197 | } |
Tiger Huang | 82fd0ad | 2020-03-09 17:55:47 +0800 | [diff] [blame] | 3198 | if (sb) mStatusBarController.showTransient(); |
| 3199 | if (nb) mNavigationBarController.showTransient(); |
| 3200 | updateSystemUiVisibilityLw(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3201 | } |
| 3202 | } |
Tiger Huang | 82fd0ad | 2020-03-09 17:55:47 +0800 | [diff] [blame] | 3203 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3204 | } |
| 3205 | |
| 3206 | private void disposeInputConsumer(InputConsumer inputConsumer) { |
| 3207 | if (inputConsumer != null) { |
Arthur Hung | de76725 | 2020-02-03 19:22:16 +0800 | [diff] [blame] | 3208 | inputConsumer.dispose(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3209 | } |
| 3210 | } |
| 3211 | |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3212 | boolean isKeyguardShowing() { |
| 3213 | return mService.mPolicy.isKeyguardShowing(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3214 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3215 | private boolean isKeyguardOccluded() { |
| 3216 | // TODO (b/113840485): Handle per display keyguard. |
| 3217 | return mService.mPolicy.isKeyguardOccluded(); |
| 3218 | } |
| 3219 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3220 | InsetsPolicy getInsetsPolicy() { |
| 3221 | return mDisplayContent.getInsetsPolicy(); |
| 3222 | } |
| 3223 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3224 | void resetSystemUiVisibilityLw() { |
| 3225 | mLastSystemUiFlags = 0; |
| 3226 | updateSystemUiVisibilityLw(); |
| 3227 | } |
| 3228 | |
Tiger Huang | dd6db47 | 2020-02-13 21:38:46 +0800 | [diff] [blame] | 3229 | int updateSystemUiVisibilityLw() { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3230 | // If there is no window focused, there will be nobody to handle the events |
| 3231 | // anyway, so just hang on in whatever state we're in until things settle down. |
| 3232 | WindowState winCandidate = mFocusedWindow != null ? mFocusedWindow |
| 3233 | : mTopFullscreenOpaqueWindowState; |
| 3234 | if (winCandidate == null) { |
| 3235 | return 0; |
| 3236 | } |
| 3237 | |
| 3238 | // The immersive mode confirmation should never affect the system bar visibility, otherwise |
| 3239 | // it will unhide the navigation bar and hide itself. |
| 3240 | if (winCandidate.getAttrs().token == mImmersiveModeConfirmation.getWindowToken()) { |
| 3241 | |
| 3242 | // The immersive mode confirmation took the focus from mLastFocusedWindow which was |
| 3243 | // controlling the system ui visibility. So if mLastFocusedWindow can still receive |
| 3244 | // keys, we let it keep controlling the visibility. |
| 3245 | final boolean lastFocusCanReceiveKeys = |
| 3246 | (mLastFocusedWindow != null && mLastFocusedWindow.canReceiveKeys()); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3247 | winCandidate = isKeyguardShowing() ? mNotificationShade |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3248 | : lastFocusCanReceiveKeys ? mLastFocusedWindow |
| 3249 | : mTopFullscreenOpaqueWindowState; |
| 3250 | if (winCandidate == null) { |
| 3251 | return 0; |
| 3252 | } |
| 3253 | } |
| 3254 | final WindowState win = winCandidate; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3255 | if (win.getAttrs().type == TYPE_NOTIFICATION_SHADE && isKeyguardShowing() |
| 3256 | && isKeyguardOccluded()) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3257 | // We are updating at a point where the keyguard has gotten |
| 3258 | // focus, but we were last in a state where the top window is |
| 3259 | // hiding it. This is probably because the keyguard as been |
| 3260 | // shown while the top window was displayed, so we want to ignore |
| 3261 | // it here because this is just a very transient change and it |
| 3262 | // will quickly lose focus once it correctly gets hidden. |
| 3263 | return 0; |
| 3264 | } |
| 3265 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 3266 | mDisplayContent.getInsetsPolicy().updateBarControlTarget(win); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 3267 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3268 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
| 3269 | & ~mResettingSystemUiFlags |
| 3270 | & ~mForceClearedSystemUiFlags; |
| 3271 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
| 3272 | tmpVisibility |
| 3273 | &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
| 3274 | } |
| 3275 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3276 | final int fullscreenAppearance = updateLightStatusBarAppearanceLw(0 /* vis */, |
| 3277 | mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState); |
| 3278 | final int dockedAppearance = updateLightStatusBarAppearanceLw(0 /* vis */, |
| 3279 | mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState); |
Evan Rosky | 40bf15c | 2020-04-02 20:23:36 -0700 | [diff] [blame] | 3280 | final boolean inSplitScreen = |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 3281 | mService.mRoot.getDefaultTaskDisplayArea().isSplitScreenModeActivated(); |
Evan Rosky | 40bf15c | 2020-04-02 20:23:36 -0700 | [diff] [blame] | 3282 | if (inSplitScreen) { |
| 3283 | mService.getStackBounds(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, |
| 3284 | mDockedStackBounds); |
| 3285 | } else { |
| 3286 | mDockedStackBounds.setEmpty(); |
| 3287 | } |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3288 | mService.getStackBounds(inSplitScreen ? WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 3289 | : WINDOWING_MODE_FULLSCREEN, |
Tiger Huang | d5f0b9a | 2019-10-10 10:34:57 +0200 | [diff] [blame] | 3290 | ACTIVITY_TYPE_UNDEFINED, mNonDockedStackBounds); |
Tiger Huang | e218e42 | 2020-03-06 21:36:12 +0800 | [diff] [blame] | 3291 | final Pair<Integer, WindowState> result = |
Tarandeep Singh | e439dec | 2019-04-22 12:28:43 -0700 | [diff] [blame] | 3292 | updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
| 3293 | final int visibility = result.first; |
Tiger Huang | e218e42 | 2020-03-06 21:36:12 +0800 | [diff] [blame] | 3294 | final WindowState navColorWin = result.second; |
| 3295 | final boolean isNavbarColorManagedByIme = |
| 3296 | navColorWin != null && navColorWin == mDisplayContent.mInputMethodWindow; |
| 3297 | final int opaqueAppearance = InsetsFlags.getAppearance(visibility) |
| 3298 | & (APPEARANCE_OPAQUE_STATUS_BARS | APPEARANCE_OPAQUE_NAVIGATION_BARS); |
| 3299 | final int appearance = ViewRootImpl.sNewInsetsMode == NEW_INSETS_MODE_FULL |
| 3300 | ? updateLightNavigationBarAppearanceLw(win.mAttrs.insetsFlags.appearance, |
| 3301 | mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState, |
| 3302 | mDisplayContent.mInputMethodWindow, navColorWin) | opaqueAppearance |
| 3303 | : InsetsFlags.getAppearance(visibility); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3304 | final int diff = visibility ^ mLastSystemUiFlags; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3305 | final InsetsPolicy insetsPolicy = getInsetsPolicy(); |
| 3306 | final boolean isFullscreen = (visibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
| 3307 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)) != 0 |
| 3308 | || (PolicyControl.getWindowFlags(win, win.mAttrs) & FLAG_FULLSCREEN) != 0 |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 3309 | || (mStatusBar != null && insetsPolicy.isHidden(ITYPE_STATUS_BAR)) |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3310 | || (mNavigationBar != null && insetsPolicy.isHidden( |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 3311 | ITYPE_NAVIGATION_BAR)); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3312 | final int behavior = win.mAttrs.insetsFlags.behavior; |
| 3313 | final boolean isImmersive = (visibility & (View.SYSTEM_UI_FLAG_IMMERSIVE |
| 3314 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)) != 0 |
| 3315 | || behavior == BEHAVIOR_SHOW_BARS_BY_SWIPE |
| 3316 | || behavior == BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE; |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 3317 | if (diff == 0 |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3318 | && mLastAppearance == appearance |
| 3319 | && mLastFullscreenAppearance == fullscreenAppearance |
| 3320 | && mLastDockedAppearance == dockedAppearance |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 3321 | && mLastBehavior == behavior |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3322 | && mLastFocusIsFullscreen == isFullscreen |
| 3323 | && mLastFocusIsImmersive == isImmersive |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3324 | && mLastNonDockedStackBounds.equals(mNonDockedStackBounds) |
| 3325 | && mLastDockedStackBounds.equals(mDockedStackBounds)) { |
| 3326 | return 0; |
| 3327 | } |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 3328 | |
| 3329 | // Obtains which types should show transient and which types should abort transient. |
| 3330 | // If there is no transient state change, this pair will contain two empty arrays. |
| 3331 | final Pair<int[], int[]> transientState = getTransientState(visibility, mLastSystemUiFlags); |
| 3332 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3333 | mLastSystemUiFlags = visibility; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3334 | mLastAppearance = appearance; |
| 3335 | mLastFullscreenAppearance = fullscreenAppearance; |
| 3336 | mLastDockedAppearance = dockedAppearance; |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 3337 | mLastBehavior = behavior; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3338 | mLastFocusIsFullscreen = isFullscreen; |
| 3339 | mLastFocusIsImmersive = isImmersive; |
Riddle Hsu | 4d6a63f | 2019-03-29 19:14:43 +0800 | [diff] [blame] | 3340 | mLastNonDockedStackBounds.set(mNonDockedStackBounds); |
| 3341 | mLastDockedStackBounds.set(mDockedStackBounds); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3342 | final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds); |
| 3343 | final Rect dockedStackBounds = new Rect(mDockedStackBounds); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3344 | final AppearanceRegion[] appearanceRegions = inSplitScreen |
| 3345 | ? new AppearanceRegion[]{ |
| 3346 | new AppearanceRegion(fullscreenAppearance, fullscreenStackBounds), |
| 3347 | new AppearanceRegion(dockedAppearance, dockedStackBounds)} |
| 3348 | : new AppearanceRegion[]{ |
| 3349 | new AppearanceRegion(fullscreenAppearance, fullscreenStackBounds)}; |
Vishnu Nair | 015d8cd | 2019-11-18 15:56:30 -0800 | [diff] [blame] | 3350 | String cause = win.toString(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3351 | mHandler.post(() -> { |
| 3352 | StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); |
| 3353 | if (statusBar != null) { |
| 3354 | final int displayId = getDisplayId(); |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 3355 | statusBar.setDisableFlags(displayId, visibility & StatusBarManager.DISABLE_MASK, |
Vishnu Nair | 015d8cd | 2019-11-18 15:56:30 -0800 | [diff] [blame] | 3356 | cause); |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 3357 | if (transientState.first.length > 0) { |
| 3358 | statusBar.showTransient(displayId, transientState.first); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3359 | } |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 3360 | if (transientState.second.length > 0) { |
| 3361 | statusBar.abortTransient(displayId, transientState.second); |
| 3362 | } |
| 3363 | statusBar.onSystemBarAppearanceChanged(displayId, appearance, |
| 3364 | appearanceRegions, isNavbarColorManagedByIme); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3365 | statusBar.topAppWindowChanged(displayId, isFullscreen, isImmersive); |
| 3366 | |
| 3367 | // TODO(b/118118435): Remove this after removing system UI visibilities. |
Vishnu Nair | 015d8cd | 2019-11-18 15:56:30 -0800 | [diff] [blame] | 3368 | synchronized (mLock) { |
| 3369 | mDisplayContent.statusBarVisibilityChanged( |
| 3370 | visibility & ~(View.STATUS_BAR_UNHIDE | View.NAVIGATION_BAR_UNHIDE)); |
| 3371 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3372 | } |
| 3373 | }); |
| 3374 | return diff; |
| 3375 | } |
| 3376 | |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 3377 | private static Pair<int[], int[]> getTransientState(int vis, int oldVis) { |
| 3378 | final IntArray typesToShow = new IntArray(0); |
| 3379 | final IntArray typesToAbort = new IntArray(0); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 3380 | updateTransientState(vis, oldVis, View.STATUS_BAR_TRANSIENT, ITYPE_STATUS_BAR, typesToShow, |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 3381 | typesToAbort); |
| 3382 | updateTransientState(vis, oldVis, View.NAVIGATION_BAR_TRANSIENT, |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 3383 | ITYPE_NAVIGATION_BAR, typesToShow, typesToAbort); |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 3384 | return Pair.create(typesToShow.toArray(), typesToAbort.toArray()); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3385 | } |
| 3386 | |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 3387 | private static void updateTransientState(int vis, int oldVis, int transientFlag, |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 3388 | @InternalInsetsType int type, IntArray typesToShow, IntArray typesToAbort) { |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 3389 | final boolean wasTransient = (oldVis & transientFlag) != 0; |
| 3390 | final boolean isTransient = (vis & transientFlag) != 0; |
| 3391 | if (!wasTransient && isTransient) { |
| 3392 | typesToShow.add(type); |
| 3393 | } else if (wasTransient && !isTransient) { |
| 3394 | typesToAbort.add(type); |
| 3395 | } |
| 3396 | } |
| 3397 | |
| 3398 | private int updateLightStatusBarAppearanceLw(@Appearance int appearance, WindowState opaque, |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3399 | WindowState opaqueOrDimming) { |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3400 | final boolean onKeyguard = isKeyguardShowing() && !isKeyguardOccluded(); |
| 3401 | final WindowState statusColorWin = onKeyguard ? mNotificationShade : opaqueOrDimming; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3402 | if (statusColorWin != null && (statusColorWin == opaque || onKeyguard)) { |
| 3403 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 3404 | // its light flag. |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 3405 | appearance &= ~APPEARANCE_LIGHT_STATUS_BARS; |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 3406 | final int legacyAppearance = InsetsFlags.getAppearance( |
| 3407 | PolicyControl.getSystemUiVisibility(statusColorWin, null)); |
| 3408 | appearance |= (statusColorWin.mAttrs.insetsFlags.appearance | legacyAppearance) |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 3409 | & APPEARANCE_LIGHT_STATUS_BARS; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3410 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 3411 | // Otherwise if it's dimming, clear the light flag. |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 3412 | appearance &= ~APPEARANCE_LIGHT_STATUS_BARS; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3413 | } |
| 3414 | return appearance; |
| 3415 | } |
| 3416 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3417 | @VisibleForTesting |
| 3418 | @Nullable |
| 3419 | static WindowState chooseNavigationColorWindowLw(WindowState opaque, |
| 3420 | WindowState opaqueOrDimming, WindowState imeWindow, |
| 3421 | @NavigationBarPosition int navBarPosition) { |
| 3422 | // If the IME window is visible and FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS is set, then IME |
| 3423 | // window can be navigation color window. |
| 3424 | final boolean imeWindowCanNavColorWindow = imeWindow != null |
| 3425 | && imeWindow.isVisibleLw() |
| 3426 | && navBarPosition == NAV_BAR_BOTTOM |
| 3427 | && (PolicyControl.getWindowFlags(imeWindow, null) |
| 3428 | & WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0; |
| 3429 | |
| 3430 | if (opaque != null && opaqueOrDimming == opaque) { |
| 3431 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect it |
| 3432 | // unless IME window is also eligible, since currently the IME window is always show |
| 3433 | // above the opaque fullscreen app window, regardless of the IME target window. |
| 3434 | // TODO(b/31559891): Maybe we need to revisit this condition once b/31559891 is fixed. |
| 3435 | return imeWindowCanNavColorWindow ? imeWindow : opaque; |
| 3436 | } |
| 3437 | |
| 3438 | if (opaqueOrDimming == null || !opaqueOrDimming.isDimming()) { |
| 3439 | // No dimming window is involved. Determine the result only with the IME window. |
| 3440 | return imeWindowCanNavColorWindow ? imeWindow : null; |
| 3441 | } |
| 3442 | |
| 3443 | if (!imeWindowCanNavColorWindow) { |
| 3444 | // No IME window is involved. Determine the result only with opaqueOrDimming. |
| 3445 | return opaqueOrDimming; |
| 3446 | } |
| 3447 | |
| 3448 | // The IME window and the dimming window are competing. Check if the dimming window can be |
| 3449 | // IME target or not. |
| 3450 | if (LayoutParams.mayUseInputMethod(PolicyControl.getWindowFlags(opaqueOrDimming, null))) { |
| 3451 | // The IME window is above the dimming window. |
| 3452 | return imeWindow; |
| 3453 | } else { |
| 3454 | // The dimming window is above the IME window. |
| 3455 | return opaqueOrDimming; |
| 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | @VisibleForTesting |
| 3460 | static int updateLightNavigationBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming, |
| 3461 | WindowState imeWindow, WindowState navColorWin) { |
| 3462 | |
| 3463 | if (navColorWin != null) { |
| 3464 | if (navColorWin == imeWindow || navColorWin == opaque) { |
| 3465 | // Respect the light flag. |
| 3466 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 3467 | vis |= PolicyControl.getSystemUiVisibility(navColorWin, null) |
| 3468 | & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 3469 | } else if (navColorWin == opaqueOrDimming && navColorWin.isDimming()) { |
| 3470 | // Clear the light flag for dimming window. |
| 3471 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 3472 | } |
| 3473 | } |
| 3474 | return vis; |
| 3475 | } |
| 3476 | |
Tiger Huang | e218e42 | 2020-03-06 21:36:12 +0800 | [diff] [blame] | 3477 | @VisibleForTesting |
| 3478 | static int updateLightNavigationBarAppearanceLw(int appearance, WindowState opaque, |
| 3479 | WindowState opaqueOrDimming, WindowState imeWindow, WindowState navColorWin) { |
| 3480 | |
| 3481 | if (navColorWin != null) { |
| 3482 | if (navColorWin == imeWindow || navColorWin == opaque) { |
| 3483 | // Respect the light flag. |
| 3484 | appearance &= ~APPEARANCE_LIGHT_NAVIGATION_BARS; |
| 3485 | appearance |= navColorWin.mAttrs.insetsFlags.appearance |
| 3486 | & APPEARANCE_LIGHT_NAVIGATION_BARS; |
| 3487 | } else if (navColorWin == opaqueOrDimming && navColorWin.isDimming()) { |
| 3488 | // Clear the light flag for dimming window. |
| 3489 | appearance &= ~APPEARANCE_LIGHT_NAVIGATION_BARS; |
| 3490 | } |
| 3491 | } |
| 3492 | return appearance; |
| 3493 | } |
| 3494 | |
| 3495 | private Pair<Integer, WindowState> updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 3496 | final boolean dockedStackVisible = mDisplayContent.getDefaultTaskDisplayArea() |
| 3497 | .isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
| 3498 | final boolean freeformStackVisible = mDisplayContent.getDefaultTaskDisplayArea() |
| 3499 | .isStackVisible(WINDOWING_MODE_FREEFORM); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3500 | final boolean resizing = mDisplayContent.getDockedDividerController().isResizing(); |
| 3501 | |
| 3502 | // We need to force system bars when the docked stack is visible, when the freeform stack |
hyok.kim | 332ccfc | 2019-07-02 15:39:43 +0900 | [diff] [blame] | 3503 | // is focused but also when we are resizing for the transitions when docked stack |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3504 | // visibility changes. |
hyok.kim | 332ccfc | 2019-07-02 15:39:43 +0900 | [diff] [blame] | 3505 | mForceShowSystemBars = dockedStackVisible || win.inFreeformWindowingMode() || resizing |
Brad Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 3506 | || mForceShowSystemBarsFromExternal; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3507 | final boolean forceOpaqueStatusBar = mForceShowSystemBars && !isKeyguardShowing(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3508 | |
| 3509 | // apply translucent bar vis flags |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3510 | WindowState fullscreenTransWin = isKeyguardShowing() && !isKeyguardOccluded() |
| 3511 | ? mNotificationShade |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3512 | : mTopFullscreenOpaqueWindowState; |
| 3513 | vis = mStatusBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); |
| 3514 | vis = mNavigationBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); |
Adrian Roos | faba406 | 2019-05-14 15:27:17 +0200 | [diff] [blame] | 3515 | int dockedVis = mStatusBarController.applyTranslucentFlagLw( |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3516 | mTopDockedOpaqueWindowState, 0, 0); |
Adrian Roos | faba406 | 2019-05-14 15:27:17 +0200 | [diff] [blame] | 3517 | dockedVis = mNavigationBarController.applyTranslucentFlagLw( |
| 3518 | mTopDockedOpaqueWindowState, dockedVis, 0); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3519 | |
| 3520 | final boolean fullscreenDrawsStatusBarBackground = |
| 3521 | drawsStatusBarBackground(vis, mTopFullscreenOpaqueWindowState); |
| 3522 | final boolean dockedDrawsStatusBarBackground = |
| 3523 | drawsStatusBarBackground(dockedVis, mTopDockedOpaqueWindowState); |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 3524 | final boolean fullscreenDrawsNavBarBackground = |
| 3525 | drawsNavigationBarBackground(vis, mTopFullscreenOpaqueWindowState); |
Adrian Roos | faba406 | 2019-05-14 15:27:17 +0200 | [diff] [blame] | 3526 | final boolean dockedDrawsNavigationBarBackground = |
| 3527 | drawsNavigationBarBackground(dockedVis, mTopDockedOpaqueWindowState); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3528 | |
| 3529 | // prevent status bar interaction from clearing certain flags |
| 3530 | int type = win.getAttrs().type; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3531 | boolean notificationShadeHasFocus = type == TYPE_NOTIFICATION_SHADE; |
| 3532 | if (notificationShadeHasFocus && !isKeyguardShowing()) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3533 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 3534 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 3535 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
| 3536 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 3537 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 3538 | if (isKeyguardOccluded()) { |
| 3539 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 3540 | } |
| 3541 | vis = (vis & ~flags) | (oldVis & flags); |
| 3542 | } |
| 3543 | |
| 3544 | if (fullscreenDrawsStatusBarBackground && dockedDrawsStatusBarBackground) { |
| 3545 | vis |= View.STATUS_BAR_TRANSPARENT; |
| 3546 | vis &= ~View.STATUS_BAR_TRANSLUCENT; |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 3547 | } else if (forceOpaqueStatusBar) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3548 | vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT); |
| 3549 | } |
| 3550 | |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 3551 | vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing, |
Adrian Roos | faba406 | 2019-05-14 15:27:17 +0200 | [diff] [blame] | 3552 | fullscreenDrawsNavBarBackground, dockedDrawsNavigationBarBackground); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3553 | |
| 3554 | // update status bar |
| 3555 | boolean immersiveSticky = |
| 3556 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 3557 | final boolean hideStatusBarWM = |
| 3558 | mTopFullscreenOpaqueWindowState != null |
| 3559 | && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
| 3560 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 3561 | final boolean hideStatusBarSysui = |
| 3562 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
| 3563 | final boolean hideNavBarSysui = |
| 3564 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
| 3565 | |
| 3566 | final boolean transientStatusBarAllowed = mStatusBar != null |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3567 | && (notificationShadeHasFocus || (!mForceShowSystemBars |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3568 | && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky)))); |
| 3569 | |
| 3570 | final boolean transientNavBarAllowed = mNavigationBar != null |
| 3571 | && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky; |
| 3572 | |
| 3573 | final long now = SystemClock.uptimeMillis(); |
| 3574 | final boolean pendingPanic = mPendingPanicGestureUptime != 0 |
| 3575 | && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION; |
| 3576 | final DisplayPolicy defaultDisplayPolicy = |
| 3577 | mService.getDefaultDisplayContentLocked().getDisplayPolicy(); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3578 | if (pendingPanic && hideNavBarSysui && !isKeyguardShowing() |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3579 | // TODO (b/111955725): Show keyguard presentation on all external displays |
| 3580 | && defaultDisplayPolicy.isKeyguardDrawComplete()) { |
| 3581 | // The user performed the panic gesture recently, we're about to hide the bars, |
| 3582 | // we're no longer on the Keyguard and the screen is ready. We can now request the bars. |
| 3583 | mPendingPanicGestureUptime = 0; |
| 3584 | mStatusBarController.showTransient(); |
| 3585 | if (!isNavBarEmpty(vis)) { |
| 3586 | mNavigationBarController.showTransient(); |
| 3587 | } |
| 3588 | } |
| 3589 | |
| 3590 | final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
| 3591 | && !transientStatusBarAllowed && hideStatusBarSysui; |
| 3592 | final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
| 3593 | && !transientNavBarAllowed; |
| 3594 | if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) { |
| 3595 | // clear the clearable flags instead |
| 3596 | clearClearableFlagsLw(); |
| 3597 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 3598 | } |
| 3599 | |
| 3600 | final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 3601 | immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 3602 | final boolean navAllowedHidden = immersive || immersiveSticky; |
| 3603 | |
| 3604 | if (hideNavBarSysui && !navAllowedHidden |
| 3605 | && mService.mPolicy.getWindowLayerLw(win) |
| 3606 | > mService.mPolicy.getWindowLayerFromTypeLw(TYPE_INPUT_CONSUMER)) { |
| 3607 | // We can't hide the navbar from this window otherwise the input consumer would not get |
| 3608 | // the input events. |
| 3609 | vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); |
| 3610 | } |
| 3611 | |
| 3612 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 3613 | |
| 3614 | // update navigation bar |
Tiger Huang | dd6db47 | 2020-02-13 21:38:46 +0800 | [diff] [blame] | 3615 | boolean newInsetsMode = ViewRootImpl.sNewInsetsMode == NEW_INSETS_MODE_FULL; |
| 3616 | boolean oldImmersiveMode = newInsetsMode ? mLastImmersiveMode : isImmersiveMode(oldVis); |
| 3617 | boolean newImmersiveMode = newInsetsMode ? isImmersiveMode(win) : isImmersiveMode(vis); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3618 | if (oldImmersiveMode != newImmersiveMode) { |
Tiger Huang | dd6db47 | 2020-02-13 21:38:46 +0800 | [diff] [blame] | 3619 | mLastImmersiveMode = newImmersiveMode; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3620 | final String pkg = win.getOwningPackage(); |
| 3621 | mImmersiveModeConfirmation.immersiveModeChangedLw(pkg, newImmersiveMode, |
| 3622 | mService.mPolicy.isUserSetupComplete(), |
| 3623 | isNavBarEmpty(win.getSystemUiVisibility())); |
| 3624 | } |
| 3625 | |
| 3626 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 3627 | |
| 3628 | final WindowState navColorWin = chooseNavigationColorWindowLw( |
| 3629 | mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState, |
| 3630 | mDisplayContent.mInputMethodWindow, mNavigationBarPosition); |
| 3631 | vis = updateLightNavigationBarLw(vis, mTopFullscreenOpaqueWindowState, |
| 3632 | mTopFullscreenOpaqueOrDimmingWindowState, |
| 3633 | mDisplayContent.mInputMethodWindow, navColorWin); |
| 3634 | |
Tiger Huang | e218e42 | 2020-03-06 21:36:12 +0800 | [diff] [blame] | 3635 | return Pair.create(vis, navColorWin); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3636 | } |
| 3637 | |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 3638 | private boolean drawsBarBackground(int vis, WindowState win, BarController controller, |
| 3639 | int translucentFlag) { |
| 3640 | if (!controller.isTransparentAllowed(win)) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3641 | return false; |
| 3642 | } |
| 3643 | if (win == null) { |
| 3644 | return true; |
| 3645 | } |
| 3646 | |
| 3647 | final boolean drawsSystemBars = |
| 3648 | (win.getAttrs().flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0; |
| 3649 | final boolean forceDrawsSystemBars = |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 3650 | (win.getAttrs().privateFlags & PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS) != 0; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3651 | |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 3652 | return forceDrawsSystemBars || drawsSystemBars && (vis & translucentFlag) == 0; |
| 3653 | } |
| 3654 | |
| 3655 | private boolean drawsStatusBarBackground(int vis, WindowState win) { |
| 3656 | return drawsBarBackground(vis, win, mStatusBarController, FLAG_TRANSLUCENT_STATUS); |
| 3657 | } |
| 3658 | |
| 3659 | private boolean drawsNavigationBarBackground(int vis, WindowState win) { |
| 3660 | return drawsBarBackground(vis, win, mNavigationBarController, FLAG_TRANSLUCENT_NAVIGATION); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | /** |
| 3664 | * @return the current visibility flags with the nav-bar opacity related flags toggled based |
| 3665 | * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}. |
| 3666 | */ |
| 3667 | private int configureNavBarOpacity(int visibility, boolean dockedStackVisible, |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 3668 | boolean freeformStackVisible, boolean isDockedDividerResizing, |
Adrian Roos | faba406 | 2019-05-14 15:27:17 +0200 | [diff] [blame] | 3669 | boolean fullscreenDrawsBackground, boolean dockedDrawsNavigationBarBackground) { |
| 3670 | if (mNavBarOpacityMode == NAV_BAR_FORCE_TRANSPARENT) { |
| 3671 | if (fullscreenDrawsBackground && dockedDrawsNavigationBarBackground) { |
| 3672 | visibility = setNavBarTransparentFlag(visibility); |
| 3673 | } else if (dockedStackVisible) { |
| 3674 | visibility = setNavBarOpaqueFlag(visibility); |
| 3675 | } |
| 3676 | } else if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3677 | if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) { |
HEO SEUNG | 22d3ec2 | 2019-05-30 20:28:53 +0900 | [diff] [blame] | 3678 | if (mIsFreeformWindowOverlappingWithNavBar) { |
| 3679 | visibility = setNavBarTranslucentFlag(visibility); |
| 3680 | } else { |
| 3681 | visibility = setNavBarOpaqueFlag(visibility); |
| 3682 | } |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 3683 | } else if (fullscreenDrawsBackground) { |
| 3684 | visibility = setNavBarTransparentFlag(visibility); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3685 | } |
| 3686 | } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) { |
| 3687 | if (isDockedDividerResizing) { |
| 3688 | visibility = setNavBarOpaqueFlag(visibility); |
| 3689 | } else if (freeformStackVisible) { |
| 3690 | visibility = setNavBarTranslucentFlag(visibility); |
| 3691 | } else { |
| 3692 | visibility = setNavBarOpaqueFlag(visibility); |
| 3693 | } |
| 3694 | } |
| 3695 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3696 | return visibility; |
| 3697 | } |
| 3698 | |
| 3699 | private int setNavBarOpaqueFlag(int visibility) { |
| 3700 | return visibility & ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT); |
| 3701 | } |
| 3702 | |
| 3703 | private int setNavBarTranslucentFlag(int visibility) { |
| 3704 | visibility &= ~View.NAVIGATION_BAR_TRANSPARENT; |
| 3705 | return visibility | View.NAVIGATION_BAR_TRANSLUCENT; |
| 3706 | } |
| 3707 | |
Jorim Jaggi | a6aabac | 2019-03-11 14:23:16 -0700 | [diff] [blame] | 3708 | private int setNavBarTransparentFlag(int visibility) { |
| 3709 | visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT; |
| 3710 | return visibility | View.NAVIGATION_BAR_TRANSPARENT; |
| 3711 | } |
| 3712 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3713 | private void clearClearableFlagsLw() { |
| 3714 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 3715 | if (newVal != mResettingSystemUiFlags) { |
| 3716 | mResettingSystemUiFlags = newVal; |
| 3717 | mDisplayContent.reevaluateStatusBarVisibility(); |
| 3718 | } |
| 3719 | } |
| 3720 | |
Tiger Huang | dd6db47 | 2020-02-13 21:38:46 +0800 | [diff] [blame] | 3721 | // TODO(b/118118435): Remove this after migration |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3722 | private boolean isImmersiveMode(int vis) { |
| 3723 | final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
| 3724 | return mNavigationBar != null |
| 3725 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
| 3726 | && (vis & flags) != 0 |
| 3727 | && canHideNavigationBar(); |
| 3728 | } |
| 3729 | |
Tiger Huang | dd6db47 | 2020-02-13 21:38:46 +0800 | [diff] [blame] | 3730 | private boolean isImmersiveMode(WindowState win) { |
| 3731 | final int behavior = win.mAttrs.insetsFlags.behavior; |
| 3732 | return mNavigationBar != null |
| 3733 | && canHideNavigationBar() |
| 3734 | && (behavior == BEHAVIOR_SHOW_BARS_BY_SWIPE |
| 3735 | || behavior == BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE) |
| 3736 | && getInsetsPolicy().isHidden(ITYPE_NAVIGATION_BAR) |
| 3737 | && win != getNotificationShade(); |
| 3738 | } |
| 3739 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3740 | /** |
| 3741 | * @return whether the navigation bar can be hidden, e.g. the device has a navigation bar |
| 3742 | */ |
| 3743 | private boolean canHideNavigationBar() { |
| 3744 | return hasNavigationBar(); |
| 3745 | } |
| 3746 | |
| 3747 | private static boolean isNavBarEmpty(int systemUiFlags) { |
| 3748 | final int disableNavigationBar = (View.STATUS_BAR_DISABLE_HOME |
| 3749 | | View.STATUS_BAR_DISABLE_BACK |
| 3750 | | View.STATUS_BAR_DISABLE_RECENT); |
| 3751 | |
| 3752 | return (systemUiFlags & disableNavigationBar) == disableNavigationBar; |
| 3753 | } |
| 3754 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3755 | private final Runnable mHiddenNavPanic = new Runnable() { |
| 3756 | @Override |
| 3757 | public void run() { |
| 3758 | synchronized (mLock) { |
| 3759 | if (!mService.mPolicy.isUserSetupComplete()) { |
| 3760 | // Swipe-up for navigation bar is disabled during setup |
| 3761 | return; |
| 3762 | } |
| 3763 | mPendingPanicGestureUptime = SystemClock.uptimeMillis(); |
| 3764 | if (!isNavBarEmpty(mLastSystemUiFlags)) { |
| 3765 | mNavigationBarController.showTransient(); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3766 | mDisplayContent.getInsetsPolicy().showTransient(IntArray.wrap( |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 3767 | new int[] {ITYPE_NAVIGATION_BAR})); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3768 | } |
| 3769 | } |
| 3770 | } |
| 3771 | }; |
| 3772 | |
| 3773 | void onPowerKeyDown(boolean isScreenOn) { |
| 3774 | // Detect user pressing the power button in panic when an application has |
| 3775 | // taken over the whole screen. |
| 3776 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(isScreenOn, |
| 3777 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags), |
| 3778 | isNavBarEmpty(mLastSystemUiFlags)); |
| 3779 | if (panic) { |
| 3780 | mHandler.post(mHiddenNavPanic); |
| 3781 | } |
| 3782 | } |
| 3783 | |
| 3784 | void onVrStateChangedLw(boolean enabled) { |
| 3785 | mImmersiveModeConfirmation.onVrStateChangedLw(enabled); |
| 3786 | } |
| 3787 | |
| 3788 | /** |
| 3789 | * Called when the state of lock task mode changes. This should be used to disable immersive |
| 3790 | * mode confirmation. |
| 3791 | * |
| 3792 | * @param lockTaskState the new lock task mode state. One of |
| 3793 | * {@link ActivityManager#LOCK_TASK_MODE_NONE}, |
| 3794 | * {@link ActivityManager#LOCK_TASK_MODE_LOCKED}, |
| 3795 | * {@link ActivityManager#LOCK_TASK_MODE_PINNED}. |
| 3796 | */ |
| 3797 | public void onLockTaskStateChangedLw(int lockTaskState) { |
| 3798 | mImmersiveModeConfirmation.onLockTaskModeChangedLw(lockTaskState); |
| 3799 | } |
| 3800 | |
| 3801 | /** |
| 3802 | * Request a screenshot be taken. |
| 3803 | * |
| 3804 | * @param screenshotType The type of screenshot, for example either |
| 3805 | * {@link WindowManager#TAKE_SCREENSHOT_FULLSCREEN} or |
| 3806 | * {@link WindowManager#TAKE_SCREENSHOT_SELECTED_REGION} |
Miranda Kephart | 7b2c313 | 2020-03-27 09:54:14 -0400 | [diff] [blame] | 3807 | * @param source Where the screenshot originated from (see WindowManager.ScreenshotSource) |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3808 | */ |
Miranda Kephart | 7b2c313 | 2020-03-27 09:54:14 -0400 | [diff] [blame] | 3809 | public void takeScreenshot(int screenshotType, int source) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3810 | if (mScreenshotHelper != null) { |
| 3811 | mScreenshotHelper.takeScreenshot(screenshotType, |
| 3812 | mStatusBar != null && mStatusBar.isVisibleLw(), |
James O'Leary | fa5bb7a | 2019-09-05 13:43:29 -0400 | [diff] [blame] | 3813 | mNavigationBar != null && mNavigationBar.isVisibleLw(), |
Miranda Kephart | 7b2c313 | 2020-03-27 09:54:14 -0400 | [diff] [blame] | 3814 | source, mHandler, null /* completionConsumer */); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3815 | } |
| 3816 | } |
| 3817 | |
Ady Abraham | f3e0531 | 2019-05-13 18:04:59 -0700 | [diff] [blame] | 3818 | RefreshRatePolicy getRefreshRatePolicy() { |
| 3819 | return mRefreshRatePolicy; |
| 3820 | } |
| 3821 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 3822 | void dump(String prefix, PrintWriter pw) { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3823 | pw.print(prefix); pw.println("DisplayPolicy"); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3824 | prefix += " "; |
| 3825 | pw.print(prefix); |
| 3826 | pw.print("mCarDockEnablesAccelerometer="); pw.print(mCarDockEnablesAccelerometer); |
| 3827 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 3828 | pw.println(mDeskDockEnablesAccelerometer); |
| 3829 | pw.print(prefix); pw.print("mDockMode="); pw.print(Intent.dockStateToString(mDockMode)); |
| 3830 | pw.print(" mLidState="); pw.println(WindowManagerFuncs.lidStateToString(mLidState)); |
| 3831 | pw.print(prefix); pw.print("mAwake="); pw.print(mAwake); |
| 3832 | pw.print(" mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 3833 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 3834 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 3835 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 3836 | pw.print(prefix); pw.print("mHdmiPlugged="); pw.println(mHdmiPlugged); |
| 3837 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 3838 | || mForceClearedSystemUiFlags != 0) { |
| 3839 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 3840 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 3841 | pw.print(" mResettingSystemUiFlags=0x"); |
| 3842 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 3843 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 3844 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
| 3845 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3846 | pw.print(prefix); pw.print("mShowingDream="); pw.print(mShowingDream); |
| 3847 | pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3848 | if (mStatusBar != null) { |
| 3849 | pw.print(prefix); pw.print("mStatusBar="); pw.print(mStatusBar); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3850 | } |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3851 | if (mNotificationShade != null) { |
| 3852 | pw.print(prefix); pw.print("mExpandedPanel="); pw.print(mNotificationShade); |
| 3853 | } |
| 3854 | pw.print(" isKeyguardShowing="); pw.println(isKeyguardShowing()); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3855 | if (mNavigationBar != null) { |
| 3856 | pw.print(prefix); pw.print("mNavigationBar="); pw.println(mNavigationBar); |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 3857 | pw.print(prefix); pw.print("mNavBarOpacityMode="); pw.println(mNavBarOpacityMode); |
| 3858 | pw.print(prefix); pw.print("mNavigationBarCanMove="); pw.println(mNavigationBarCanMove); |
| 3859 | pw.print(prefix); pw.print("mNavigationBarPosition="); |
| 3860 | pw.println(mNavigationBarPosition); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3861 | } |
| 3862 | if (mFocusedWindow != null) { |
| 3863 | pw.print(prefix); pw.print("mFocusedWindow="); pw.println(mFocusedWindow); |
| 3864 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3865 | if (mTopFullscreenOpaqueWindowState != null) { |
| 3866 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 3867 | pw.println(mTopFullscreenOpaqueWindowState); |
| 3868 | } |
| 3869 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 3870 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 3871 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 3872 | } |
| 3873 | if (mForcingShowNavBar) { |
| 3874 | pw.print(prefix); pw.print("mForcingShowNavBar="); pw.println(mForcingShowNavBar); |
| 3875 | pw.print(prefix); pw.print("mForcingShowNavBarLayer="); |
| 3876 | pw.println(mForcingShowNavBarLayer); |
| 3877 | } |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3878 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.println(mTopIsFullscreen); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3879 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3880 | pw.print(prefix); pw.print("mForceShowSystemBarsFromExternal="); |
| 3881 | pw.print(mForceShowSystemBarsFromExternal); |
| 3882 | pw.print(" mAllowLockscreenWhenOn="); pw.println(mAllowLockscreenWhenOn); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3883 | mStatusBarController.dump(pw, prefix); |
| 3884 | mNavigationBarController.dump(pw, prefix); |
| 3885 | |
| 3886 | pw.print(prefix); pw.println("Looper state:"); |
| 3887 | mHandler.getLooper().dump(new PrintWriterPrinter(pw), prefix + " "); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 3888 | } |
Arthur Hung | 2047992 | 2019-02-27 17:13:22 +0800 | [diff] [blame] | 3889 | |
| 3890 | private boolean supportsPointerLocation() { |
| 3891 | return mDisplayContent.isDefaultDisplay || !mDisplayContent.isPrivate(); |
| 3892 | } |
| 3893 | |
| 3894 | void setPointerLocationEnabled(boolean pointerLocationEnabled) { |
| 3895 | if (!supportsPointerLocation()) { |
| 3896 | return; |
| 3897 | } |
| 3898 | |
| 3899 | mHandler.sendEmptyMessage(pointerLocationEnabled |
| 3900 | ? MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
| 3901 | } |
| 3902 | |
| 3903 | private void enablePointerLocation() { |
| 3904 | if (mPointerLocationView != null) { |
| 3905 | return; |
| 3906 | } |
| 3907 | |
| 3908 | mPointerLocationView = new PointerLocationView(mContext); |
| 3909 | mPointerLocationView.setPrintCoords(false); |
| 3910 | final WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 3911 | WindowManager.LayoutParams.MATCH_PARENT, |
| 3912 | WindowManager.LayoutParams.MATCH_PARENT); |
| 3913 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Arthur Hung | af7f6a9 | 2020-03-16 19:17:47 +0800 | [diff] [blame] | 3914 | lp.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
Arthur Hung | 2047992 | 2019-02-27 17:13:22 +0800 | [diff] [blame] | 3915 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 3916 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Arthur Hung | af7f6a9 | 2020-03-16 19:17:47 +0800 | [diff] [blame] | 3917 | lp.setFitInsetsTypes(0); |
Arthur Hung | 2047992 | 2019-02-27 17:13:22 +0800 | [diff] [blame] | 3918 | lp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
| 3919 | if (ActivityManager.isHighEndGfx()) { |
| 3920 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 3921 | lp.privateFlags |= |
| 3922 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 3923 | } |
| 3924 | lp.format = PixelFormat.TRANSLUCENT; |
| 3925 | lp.setTitle("PointerLocation - display " + getDisplayId()); |
| 3926 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
| 3927 | final WindowManager wm = mContext.getSystemService(WindowManager.class); |
| 3928 | wm.addView(mPointerLocationView, lp); |
| 3929 | mDisplayContent.registerPointerEventListener(mPointerLocationView); |
| 3930 | } |
| 3931 | |
| 3932 | private void disablePointerLocation() { |
| 3933 | if (mPointerLocationView == null) { |
| 3934 | return; |
| 3935 | } |
| 3936 | |
| 3937 | mDisplayContent.unregisterPointerEventListener(mPointerLocationView); |
| 3938 | final WindowManager wm = mContext.getSystemService(WindowManager.class); |
| 3939 | wm.removeView(mPointerLocationView); |
| 3940 | mPointerLocationView = null; |
| 3941 | } |
HEO SEUNG | 22d3ec2 | 2019-05-30 20:28:53 +0900 | [diff] [blame] | 3942 | |
Arthur Hung | fbc8f41 | 2019-08-01 19:57:54 +0800 | [diff] [blame] | 3943 | /** |
| 3944 | * Check if the window could be excluded from checking if the display has content. |
| 3945 | * |
| 3946 | * @param w WindowState to check if should be excluded. |
| 3947 | * @return True if the window type is PointerLocation which is excluded. |
| 3948 | */ |
| 3949 | boolean isWindowExcludedFromContent(WindowState w) { |
| 3950 | if (w != null && mPointerLocationView != null) { |
| 3951 | return w.mClient == mPointerLocationView.getWindowToken(); |
| 3952 | } |
| 3953 | |
| 3954 | return false; |
| 3955 | } |
| 3956 | |
Mehdi Alizadeh | f2b28e9 | 2019-12-05 20:13:49 -0800 | [diff] [blame] | 3957 | void release() { |
| 3958 | mHandler.post(mGestureNavigationSettingsObserver::unregister); |
| 3959 | } |
| 3960 | |
HEO SEUNG | 22d3ec2 | 2019-05-30 20:28:53 +0900 | [diff] [blame] | 3961 | @VisibleForTesting |
| 3962 | static boolean isOverlappingWithNavBar(WindowState targetWindow, WindowState navBarWindow) { |
| 3963 | if (navBarWindow == null || !navBarWindow.isVisibleLw() |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3964 | || targetWindow.mActivityRecord == null || !targetWindow.isVisibleLw()) { |
HEO SEUNG | 22d3ec2 | 2019-05-30 20:28:53 +0900 | [diff] [blame] | 3965 | return false; |
| 3966 | } |
| 3967 | |
| 3968 | return Rect.intersects(targetWindow.getFrameLw(), navBarWindow.getFrameLw()); |
| 3969 | } |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 3970 | } |