The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
Jeff Brown | 37df39a9 | 2015-02-25 15:42:31 -0800 | [diff] [blame] | 2 | * Copyright (C) 2006 The Android Open Source Project |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 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 | |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 17 | package com.android.server.policy; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 18 | |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 19 | import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 20 | import static android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 21 | import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
| 22 | import static android.app.AppOpsManager.OP_TOAST_WINDOW; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 23 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
| 24 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 25 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 26 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 27 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 28 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 29 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Robert Carr | 7ad24ba | 2017-06-20 17:26:06 -0700 | [diff] [blame] | 30 | import static android.content.Context.CONTEXT_RESTRICTED; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 31 | import static android.content.Context.DISPLAY_SERVICE; |
| 32 | import static android.content.Context.WINDOW_SERVICE; |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 33 | import static android.content.pm.PackageManager.FEATURE_LEANBACK; |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 34 | import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 35 | import static android.content.pm.PackageManager.FEATURE_WATCH; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 36 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 37 | import static android.content.res.Configuration.EMPTY; |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 38 | import static android.content.res.Configuration.UI_MODE_TYPE_CAR; |
| 39 | import static android.content.res.Configuration.UI_MODE_TYPE_MASK; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 40 | import static android.os.Build.VERSION_CODES.M; |
| 41 | import static android.os.Build.VERSION_CODES.O; |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 42 | import static android.provider.Settings.Secure.VOLUME_HUSH_OFF; |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 43 | import static android.view.Display.DEFAULT_DISPLAY; |
| 44 | import static android.view.Display.STATE_OFF; |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 45 | import static android.view.WindowManager.DOCKED_LEFT; |
| 46 | import static android.view.WindowManager.DOCKED_RIGHT; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 47 | import static android.view.WindowManager.DOCKED_TOP; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 48 | import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 49 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 50 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 51 | import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW; |
| 52 | import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| 53 | import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
| 54 | import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN; |
| 55 | import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN; |
| 56 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR; |
| 57 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR; |
| 58 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN; |
| 59 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
| 60 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
| 61 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 62 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 63 | import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; |
| 64 | import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 65 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 66 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
| 67 | import static android.view.WindowManager.LayoutParams.LAST_SYSTEM_WINDOW; |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 68 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
| 69 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 70 | import static android.view.WindowManager.LayoutParams.MATCH_PARENT; |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 71 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 72 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND; |
| 73 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 74 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR; |
Adrian Roos | 4bef62e | 2018-03-21 19:52:09 +0100 | [diff] [blame] | 75 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY; |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 76 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_SCREEN_DECOR; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 77 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 78 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
| 79 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR; |
| 80 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE; |
| 81 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT; |
| 82 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE; |
| 83 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS; |
| 84 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; |
| 85 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 86 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 87 | import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 88 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 89 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Adrian Roos | c8045bf | 2018-03-29 19:41:30 +0200 | [diff] [blame] | 90 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 91 | import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; |
| 92 | import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY; |
| 93 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 94 | import static android.view.WindowManager.LayoutParams.TYPE_DREAM; |
| 95 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER; |
| 96 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 97 | import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; |
| 98 | import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY; |
| 99 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
| 100 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; |
| 101 | import static android.view.WindowManager.LayoutParams.TYPE_PHONE; |
| 102 | import static android.view.WindowManager.LayoutParams.TYPE_POINTER; |
Wale Ogunwale | 5b6714c | 2016-11-01 20:54:46 -0700 | [diff] [blame] | 103 | import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 104 | import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE; |
| 105 | import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION; |
| 106 | import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG; |
| 107 | import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT; |
| 108 | import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR; |
| 109 | import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
| 110 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
| 111 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; |
| 112 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; |
| 113 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; |
| 114 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
| 115 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
| 116 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; |
| 117 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
| 118 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; |
| 119 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING; |
| 120 | import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; |
| 121 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 122 | import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 123 | import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN; |
| 124 | import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 125 | import static android.view.WindowManagerGlobal.ADD_OKAY; |
| 126 | import static android.view.WindowManagerGlobal.ADD_PERMISSION_DENIED; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 127 | |
| 128 | import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; |
| 129 | import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; |
| 130 | import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; |
| 131 | import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 132 | import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
| 133 | import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 134 | import static com.android.server.wm.WindowManagerPolicyProto.FOCUSED_APP_TOKEN; |
| 135 | import static com.android.server.wm.WindowManagerPolicyProto.FOCUSED_WINDOW; |
| 136 | import static com.android.server.wm.WindowManagerPolicyProto.FORCE_STATUS_BAR; |
| 137 | import static com.android.server.wm.WindowManagerPolicyProto.FORCE_STATUS_BAR_FROM_KEYGUARD; |
| 138 | import static com.android.server.wm.WindowManagerPolicyProto.KEYGUARD_DELEGATE; |
| 139 | import static com.android.server.wm.WindowManagerPolicyProto.KEYGUARD_DRAW_COMPLETE; |
| 140 | import static com.android.server.wm.WindowManagerPolicyProto.KEYGUARD_OCCLUDED; |
| 141 | import static com.android.server.wm.WindowManagerPolicyProto.KEYGUARD_OCCLUDED_CHANGED; |
| 142 | import static com.android.server.wm.WindowManagerPolicyProto.KEYGUARD_OCCLUDED_PENDING; |
| 143 | import static com.android.server.wm.WindowManagerPolicyProto.LAST_SYSTEM_UI_FLAGS; |
| 144 | import static com.android.server.wm.WindowManagerPolicyProto.NAVIGATION_BAR; |
| 145 | import static com.android.server.wm.WindowManagerPolicyProto.ORIENTATION; |
| 146 | import static com.android.server.wm.WindowManagerPolicyProto.ORIENTATION_LISTENER; |
| 147 | import static com.android.server.wm.WindowManagerPolicyProto.ROTATION; |
| 148 | import static com.android.server.wm.WindowManagerPolicyProto.ROTATION_MODE; |
| 149 | import static com.android.server.wm.WindowManagerPolicyProto.SCREEN_ON_FULLY; |
| 150 | import static com.android.server.wm.WindowManagerPolicyProto.STATUS_BAR; |
| 151 | import static com.android.server.wm.WindowManagerPolicyProto.TOP_FULLSCREEN_OPAQUE_OR_DIMMING_WINDOW; |
| 152 | import static com.android.server.wm.WindowManagerPolicyProto.TOP_FULLSCREEN_OPAQUE_WINDOW; |
| 153 | import static com.android.server.wm.WindowManagerPolicyProto.WINDOW_MANAGER_DRAW_COMPLETE; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 154 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 155 | import android.annotation.Nullable; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 156 | import android.app.ActivityManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 157 | import android.app.ActivityManagerInternal; |
| 158 | import android.app.ActivityManagerInternal.SleepToken; |
Jason Monk | f506bf3 | 2017-08-23 10:56:34 -0400 | [diff] [blame] | 159 | import android.app.ActivityThread; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 160 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 161 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 162 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 163 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 164 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 165 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 166 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 167 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 168 | import android.content.ContentResolver; |
| 169 | import android.content.Context; |
| 170 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 171 | import android.content.IntentFilter; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 172 | import android.content.pm.ActivityInfo; |
Svet Ganov | 03f2afc | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 173 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 174 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 175 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 176 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 177 | import android.content.res.Configuration; |
| 178 | import android.content.res.Resources; |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 179 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 180 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 181 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 182 | import android.graphics.Rect; |
Jorim Jaggi | 7d0d102 | 2017-02-23 15:35:51 +0100 | [diff] [blame] | 183 | import android.graphics.drawable.Drawable; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 184 | import android.hardware.display.DisplayManager; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 185 | import android.hardware.hdmi.HdmiControlManager; |
| 186 | import android.hardware.hdmi.HdmiPlaybackClient; |
| 187 | import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback; |
Vladislav Kaznacheev | 19dab2d | 2017-02-07 10:12:51 -0800 | [diff] [blame] | 188 | import android.hardware.input.InputManager; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 189 | import android.hardware.input.InputManagerInternal; |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 190 | import android.hardware.power.V1_0.PowerHint; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 191 | import android.media.AudioAttributes; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 192 | import android.media.AudioManager; |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 193 | import android.media.AudioManagerInternal; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 194 | import android.media.AudioSystem; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 195 | import android.media.IAudioService; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 196 | import android.media.session.MediaSessionLegacyHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 197 | import android.os.Binder; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 198 | import android.os.Bundle; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 199 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 200 | import android.os.Handler; |
| 201 | import android.os.IBinder; |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 202 | import android.os.IDeviceIdleController; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 203 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 204 | import android.os.Message; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 205 | import android.os.PowerManager; |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 206 | import android.os.PowerManagerInternal; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 207 | import android.os.Process; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 208 | import android.os.RemoteException; |
| 209 | import android.os.ServiceManager; |
Jeff Sharkey | 8918298 | 2017-11-01 19:02:56 -0600 | [diff] [blame] | 210 | import android.os.StrictMode; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 211 | import android.os.SystemClock; |
| 212 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 213 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 214 | import android.os.UserHandle; |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 215 | import android.os.VibrationEffect; |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 216 | import android.os.Vibrator; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 217 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 218 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 219 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 220 | import android.service.dreams.DreamService; |
| 221 | import android.service.dreams.IDreamManager; |
Santos Cordon | c09d89c | 2017-04-13 16:12:02 -0700 | [diff] [blame] | 222 | import android.service.vr.IPersistentVrStateCallbacks; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 223 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 224 | import android.telecom.TelecomManager; |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 225 | import android.util.ArraySet; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 226 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 227 | import android.util.EventLog; |
| 228 | import android.util.Log; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 229 | import android.util.LongSparseArray; |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 230 | import android.util.MutableBoolean; |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 231 | import android.util.PrintWriterPrinter; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 232 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 233 | import android.util.SparseArray; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 234 | import android.util.proto.ProtoOutputStream; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 235 | import android.view.Display; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 236 | import android.view.DisplayCutout; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 237 | import android.view.Gravity; |
| 238 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 239 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 240 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 241 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 242 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 243 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 244 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 245 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 246 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 247 | import android.view.KeyEvent; |
| 248 | import android.view.MotionEvent; |
Vladislav Kaznacheev | 19dab2d | 2017-02-07 10:12:51 -0800 | [diff] [blame] | 249 | import android.view.PointerIcon; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 250 | import android.view.Surface; |
| 251 | import android.view.View; |
| 252 | import android.view.ViewConfiguration; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 253 | import android.view.WindowManager; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 254 | import android.view.WindowManager.LayoutParams; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 255 | import android.view.WindowManagerGlobal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 256 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 257 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 258 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 259 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 260 | import android.view.animation.AnimationUtils; |
Felipe Leme | 5f97880 | 2017-06-08 13:01:13 -0700 | [diff] [blame] | 261 | import android.view.autofill.AutofillManagerInternal; |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 262 | import android.view.inputmethod.InputMethodManagerInternal; |
Yohei Yukawa | abbe1ac | 2017-04-18 09:43:05 -0700 | [diff] [blame] | 263 | |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 264 | import com.android.internal.R; |
Phil Weaver | b9f0612 | 2017-11-30 10:48:17 -0800 | [diff] [blame] | 265 | import com.android.internal.accessibility.AccessibilityShortcutController; |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 266 | import com.android.internal.annotations.GuardedBy; |
Adrian Roos | e1856fe | 2017-11-24 19:39:12 +0100 | [diff] [blame] | 267 | import com.android.internal.annotations.VisibleForTesting; |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 268 | import com.android.internal.logging.MetricsLogger; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 269 | import com.android.internal.policy.IKeyguardDismissCallback; |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 270 | import com.android.internal.policy.IShortcutService; |
Winson Chung | 2a35e6d | 2018-01-13 14:27:50 -0800 | [diff] [blame] | 271 | import com.android.internal.policy.KeyguardDismissCallback; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 272 | import com.android.internal.policy.PhoneWindow; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 273 | import com.android.internal.statusbar.IStatusBarService; |
Phil Weaver | b9f0612 | 2017-11-30 10:48:17 -0800 | [diff] [blame] | 274 | import com.android.internal.util.ArrayUtils; |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 275 | import com.android.internal.util.ScreenshotHelper; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 276 | import com.android.internal.util.ScreenShapeHelper; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 277 | import com.android.internal.widget.PointerLocationView; |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 278 | import com.android.server.GestureLauncherService; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 279 | import com.android.server.LocalServices; |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 280 | import com.android.server.SystemServiceManager; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 281 | import com.android.server.policy.keyguard.KeyguardServiceDelegate; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 282 | import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener; |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 283 | import com.android.server.policy.keyguard.KeyguardStateMonitor.StateCallback; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 284 | import com.android.server.statusbar.StatusBarManagerInternal; |
Ruben Brunk | fecb615 | 2016-10-28 20:18:57 -0700 | [diff] [blame] | 285 | import com.android.server.vr.VrManagerInternal; |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 286 | import com.android.server.wm.AppTransition; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 287 | import com.android.server.wm.DisplayFrames; |
| 288 | import com.android.server.wm.WindowManagerInternal; |
| 289 | import com.android.server.wm.WindowManagerInternal.AppTransitionListener; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 290 | |
| 291 | import java.io.File; |
| 292 | import java.io.FileReader; |
| 293 | import java.io.IOException; |
| 294 | import java.io.PrintWriter; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 295 | import java.util.List; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 296 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 297 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 298 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 299 | * introduces a new method suffix, Lp, for an internal lock of the |
| 300 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 301 | * can be acquired with either the Lw and Li lock held, so has the restrictions |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 302 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 303 | */ |
| 304 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 305 | static final String TAG = "WindowManager"; |
| 306 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 307 | static final boolean localLOGV = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 308 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 309 | static final boolean DEBUG_KEYGUARD = false; |
| 310 | static final boolean DEBUG_LAYOUT = false; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 311 | static final boolean DEBUG_SPLASH_SCREEN = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 312 | static final boolean DEBUG_WAKEUP = false; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 313 | static final boolean SHOW_SPLASH_SCREENS = true; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 314 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 315 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 316 | // No longer recommended for desk docks; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 317 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 318 | |
Zak Cohen | db6ca49 | 2017-01-26 14:09:00 -0800 | [diff] [blame] | 319 | // Whether to allow devices placed in vr headset viewers to have an alternative Home intent. |
| 320 | static final boolean ENABLE_VR_HEADSET_HOME_CAPTURE = true; |
| 321 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 322 | static final boolean ALTERNATE_CAR_MODE_NAV_SIZE = false; |
| 323 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 324 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 325 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 326 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 327 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 328 | static final int SHORT_PRESS_POWER_GO_HOME = 4; |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 329 | static final int SHORT_PRESS_POWER_CLOSE_IME_OR_GO_HOME = 5; |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 330 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 331 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 332 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 333 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 334 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 335 | static final int LONG_PRESS_POWER_GO_TO_VOICE_ASSIST = 4; |
| 336 | |
| 337 | static final int VERY_LONG_PRESS_POWER_NOTHING = 0; |
| 338 | static final int VERY_LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 339 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 340 | static final int MULTI_PRESS_POWER_NOTHING = 0; |
| 341 | static final int MULTI_PRESS_POWER_THEATER_MODE = 1; |
| 342 | static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2; |
| 343 | |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 344 | static final int LONG_PRESS_BACK_NOTHING = 0; |
| 345 | static final int LONG_PRESS_BACK_GO_TO_VOICE_ASSIST = 1; |
| 346 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 347 | // These need to match the documentation/constant in |
| 348 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 349 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Sid Soundararajan | ff662fa | 2017-03-15 16:24:24 -0700 | [diff] [blame] | 350 | static final int LONG_PRESS_HOME_ALL_APPS = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 351 | static final int LONG_PRESS_HOME_ASSIST = 2; |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 352 | static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 353 | |
| 354 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 355 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 356 | |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 357 | static final int SHORT_PRESS_WINDOW_NOTHING = 0; |
| 358 | static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1; |
| 359 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 360 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0; |
| 361 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1; |
| 362 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 363 | static final int PENDING_KEY_NULL = -1; |
| 364 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 365 | // Controls navigation bar opacity depending on which workspace stacks are currently |
| 366 | // visible. |
| 367 | // Nav bar is always opaque when either the freeform stack or docked stack is visible. |
| 368 | static final int NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED = 0; |
| 369 | // Nav bar is always translucent when the freeform stack is visible, otherwise always opaque. |
| 370 | static final int NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE = 1; |
| 371 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 372 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 373 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 374 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 375 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 376 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
Winson Chung | ed376a3 | 2017-09-07 14:05:42 -0700 | [diff] [blame] | 377 | static public final String SYSTEM_DIALOG_REASON_SCREENSHOT = "screenshot"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 378 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 379 | /** |
| 380 | * These are the system UI flags that, when changing, can cause the layout |
| 381 | * of the screen to change. |
| 382 | */ |
| 383 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 384 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 385 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 386 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 387 | | View.NAVIGATION_BAR_TRANSLUCENT |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 388 | | View.STATUS_BAR_TRANSPARENT |
| 389 | | View.NAVIGATION_BAR_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 390 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 391 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 392 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 393 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 394 | .build(); |
| 395 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 396 | // The panic gesture may become active only after the keyguard is dismissed and the immersive |
| 397 | // app shows again. If that doesn't happen for 30s we drop the gesture. |
| 398 | private static final long PANIC_GESTURE_EXPIRATION = 30000; |
| 399 | |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 400 | private static final String SYSUI_PACKAGE = "com.android.systemui"; |
| 401 | private static final String SYSUI_SCREENSHOT_SERVICE = |
| 402 | "com.android.systemui.screenshot.TakeScreenshotService"; |
| 403 | private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER = |
| 404 | "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver"; |
| 405 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 406 | /** |
| 407 | * Keyguard stuff |
| 408 | */ |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 409 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 410 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 411 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 412 | * |
| 413 | * These are special keys that are used to launch particular kinds of applications, |
| 414 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 415 | * usage page. We don't support quite that many yet... |
| 416 | */ |
| 417 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 418 | static { |
| 419 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 420 | sApplicationLaunchKeyCategories.append( |
| 421 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 422 | sApplicationLaunchKeyCategories.append( |
| 423 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 424 | sApplicationLaunchKeyCategories.append( |
| 425 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 426 | sApplicationLaunchKeyCategories.append( |
| 427 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 428 | sApplicationLaunchKeyCategories.append( |
| 429 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 430 | sApplicationLaunchKeyCategories.append( |
| 431 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 432 | } |
| 433 | |
Yoshiaki Naka | e1bdfc82 | 2017-09-15 15:24:34 +0900 | [diff] [blame] | 434 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 435 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 436 | /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */ |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 437 | static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 438 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 439 | /** Amount of time (in milliseconds) a toast window can be shown. */ |
| 440 | public static final int TOAST_WINDOW_TIMEOUT = 3500; // 3.5 seconds |
| 441 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 442 | /** |
| 443 | * Lock protecting internal state. Must not call out into window |
| 444 | * manager with lock held. (This lock will be acquired in places |
| 445 | * where the window manager is calling in with its own lock held.) |
| 446 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 447 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 448 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 449 | Context mContext; |
| 450 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 451 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 452 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 453 | PowerManager mPowerManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 454 | ActivityManagerInternal mActivityManagerInternal; |
Felipe Leme | 5f97880 | 2017-06-08 13:01:13 -0700 | [diff] [blame] | 455 | AutofillManagerInternal mAutofillManagerInternal; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 456 | InputManagerInternal mInputManagerInternal; |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 457 | InputMethodManagerInternal mInputMethodManagerInternal; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 458 | DreamManagerInternal mDreamManagerInternal; |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 459 | PowerManagerInternal mPowerManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 460 | IStatusBarService mStatusBarService; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 461 | StatusBarManagerInternal mStatusBarManagerInternal; |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 462 | AudioManagerInternal mAudioManagerInternal; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 463 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 464 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 465 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 466 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 467 | AccessibilityManager mAccessibilityManager; |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 468 | BurnInProtectionHelper mBurnInProtectionHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 469 | AppOpsManager mAppOpsManager; |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 470 | private ScreenshotHelper mScreenshotHelper; |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 471 | private boolean mHasFeatureWatch; |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 472 | private boolean mHasFeatureLeanback; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 473 | |
Zak Cohen | 732aeb0 | 2017-01-29 14:19:52 -0800 | [diff] [blame] | 474 | // Assigned on main thread, accessed on UI thread |
| 475 | volatile VrManagerInternal mVrManagerInternal; |
| 476 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 477 | // Vibrator pattern for haptic feedback of a long press. |
| 478 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 479 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 480 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 481 | long[] mCalendarDateVibePattern; |
| 482 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 483 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 484 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 485 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 486 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 487 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 488 | |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 489 | /** Controller that supports enabling an AccessibilityService by holding down the volume keys */ |
| 490 | private AccessibilityShortcutController mAccessibilityShortcutController; |
| 491 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 492 | boolean mSafeMode; |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 493 | private final ArraySet<WindowState> mScreenDecorWindows = new ArraySet<>(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 494 | WindowState mStatusBar = null; |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 495 | private final int[] mStatusBarHeightForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 496 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 497 | boolean mHasNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 498 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
Yohei Yukawa | d0a66b2 | 2018-01-10 13:19:54 -0800 | [diff] [blame] | 499 | @NavigationBarPosition |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 500 | int mNavigationBarPosition = NAV_BAR_BOTTOM; |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 501 | int[] mNavigationBarHeightForRotationDefault = new int[4]; |
| 502 | int[] mNavigationBarWidthForRotationDefault = new int[4]; |
| 503 | int[] mNavigationBarHeightForRotationInCarMode = new int[4]; |
| 504 | int[] mNavigationBarWidthForRotationInCarMode = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 505 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 506 | private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>(); |
| 507 | |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 508 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 509 | // This is for car dock and this is updated from resource. |
| 510 | private boolean mEnableCarDockHomeCapture = true; |
| 511 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 512 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 513 | KeyguardServiceDelegate mKeyguardDelegate; |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 514 | private boolean mKeyguardBound; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 515 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 516 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 517 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 518 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 519 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 520 | } |
| 521 | }; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 522 | final DrawnListener mKeyguardDrawnCallback = new DrawnListener() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 523 | @Override |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 524 | public void onDrawn() { |
| 525 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 526 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 527 | } |
| 528 | }; |
| 529 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 530 | GlobalActions mGlobalActions; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 531 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 532 | WindowState mLastInputMethodWindow = null; |
| 533 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 534 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 535 | // FIXME This state is shared between the input reader and handler thread. |
| 536 | // Technically it's broken and buggy but it has been like this for many years |
| 537 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 538 | // so that only one thread is involved in handling input policy. Unfortunately |
| 539 | // it's on a critical path for power management so we can't just post the work to the |
| 540 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 541 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 542 | volatile boolean mPowerKeyHandled; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 543 | volatile boolean mBackKeyHandled; |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 544 | volatile boolean mBeganFromNonInteractive; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 545 | volatile int mPowerKeyPressCounter; |
| 546 | volatile boolean mEndCallKeyHandled; |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 547 | volatile boolean mCameraGestureTriggeredDuringGoingToSleep; |
| 548 | volatile boolean mGoingToSleep; |
Selim Cinek | ab55ba5 | 2017-08-02 16:45:51 -0700 | [diff] [blame] | 549 | volatile boolean mRequestedOrGoingToSleep; |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 550 | volatile boolean mRecentsVisible; |
Matthew Ng | 64543e6 | 2018-02-28 17:35:10 -0800 | [diff] [blame] | 551 | volatile boolean mNavBarVirtualKeyHapticFeedbackEnabled; |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 552 | volatile boolean mPictureInPictureVisible; |
Santos Cordon | c09d89c | 2017-04-13 16:12:02 -0700 | [diff] [blame] | 553 | // Written by vr manager thread, only read in this class. |
| 554 | volatile private boolean mPersistentVrModeEnabled; |
Yohei Yukawa | abbe1ac | 2017-04-18 09:43:05 -0700 | [diff] [blame] | 555 | volatile private boolean mDismissImeOnBackKeyPressed; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 556 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 557 | // Used to hold the last user key used to wake the device. This helps us prevent up events |
| 558 | // from being passed to the foregrounded app without a corresponding down event |
| 559 | volatile int mPendingWakeKey = PENDING_KEY_NULL; |
| 560 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 561 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 562 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 563 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 564 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 565 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 566 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 567 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 568 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 569 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 570 | boolean mHdmiPlugged; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 571 | HdmiControl mHdmiControl; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 572 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 573 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 574 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 575 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 576 | int mCarDockRotation; |
| 577 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 578 | int mUndockedHdmiRotation; |
| 579 | int mDemoHdmiRotation; |
| 580 | boolean mDemoHdmiRotationLock; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 581 | int mDemoRotation; |
| 582 | boolean mDemoRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 583 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 584 | boolean mWakeGestureEnabledSetting; |
| 585 | MyWakeGestureListener mWakeGestureListener; |
| 586 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 587 | // Default display does not rotate, apps that require non-default orientation will have to |
| 588 | // have the orientation emulated. |
| 589 | private boolean mForceDefaultOrientation = false; |
| 590 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 591 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 592 | int mUserRotation = Surface.ROTATION_0; |
| 593 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 594 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 595 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 596 | boolean mCarDockEnablesAccelerometer; |
| 597 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 598 | int mLidKeyboardAccessibility; |
| 599 | int mLidNavigationAccessibility; |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 600 | boolean mLidControlsScreenLock; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 601 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 602 | int mShortPressOnPowerBehavior; |
| 603 | int mLongPressOnPowerBehavior; |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 604 | int mVeryLongPressOnPowerBehavior; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 605 | int mDoublePressOnPowerBehavior; |
| 606 | int mTriplePressOnPowerBehavior; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 607 | int mLongPressOnBackBehavior; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 608 | int mShortPressOnSleepBehavior; |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 609 | int mShortPressOnWindowBehavior; |
Adrian Roos | e94c15c | 2017-05-09 13:17:54 -0700 | [diff] [blame] | 610 | volatile boolean mAwake; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 611 | boolean mScreenOnEarly; |
| 612 | boolean mScreenOnFully; |
| 613 | ScreenOnListener mScreenOnListener; |
| 614 | boolean mKeyguardDrawComplete; |
| 615 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 616 | boolean mOrientationSensorEnabled = false; |
| 617 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 618 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 619 | boolean mTranslucentDecorEnabled = true; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 620 | boolean mUseTvRouting; |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 621 | int mVeryLongPressTimeout; |
Michael Kwan | 7f17169 | 2018-04-04 14:00:53 -0700 | [diff] [blame] | 622 | boolean mAllowStartActivityForLongPressOnPowerDuringSetup; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 623 | |
Karthik Ravi Shankar | 86ecf34 | 2017-04-28 15:35:58 -0700 | [diff] [blame] | 624 | private boolean mHandleVolumeKeysInWM; |
| 625 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 626 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 627 | |
| 628 | // The last window we were told about in focusChanged. |
| 629 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 630 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 631 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 632 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 633 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 634 | // During layout, the layer at which the doc window is placed. |
| 635 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 636 | // During layout, this is the layer of the status bar. |
| 637 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 638 | int mLastSystemUiFlags; |
| 639 | // Bits that we are in the process of clearing, so we want to prevent |
| 640 | // them from being set by applications until everything has been updated |
| 641 | // to have them clear. |
| 642 | int mResettingSystemUiFlags = 0; |
| 643 | // Bits that we are currently always keeping cleared. |
| 644 | int mForceClearedSystemUiFlags = 0; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 645 | int mLastFullscreenStackSysUiFlags; |
| 646 | int mLastDockedStackSysUiFlags; |
| 647 | final Rect mNonDockedStackBounds = new Rect(); |
| 648 | final Rect mDockedStackBounds = new Rect(); |
| 649 | final Rect mLastNonDockedStackBounds = new Rect(); |
| 650 | final Rect mLastDockedStackBounds = new Rect(); |
| 651 | |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 652 | // What we last reported to system UI about whether the compatibility |
| 653 | // menu needs to be displayed. |
| 654 | boolean mLastFocusNeedsMenu = false; |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 655 | // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending. |
| 656 | private long mPendingPanicGestureUptime; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 657 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 658 | InputConsumer mInputConsumer = null; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 659 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 660 | static final Rect mTmpParentFrame = new Rect(); |
| 661 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 662 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 663 | static final Rect mTmpContentFrame = new Rect(); |
| 664 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 665 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 666 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 667 | static final Rect mTmpNavigationFrame = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 668 | static final Rect mTmpOutsetFrame = new Rect(); |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 669 | private static final Rect mTmpDisplayCutoutSafeExceptMaybeBarsRect = new Rect(); |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 670 | private static final Rect mTmpRect = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 671 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 672 | WindowState mTopFullscreenOpaqueWindowState; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 673 | WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 674 | WindowState mTopDockedOpaqueWindowState; |
| 675 | WindowState mTopDockedOpaqueOrDimmingWindowState; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 676 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 677 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 678 | boolean mForceStatusBarFromKeyguard; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 679 | private boolean mForceStatusBarTransparent; |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 680 | int mNavBarOpacityMode = NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 681 | boolean mForcingShowNavBar; |
| 682 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 683 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 684 | private boolean mPendingKeyguardOccluded; |
| 685 | private boolean mKeyguardOccludedChanged; |
Yoshiaki Naka | e1bdfc82 | 2017-09-15 15:24:34 +0900 | [diff] [blame] | 686 | private boolean mNotifyUserActivity; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 687 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 688 | boolean mShowingDream; |
Jorim Jaggi | 77e1043 | 2016-10-26 17:43:56 -0700 | [diff] [blame] | 689 | private boolean mLastShowingDream; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 690 | boolean mDreamingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 691 | boolean mDreamingSleepTokenNeeded; |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 692 | private boolean mWindowSleepTokenNeeded; |
| 693 | private boolean mLastWindowSleepTokenNeeded; |
| 694 | |
| 695 | @GuardedBy("mHandler") |
| 696 | private SleepToken mWindowSleepToken; |
| 697 | |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 698 | SleepToken mDreamingSleepToken; |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 699 | SleepToken mScreenOffSleepToken; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 700 | volatile boolean mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 701 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 702 | boolean mHomeConsumed; |
| 703 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 704 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 705 | Intent mCarDockIntent; |
| 706 | Intent mDeskDockIntent; |
Zak Cohen | db6ca49 | 2017-01-26 14:09:00 -0800 | [diff] [blame] | 707 | Intent mVrHeadsetHomeIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 708 | boolean mSearchKeyShortcutPending; |
| 709 | boolean mConsumeSearchKeyUp; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 710 | boolean mPendingMetaAction; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 711 | boolean mPendingCapsLockToggle; |
| 712 | int mMetaState; |
| 713 | int mInitialMetaState; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 714 | boolean mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 715 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 716 | // support for activating the lock screen while the screen is on |
| 717 | boolean mAllowLockscreenWhenOn; |
| 718 | int mLockScreenTimeout; |
| 719 | boolean mLockScreenTimerActive; |
| 720 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 721 | // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.) |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 722 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 723 | |
| 724 | // Behavior of POWER button while in-call and screen on. |
| 725 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 726 | int mIncallPowerBehavior; |
| 727 | |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 728 | // Behavior of Back button while in-call and screen on |
| 729 | int mIncallBackBehavior; |
| 730 | |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 731 | // Behavior of rotation suggestions. (See Settings.Secure.SHOW_ROTATION_SUGGESTION) |
| 732 | int mShowRotationSuggestions; |
| 733 | |
Siarhei Vishniakou | e5e0d9f | 2018-03-05 20:09:08 -0800 | [diff] [blame] | 734 | // Whether system navigation keys are enabled |
| 735 | boolean mSystemNavigationKeysEnabled; |
| 736 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 737 | Display mDisplay; |
| 738 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 739 | int mLandscapeRotation = 0; // default landscape rotation |
| 740 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 741 | int mPortraitRotation = 0; // default portrait rotation |
| 742 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 743 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 744 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 745 | private int mLongPressOnHomeBehavior; |
| 746 | |
| 747 | // What we do when the user double-taps on home |
| 748 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 749 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 750 | // Allowed theater mode wake actions |
| 751 | private boolean mAllowTheaterModeWakeFromKey; |
| 752 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 753 | private boolean mAllowTheaterModeWakeFromMotion; |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 754 | private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 755 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 756 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 757 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 758 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 759 | // Whether to support long press from power button in non-interactive mode |
| 760 | private boolean mSupportLongPressPowerWhenNonInteractive; |
| 761 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 762 | // Whether to go to sleep entering theater mode from power button |
| 763 | private boolean mGoToSleepOnButtonPressTheaterMode; |
| 764 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 765 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 766 | // Time to volume and power must be pressed within this interval of each other. |
| 767 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 768 | // Increase the chord delay when taking a screenshot from the keyguard |
| 769 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 770 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 771 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 772 | private long mScreenshotChordVolumeDownKeyTime; |
| 773 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 774 | private boolean mA11yShortcutChordVolumeUpKeyTriggered; |
| 775 | private long mA11yShortcutChordVolumeUpKeyTime; |
| 776 | private boolean mA11yShortcutChordVolumeUpKeyConsumed; |
| 777 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 778 | private boolean mScreenshotChordPowerKeyTriggered; |
| 779 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 780 | |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 781 | // Ringer toggle should reuse timing and triggering from screenshot power and a11y vol up |
| 782 | private int mRingerToggleChord = VOLUME_HUSH_OFF; |
| 783 | |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 784 | private static final long BUGREPORT_TV_GESTURE_TIMEOUT_MILLIS = 1000; |
| 785 | |
| 786 | private boolean mBugreportTvKey1Pressed; |
| 787 | private boolean mBugreportTvKey2Pressed; |
| 788 | private boolean mBugreportTvScheduled; |
| 789 | |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 790 | private boolean mAccessibilityTvKey1Pressed; |
| 791 | private boolean mAccessibilityTvKey2Pressed; |
| 792 | private boolean mAccessibilityTvScheduled; |
| 793 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 794 | /* The number of steps between min and max brightness */ |
| 795 | private static final int BRIGHTNESS_STEPS = 10; |
| 796 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 797 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 798 | ShortcutManager mShortcutManager; |
| 799 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 800 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 801 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 802 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 803 | private int mCurrentUserId; |
| 804 | |
Phil Weaver | d755160 | 2018-02-15 15:01:04 -0800 | [diff] [blame] | 805 | /* Whether accessibility is magnifying the screen */ |
| 806 | private boolean mScreenMagnificationActive; |
| 807 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 808 | // Maps global key codes to the components that will handle them. |
| 809 | private GlobalKeyManager mGlobalKeyManager; |
| 810 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 811 | // Fallback actions by key code. |
| 812 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 813 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 814 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 815 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 816 | = new LogDecelerateInterpolator(100, 0); |
| 817 | |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 818 | private final MutableBoolean mTmpBoolean = new MutableBoolean(false); |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 819 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 820 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 821 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 822 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 823 | private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 824 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 825 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 826 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 827 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 828 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 829 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 830 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 831 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 832 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 833 | private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 834 | private static final int MSG_REQUEST_TRANSIENT_BARS = 16; |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 835 | private static final int MSG_SHOW_PICTURE_IN_PICTURE_MENU = 17; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 836 | private static final int MSG_BACK_LONG_PRESS = 18; |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 837 | private static final int MSG_DISPOSE_INPUT_CONSUMER = 19; |
Erik Wolsheimer | bb97879 | 2017-12-11 13:45:21 -0800 | [diff] [blame] | 838 | private static final int MSG_ACCESSIBILITY_SHORTCUT = 20; |
| 839 | private static final int MSG_BUGREPORT_TV = 21; |
| 840 | private static final int MSG_ACCESSIBILITY_TV = 22; |
| 841 | private static final int MSG_DISPATCH_BACK_KEY_TO_AUTOFILL = 23; |
| 842 | private static final int MSG_SYSTEM_KEY_PRESS = 24; |
| 843 | private static final int MSG_HANDLE_ALL_APPS = 25; |
| 844 | private static final int MSG_LAUNCH_ASSIST = 26; |
| 845 | private static final int MSG_LAUNCH_ASSIST_LONG_PRESS = 27; |
| 846 | private static final int MSG_POWER_VERY_LONG_PRESS = 28; |
Yoshiaki Naka | e1bdfc82 | 2017-09-15 15:24:34 +0900 | [diff] [blame] | 847 | private static final int MSG_NOTIFY_USER_ACTIVITY = 29; |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 848 | private static final int MSG_RINGER_TOGGLE_CHORD = 30; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 849 | |
| 850 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0; |
| 851 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 852 | |
| 853 | private class PolicyHandler extends Handler { |
| 854 | @Override |
| 855 | public void handleMessage(Message msg) { |
| 856 | switch (msg.what) { |
| 857 | case MSG_ENABLE_POINTER_LOCATION: |
| 858 | enablePointerLocation(); |
| 859 | break; |
| 860 | case MSG_DISABLE_POINTER_LOCATION: |
| 861 | disablePointerLocation(); |
| 862 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 863 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 864 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 865 | break; |
| 866 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 867 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 868 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 869 | case MSG_DISPATCH_SHOW_RECENTS: |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 870 | showRecentApps(false); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 871 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 872 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 873 | showGlobalActionsInternal(); |
| 874 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 875 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 876 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 877 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 878 | break; |
| 879 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 880 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 881 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 882 | break; |
| 883 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 884 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 885 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 886 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 887 | case MSG_HIDE_BOOT_MESSAGE: |
| 888 | handleHideBootMessage(); |
| 889 | break; |
Siarhei Vishniakou | 191cf1b | 2017-08-17 16:17:22 -0700 | [diff] [blame] | 890 | case MSG_LAUNCH_ASSIST: |
| 891 | final int deviceId = msg.arg1; |
| 892 | final String hint = (String) msg.obj; |
| 893 | launchAssistAction(hint, deviceId); |
| 894 | break; |
| 895 | case MSG_LAUNCH_ASSIST_LONG_PRESS: |
| 896 | launchAssistLongPressAction(); |
| 897 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 898 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
Siarhei Vishniakou | 191cf1b | 2017-08-17 16:17:22 -0700 | [diff] [blame] | 899 | launchVoiceAssistWithWakeLock(); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 900 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 901 | case MSG_POWER_DELAYED_PRESS: |
| 902 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 903 | finishPowerKeyPress(); |
| 904 | break; |
| 905 | case MSG_POWER_LONG_PRESS: |
| 906 | powerLongPress(); |
| 907 | break; |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 908 | case MSG_POWER_VERY_LONG_PRESS: |
| 909 | powerVeryLongPress(); |
| 910 | break; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 911 | case MSG_UPDATE_DREAMING_SLEEP_TOKEN: |
| 912 | updateDreamingSleepToken(msg.arg1 != 0); |
| 913 | break; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 914 | case MSG_REQUEST_TRANSIENT_BARS: |
| 915 | WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ? |
| 916 | mStatusBar : mNavigationBar; |
| 917 | if (targetBar != null) { |
| 918 | requestTransientBars(targetBar); |
| 919 | } |
| 920 | break; |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 921 | case MSG_SHOW_PICTURE_IN_PICTURE_MENU: |
| 922 | showPictureInPictureMenuInternal(); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 923 | break; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 924 | case MSG_BACK_LONG_PRESS: |
| 925 | backLongPress(); |
| 926 | break; |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 927 | case MSG_DISPOSE_INPUT_CONSUMER: |
| 928 | disposeInputConsumer((InputConsumer) msg.obj); |
| 929 | break; |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 930 | case MSG_ACCESSIBILITY_SHORTCUT: |
| 931 | accessibilityShortcutActivated(); |
| 932 | break; |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 933 | case MSG_BUGREPORT_TV: |
| 934 | takeBugreport(); |
| 935 | break; |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 936 | case MSG_ACCESSIBILITY_TV: |
| 937 | if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(false)) { |
| 938 | accessibilityShortcutActivated(); |
| 939 | } |
| 940 | break; |
Felipe Leme | 5f97880 | 2017-06-08 13:01:13 -0700 | [diff] [blame] | 941 | case MSG_DISPATCH_BACK_KEY_TO_AUTOFILL: |
| 942 | mAutofillManagerInternal.onBackKeyPressed(); |
| 943 | break; |
Philip Quinn | 4b5b3c6 | 2017-07-20 21:07:58 -0700 | [diff] [blame] | 944 | case MSG_SYSTEM_KEY_PRESS: |
| 945 | sendSystemKeyToStatusBar(msg.arg1); |
| 946 | break; |
Sujith Ramakrishnan | f8942c0 | 2017-07-18 18:35:14 -0700 | [diff] [blame] | 947 | case MSG_HANDLE_ALL_APPS: |
| 948 | launchAllAppsAction(); |
| 949 | break; |
Yoshiaki Naka | e1bdfc82 | 2017-09-15 15:24:34 +0900 | [diff] [blame] | 950 | case MSG_NOTIFY_USER_ACTIVITY: |
| 951 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
| 952 | Intent intent = new Intent(ACTION_USER_ACTIVITY_NOTIFICATION); |
| 953 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 954 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL, |
| 955 | android.Manifest.permission.USER_ACTIVITY); |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 956 | case MSG_RINGER_TOGGLE_CHORD: |
| 957 | handleRingerChordGesture(); |
Yoshiaki Naka | e1bdfc82 | 2017-09-15 15:24:34 +0900 | [diff] [blame] | 958 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 959 | } |
| 960 | } |
| 961 | } |
| 962 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 963 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 964 | @Override |
| 965 | public void onUEvent(UEventObserver.UEvent event) { |
| 966 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 967 | } |
| 968 | }; |
| 969 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 970 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 971 | SettingsObserver(Handler handler) { |
| 972 | super(handler); |
| 973 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 974 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 975 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 976 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 977 | ContentResolver resolver = mContext.getContentResolver(); |
| 978 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 979 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 980 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 981 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 982 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 983 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 984 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 985 | Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR), false, this, |
| 986 | UserHandle.USER_ALL); |
| 987 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 988 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 989 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 990 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 991 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 992 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 993 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 994 | Settings.System.USER_ROTATION), false, this, |
| 995 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 996 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 997 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 998 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 999 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1000 | Settings.System.POINTER_LOCATION), false, this, |
| 1001 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1002 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1003 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 1004 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 1005 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1006 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1007 | UserHandle.USER_ALL); |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 1008 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 1009 | Settings.Secure.SHOW_ROTATION_SUGGESTIONS), false, this, |
| 1010 | UserHandle.USER_ALL); |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 1011 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 1012 | Settings.Secure.VOLUME_HUSH_GESTURE), false, this, |
| 1013 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1014 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 1015 | Settings.Global.POLICY_CONTROL), false, this, |
| 1016 | UserHandle.USER_ALL); |
Kevin Chyn | f823d3e | 2018-03-20 14:42:39 -0700 | [diff] [blame] | 1017 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Siarhei Vishniakou | e5e0d9f | 2018-03-05 20:09:08 -0800 | [diff] [blame] | 1018 | Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED), false, this, |
| 1019 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1020 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1024 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1025 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1026 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1027 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1028 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1029 | class MyWakeGestureListener extends WakeGestureListener { |
| 1030 | MyWakeGestureListener(Context context, Handler handler) { |
| 1031 | super(context, handler); |
| 1032 | } |
| 1033 | |
| 1034 | @Override |
| 1035 | public void onWakeUp() { |
| 1036 | synchronized (mLock) { |
| 1037 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 1038 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1039 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture, |
| 1040 | "android.policy:GESTURE"); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | } |
| 1044 | } |
| 1045 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1046 | class MyOrientationListener extends WindowOrientationListener { |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 1047 | |
| 1048 | private SparseArray<Runnable> mRunnableCache; |
| 1049 | |
| 1050 | MyOrientationListener(Context context, Handler handler) { |
| 1051 | super(context, handler); |
| 1052 | mRunnableCache = new SparseArray<>(5); |
| 1053 | } |
| 1054 | |
| 1055 | private class UpdateRunnable implements Runnable { |
| 1056 | private final int mRotation; |
| 1057 | UpdateRunnable(int rotation) { |
| 1058 | mRotation = rotation; |
| 1059 | } |
| 1060 | |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 1061 | @Override |
| 1062 | public void run() { |
Tim Murray | 1f40764 | 2015-10-01 17:07:12 -0700 | [diff] [blame] | 1063 | // send interaction hint to improve redraw performance |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 1064 | mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0); |
Mike Digman | be875db | 2018-01-26 11:13:23 -0800 | [diff] [blame] | 1065 | if (isRotationChoicePossible(mCurrentAppOrientation)) { |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 1066 | final boolean isValid = isValidRotationChoice(mCurrentAppOrientation, |
| 1067 | mRotation); |
| 1068 | sendProposedRotationChangeToStatusBarInternal(mRotation, isValid); |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 1069 | } else { |
| 1070 | updateRotation(false); |
| 1071 | } |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 1072 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1073 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1074 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1075 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1076 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1077 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 1078 | Runnable r = mRunnableCache.get(rotation, null); |
| 1079 | if (r == null){ |
| 1080 | r = new UpdateRunnable(rotation); |
| 1081 | mRunnableCache.put(rotation, r); |
| 1082 | } |
| 1083 | mHandler.post(r); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1084 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1085 | } |
| 1086 | MyOrientationListener mOrientationListener; |
| 1087 | |
Santos Cordon | c09d89c | 2017-04-13 16:12:02 -0700 | [diff] [blame] | 1088 | final IPersistentVrStateCallbacks mPersistentVrModeListener = |
| 1089 | new IPersistentVrStateCallbacks.Stub() { |
| 1090 | @Override |
| 1091 | public void onPersistentVrStateChanged(boolean enabled) { |
| 1092 | mPersistentVrModeEnabled = enabled; |
| 1093 | } |
| 1094 | }; |
| 1095 | |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 1096 | private final StatusBarController mStatusBarController = new StatusBarController(); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 1097 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1098 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 1099 | View.NAVIGATION_BAR_TRANSIENT, |
| 1100 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 1101 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 1102 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1103 | FLAG_TRANSLUCENT_NAVIGATION, |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 1104 | View.NAVIGATION_BAR_TRANSPARENT); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 1105 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1106 | private final BarController.OnBarVisibilityChangedListener mNavBarVisibilityListener = |
| 1107 | new BarController.OnBarVisibilityChangedListener() { |
| 1108 | @Override |
| 1109 | public void onBarVisibilityChanged(boolean visible) { |
Casey Burkhardt | 469a208 | 2017-06-13 20:12:42 -0700 | [diff] [blame] | 1110 | mAccessibilityManager.notifyAccessibilityButtonVisibilityChanged(visible); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1111 | } |
| 1112 | }; |
| 1113 | |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 1114 | private final Runnable mAcquireSleepTokenRunnable = () -> { |
| 1115 | if (mWindowSleepToken != null) { |
| 1116 | return; |
| 1117 | } |
| 1118 | mWindowSleepToken = mActivityManagerInternal.acquireSleepToken("WindowSleepToken", |
| 1119 | DEFAULT_DISPLAY); |
| 1120 | }; |
| 1121 | |
| 1122 | private final Runnable mReleaseSleepTokenRunnable = () -> { |
| 1123 | if (mWindowSleepToken == null) { |
| 1124 | return; |
| 1125 | } |
| 1126 | mWindowSleepToken.release(); |
| 1127 | mWindowSleepToken = null; |
| 1128 | }; |
| 1129 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1130 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1131 | |
Adrian Roos | e1856fe | 2017-11-24 19:39:12 +0100 | [diff] [blame] | 1132 | @VisibleForTesting |
| 1133 | SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1134 | |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 1135 | private void handleRingerChordGesture() { |
| 1136 | if (mRingerToggleChord == VOLUME_HUSH_OFF) { |
| 1137 | return; |
| 1138 | } |
| 1139 | getAudioManagerInternal(); |
| 1140 | mAudioManagerInternal.silenceRingerModeInternal("volume_hush"); |
| 1141 | } |
| 1142 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1143 | IStatusBarService getStatusBarService() { |
| 1144 | synchronized (mServiceAquireLock) { |
| 1145 | if (mStatusBarService == null) { |
| 1146 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 1147 | ServiceManager.getService("statusbar")); |
| 1148 | } |
| 1149 | return mStatusBarService; |
| 1150 | } |
| 1151 | } |
| 1152 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 1153 | StatusBarManagerInternal getStatusBarManagerInternal() { |
| 1154 | synchronized (mServiceAquireLock) { |
| 1155 | if (mStatusBarManagerInternal == null) { |
| 1156 | mStatusBarManagerInternal = |
| 1157 | LocalServices.getService(StatusBarManagerInternal.class); |
| 1158 | } |
| 1159 | return mStatusBarManagerInternal; |
| 1160 | } |
| 1161 | } |
| 1162 | |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 1163 | AudioManagerInternal getAudioManagerInternal() { |
| 1164 | synchronized (mServiceAquireLock) { |
| 1165 | if (mAudioManagerInternal == null) { |
| 1166 | mAudioManagerInternal = LocalServices.getService(AudioManagerInternal.class); |
| 1167 | } |
| 1168 | return mAudioManagerInternal; |
| 1169 | } |
| 1170 | } |
| 1171 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 1172 | /* |
| 1173 | * We always let the sensor be switched on by default except when |
| 1174 | * the user has explicitly disabled sensor based rotation or when the |
| 1175 | * screen is switched off. |
| 1176 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1177 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1178 | if (mSupportAutoRotation) { |
| 1179 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 1180 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 1181 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 1182 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 1183 | // If the application has explicitly requested to follow the |
| 1184 | // orientation, then we need to turn the sensor on. |
| 1185 | return true; |
| 1186 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1187 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1188 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 1189 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 1190 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 1191 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1192 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 1193 | // orientation management, |
| 1194 | return true; |
| 1195 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1196 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1197 | // If the setting for using the sensor by default is enabled, then |
| 1198 | // we will always leave it on. Note that the user could go to |
| 1199 | // a window that forces an orientation that does not use the |
| 1200 | // sensor and in theory we could turn it off... however, when next |
| 1201 | // turning it on we won't have a good value for the current |
| 1202 | // orientation for a little bit, which can cause orientation |
| 1203 | // changes to lag, so we'd like to keep it always on. (It will |
| 1204 | // still be turned off when the screen is off.) |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 1205 | |
| 1206 | // When locked we can provide rotation suggestions users can approve to change the |
| 1207 | // current screen rotation. To do this the sensor needs to be running. |
| 1208 | return mSupportAutoRotation && |
| 1209 | mShowRotationSuggestions == Settings.Secure.SHOW_ROTATION_SUGGESTIONS_ENABLED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1210 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1211 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1212 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1213 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1214 | /* |
| 1215 | * Various use cases for invoking this function |
| 1216 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1217 | * screen turned on and current app has sensor based orientation, enable listeners |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1218 | * if not already enabled |
| 1219 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 1220 | * already enabled |
| 1221 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 1222 | * screen turning on and current app has nosensor based orientation, do nothing |
| 1223 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1224 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1225 | if (!mOrientationListener.canDetectOrientation()) { |
| 1226 | // If sensor is turned off or nonexistent for some reason |
| 1227 | return; |
| 1228 | } |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 1229 | // Could have been invoked due to screen turning on or off or |
| 1230 | // change of the currently visible window's orientation. |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1231 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 1232 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 1233 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled |
| 1234 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 1235 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 1236 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1237 | boolean disable = true; |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 1238 | // Note: We postpone the rotating of the screen until the keyguard as well as the |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 1239 | // window manager have reported a draw complete or the keyguard is going away in dismiss |
| 1240 | // mode. |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 1241 | if (mScreenOnEarly && mAwake && ((mKeyguardDrawComplete && mWindowManagerDrawComplete))) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1242 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1243 | disable = false; |
| 1244 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1245 | if (!mOrientationSensorEnabled) { |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 1246 | // Don't clear the current sensor orientation if the keyguard is going away in |
| 1247 | // dismiss mode. This allows window manager to use the last sensor reading to |
| 1248 | // determine the orientation vs. falling back to the last known orientation if |
| 1249 | // the sensor reading was cleared which can cause it to relaunch the app that |
| 1250 | // will show in the wrong orientation first before correcting leading to app |
| 1251 | // launch delays. |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 1252 | mOrientationListener.enable(true /* clearCurrentRotation */); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1253 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1254 | mOrientationSensorEnabled = true; |
| 1255 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1256 | } |
| 1257 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1258 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1259 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1260 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1261 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1262 | mOrientationSensorEnabled = false; |
| 1263 | } |
| 1264 | } |
| 1265 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1266 | private void interceptBackKeyDown() { |
Nimrod Gileadi | 580135c | 2016-10-31 20:42:19 +0000 | [diff] [blame] | 1267 | MetricsLogger.count(mContext, "key_back_down", 1); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1268 | // Reset back key state for long press |
| 1269 | mBackKeyHandled = false; |
| 1270 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1271 | if (hasLongPressOnBackBehavior()) { |
| 1272 | Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS); |
| 1273 | msg.setAsynchronous(true); |
| 1274 | mHandler.sendMessageDelayed(msg, |
| 1275 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | // returns true if the key was handled and should not be passed to the user |
| 1280 | private boolean interceptBackKeyUp(KeyEvent event) { |
| 1281 | // Cache handled state |
| 1282 | boolean handled = mBackKeyHandled; |
| 1283 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1284 | // Reset back long press state |
| 1285 | cancelPendingBackKeyAction(); |
| 1286 | |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 1287 | if (mHasFeatureWatch) { |
| 1288 | TelecomManager telecomManager = getTelecommService(); |
| 1289 | |
| 1290 | if (telecomManager != null) { |
| 1291 | if (telecomManager.isRinging()) { |
| 1292 | // Pressing back while there's a ringing incoming |
| 1293 | // call should silence the ringer. |
| 1294 | telecomManager.silenceRinger(); |
| 1295 | |
| 1296 | // It should not prevent navigating away |
| 1297 | return false; |
| 1298 | } else if ( |
| 1299 | (mIncallBackBehavior & Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 1300 | && telecomManager.isInCall()) { |
| 1301 | // Otherwise, if "Back button ends call" is enabled, |
| 1302 | // the Back button will hang up any current active call. |
| 1303 | return telecomManager.endCall(); |
| 1304 | } |
| 1305 | } |
| 1306 | } |
| 1307 | |
Felipe Leme | 5f97880 | 2017-06-08 13:01:13 -0700 | [diff] [blame] | 1308 | if (mAutofillManagerInternal != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) { |
| 1309 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DISPATCH_BACK_KEY_TO_AUTOFILL)); |
| 1310 | } |
| 1311 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1312 | return handled; |
| 1313 | } |
| 1314 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1315 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 1316 | // Hold a wake lock until the power key is released. |
| 1317 | if (!mPowerKeyWakeLock.isHeld()) { |
| 1318 | mPowerKeyWakeLock.acquire(); |
| 1319 | } |
| 1320 | |
| 1321 | // Cancel multi-press detection timeout. |
| 1322 | if (mPowerKeyPressCounter != 0) { |
| 1323 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 1324 | } |
| 1325 | |
| 1326 | // Detect user pressing the power button in panic when an application has |
| 1327 | // taken over the whole screen. |
| 1328 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
Adrian Roos | 7aaa551 | 2016-07-12 15:27:24 -0700 | [diff] [blame] | 1329 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags), |
| 1330 | isNavBarEmpty(mLastSystemUiFlags)); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1331 | if (panic) { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 1332 | mHandler.post(mHiddenNavPanic); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 1335 | // Abort possibly stuck animations. |
| 1336 | mHandler.post(mWindowManagerFuncs::triggerAnimationFailsafe); |
| 1337 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1338 | // Latch power key state to detect screenshot chord. |
| 1339 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 1340 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 1341 | mScreenshotChordPowerKeyTriggered = true; |
| 1342 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 1343 | interceptScreenshotChord(); |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 1344 | interceptRingerToggleChord(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | // Stop ringing or end call if configured to do so when power is pressed. |
| 1348 | TelecomManager telecomManager = getTelecommService(); |
| 1349 | boolean hungUp = false; |
| 1350 | if (telecomManager != null) { |
| 1351 | if (telecomManager.isRinging()) { |
| 1352 | // Pressing Power while there's a ringing incoming |
| 1353 | // call should silence the ringer. |
| 1354 | telecomManager.silenceRinger(); |
| 1355 | } else if ((mIncallPowerBehavior |
| 1356 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 1357 | && telecomManager.isInCall() && interactive) { |
| 1358 | // Otherwise, if "Power button ends call" is enabled, |
| 1359 | // the Power button will hang up any current active call. |
| 1360 | hungUp = telecomManager.endCall(); |
| 1361 | } |
| 1362 | } |
| 1363 | |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1364 | GestureLauncherService gestureService = LocalServices.getService( |
| 1365 | GestureLauncherService.class); |
| 1366 | boolean gesturedServiceIntercepted = false; |
| 1367 | if (gestureService != null) { |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 1368 | gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive, |
| 1369 | mTmpBoolean); |
Selim Cinek | ab55ba5 | 2017-08-02 16:45:51 -0700 | [diff] [blame] | 1370 | if (mTmpBoolean.value && mRequestedOrGoingToSleep) { |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 1371 | mCameraGestureTriggeredDuringGoingToSleep = true; |
| 1372 | } |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1373 | } |
| 1374 | |
Philip Quinn | c3a503d | 2017-07-18 23:23:41 -0700 | [diff] [blame] | 1375 | // Inform the StatusBar; but do not allow it to consume the event. |
Philip Quinn | 4b5b3c6 | 2017-07-20 21:07:58 -0700 | [diff] [blame] | 1376 | sendSystemKeyToStatusBarAsync(event.getKeyCode()); |
Philip Quinn | c3a503d | 2017-07-18 23:23:41 -0700 | [diff] [blame] | 1377 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1378 | // If the power key has still not yet been handled, then detect short |
| 1379 | // press, long press, or multi press and decide what to do. |
| 1380 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1381 | || mA11yShortcutChordVolumeUpKeyTriggered || gesturedServiceIntercepted; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1382 | if (!mPowerKeyHandled) { |
| 1383 | if (interactive) { |
| 1384 | // When interactive, we're already awake. |
| 1385 | // Wait for a long press or for the button to be released to decide what to do. |
| 1386 | if (hasLongPressOnPowerBehavior()) { |
Erik Wolsheimer | 6e02984 | 2018-02-13 11:34:00 -0800 | [diff] [blame] | 1387 | if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 1388 | powerLongPress(); |
| 1389 | } else { |
| 1390 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 1391 | msg.setAsynchronous(true); |
| 1392 | mHandler.sendMessageDelayed(msg, |
| 1393 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 1394 | |
Erik Wolsheimer | 6e02984 | 2018-02-13 11:34:00 -0800 | [diff] [blame] | 1395 | if (hasVeryLongPressOnPowerBehavior()) { |
| 1396 | Message longMsg = mHandler.obtainMessage(MSG_POWER_VERY_LONG_PRESS); |
| 1397 | longMsg.setAsynchronous(true); |
| 1398 | mHandler.sendMessageDelayed(longMsg, mVeryLongPressTimeout); |
| 1399 | } |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 1400 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1401 | } |
| 1402 | } else { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1403 | wakeUpFromPowerKey(event.getDownTime()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1404 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1405 | if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { |
Erik Wolsheimer | 6e02984 | 2018-02-13 11:34:00 -0800 | [diff] [blame] | 1406 | if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 1407 | powerLongPress(); |
| 1408 | } else { |
| 1409 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 1410 | msg.setAsynchronous(true); |
| 1411 | mHandler.sendMessageDelayed(msg, |
| 1412 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 1413 | |
Erik Wolsheimer | 6e02984 | 2018-02-13 11:34:00 -0800 | [diff] [blame] | 1414 | if (hasVeryLongPressOnPowerBehavior()) { |
| 1415 | Message longMsg = mHandler.obtainMessage(MSG_POWER_VERY_LONG_PRESS); |
| 1416 | longMsg.setAsynchronous(true); |
| 1417 | mHandler.sendMessageDelayed(longMsg, mVeryLongPressTimeout); |
| 1418 | } |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 1419 | } |
| 1420 | |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1421 | mBeganFromNonInteractive = true; |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1422 | } else { |
| 1423 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1424 | |
| 1425 | if (maxCount <= 1) { |
| 1426 | mPowerKeyHandled = true; |
| 1427 | } else { |
| 1428 | mBeganFromNonInteractive = true; |
| 1429 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1430 | } |
| 1431 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1432 | } |
| 1433 | } |
| 1434 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1435 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 1436 | final boolean handled = canceled || mPowerKeyHandled; |
| 1437 | mScreenshotChordPowerKeyTriggered = false; |
| 1438 | cancelPendingScreenshotChordAction(); |
| 1439 | cancelPendingPowerKeyAction(); |
| 1440 | |
| 1441 | if (!handled) { |
| 1442 | // Figure out how to handle the key now that it has been released. |
| 1443 | mPowerKeyPressCounter += 1; |
| 1444 | |
| 1445 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1446 | final long eventTime = event.getDownTime(); |
| 1447 | if (mPowerKeyPressCounter < maxCount) { |
| 1448 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 1449 | // Continue holding the wake lock. |
| 1450 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 1451 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 1452 | msg.setAsynchronous(true); |
Alain Vongsouvanh | 0f63a54 | 2017-04-10 17:13:17 -0700 | [diff] [blame] | 1453 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getMultiPressTimeout()); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1454 | return; |
| 1455 | } |
| 1456 | |
| 1457 | // No other actions. Handle it immediately. |
| 1458 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1459 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1460 | |
| 1461 | // Done. Reset our state. |
| 1462 | finishPowerKeyPress(); |
| 1463 | } |
| 1464 | |
| 1465 | private void finishPowerKeyPress() { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1466 | mBeganFromNonInteractive = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1467 | mPowerKeyPressCounter = 0; |
| 1468 | if (mPowerKeyWakeLock.isHeld()) { |
| 1469 | mPowerKeyWakeLock.release(); |
| 1470 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | private void cancelPendingPowerKeyAction() { |
| 1474 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1475 | mPowerKeyHandled = true; |
| 1476 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1477 | } |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 1478 | if (hasVeryLongPressOnPowerBehavior()) { |
| 1479 | mHandler.removeMessages(MSG_POWER_VERY_LONG_PRESS); |
| 1480 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1481 | } |
| 1482 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1483 | private void cancelPendingBackKeyAction() { |
| 1484 | if (!mBackKeyHandled) { |
| 1485 | mBackKeyHandled = true; |
| 1486 | mHandler.removeMessages(MSG_BACK_LONG_PRESS); |
| 1487 | } |
| 1488 | } |
| 1489 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1490 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 1491 | if (mScreenOnEarly && !mScreenOnFully) { |
| 1492 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 1493 | + "already in the process of turning the screen on."); |
| 1494 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 1495 | } |
Siarhei Vishniakou | bd8c29c | 2018-03-05 20:43:23 -0800 | [diff] [blame] | 1496 | Slog.d(TAG, "powerPress: eventTime=" + eventTime + " interactive=" + interactive |
| 1497 | + " count=" + count + " beganFromNonInteractive=" + mBeganFromNonInteractive + |
| 1498 | " mShortPressOnPowerBehavior=" + mShortPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1499 | |
| 1500 | if (count == 2) { |
| 1501 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 1502 | } else if (count == 3) { |
| 1503 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1504 | } else if (interactive && !mBeganFromNonInteractive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1505 | switch (mShortPressOnPowerBehavior) { |
| 1506 | case SHORT_PRESS_POWER_NOTHING: |
| 1507 | break; |
| 1508 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
Selim Cinek | ab55ba5 | 2017-08-02 16:45:51 -0700 | [diff] [blame] | 1509 | goToSleep(eventTime, PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1510 | break; |
| 1511 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
Selim Cinek | ab55ba5 | 2017-08-02 16:45:51 -0700 | [diff] [blame] | 1512 | goToSleep(eventTime, PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1513 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1514 | break; |
| 1515 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
Selim Cinek | ab55ba5 | 2017-08-02 16:45:51 -0700 | [diff] [blame] | 1516 | goToSleep(eventTime, PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1517 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1518 | launchHomeFromHotKey(); |
| 1519 | break; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1520 | case SHORT_PRESS_POWER_GO_HOME: |
Andrew Zeng | b4045d3 | 2017-03-16 17:25:07 -0700 | [diff] [blame] | 1521 | shortPressPowerGoHome(); |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1522 | break; |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 1523 | case SHORT_PRESS_POWER_CLOSE_IME_OR_GO_HOME: { |
Yohei Yukawa | abbe1ac | 2017-04-18 09:43:05 -0700 | [diff] [blame] | 1524 | if (mDismissImeOnBackKeyPressed) { |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 1525 | if (mInputMethodManagerInternal == null) { |
| 1526 | mInputMethodManagerInternal = |
| 1527 | LocalServices.getService(InputMethodManagerInternal.class); |
| 1528 | } |
| 1529 | if (mInputMethodManagerInternal != null) { |
| 1530 | mInputMethodManagerInternal.hideCurrentInputMethod(); |
| 1531 | } |
| 1532 | } else { |
Andrew Zeng | b4045d3 | 2017-03-16 17:25:07 -0700 | [diff] [blame] | 1533 | shortPressPowerGoHome(); |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 1534 | } |
| 1535 | break; |
| 1536 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1537 | } |
| 1538 | } |
| 1539 | } |
| 1540 | |
Selim Cinek | ab55ba5 | 2017-08-02 16:45:51 -0700 | [diff] [blame] | 1541 | private void goToSleep(long eventTime, int reason, int flags) { |
| 1542 | mRequestedOrGoingToSleep = true; |
| 1543 | mPowerManager.goToSleep(eventTime, reason, flags); |
| 1544 | } |
| 1545 | |
Andrew Zeng | b4045d3 | 2017-03-16 17:25:07 -0700 | [diff] [blame] | 1546 | private void shortPressPowerGoHome() { |
| 1547 | launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/); |
| 1548 | if (isKeyguardShowingAndNotOccluded()) { |
| 1549 | // Notify keyguard so it can do any special handling for the power button since the |
| 1550 | // device will not power off and only launch home. |
| 1551 | mKeyguardDelegate.onShortPowerPressedGoHome(); |
| 1552 | } |
| 1553 | } |
| 1554 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1555 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 1556 | switch (behavior) { |
| 1557 | case MULTI_PRESS_POWER_NOTHING: |
| 1558 | break; |
| 1559 | case MULTI_PRESS_POWER_THEATER_MODE: |
Bryce Lee | 3ae447e | 2015-06-30 12:31:41 -0700 | [diff] [blame] | 1560 | if (!isUserSetupComplete()) { |
| 1561 | Slog.i(TAG, "Ignoring toggling theater mode - device not setup."); |
| 1562 | break; |
| 1563 | } |
| 1564 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1565 | if (isTheaterModeEnabled()) { |
| 1566 | Slog.i(TAG, "Toggling theater mode off."); |
| 1567 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1568 | Settings.Global.THEATER_MODE_ON, 0); |
| 1569 | if (!interactive) { |
| 1570 | wakeUpFromPowerKey(eventTime); |
| 1571 | } |
| 1572 | } else { |
| 1573 | Slog.i(TAG, "Toggling theater mode on."); |
| 1574 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1575 | Settings.Global.THEATER_MODE_ON, 1); |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1576 | |
| 1577 | if (mGoToSleepOnButtonPressTheaterMode && interactive) { |
Selim Cinek | ab55ba5 | 2017-08-02 16:45:51 -0700 | [diff] [blame] | 1578 | goToSleep(eventTime, PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1579 | } |
| 1580 | } |
| 1581 | break; |
| 1582 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
Jeff Brown | 7b5be5e | 2014-11-12 18:45:31 -0800 | [diff] [blame] | 1583 | Slog.i(TAG, "Starting brightness boost."); |
| 1584 | if (!interactive) { |
| 1585 | wakeUpFromPowerKey(eventTime); |
| 1586 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1587 | mPowerManager.boostScreenBrightness(eventTime); |
| 1588 | break; |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | private int getMaxMultiPressPowerCount() { |
| 1593 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1594 | return 3; |
| 1595 | } |
| 1596 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1597 | return 2; |
| 1598 | } |
| 1599 | return 1; |
| 1600 | } |
| 1601 | |
| 1602 | private void powerLongPress() { |
| 1603 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1604 | switch (behavior) { |
| 1605 | case LONG_PRESS_POWER_NOTHING: |
| 1606 | break; |
| 1607 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1608 | mPowerKeyHandled = true; |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1609 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1610 | showGlobalActionsInternal(); |
| 1611 | break; |
| 1612 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1613 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1614 | mPowerKeyHandled = true; |
| 1615 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1616 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1617 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1618 | break; |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 1619 | case LONG_PRESS_POWER_GO_TO_VOICE_ASSIST: |
| 1620 | mPowerKeyHandled = true; |
| 1621 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1622 | final boolean keyguardActive = mKeyguardDelegate == null |
| 1623 | ? false |
| 1624 | : mKeyguardDelegate.isShowing(); |
| 1625 | if (!keyguardActive) { |
| 1626 | Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST); |
Michael Kwan | 7f17169 | 2018-04-04 14:00:53 -0700 | [diff] [blame] | 1627 | if (mAllowStartActivityForLongPressOnPowerDuringSetup) { |
| 1628 | mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
| 1629 | } else { |
| 1630 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
| 1631 | } |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 1632 | } |
| 1633 | break; |
| 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | private void powerVeryLongPress() { |
| 1638 | switch (mVeryLongPressOnPowerBehavior) { |
| 1639 | case VERY_LONG_PRESS_POWER_NOTHING: |
| 1640 | break; |
| 1641 | case VERY_LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1642 | mPowerKeyHandled = true; |
| 1643 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1644 | showGlobalActionsInternal(); |
| 1645 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1646 | } |
| 1647 | } |
| 1648 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1649 | private void backLongPress() { |
| 1650 | mBackKeyHandled = true; |
| 1651 | |
| 1652 | switch (mLongPressOnBackBehavior) { |
| 1653 | case LONG_PRESS_BACK_NOTHING: |
| 1654 | break; |
| 1655 | case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST: |
Nancy Zheng | 0d85ee2 | 2016-09-29 09:15:56 -0700 | [diff] [blame] | 1656 | final boolean keyguardActive = mKeyguardDelegate == null |
| 1657 | ? false |
| 1658 | : mKeyguardDelegate.isShowing(); |
| 1659 | if (!keyguardActive) { |
| 1660 | Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST); |
| 1661 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
| 1662 | } |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1663 | break; |
| 1664 | } |
| 1665 | } |
| 1666 | |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1667 | private void accessibilityShortcutActivated() { |
| 1668 | mAccessibilityShortcutController.performAccessibilityShortcut(); |
| 1669 | } |
| 1670 | |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 1671 | private void disposeInputConsumer(InputConsumer inputConsumer) { |
| 1672 | if (inputConsumer != null) { |
| 1673 | inputConsumer.dismiss(); |
| 1674 | } |
| 1675 | } |
| 1676 | |
Siarhei Vishniakou | 191cf1b | 2017-08-17 16:17:22 -0700 | [diff] [blame] | 1677 | private void sleepPress() { |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1678 | if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) { |
| 1679 | launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | private void sleepRelease(long eventTime) { |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1684 | switch (mShortPressOnSleepBehavior) { |
| 1685 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1686 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1687 | Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)"); |
Selim Cinek | ab55ba5 | 2017-08-02 16:45:51 -0700 | [diff] [blame] | 1688 | goToSleep(eventTime, PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1689 | break; |
| 1690 | } |
| 1691 | } |
| 1692 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1693 | private int getResolvedLongPressOnPowerBehavior() { |
| 1694 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1695 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1696 | } |
| 1697 | return mLongPressOnPowerBehavior; |
| 1698 | } |
| 1699 | |
| 1700 | private boolean hasLongPressOnPowerBehavior() { |
| 1701 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 1704 | private boolean hasVeryLongPressOnPowerBehavior() { |
| 1705 | return mVeryLongPressOnPowerBehavior != VERY_LONG_PRESS_POWER_NOTHING; |
| 1706 | } |
| 1707 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1708 | private boolean hasLongPressOnBackBehavior() { |
| 1709 | return mLongPressOnBackBehavior != LONG_PRESS_BACK_NOTHING; |
| 1710 | } |
| 1711 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1712 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1713 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1714 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1715 | && !mA11yShortcutChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1716 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1717 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1718 | && now <= mScreenshotChordPowerKeyTime |
| 1719 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1720 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1721 | cancelPendingPowerKeyAction(); |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1722 | mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN); |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1723 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1724 | } |
| 1725 | } |
| 1726 | } |
| 1727 | |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1728 | private void interceptAccessibilityShortcutChord() { |
Phil Weaver | ce687c5 | 2017-03-15 08:51:52 -0700 | [diff] [blame] | 1729 | if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(isKeyguardLocked()) |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1730 | && mScreenshotChordVolumeDownKeyTriggered && mA11yShortcutChordVolumeUpKeyTriggered |
| 1731 | && !mScreenshotChordPowerKeyTriggered) { |
| 1732 | final long now = SystemClock.uptimeMillis(); |
| 1733 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1734 | && now <= mA11yShortcutChordVolumeUpKeyTime |
| 1735 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1736 | mScreenshotChordVolumeDownKeyConsumed = true; |
| 1737 | mA11yShortcutChordVolumeUpKeyConsumed = true; |
| 1738 | mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_ACCESSIBILITY_SHORTCUT), |
Eugene Susla | 5f19cd3 | 2017-10-19 14:00:59 -0700 | [diff] [blame] | 1739 | getAccessibilityShortcutTimeout()); |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1740 | } |
| 1741 | } |
| 1742 | } |
| 1743 | |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 1744 | private void interceptRingerToggleChord() { |
| 1745 | if (mRingerToggleChord != Settings.Secure.VOLUME_HUSH_OFF |
| 1746 | && mScreenshotChordPowerKeyTriggered && mA11yShortcutChordVolumeUpKeyTriggered) { |
| 1747 | final long now = SystemClock.uptimeMillis(); |
| 1748 | if (now <= mA11yShortcutChordVolumeUpKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1749 | && now <= mScreenshotChordPowerKeyTime |
| 1750 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1751 | mA11yShortcutChordVolumeUpKeyConsumed = true; |
| 1752 | cancelPendingPowerKeyAction(); |
| 1753 | |
| 1754 | mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_RINGER_TOGGLE_CHORD), |
| 1755 | getRingerToggleChordDelay()); |
| 1756 | } |
| 1757 | } |
| 1758 | } |
| 1759 | |
Eugene Susla | 5f19cd3 | 2017-10-19 14:00:59 -0700 | [diff] [blame] | 1760 | private long getAccessibilityShortcutTimeout() { |
| 1761 | ViewConfiguration config = ViewConfiguration.get(mContext); |
Phil Weaver | 8b78ddfd | 2017-11-07 16:39:19 -0800 | [diff] [blame] | 1762 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1763 | Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, 0, mCurrentUserId) == 0 |
| 1764 | ? config.getAccessibilityShortcutKeyTimeout() |
| 1765 | : config.getAccessibilityShortcutKeyTimeoutAfterConfirmation(); |
Eugene Susla | 5f19cd3 | 2017-10-19 14:00:59 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1768 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1769 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1770 | // Double the time it takes to take a screenshot from the keyguard |
| 1771 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1772 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1773 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1774 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 1777 | private long getRingerToggleChordDelay() { |
| 1778 | // Always timeout like a tap |
| 1779 | return ViewConfiguration.getTapTimeout(); |
| 1780 | } |
| 1781 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1782 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1783 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1786 | private void cancelPendingAccessibilityShortcutAction() { |
| 1787 | mHandler.removeMessages(MSG_ACCESSIBILITY_SHORTCUT); |
| 1788 | } |
| 1789 | |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 1790 | private void cancelPendingRingerToggleChordAction() { |
| 1791 | mHandler.removeMessages(MSG_RINGER_TOGGLE_CHORD); |
| 1792 | } |
| 1793 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1794 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1795 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1796 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1797 | mEndCallKeyHandled = true; |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1798 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1799 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1800 | } |
| 1801 | }; |
| 1802 | |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1803 | private class ScreenshotRunnable implements Runnable { |
| 1804 | private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN; |
| 1805 | |
| 1806 | public void setScreenshotType(int screenshotType) { |
| 1807 | mScreenshotType = screenshotType; |
| 1808 | } |
| 1809 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1810 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1811 | public void run() { |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 1812 | mScreenshotHelper.takeScreenshot(mScreenshotType, |
| 1813 | mStatusBar != null && mStatusBar.isVisibleLw(), |
| 1814 | mNavigationBar != null && mNavigationBar.isVisibleLw(), mHandler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1815 | } |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1819 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1820 | @Override |
| 1821 | public void showGlobalActions() { |
| 1822 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1823 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1824 | } |
| 1825 | |
| 1826 | void showGlobalActionsInternal() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1827 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1828 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1829 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1830 | final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1831 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1832 | if (keyguardShowing) { |
| 1833 | // since it took two seconds of long press to bring this up, |
| 1834 | // poke the wake lock so they have some time to see the dialog. |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1835 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1840 | return Settings.Global.getInt( |
| 1841 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1842 | } |
| 1843 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1844 | boolean isUserSetupComplete() { |
Sujith Ramakrishnan | 0390fff | 2017-06-08 18:18:12 -0700 | [diff] [blame] | 1845 | boolean isSetupComplete = Settings.Secure.getIntForUser(mContext.getContentResolver(), |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1846 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
Sujith Ramakrishnan | 0390fff | 2017-06-08 18:18:12 -0700 | [diff] [blame] | 1847 | if (mHasFeatureLeanback) { |
| 1848 | isSetupComplete &= isTvUserSetupComplete(); |
| 1849 | } |
| 1850 | return isSetupComplete; |
| 1851 | } |
| 1852 | |
| 1853 | private boolean isTvUserSetupComplete() { |
| 1854 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1855 | Settings.Secure.TV_USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1856 | } |
| 1857 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1858 | private void handleShortPressOnHome() { |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1859 | // Turn on the connected TV and switch HDMI input if we're a HDMI playback device. |
Andrii Kulian | eb4a794 | 2016-12-21 12:18:05 -0800 | [diff] [blame] | 1860 | final HdmiControl hdmiControl = getHdmiControl(); |
| 1861 | if (hdmiControl != null) { |
| 1862 | hdmiControl.turnOnTv(); |
| 1863 | } |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1864 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1865 | // If there's a dream running then use home to escape the dream |
| 1866 | // but don't actually go home. |
| 1867 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1868 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1869 | return; |
| 1870 | } |
| 1871 | |
| 1872 | // Go home! |
| 1873 | launchHomeFromHotKey(); |
| 1874 | } |
| 1875 | |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1876 | /** |
| 1877 | * Creates an accessor to HDMI control service that performs the operation of |
| 1878 | * turning on TV (optional) and switching input to us. If HDMI control service |
| 1879 | * is not available or we're not a HDMI playback device, the operation is no-op. |
Andrii Kulian | eb4a794 | 2016-12-21 12:18:05 -0800 | [diff] [blame] | 1880 | * @return {@link HdmiControl} instance if available, null otherwise. |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1881 | */ |
| 1882 | private HdmiControl getHdmiControl() { |
| 1883 | if (null == mHdmiControl) { |
Andrii Kulian | eb4a794 | 2016-12-21 12:18:05 -0800 | [diff] [blame] | 1884 | if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) { |
| 1885 | return null; |
| 1886 | } |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1887 | HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService( |
| 1888 | Context.HDMI_CONTROL_SERVICE); |
| 1889 | HdmiPlaybackClient client = null; |
| 1890 | if (manager != null) { |
| 1891 | client = manager.getPlaybackClient(); |
| 1892 | } |
| 1893 | mHdmiControl = new HdmiControl(client); |
| 1894 | } |
| 1895 | return mHdmiControl; |
| 1896 | } |
| 1897 | |
| 1898 | private static class HdmiControl { |
| 1899 | private final HdmiPlaybackClient mClient; |
| 1900 | |
| 1901 | private HdmiControl(HdmiPlaybackClient client) { |
| 1902 | mClient = client; |
| 1903 | } |
| 1904 | |
| 1905 | public void turnOnTv() { |
| 1906 | if (mClient == null) { |
| 1907 | return; |
| 1908 | } |
| 1909 | mClient.oneTouchPlay(new OneTouchPlayCallback() { |
| 1910 | @Override |
| 1911 | public void onComplete(int result) { |
| 1912 | if (result != HdmiControlManager.RESULT_SUCCESS) { |
| 1913 | Log.w(TAG, "One touch play failed: " + result); |
| 1914 | } |
| 1915 | } |
| 1916 | }); |
| 1917 | } |
| 1918 | } |
| 1919 | |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 1920 | private void handleLongPressOnHome(int deviceId) { |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1921 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) { |
| 1922 | return; |
| 1923 | } |
| 1924 | mHomeConsumed = true; |
| 1925 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1926 | switch (mLongPressOnHomeBehavior) { |
Sid Soundararajan | ff662fa | 2017-03-15 16:24:24 -0700 | [diff] [blame] | 1927 | case LONG_PRESS_HOME_ALL_APPS: |
| 1928 | launchAllAppsAction(); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1929 | break; |
| 1930 | case LONG_PRESS_HOME_ASSIST: |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 1931 | launchAssistAction(null, deviceId); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1932 | break; |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1933 | default: |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 1934 | Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1935 | break; |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1936 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1937 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1938 | |
Sid Soundararajan | ff662fa | 2017-03-15 16:24:24 -0700 | [diff] [blame] | 1939 | private void launchAllAppsAction() { |
| 1940 | Intent intent = new Intent(Intent.ACTION_ALL_APPS); |
Sujith Ramakrishnan | f8942c0 | 2017-07-18 18:35:14 -0700 | [diff] [blame] | 1941 | if (mHasFeatureLeanback) { |
| 1942 | final PackageManager pm = mContext.getPackageManager(); |
| 1943 | Intent intentLauncher = new Intent(Intent.ACTION_MAIN); |
| 1944 | intentLauncher.addCategory(Intent.CATEGORY_HOME); |
| 1945 | ResolveInfo resolveInfo = pm.resolveActivityAsUser(intentLauncher, |
| 1946 | PackageManager.MATCH_SYSTEM_ONLY, |
| 1947 | mCurrentUserId); |
| 1948 | if (resolveInfo != null) { |
| 1949 | intent.setPackage(resolveInfo.activityInfo.packageName); |
| 1950 | } |
| 1951 | } |
Sid Soundararajan | ff662fa | 2017-03-15 16:24:24 -0700 | [diff] [blame] | 1952 | startActivityAsUser(intent, UserHandle.CURRENT); |
| 1953 | } |
| 1954 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1955 | private void handleDoubleTapOnHome() { |
| 1956 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1957 | mHomeConsumed = true; |
| 1958 | toggleRecentApps(); |
| 1959 | } |
| 1960 | } |
| 1961 | |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 1962 | private void showPictureInPictureMenu(KeyEvent event) { |
| 1963 | if (DEBUG_INPUT) Log.d(TAG, "showPictureInPictureMenu event=" + event); |
| 1964 | mHandler.removeMessages(MSG_SHOW_PICTURE_IN_PICTURE_MENU); |
| 1965 | Message msg = mHandler.obtainMessage(MSG_SHOW_PICTURE_IN_PICTURE_MENU); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1966 | msg.setAsynchronous(true); |
| 1967 | msg.sendToTarget(); |
| 1968 | } |
| 1969 | |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 1970 | private void showPictureInPictureMenuInternal() { |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 1971 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 1972 | if (statusbar != null) { |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 1973 | statusbar.showPictureInPictureMenu(); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1974 | } |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1975 | } |
| 1976 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1977 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1978 | @Override |
| 1979 | public void run() { |
| 1980 | if (mHomeDoubleTapPending) { |
| 1981 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1982 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1983 | } |
| 1984 | } |
| 1985 | }; |
| 1986 | |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1987 | private boolean isRoundWindow() { |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1988 | return mContext.getResources().getConfiguration().isScreenRound(); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1989 | } |
| 1990 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1991 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1992 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1993 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1994 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1995 | mContext = context; |
| 1996 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1997 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1998 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 1999 | mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 2000 | mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2001 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 2002 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2003 | mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 2004 | mHasFeatureWatch = mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH); |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 2005 | mHasFeatureLeanback = mContext.getPackageManager().hasSystemFeature(FEATURE_LEANBACK); |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 2006 | mAccessibilityShortcutController = |
Phil Weaver | ce687c5 | 2017-03-15 08:51:52 -0700 | [diff] [blame] | 2007 | new AccessibilityShortcutController(mContext, new Handler(), mCurrentUserId); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 2008 | // Init display burn-in protection |
| 2009 | boolean burnInProtectionEnabled = context.getResources().getBoolean( |
| 2010 | com.android.internal.R.bool.config_enableBurnInProtection); |
| 2011 | // Allow a system property to override this. Used by developer settings. |
| 2012 | boolean burnInProtectionDevMode = |
| 2013 | SystemProperties.getBoolean("persist.debug.force_burn_in", false); |
| 2014 | if (burnInProtectionEnabled || burnInProtectionDevMode) { |
| 2015 | final int minHorizontal; |
| 2016 | final int maxHorizontal; |
| 2017 | final int minVertical; |
| 2018 | final int maxVertical; |
| 2019 | final int maxRadius; |
| 2020 | if (burnInProtectionDevMode) { |
| 2021 | minHorizontal = -8; |
| 2022 | maxHorizontal = 8; |
| 2023 | minVertical = -8; |
| 2024 | maxVertical = -4; |
| 2025 | maxRadius = (isRoundWindow()) ? 6 : -1; |
| 2026 | } else { |
| 2027 | Resources resources = context.getResources(); |
| 2028 | minHorizontal = resources.getInteger( |
| 2029 | com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); |
| 2030 | maxHorizontal = resources.getInteger( |
| 2031 | com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); |
| 2032 | minVertical = resources.getInteger( |
| 2033 | com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); |
| 2034 | maxVertical = resources.getInteger( |
| 2035 | com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); |
| 2036 | maxRadius = resources.getInteger( |
| 2037 | com.android.internal.R.integer.config_burnInProtectionMaxRadius); |
| 2038 | } |
| 2039 | mBurnInProtectionHelper = new BurnInProtectionHelper( |
| 2040 | context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 2041 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 2042 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2043 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 2044 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 2045 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 2046 | try { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 2047 | mOrientationListener.setCurrentRotation(windowManager.getDefaultDisplayRotation()); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 2048 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2049 | mSettingsObserver = new SettingsObserver(mHandler); |
| 2050 | mSettingsObserver.observe(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2051 | mShortcutManager = new ShortcutManager(context); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 2052 | mUiMode = context.getResources().getInteger( |
| 2053 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2054 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 2055 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 2056 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2057 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 2058 | mEnableCarDockHomeCapture = context.getResources().getBoolean( |
| 2059 | com.android.internal.R.bool.config_enableCarDockHomeLaunch); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2060 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 2061 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 2062 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2063 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 2064 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 2065 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 2066 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2067 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Zak Cohen | db6ca49 | 2017-01-26 14:09:00 -0800 | [diff] [blame] | 2068 | mVrHeadsetHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 2069 | mVrHeadsetHomeIntent.addCategory(Intent.CATEGORY_VR_HOME); |
| 2070 | mVrHeadsetHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2071 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 2072 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 2073 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 2074 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2075 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2076 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 2077 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2078 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 2079 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 2080 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2081 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2082 | com.android.internal.R.integer.config_lidOpenRotation); |
| 2083 | mCarDockRotation = readRotation( |
| 2084 | com.android.internal.R.integer.config_carDockRotation); |
| 2085 | mDeskDockRotation = readRotation( |
| 2086 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 2087 | mUndockedHdmiRotation = readRotation( |
| 2088 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 2089 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 2090 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 2091 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 2092 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2093 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 2094 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 2095 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 2096 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 2097 | mLidControlsScreenLock = mContext.getResources().getBoolean( |
| 2098 | com.android.internal.R.bool.config_lidControlsScreenLock); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 2099 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 2100 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 2101 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 2102 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 2103 | |
| 2104 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 2105 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 2106 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 2107 | || mContext.getResources().getBoolean( |
| 2108 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 2109 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 2110 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 2111 | mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( |
| 2112 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 2113 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 2114 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 2115 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 2116 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 2117 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 2118 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 2119 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 2120 | mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( |
| 2121 | com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); |
| 2122 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 2123 | mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( |
| 2124 | com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); |
| 2125 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 2126 | mLongPressOnBackBehavior = mContext.getResources().getInteger( |
| 2127 | com.android.internal.R.integer.config_longPressOnBackBehavior); |
| 2128 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2129 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 2130 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 2131 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 2132 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 2133 | mVeryLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 2134 | com.android.internal.R.integer.config_veryLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2135 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 2136 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 2137 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 2138 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 2139 | mShortPressOnSleepBehavior = mContext.getResources().getInteger( |
| 2140 | com.android.internal.R.integer.config_shortPressOnSleepBehavior); |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 2141 | mVeryLongPressTimeout = mContext.getResources().getInteger( |
| 2142 | com.android.internal.R.integer.config_veryLongPressTimeout); |
Michael Kwan | 7f17169 | 2018-04-04 14:00:53 -0700 | [diff] [blame] | 2143 | mAllowStartActivityForLongPressOnPowerDuringSetup = mContext.getResources().getBoolean( |
| 2144 | com.android.internal.R.bool.config_allowStartActivityForLongPressOnPowerInSetup); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2145 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 2146 | mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 2147 | |
Karthik Ravi Shankar | 86ecf34 | 2017-04-28 15:35:58 -0700 | [diff] [blame] | 2148 | mHandleVolumeKeysInWM = mContext.getResources().getBoolean( |
| 2149 | com.android.internal.R.bool.config_handleVolumeKeysInWindowManager); |
| 2150 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2151 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2152 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 2153 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 2154 | Context.ACCESSIBILITY_SERVICE); |
| 2155 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2156 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 2157 | IntentFilter filter = new IntentFilter(); |
| 2158 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 2159 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 2160 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 2161 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2162 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 2163 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 2164 | if (intent != null) { |
| 2165 | // Retrieve current sticky dock event broadcast. |
| 2166 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 2167 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 2168 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 2169 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 2170 | // register for dream-related broadcasts |
| 2171 | filter = new IntentFilter(); |
| 2172 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 2173 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 2174 | context.registerReceiver(mDreamReceiver, filter); |
| 2175 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2176 | // register for multiuser-relevant broadcasts |
| 2177 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 2178 | context.registerReceiver(mMultiuserReceiver, filter); |
| 2179 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 2180 | // monitor for system gestures |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2181 | // TODO(multi-display): Needs to be display specific. |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 2182 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 2183 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 2184 | @Override |
| 2185 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2186 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2187 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2188 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2189 | } |
| 2190 | @Override |
| 2191 | public void onSwipeFromBottom() { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 2192 | if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_BOTTOM) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2193 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2194 | } |
| 2195 | } |
| 2196 | @Override |
| 2197 | public void onSwipeFromRight() { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 2198 | if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_RIGHT) { |
| 2199 | requestTransientBars(mNavigationBar); |
| 2200 | } |
| 2201 | } |
| 2202 | @Override |
| 2203 | public void onSwipeFromLeft() { |
| 2204 | if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_LEFT) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2205 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2206 | } |
| 2207 | } |
| 2208 | @Override |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 2209 | public void onFling(int duration) { |
| 2210 | if (mPowerManagerInternal != null) { |
| 2211 | mPowerManagerInternal.powerHint( |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 2212 | PowerHint.INTERACTION, duration); |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 2213 | } |
| 2214 | } |
| 2215 | @Override |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2216 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 2217 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2218 | } |
Adrian Roos | 3595be4 | 2015-03-05 16:31:15 +0100 | [diff] [blame] | 2219 | @Override |
| 2220 | public void onDown() { |
| 2221 | mOrientationListener.onTouchStart(); |
| 2222 | } |
| 2223 | @Override |
| 2224 | public void onUpOrCancel() { |
| 2225 | mOrientationListener.onTouchEnd(); |
| 2226 | } |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 2227 | @Override |
| 2228 | public void onMouseHoverAtTop() { |
| 2229 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 2230 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 2231 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS; |
| 2232 | mHandler.sendMessageDelayed(msg, 500); |
| 2233 | } |
| 2234 | @Override |
| 2235 | public void onMouseHoverAtBottom() { |
| 2236 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 2237 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 2238 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION; |
| 2239 | mHandler.sendMessageDelayed(msg, 500); |
| 2240 | } |
| 2241 | @Override |
| 2242 | public void onMouseLeaveFromEdge() { |
| 2243 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 2244 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2245 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2246 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 2247 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 2248 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 2249 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2250 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 2251 | com.android.internal.R.array.config_longPressVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 2252 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 2253 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2254 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 2255 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 2256 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2257 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 2258 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 2259 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2260 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 2261 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 2262 | // Controls rotation and the like. |
| 2263 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 2264 | |
| 2265 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 2266 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 2267 | startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 2268 | finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 2269 | } |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 2270 | |
| 2271 | mWindowManagerInternal.registerAppTransitionListener( |
| 2272 | mStatusBarController.getAppTransitionListener()); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2273 | mWindowManagerInternal.registerAppTransitionListener(new AppTransitionListener() { |
| 2274 | @Override |
| 2275 | public int onAppTransitionStartingLocked(int transit, IBinder openToken, |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2276 | IBinder closeToken, long duration, long statusBarAnimationStartTime, |
| 2277 | long statusBarAnimationDuration) { |
| 2278 | return handleStartTransitionForKeyguardLw(transit, duration); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | @Override |
| 2282 | public void onAppTransitionCancelledLocked(int transit) { |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2283 | handleStartTransitionForKeyguardLw(transit, 0 /* duration */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2284 | } |
| 2285 | }); |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 2286 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext, |
| 2287 | new StateCallback() { |
| 2288 | @Override |
| 2289 | public void onTrustedChanged() { |
| 2290 | mWindowManagerFuncs.notifyKeyguardTrustedChanged(); |
| 2291 | } |
| 2292 | }); |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 2293 | mScreenshotHelper = new ScreenshotHelper(mContext); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2296 | /** |
| 2297 | * Read values from config.xml that may be overridden depending on |
| 2298 | * the configuration of the device. |
| 2299 | * eg. Disable long press on home goes to recents on sw600dp. |
| 2300 | */ |
| 2301 | private void readConfigurationDependentBehaviors() { |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 2302 | final Resources res = mContext.getResources(); |
| 2303 | |
| 2304 | mLongPressOnHomeBehavior = res.getInteger( |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2305 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 2306 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 2307 | mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) { |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2308 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 2309 | } |
| 2310 | |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 2311 | mDoubleTapOnHomeBehavior = res.getInteger( |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2312 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 2313 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 2314 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2315 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 2316 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 2317 | |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 2318 | mShortPressOnWindowBehavior = SHORT_PRESS_WINDOW_NOTHING; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 2319 | if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) { |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 2320 | mShortPressOnWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 2321 | } |
Yorke Lee | 2e4b732 | 2016-03-02 17:33:06 -0800 | [diff] [blame] | 2322 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 2323 | mNavBarOpacityMode = res.getInteger( |
| 2324 | com.android.internal.R.integer.config_navBarOpacityMode); |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 2327 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 2328 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 2329 | // This method might be called before the policy has been fully initialized |
| 2330 | // or for other displays we don't care about. |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 2331 | // TODO(multi-display): Define policy for secondary displays. |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 2332 | if (mContext == null || display.getDisplayId() != DEFAULT_DISPLAY) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 2333 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2334 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2335 | mDisplay = display; |
| 2336 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2337 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2338 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2339 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 2340 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2341 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2342 | mLandscapeRotation = Surface.ROTATION_0; |
| 2343 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2344 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2345 | mPortraitRotation = Surface.ROTATION_90; |
| 2346 | mUpsideDownRotation = Surface.ROTATION_270; |
| 2347 | } else { |
| 2348 | mPortraitRotation = Surface.ROTATION_270; |
| 2349 | mUpsideDownRotation = Surface.ROTATION_90; |
| 2350 | } |
| 2351 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 2352 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2353 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2354 | mPortraitRotation = Surface.ROTATION_0; |
| 2355 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2356 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2357 | mLandscapeRotation = Surface.ROTATION_270; |
| 2358 | mSeascapeRotation = Surface.ROTATION_90; |
| 2359 | } else { |
| 2360 | mLandscapeRotation = Surface.ROTATION_90; |
| 2361 | mSeascapeRotation = Surface.ROTATION_270; |
| 2362 | } |
| 2363 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 2364 | |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2365 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 2366 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2367 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2368 | |
Devin Kim | d7b12b4 | 2014-05-05 14:34:58 -0700 | [diff] [blame] | 2369 | // Allow the navigation bar to move on non-square small devices (phones). |
| 2370 | mNavigationBarCanMove = width != height && shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 2371 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2372 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2373 | |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2374 | // Allow a system property to override this. Used by the emulator. |
| 2375 | // See also hasNavigationBar(). |
| 2376 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 2377 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2378 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2379 | } else if ("0".equals(navBarOverride)) { |
| 2380 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 2381 | } |
| 2382 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 2383 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 2384 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 2385 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 2386 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 2387 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 2388 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 2389 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 2390 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2391 | |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 2392 | // For demo purposes, allow the rotation of the remote display to be controlled. |
| 2393 | // By default, remote display locks rotation to landscape. |
| 2394 | if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { |
| 2395 | mDemoRotation = mPortraitRotation; |
| 2396 | } else { |
| 2397 | mDemoRotation = mLandscapeRotation; |
| 2398 | } |
| 2399 | mDemoRotationLock = SystemProperties.getBoolean( |
| 2400 | "persist.demo.rotationlock", false); |
| 2401 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2402 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 2403 | // http://developer.android.com/guide/practices/screens_support.html#range |
Dean Harding | d12a804 | 2017-10-10 14:46:26 -0700 | [diff] [blame] | 2404 | // For car, ignore the dp limitation. It's physically impossible to rotate the car's screen |
| 2405 | // so if the orientation is forced, we need to respect that no matter what. |
Dake Gu | 9523121 | 2018-01-09 17:13:56 -0800 | [diff] [blame] | 2406 | final boolean isCar = mContext.getPackageManager().hasSystemFeature( |
Dean Harding | d12a804 | 2017-10-10 14:46:26 -0700 | [diff] [blame] | 2407 | PackageManager.FEATURE_AUTOMOTIVE); |
Dake Gu | 9523121 | 2018-01-09 17:13:56 -0800 | [diff] [blame] | 2408 | // For TV, it's usually 960dp x 540dp, ignore the size limitation. |
| 2409 | // so if the orientation is forced, we need to respect that no matter what. |
| 2410 | final boolean isTv = mContext.getPackageManager().hasSystemFeature( |
| 2411 | PackageManager.FEATURE_LEANBACK); |
| 2412 | mForceDefaultOrientation = ((longSizeDp >= 960 && shortSizeDp >= 720) || isCar || isTv) && |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2413 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 2414 | // For debug purposes the next line turns this feature off with: |
| 2415 | // $ adb shell setprop config.override_forced_orient true |
| 2416 | // $ adb shell wm size reset |
| 2417 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 2418 | } |
| 2419 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2420 | /** |
| 2421 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 2422 | * navigation bar and touch exploration is not enabled |
| 2423 | */ |
| 2424 | private boolean canHideNavigationBar() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 2425 | return mHasNavigationBar; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2426 | } |
| 2427 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2428 | @Override |
| 2429 | public boolean isDefaultOrientationForced() { |
| 2430 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2433 | public void updateSettings() { |
| 2434 | ContentResolver resolver = mContext.getContentResolver(); |
| 2435 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2436 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2437 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 2438 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2439 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 2440 | UserHandle.USER_CURRENT); |
| 2441 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 2442 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2443 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 2444 | UserHandle.USER_CURRENT); |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 2445 | mIncallBackBehavior = Settings.Secure.getIntForUser(resolver, |
| 2446 | Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR, |
| 2447 | Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_DEFAULT, |
| 2448 | UserHandle.USER_CURRENT); |
Siarhei Vishniakou | e5e0d9f | 2018-03-05 20:09:08 -0800 | [diff] [blame] | 2449 | mSystemNavigationKeysEnabled = Settings.Secure.getIntForUser(resolver, |
| 2450 | Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, |
| 2451 | 0, UserHandle.USER_CURRENT) == 1; |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 2452 | mRingerToggleChord = Settings.Secure.getIntForUser(resolver, |
| 2453 | Settings.Secure.VOLUME_HUSH_GESTURE, VOLUME_HUSH_OFF, |
| 2454 | UserHandle.USER_CURRENT); |
| 2455 | if (!mContext.getResources() |
| 2456 | .getBoolean(com.android.internal.R.bool.config_volumeHushGestureEnabled)) { |
| 2457 | mRingerToggleChord = Settings.Secure.VOLUME_HUSH_OFF; |
| 2458 | } |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 2459 | // Configure rotation suggestions. |
| 2460 | int showRotationSuggestions = Settings.Secure.getIntForUser(resolver, |
| 2461 | Settings.Secure.SHOW_ROTATION_SUGGESTIONS, |
| 2462 | Settings.Secure.SHOW_ROTATION_SUGGESTIONS_DEFAULT, |
| 2463 | UserHandle.USER_CURRENT); |
| 2464 | if (mShowRotationSuggestions != showRotationSuggestions) { |
| 2465 | mShowRotationSuggestions = showRotationSuggestions; |
| 2466 | updateOrientationListenerLp(); // Enable, disable the orientation listener |
| 2467 | } |
| 2468 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 2469 | // Configure wake gesture. |
| 2470 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 2471 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 2472 | UserHandle.USER_CURRENT) != 0; |
| 2473 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 2474 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 2475 | updateWakeGestureListenerLp(); |
| 2476 | } |
| 2477 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 2478 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2479 | int userRotation = Settings.System.getIntForUser(resolver, |
| 2480 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 2481 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 2482 | if (mUserRotation != userRotation) { |
| 2483 | mUserRotation = userRotation; |
| 2484 | updateRotation = true; |
| 2485 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2486 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 2487 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 2488 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 2489 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 2490 | if (mUserRotationMode != userRotationMode) { |
| 2491 | mUserRotationMode = userRotationMode; |
| 2492 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2493 | updateOrientationListenerLp(); |
| 2494 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 2495 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2496 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2497 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 2498 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2499 | if (mPointerLocationMode != pointerLocation) { |
| 2500 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2501 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 2502 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2503 | } |
| 2504 | } |
| 2505 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2506 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 2507 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 2508 | String imId = Settings.Secure.getStringForUser(resolver, |
| 2509 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2510 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 2511 | if (mHasSoftInput != hasSoftInput) { |
| 2512 | mHasSoftInput = hasSoftInput; |
| 2513 | updateRotation = true; |
| 2514 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2515 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 2516 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 2517 | } |
tiger_huang | cc6366d | 2015-06-29 17:17:30 +0800 | [diff] [blame] | 2518 | } |
| 2519 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 2520 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2521 | } |
| 2522 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 2523 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2524 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 2527 | private void updateWakeGestureListenerLp() { |
| 2528 | if (shouldEnableWakeGestureLp()) { |
| 2529 | mWakeGestureListener.requestWakeUpTrigger(); |
| 2530 | } else { |
| 2531 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 2532 | } |
| 2533 | } |
| 2534 | |
| 2535 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 2536 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 2537 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 2538 | && mWakeGestureListener.isSupported(); |
| 2539 | } |
| 2540 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2541 | private void enablePointerLocation() { |
| 2542 | if (mPointerLocationView == null) { |
| 2543 | mPointerLocationView = new PointerLocationView(mContext); |
| 2544 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2545 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 2546 | WindowManager.LayoutParams.MATCH_PARENT, |
| 2547 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 2548 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 2549 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 2550 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 2551 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 2552 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Adrian Roos | 7851ace | 2018-04-12 10:20:47 +0200 | [diff] [blame] | 2553 | lp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 2554 | if (ActivityManager.isHighEndGfx()) { |
| 2555 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 2556 | lp.privateFlags |= |
| 2557 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 2558 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2559 | lp.format = PixelFormat.TRANSLUCENT; |
| 2560 | lp.setTitle("PointerLocation"); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2561 | WindowManager wm = (WindowManager) mContext.getSystemService(WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2562 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2563 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 2564 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2565 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2566 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2567 | |
| 2568 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2569 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 2570 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2571 | WindowManager wm = (WindowManager) mContext.getSystemService(WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2572 | wm.removeView(mPointerLocationView); |
| 2573 | mPointerLocationView = null; |
| 2574 | } |
| 2575 | } |
| 2576 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2577 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2578 | try { |
| 2579 | int rotation = mContext.getResources().getInteger(resID); |
| 2580 | switch (rotation) { |
| 2581 | case 0: |
| 2582 | return Surface.ROTATION_0; |
| 2583 | case 90: |
| 2584 | return Surface.ROTATION_90; |
| 2585 | case 180: |
| 2586 | return Surface.ROTATION_180; |
| 2587 | case 270: |
| 2588 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2589 | } |
| 2590 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2591 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2592 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2593 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2594 | } |
| 2595 | |
| 2596 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2597 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2598 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
Adrian Roos | 4bef62e | 2018-03-21 19:52:09 +0100 | [diff] [blame] | 2599 | final int type = attrs.type; |
| 2600 | final boolean isRoundedCornerOverlay = |
| 2601 | (attrs.privateFlags & PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0; |
| 2602 | |
| 2603 | if (isRoundedCornerOverlay && mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW) |
| 2604 | != PERMISSION_GRANTED) { |
| 2605 | return ADD_PERMISSION_DENIED; |
| 2606 | } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2607 | |
| 2608 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 2609 | |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 2610 | if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) |
| 2611 | || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) |
| 2612 | || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { |
| 2613 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
| 2614 | } |
| 2615 | |
| 2616 | if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { |
| 2617 | // Window manager will make sure these are okay. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2618 | return ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2619 | } |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2620 | |
| 2621 | if (!isSystemAlertWindowType(type)) { |
| 2622 | switch (type) { |
| 2623 | case TYPE_TOAST: |
| 2624 | // Only apps that target older than O SDK can add window without a token, after |
| 2625 | // that we require a token so apps cannot add toasts directly as the token is |
| 2626 | // added by the notification system. |
| 2627 | // Window manager does the checking for this. |
| 2628 | outAppOp[0] = OP_TOAST_WINDOW; |
| 2629 | return ADD_OKAY; |
| 2630 | case TYPE_DREAM: |
| 2631 | case TYPE_INPUT_METHOD: |
| 2632 | case TYPE_WALLPAPER: |
| 2633 | case TYPE_PRESENTATION: |
| 2634 | case TYPE_PRIVATE_PRESENTATION: |
| 2635 | case TYPE_VOICE_INTERACTION: |
| 2636 | case TYPE_ACCESSIBILITY_OVERLAY: |
| 2637 | case TYPE_QS_DIALOG: |
| 2638 | // The window manager will check these. |
| 2639 | return ADD_OKAY; |
| 2640 | } |
| 2641 | return mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW) |
| 2642 | == PERMISSION_GRANTED ? ADD_OKAY : ADD_PERMISSION_DENIED; |
| 2643 | } |
| 2644 | |
| 2645 | // Things get a little more interesting for alert windows... |
| 2646 | outAppOp[0] = OP_SYSTEM_ALERT_WINDOW; |
| 2647 | |
| 2648 | final int callingUid = Binder.getCallingUid(); |
| 2649 | // system processes will be automatically granted privilege to draw |
| 2650 | if (UserHandle.getAppId(callingUid) == Process.SYSTEM_UID) { |
| 2651 | return ADD_OKAY; |
| 2652 | } |
| 2653 | |
| 2654 | ApplicationInfo appInfo; |
| 2655 | try { |
Tony Mak | 22295fd | 2017-03-20 16:17:54 +0000 | [diff] [blame] | 2656 | appInfo = mContext.getPackageManager().getApplicationInfoAsUser( |
| 2657 | attrs.packageName, |
| 2658 | 0 /* flags */, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2659 | UserHandle.getUserId(callingUid)); |
| 2660 | } catch (PackageManager.NameNotFoundException e) { |
| 2661 | appInfo = null; |
| 2662 | } |
| 2663 | |
| 2664 | if (appInfo == null || (type != TYPE_APPLICATION_OVERLAY && appInfo.targetSdkVersion >= O)) { |
| 2665 | /** |
| 2666 | * Apps targeting >= {@link Build.VERSION_CODES#O} are required to hold |
| 2667 | * {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} (system signature apps) |
| 2668 | * permission to add alert windows that aren't |
| 2669 | * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY}. |
| 2670 | */ |
Wale Ogunwale | 5aa8683 | 2017-02-28 10:40:27 -0800 | [diff] [blame] | 2671 | return (mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW) |
| 2672 | == PERMISSION_GRANTED) ? ADD_OKAY : ADD_PERMISSION_DENIED; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | // check if user has enabled this operation. SecurityException will be thrown if this app |
| 2676 | // has not been allowed by the user |
Peter Visontay | 96449f6 | 2017-12-11 18:50:03 +0000 | [diff] [blame] | 2677 | final int mode = mAppOpsManager.noteOpNoThrow(outAppOp[0], callingUid, attrs.packageName); |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2678 | switch (mode) { |
| 2679 | case AppOpsManager.MODE_ALLOWED: |
| 2680 | case AppOpsManager.MODE_IGNORED: |
| 2681 | // although we return ADD_OKAY for MODE_IGNORED, the added window will |
| 2682 | // actually be hidden in WindowManagerService |
| 2683 | return ADD_OKAY; |
| 2684 | case AppOpsManager.MODE_ERRORED: |
| 2685 | // Don't crash legacy apps |
| 2686 | if (appInfo.targetSdkVersion < M) { |
| 2687 | return ADD_OKAY; |
| 2688 | } |
| 2689 | return ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2690 | default: |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2691 | // in the default mode, we will make a decision here based on |
| 2692 | // checkCallingPermission() |
Wale Ogunwale | 5aa8683 | 2017-02-28 10:40:27 -0800 | [diff] [blame] | 2693 | return (mContext.checkCallingOrSelfPermission(SYSTEM_ALERT_WINDOW) |
| 2694 | == PERMISSION_GRANTED) ? ADD_OKAY : ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2695 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2696 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2697 | |
| 2698 | @Override |
| 2699 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 2700 | |
| 2701 | // If this switch statement is modified, modify the comment in the declarations of |
| 2702 | // the type in {@link WindowManager.LayoutParams} as well. |
| 2703 | switch (attrs.type) { |
| 2704 | default: |
| 2705 | // These are the windows that by default are shown only to the user that created |
| 2706 | // them. If this needs to be overridden, set |
| 2707 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 2708 | // {@link WindowManager.LayoutParams}. Note that permission |
| 2709 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 2710 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 2711 | return true; |
| 2712 | } |
| 2713 | break; |
| 2714 | |
| 2715 | // These are the windows that by default are shown to all users. However, to |
| 2716 | // protect against spoofing, check permissions below. |
| 2717 | case TYPE_APPLICATION_STARTING: |
| 2718 | case TYPE_BOOT_PROGRESS: |
| 2719 | case TYPE_DISPLAY_OVERLAY: |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2720 | case TYPE_INPUT_CONSUMER: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2721 | case TYPE_KEYGUARD_DIALOG: |
| 2722 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2723 | case TYPE_NAVIGATION_BAR: |
| 2724 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2725 | case TYPE_PHONE: |
| 2726 | case TYPE_POINTER: |
| 2727 | case TYPE_PRIORITY_PHONE: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2728 | case TYPE_SEARCH_BAR: |
| 2729 | case TYPE_STATUS_BAR: |
| 2730 | case TYPE_STATUS_BAR_PANEL: |
| 2731 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 2732 | case TYPE_SYSTEM_DIALOG: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2733 | case TYPE_VOLUME_OVERLAY: |
Wale Ogunwale | 5b6714c | 2016-11-01 20:54:46 -0700 | [diff] [blame] | 2734 | case TYPE_PRESENTATION: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2735 | case TYPE_PRIVATE_PRESENTATION: |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2736 | case TYPE_DOCK_DIVIDER: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2737 | break; |
| 2738 | } |
| 2739 | |
| 2740 | // Check if third party app has set window to system window type. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2741 | return mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW) != PERMISSION_GRANTED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2742 | } |
| 2743 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2744 | @Override |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 2745 | public void adjustWindowParamsLw(WindowState win, WindowManager.LayoutParams attrs, |
| 2746 | boolean hasStatusBarServicePermission) { |
| 2747 | |
| 2748 | final boolean isScreenDecor = (attrs.privateFlags & PRIVATE_FLAG_IS_SCREEN_DECOR) != 0; |
| 2749 | if (mScreenDecorWindows.contains(win)) { |
| 2750 | if (!isScreenDecor) { |
| 2751 | // No longer has the flag set, so remove from the set. |
| 2752 | mScreenDecorWindows.remove(win); |
| 2753 | } |
| 2754 | } else if (isScreenDecor && hasStatusBarServicePermission) { |
| 2755 | mScreenDecorWindows.add(win); |
| 2756 | } |
| 2757 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2758 | switch (attrs.type) { |
| 2759 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 2760 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2761 | // These types of windows can't receive input events. |
| 2762 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 2763 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 2764 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2765 | break; |
Adrian Roos | 7588597 | 2018-02-20 17:16:34 +0100 | [diff] [blame] | 2766 | case TYPE_DREAM: |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 2767 | case TYPE_WALLPAPER: |
| 2768 | // Dreams and wallpapers don't have an app window token and can thus not be |
| 2769 | // letterboxed. Hence always let them extend under the cutout. |
Adrian Roos | 7588597 | 2018-02-20 17:16:34 +0100 | [diff] [blame] | 2770 | attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
| 2771 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2772 | case TYPE_STATUS_BAR: |
| 2773 | |
| 2774 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 2775 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 2776 | // the keyguard as occluded wouldn't set these flags again. |
| 2777 | // See {@link #processKeyguardSetHiddenResultLw}. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2778 | if (mKeyguardOccluded) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2779 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 2780 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2781 | } |
| 2782 | break; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2783 | |
Muyuan Li | 36ca72c | 2016-08-06 20:24:06 -0700 | [diff] [blame] | 2784 | case TYPE_SCREENSHOT: |
| 2785 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 2786 | break; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2787 | |
| 2788 | case TYPE_TOAST: |
| 2789 | // While apps should use the dedicated toast APIs to add such windows |
| 2790 | // it possible legacy apps to add the window directly. Therefore, we |
| 2791 | // make windows added directly by the app behave as a toast as much |
| 2792 | // as possible in terms of timeout and animation. |
| 2793 | if (attrs.hideTimeoutMilliseconds < 0 |
| 2794 | || attrs.hideTimeoutMilliseconds > TOAST_WINDOW_TIMEOUT) { |
| 2795 | attrs.hideTimeoutMilliseconds = TOAST_WINDOW_TIMEOUT; |
| 2796 | } |
| 2797 | attrs.windowAnimations = com.android.internal.R.style.Animation_Toast; |
| 2798 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2799 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 2800 | |
| 2801 | if (attrs.type != TYPE_STATUS_BAR) { |
| 2802 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 2803 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2804 | } |
Adrian Roos | 7737398 | 2017-11-24 13:24:28 +0100 | [diff] [blame] | 2805 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2806 | |
Adrian Roos | 7737398 | 2017-11-24 13:24:28 +0100 | [diff] [blame] | 2807 | private int getImpliedSysUiFlagsForLayout(LayoutParams attrs) { |
| 2808 | int impliedFlags = 0; |
Ng Zhi An | c661713 | 2017-09-22 09:15:29 -0700 | [diff] [blame] | 2809 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
Adrian Roos | 7737398 | 2017-11-24 13:24:28 +0100 | [diff] [blame] | 2810 | impliedFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
Ng Zhi An | c661713 | 2017-09-22 09:15:29 -0700 | [diff] [blame] | 2811 | } |
| 2812 | final boolean forceWindowDrawsStatusBarBackground = |
| 2813 | (attrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) != 0; |
| 2814 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 |
| 2815 | || forceWindowDrawsStatusBarBackground |
| 2816 | && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT) { |
Adrian Roos | 7737398 | 2017-11-24 13:24:28 +0100 | [diff] [blame] | 2817 | impliedFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2818 | } |
Adrian Roos | 7737398 | 2017-11-24 13:24:28 +0100 | [diff] [blame] | 2819 | return impliedFlags; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2820 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2821 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2822 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 2823 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2824 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2825 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 2826 | private void readCameraLensCoverState() { |
| 2827 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 2828 | } |
| 2829 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2830 | private boolean isHidden(int accessibilityMode) { |
| 2831 | switch (accessibilityMode) { |
| 2832 | case 1: |
| 2833 | return mLidState == LID_CLOSED; |
| 2834 | case 2: |
| 2835 | return mLidState == LID_OPEN; |
| 2836 | default: |
| 2837 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2838 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2839 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2840 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2841 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2842 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2843 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 2844 | int navigationPresence) { |
| 2845 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 2846 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2847 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2848 | readLidState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2849 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2850 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 2851 | || (keyboardPresence == PRESENCE_INTERNAL |
| 2852 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2853 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2854 | if (!mHasSoftInput) { |
| 2855 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 2856 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2857 | } |
| 2858 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2859 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 2860 | || (navigationPresence == PRESENCE_INTERNAL |
| 2861 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2862 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2863 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2864 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2865 | |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2866 | @Override |
Adrian Roos | 2f1a90b | 2018-01-09 17:28:49 +0100 | [diff] [blame] | 2867 | public void onOverlayChangedLw() { |
| 2868 | onConfigurationChanged(); |
| 2869 | } |
| 2870 | |
| 2871 | @Override |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2872 | public void onConfigurationChanged() { |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 2873 | // TODO(multi-display): Define policy for secondary displays. |
Adrian Roos | e1856fe | 2017-11-24 19:39:12 +0100 | [diff] [blame] | 2874 | Context uiContext = getSystemUiContext(); |
Jason Monk | f506bf3 | 2017-08-23 10:56:34 -0400 | [diff] [blame] | 2875 | final Resources res = uiContext.getResources(); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2876 | |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 2877 | mStatusBarHeightForRotation[mPortraitRotation] = |
| 2878 | mStatusBarHeightForRotation[mUpsideDownRotation] = res.getDimensionPixelSize( |
| 2879 | com.android.internal.R.dimen.status_bar_height_portrait); |
| 2880 | mStatusBarHeightForRotation[mLandscapeRotation] = |
| 2881 | mStatusBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 2882 | com.android.internal.R.dimen.status_bar_height_landscape); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2883 | |
| 2884 | // Height of the navigation bar when presented horizontally at bottom |
| 2885 | mNavigationBarHeightForRotationDefault[mPortraitRotation] = |
| 2886 | mNavigationBarHeightForRotationDefault[mUpsideDownRotation] = |
| 2887 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
| 2888 | mNavigationBarHeightForRotationDefault[mLandscapeRotation] = |
| 2889 | mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize( |
| 2890 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
| 2891 | |
| 2892 | // Width of the navigation bar when presented vertically along one side |
| 2893 | mNavigationBarWidthForRotationDefault[mPortraitRotation] = |
| 2894 | mNavigationBarWidthForRotationDefault[mUpsideDownRotation] = |
| 2895 | mNavigationBarWidthForRotationDefault[mLandscapeRotation] = |
| 2896 | mNavigationBarWidthForRotationDefault[mSeascapeRotation] = |
| 2897 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
| 2898 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2899 | if (ALTERNATE_CAR_MODE_NAV_SIZE) { |
| 2900 | // Height of the navigation bar when presented horizontally at bottom |
| 2901 | mNavigationBarHeightForRotationInCarMode[mPortraitRotation] = |
| 2902 | mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] = |
| 2903 | res.getDimensionPixelSize( |
| 2904 | com.android.internal.R.dimen.navigation_bar_height_car_mode); |
| 2905 | mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] = |
| 2906 | mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize( |
| 2907 | com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2908 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2909 | // Width of the navigation bar when presented vertically along one side |
| 2910 | mNavigationBarWidthForRotationInCarMode[mPortraitRotation] = |
| 2911 | mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] = |
| 2912 | mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] = |
| 2913 | mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] = |
| 2914 | res.getDimensionPixelSize( |
| 2915 | com.android.internal.R.dimen.navigation_bar_width_car_mode); |
| 2916 | } |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
Adrian Roos | e1856fe | 2017-11-24 19:39:12 +0100 | [diff] [blame] | 2919 | @VisibleForTesting |
| 2920 | Context getSystemUiContext() { |
| 2921 | return ActivityThread.currentActivityThread().getSystemUiContext(); |
| 2922 | } |
| 2923 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2924 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2925 | public int getMaxWallpaperLayer() { |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2926 | return getWindowLayerFromTypeLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2929 | private int getNavigationBarWidth(int rotation, int uiMode) { |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2930 | if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2931 | return mNavigationBarWidthForRotationInCarMode[rotation]; |
| 2932 | } else { |
| 2933 | return mNavigationBarWidthForRotationDefault[rotation]; |
| 2934 | } |
| 2935 | } |
| 2936 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2937 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2938 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 2939 | int displayId, DisplayCutout displayCutout) { |
| 2940 | int width = fullWidth; |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2941 | // TODO(multi-display): Support navigation bar on secondary displays. |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 2942 | if (displayId == DEFAULT_DISPLAY && mHasNavigationBar) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2943 | // For a basic navigation bar, when we are in landscape mode we place |
| 2944 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2945 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 2946 | width -= getNavigationBarWidth(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2947 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2948 | } |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 2949 | if (displayCutout != null) { |
| 2950 | width -= displayCutout.getSafeInsetLeft() + displayCutout.getSafeInsetRight(); |
| 2951 | } |
| 2952 | return width; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2953 | } |
| 2954 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2955 | private int getNavigationBarHeight(int rotation, int uiMode) { |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2956 | if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2957 | return mNavigationBarHeightForRotationInCarMode[rotation]; |
| 2958 | } else { |
| 2959 | return mNavigationBarHeightForRotationDefault[rotation]; |
| 2960 | } |
| 2961 | } |
| 2962 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2963 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2964 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 2965 | int displayId, DisplayCutout displayCutout) { |
| 2966 | int height = fullHeight; |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2967 | // TODO(multi-display): Support navigation bar on secondary displays. |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 2968 | if (displayId == DEFAULT_DISPLAY && mHasNavigationBar) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2969 | // For a basic navigation bar, when we are in portrait mode we place |
| 2970 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2971 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 2972 | height -= getNavigationBarHeight(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2973 | } |
| 2974 | } |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 2975 | if (displayCutout != null) { |
| 2976 | height -= displayCutout.getSafeInsetTop() + displayCutout.getSafeInsetBottom(); |
| 2977 | } |
| 2978 | return height; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2979 | } |
| 2980 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2981 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2982 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 2983 | int displayId, DisplayCutout displayCutout) { |
| 2984 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode, displayId, |
| 2985 | displayCutout); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2986 | } |
| 2987 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2988 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2989 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 2990 | int displayId, DisplayCutout displayCutout) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2991 | // There is a separate status bar at the top of the display. We don't count that as part |
| 2992 | // of the fixed decor, since it can hide; however, for purposes of configurations, |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2993 | // we do want to exclude it since applications can't generally use that part |
| 2994 | // of the screen. |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2995 | // TODO(multi-display): Support status bars on secondary displays. |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 2996 | if (displayId == DEFAULT_DISPLAY) { |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 2997 | int statusBarHeight = mStatusBarHeightForRotation[rotation]; |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 2998 | if (displayCutout != null) { |
| 2999 | // If there is a cutout, it may already have accounted for some part of the status |
| 3000 | // bar height. |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 3001 | statusBarHeight = Math.max(0, statusBarHeight - displayCutout.getSafeInsetTop()); |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 3002 | } |
| 3003 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation, uiMode, displayId, |
| 3004 | displayCutout) - statusBarHeight; |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 3005 | } |
| 3006 | return fullHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3007 | } |
| 3008 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 3009 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 3010 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 3011 | return attrs.type == TYPE_STATUS_BAR; |
| 3012 | } |
| 3013 | |
| 3014 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3015 | public boolean canBeHiddenByKeyguardLw(WindowState win) { |
| 3016 | switch (win.getAttrs().type) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 3017 | case TYPE_STATUS_BAR: |
| 3018 | case TYPE_NAVIGATION_BAR: |
| 3019 | case TYPE_WALLPAPER: |
| 3020 | case TYPE_DREAM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 3021 | return false; |
| 3022 | default: |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 3023 | // Hide only windows below the keyguard host window. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 3024 | return getWindowLayerLw(win) < getWindowLayerFromTypeLw(TYPE_STATUS_BAR); |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 3025 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 3026 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 3027 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3028 | private boolean shouldBeHiddenByKeyguard(WindowState win, WindowState imeTarget) { |
| 3029 | |
| 3030 | // Keyguard visibility of window from activities are determined over activity visibility. |
| 3031 | if (win.getAppToken() != null) { |
| 3032 | return false; |
| 3033 | } |
| 3034 | |
| 3035 | final LayoutParams attrs = win.getAttrs(); |
| 3036 | final boolean showImeOverKeyguard = imeTarget != null && imeTarget.isVisibleLw() && |
| 3037 | ((imeTarget.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0 |
| 3038 | || !canBeHiddenByKeyguardLw(imeTarget)); |
| 3039 | |
| 3040 | // Show IME over the keyguard if the target allows it |
| 3041 | boolean allowWhenLocked = (win.isInputMethodWindow() || imeTarget == this) |
Jorim Jaggi | 98a9d20 | 2018-03-26 16:17:07 +0200 | [diff] [blame] | 3042 | && showImeOverKeyguard; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3043 | |
| 3044 | if (isKeyguardLocked() && isKeyguardOccluded()) { |
| 3045 | // Show SHOW_WHEN_LOCKED windows if Keyguard is occluded. |
| 3046 | allowWhenLocked |= (attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0 |
| 3047 | // Show error dialogs over apps that are shown on lockscreen |
| 3048 | || (attrs.privateFlags & PRIVATE_FLAG_SYSTEM_ERROR) != 0; |
| 3049 | } |
| 3050 | |
| 3051 | boolean keyguardLocked = isKeyguardLocked(); |
| 3052 | boolean hideDockDivider = attrs.type == TYPE_DOCK_DIVIDER |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3053 | && !mWindowManagerInternal.isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 3054 | return (keyguardLocked && !allowWhenLocked && win.getDisplayId() == DEFAULT_DISPLAY) |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3055 | || hideDockDivider; |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3058 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 3059 | @Override |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 3060 | public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme, |
| 3061 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon, |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 3062 | int logo, int windowFlags, Configuration overrideConfig, int displayId) { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 3063 | if (!SHOW_SPLASH_SCREENS) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3064 | return null; |
| 3065 | } |
| 3066 | if (packageName == null) { |
| 3067 | return null; |
| 3068 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 3069 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 3070 | WindowManager wm = null; |
| 3071 | View view = null; |
| 3072 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3073 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 3074 | Context context = mContext; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 3075 | if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen " + packageName |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 3076 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 3077 | + Integer.toHexString(theme)); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3078 | |
| 3079 | // Obtain proper context to launch on the right display. |
| 3080 | final Context displayContext = getDisplayContext(context, displayId); |
| 3081 | if (displayContext == null) { |
| 3082 | // Can't show splash screen on requested display, so skip showing at all. |
| 3083 | return null; |
| 3084 | } |
| 3085 | context = displayContext; |
| 3086 | |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 3087 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 3088 | try { |
Robert Carr | 7ad24ba | 2017-06-20 17:26:06 -0700 | [diff] [blame] | 3089 | context = context.createPackageContext(packageName, CONTEXT_RESTRICTED); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 3090 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 3091 | } catch (PackageManager.NameNotFoundException e) { |
| 3092 | // Ignore |
| 3093 | } |
| 3094 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 3095 | |
Andrii Kulian | a8a9bc5 | 2016-10-14 11:00:13 -0700 | [diff] [blame] | 3096 | if (overrideConfig != null && !overrideConfig.equals(EMPTY)) { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 3097 | if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen: creating context based" |
| 3098 | + " on overrideConfig" + overrideConfig + " for splash screen"); |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 3099 | final Context overrideContext = context.createConfigurationContext(overrideConfig); |
| 3100 | overrideContext.setTheme(theme); |
| 3101 | final TypedArray typedArray = overrideContext.obtainStyledAttributes( |
| 3102 | com.android.internal.R.styleable.Window); |
| 3103 | final int resId = typedArray.getResourceId(R.styleable.Window_windowBackground, 0); |
| 3104 | if (resId != 0 && overrideContext.getDrawable(resId) != null) { |
| 3105 | // We want to use the windowBackground for the override context if it is |
| 3106 | // available, otherwise we use the default one to make sure a themed starting |
| 3107 | // window is displayed for the app. |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 3108 | if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen: apply overrideConfig" |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 3109 | + overrideConfig + " to starting window resId=" + resId); |
| 3110 | context = overrideContext; |
| 3111 | } |
Jorim Jaggi | 7d0d102 | 2017-02-23 15:35:51 +0100 | [diff] [blame] | 3112 | typedArray.recycle(); |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | final PhoneWindow win = new PhoneWindow(context); |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 3116 | win.setIsStartingWindow(true); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 3117 | |
Phil Weaver | 155edc6 | 2016-06-09 10:24:53 -0700 | [diff] [blame] | 3118 | CharSequence label = context.getResources().getText(labelRes, null); |
| 3119 | // Only change the accessibility title if the label is localized |
| 3120 | if (label != null) { |
| 3121 | win.setTitle(label, true); |
| 3122 | } else { |
| 3123 | win.setTitle(nonLocalizedLabel, false); |
| 3124 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 3125 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 3126 | win.setType( |
| 3127 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 3128 | |
| 3129 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 3130 | // Assumes it's safe to show starting windows of launched apps while |
| 3131 | // the keyguard is being hidden. This is okay because starting windows never show |
| 3132 | // secret information. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3133 | if (mKeyguardOccluded) { |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 3134 | windowFlags |= FLAG_SHOW_WHEN_LOCKED; |
| 3135 | } |
| 3136 | } |
| 3137 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 3138 | // Force the window flags: this is a fake window, so it is not really |
| 3139 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 3140 | // flag because we do know that the next window will take input |
| 3141 | // focus, so we want to get the IME window up on top of us right away. |
| 3142 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3143 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 3144 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 3145 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 3146 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3147 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 3148 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 3149 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 3150 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 3151 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 3152 | win.setDefaultIcon(icon); |
| 3153 | win.setDefaultLogo(logo); |
| 3154 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 3155 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 3156 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 3157 | |
Phil Weaver | 266ed9a | 2016-06-08 00:34:40 +0000 | [diff] [blame] | 3158 | final WindowManager.LayoutParams params = win.getAttributes(); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 3159 | params.token = appToken; |
| 3160 | params.packageName = packageName; |
| 3161 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 3162 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 3163 | params.privateFlags |= |
| 3164 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 3165 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 3166 | |
| 3167 | if (!compatInfo.supportsScreen()) { |
| 3168 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 3169 | } |
| 3170 | |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 3171 | params.setTitle("Splash Screen " + packageName); |
Jorim Jaggi | 7d0d102 | 2017-02-23 15:35:51 +0100 | [diff] [blame] | 3172 | addSplashscreenContent(win, context); |
| 3173 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3174 | wm = (WindowManager) context.getSystemService(WINDOW_SERVICE); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 3175 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3176 | |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 3177 | if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "Adding splash screen window for " |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 3178 | + packageName + " / " + appToken + ": " + (view.getParent() != null ? view : null)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3179 | |
| 3180 | wm.addView(view, params); |
| 3181 | |
| 3182 | // Only return the view if it was successfully added to the |
| 3183 | // window manager... which we can tell by it having a parent. |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3184 | return view.getParent() != null ? new SplashScreenSurface(view, appToken) : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3185 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3186 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 3187 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 3188 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 3189 | } catch (RuntimeException e) { |
| 3190 | // don't crash if something else bad happens, for example a |
| 3191 | // failure loading resources because we are loading from an app |
| 3192 | // on external storage that has been unmounted. |
| 3193 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 3194 | } finally { |
| 3195 | if (view != null && view.getParent() == null) { |
| 3196 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 3197 | wm.removeViewImmediate(view); |
| 3198 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | return null; |
| 3202 | } |
| 3203 | |
Jorim Jaggi | 7d0d102 | 2017-02-23 15:35:51 +0100 | [diff] [blame] | 3204 | private void addSplashscreenContent(PhoneWindow win, Context ctx) { |
| 3205 | final TypedArray a = ctx.obtainStyledAttributes(R.styleable.Window); |
| 3206 | final int resId = a.getResourceId(R.styleable.Window_windowSplashscreenContent, 0); |
| 3207 | a.recycle(); |
| 3208 | if (resId == 0) { |
| 3209 | return; |
| 3210 | } |
| 3211 | final Drawable drawable = ctx.getDrawable(resId); |
| 3212 | if (drawable == null) { |
| 3213 | return; |
| 3214 | } |
| 3215 | |
| 3216 | // We wrap this into a view so the system insets get applied to the drawable. |
| 3217 | final View v = new View(ctx); |
| 3218 | v.setBackground(drawable); |
| 3219 | win.setContentView(v); |
| 3220 | } |
| 3221 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 3222 | /** Obtain proper context for showing splash screen on the provided display. */ |
| 3223 | private Context getDisplayContext(Context context, int displayId) { |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 3224 | if (displayId == DEFAULT_DISPLAY) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 3225 | // The default context fits. |
| 3226 | return context; |
| 3227 | } |
| 3228 | |
| 3229 | final DisplayManager dm = (DisplayManager) context.getSystemService(DISPLAY_SERVICE); |
| 3230 | final Display targetDisplay = dm.getDisplay(displayId); |
| 3231 | if (targetDisplay == null) { |
| 3232 | // Failed to obtain the non-default display where splash screen should be shown, |
| 3233 | // lets not show at all. |
| 3234 | return null; |
| 3235 | } |
| 3236 | |
| 3237 | return context.createDisplayContext(targetDisplay); |
| 3238 | } |
| 3239 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3240 | /** |
| 3241 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3242 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3243 | * Currently enforces that three window types are singletons: |
| 3244 | * <ul> |
| 3245 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3246 | * <li>KEYGUARD_TYPE</li> |
| 3247 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3248 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3249 | * @param win The window to be added |
| 3250 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3251 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3252 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 3253 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3254 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 3255 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3256 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 3257 | |
| 3258 | if ((attrs.privateFlags & PRIVATE_FLAG_IS_SCREEN_DECOR) != 0) { |
| 3259 | mContext.enforceCallingOrSelfPermission( |
| 3260 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 3261 | "PhoneWindowManager"); |
| 3262 | mScreenDecorWindows.add(win); |
| 3263 | } |
| 3264 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3265 | switch (attrs.type) { |
| 3266 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 3267 | mContext.enforceCallingOrSelfPermission( |
| 3268 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 3269 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3270 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3271 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3272 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3273 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3274 | } |
| 3275 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3276 | mStatusBarController.setWindow(win); |
Jorim Jaggi | 9ba2e10 | 2017-04-04 12:51:03 +0200 | [diff] [blame] | 3277 | setKeyguardOccludedLw(mKeyguardOccluded, true /* force */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3278 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3279 | case TYPE_NAVIGATION_BAR: |
| 3280 | mContext.enforceCallingOrSelfPermission( |
| 3281 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 3282 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3283 | if (mNavigationBar != null) { |
| 3284 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3285 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3286 | } |
| 3287 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3288 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3289 | mNavigationBarController.setWindow(win); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 3290 | mNavigationBarController.setOnBarVisibilityChangedListener( |
Casey Burkhardt | 469a208 | 2017-06-13 20:12:42 -0700 | [diff] [blame] | 3291 | mNavBarVisibilityListener, true); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3292 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3293 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3294 | case TYPE_NAVIGATION_BAR_PANEL: |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3295 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3296 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3297 | case TYPE_VOICE_INTERACTION_STARTING: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3298 | mContext.enforceCallingOrSelfPermission( |
| 3299 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 3300 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3301 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3302 | } |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 3303 | return ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 3307 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3308 | public void removeWindowLw(WindowState win) { |
| 3309 | if (mStatusBar == win) { |
| 3310 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3311 | mStatusBarController.setWindow(null); |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 3312 | } else if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3313 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3314 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3315 | } |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 3316 | mScreenDecorWindows.remove(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3320 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3321 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3322 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3323 | public int selectAnimationLw(WindowState win, int transit) { |
| 3324 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 3325 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3326 | if (win == mStatusBar) { |
Jorim Jaggi | 67b29d5 | 2017-06-09 18:00:00 -0700 | [diff] [blame] | 3327 | final boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 3328 | final boolean expanded = win.getAttrs().height == MATCH_PARENT |
| 3329 | && win.getAttrs().width == MATCH_PARENT; |
| 3330 | if (isKeyguard || expanded) { |
| 3331 | return -1; |
| 3332 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3333 | if (transit == TRANSIT_EXIT |
| 3334 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 67b29d5 | 2017-06-09 18:00:00 -0700 | [diff] [blame] | 3335 | return R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3336 | } else if (transit == TRANSIT_ENTER |
| 3337 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 67b29d5 | 2017-06-09 18:00:00 -0700 | [diff] [blame] | 3338 | return R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3339 | } |
| 3340 | } else if (win == mNavigationBar) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 3341 | if (win.getAttrs().windowAnimations != 0) { |
| 3342 | return 0; |
| 3343 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3344 | // This can be on either the bottom or the right or the left. |
| 3345 | if (mNavigationBarPosition == NAV_BAR_BOTTOM) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3346 | if (transit == TRANSIT_EXIT |
| 3347 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 4883281 | 2016-09-06 12:38:23 -0700 | [diff] [blame] | 3348 | if (isKeyguardShowingAndNotOccluded()) { |
| 3349 | return R.anim.dock_bottom_exit_keyguard; |
| 3350 | } else { |
| 3351 | return R.anim.dock_bottom_exit; |
| 3352 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3353 | } else if (transit == TRANSIT_ENTER |
| 3354 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3355 | return R.anim.dock_bottom_enter; |
| 3356 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3357 | } else if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3358 | if (transit == TRANSIT_EXIT |
| 3359 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3360 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3361 | } else if (transit == TRANSIT_ENTER |
| 3362 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3363 | return R.anim.dock_right_enter; |
| 3364 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3365 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
| 3366 | if (transit == TRANSIT_EXIT |
| 3367 | || transit == TRANSIT_HIDE) { |
| 3368 | return R.anim.dock_left_exit; |
| 3369 | } else if (transit == TRANSIT_ENTER |
| 3370 | || transit == TRANSIT_SHOW) { |
| 3371 | return R.anim.dock_left_enter; |
| 3372 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3373 | } |
Filip Gruszczynski | 57f76f1 | 2015-11-04 16:10:54 -0800 | [diff] [blame] | 3374 | } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) { |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 3375 | return selectDockedDividerAnimationLw(win, transit); |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3379 | if (win.hasAppShownWindows()) { |
| 3380 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 3381 | return com.android.internal.R.anim.app_starting_exit; |
| 3382 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3383 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3384 | && transit == TRANSIT_ENTER) { |
| 3385 | // Special case: we are animating in a dream, while the keyguard |
| 3386 | // is shown. We don't want an animation on the dream, because |
| 3387 | // we need it shown immediately with the keyguard animating away |
| 3388 | // to reveal it. |
| 3389 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3390 | } |
| 3391 | |
| 3392 | return 0; |
| 3393 | } |
| 3394 | |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 3395 | private int selectDockedDividerAnimationLw(WindowState win, int transit) { |
| 3396 | int insets = mWindowManagerFuncs.getDockedDividerInsetsLw(); |
| 3397 | |
| 3398 | // If the divider is behind the navigation bar, don't animate. |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 3399 | final Rect frame = win.getFrameLw(); |
| 3400 | final boolean behindNavBar = mNavigationBar != null |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3401 | && ((mNavigationBarPosition == NAV_BAR_BOTTOM |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 3402 | && frame.top + insets >= mNavigationBar.getFrameLw().top) |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3403 | || (mNavigationBarPosition == NAV_BAR_RIGHT |
| 3404 | && frame.left + insets >= mNavigationBar.getFrameLw().left) |
| 3405 | || (mNavigationBarPosition == NAV_BAR_LEFT |
| 3406 | && frame.right - insets <= mNavigationBar.getFrameLw().right)); |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 3407 | final boolean landscape = frame.height() > frame.width(); |
| 3408 | final boolean offscreenLandscape = landscape && (frame.right - insets <= 0 |
| 3409 | || frame.left + insets >= win.getDisplayFrameLw().right); |
| 3410 | final boolean offscreenPortrait = !landscape && (frame.top - insets <= 0 |
| 3411 | || frame.bottom + insets >= win.getDisplayFrameLw().bottom); |
| 3412 | final boolean offscreen = offscreenLandscape || offscreenPortrait; |
| 3413 | if (behindNavBar || offscreen) { |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 3414 | return 0; |
| 3415 | } |
| 3416 | if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) { |
| 3417 | return R.anim.fade_in; |
| 3418 | } else if (transit == TRANSIT_EXIT) { |
| 3419 | return R.anim.fade_out; |
| 3420 | } else { |
| 3421 | return 0; |
| 3422 | } |
| 3423 | } |
| 3424 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3425 | @Override |
| 3426 | public void selectRotationAnimationLw(int anim[]) { |
Adrian Roos | 7c89480 | 2017-07-19 12:25:34 +0200 | [diff] [blame] | 3427 | // If the screen is off or non-interactive, force a jumpcut. |
Adrian Roos | 3162b8f | 2017-07-25 15:37:32 +0200 | [diff] [blame] | 3428 | final boolean forceJumpcut = !mScreenOnFully || !okToAnimate(); |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3429 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 3430 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 3431 | + (mTopFullscreenOpaqueWindowState == null ? |
Adrian Roos | 7c89480 | 2017-07-19 12:25:34 +0200 | [diff] [blame] | 3432 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) |
| 3433 | + " forceJumpcut=" + forceJumpcut); |
| 3434 | if (forceJumpcut) { |
| 3435 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 3436 | anim[1] = R.anim.rotation_animation_enter; |
| 3437 | return; |
| 3438 | } |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 3439 | if (mTopFullscreenOpaqueWindowState != null) { |
| 3440 | int animationHint = mTopFullscreenOpaqueWindowState.getRotationAnimationHint(); |
| 3441 | if (animationHint < 0 && mTopIsFullscreen) { |
| 3442 | animationHint = mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation; |
| 3443 | } |
| 3444 | switch (animationHint) { |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3445 | case ROTATION_ANIMATION_CROSSFADE: |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 3446 | case ROTATION_ANIMATION_SEAMLESS: // Crossfade is fallback for seamless. |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3447 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 3448 | anim[1] = R.anim.rotation_animation_enter; |
| 3449 | break; |
| 3450 | case ROTATION_ANIMATION_JUMPCUT: |
| 3451 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 3452 | anim[1] = R.anim.rotation_animation_enter; |
| 3453 | break; |
| 3454 | case ROTATION_ANIMATION_ROTATE: |
| 3455 | default: |
| 3456 | anim[0] = anim[1] = 0; |
| 3457 | break; |
| 3458 | } |
| 3459 | } else { |
| 3460 | anim[0] = anim[1] = 0; |
| 3461 | } |
| 3462 | } |
| 3463 | |
| 3464 | @Override |
| 3465 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 3466 | boolean forceDefault) { |
| 3467 | switch (exitAnimId) { |
| 3468 | case R.anim.rotation_animation_xfade_exit: |
| 3469 | case R.anim.rotation_animation_jump_exit: |
| 3470 | // These are the only cases that matter. |
| 3471 | if (forceDefault) { |
| 3472 | return false; |
| 3473 | } |
| 3474 | int anim[] = new int[2]; |
| 3475 | selectRotationAnimationLw(anim); |
| 3476 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 3477 | default: |
| 3478 | return true; |
| 3479 | } |
| 3480 | } |
| 3481 | |
| 3482 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3483 | public Animation createHiddenByKeyguardExit(boolean onWallpaper, |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 3484 | boolean goingToNotificationShade) { |
| 3485 | if (goingToNotificationShade) { |
| 3486 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
Craig Mautner | b834080 | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 3487 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 3488 | |
| 3489 | AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? |
| 3490 | R.anim.lock_screen_behind_enter_wallpaper : |
| 3491 | R.anim.lock_screen_behind_enter); |
| 3492 | |
| 3493 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 3494 | final List<Animation> animations = set.getAnimations(); |
| 3495 | for (int i = animations.size() - 1; i >= 0; --i) { |
| 3496 | animations.get(i).setInterpolator(mLogDecelerateInterpolator); |
| 3497 | } |
| 3498 | |
| 3499 | return set; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | |
| 3503 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3504 | public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) { |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 3505 | if (goingToNotificationShade) { |
| 3506 | return null; |
| 3507 | } else { |
| 3508 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 3509 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 3510 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 3511 | |
| 3512 | private static void awakenDreams() { |
| 3513 | IDreamManager dreamManager = getDreamManager(); |
| 3514 | if (dreamManager != null) { |
| 3515 | try { |
| 3516 | dreamManager.awaken(); |
| 3517 | } catch (RemoteException e) { |
| 3518 | // fine, stay asleep then |
| 3519 | } |
| 3520 | } |
| 3521 | } |
| 3522 | |
| 3523 | static IDreamManager getDreamManager() { |
| 3524 | return IDreamManager.Stub.asInterface( |
| 3525 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 3526 | } |
| 3527 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 3528 | TelecomManager getTelecommService() { |
| 3529 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3530 | } |
| 3531 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3532 | static IAudioService getAudioService() { |
| 3533 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 3534 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 3535 | if (audioService == null) { |
| 3536 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 3537 | } |
| 3538 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | boolean keyguardOn() { |
Siarhei Vishniakou | 35fbb31 | 2017-12-13 13:48:50 -0800 | [diff] [blame] | 3542 | return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 3546 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 3547 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 3548 | }; |
| 3549 | |
| 3550 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3551 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3552 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3553 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3554 | final int keyCode = event.getKeyCode(); |
| 3555 | final int repeatCount = event.getRepeatCount(); |
| 3556 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3557 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3558 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 3559 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3560 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3561 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3562 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3563 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 3564 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3565 | } |
| 3566 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3567 | // If we think we might have a volume down & power key chord on the way |
| 3568 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 3569 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 3570 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3571 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3572 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3573 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 3574 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3575 | if (now < timeoutTime) { |
| 3576 | return timeoutTime - now; |
| 3577 | } |
| 3578 | } |
| 3579 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3580 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3581 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3582 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3583 | } |
| 3584 | return -1; |
| 3585 | } |
| 3586 | } |
| 3587 | |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 3588 | // If an accessibility shortcut might be partially complete, hold off dispatching until we |
| 3589 | // know if it is complete or not |
Phil Weaver | ce687c5 | 2017-03-15 08:51:52 -0700 | [diff] [blame] | 3590 | if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(false) |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 3591 | && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3592 | if (mScreenshotChordVolumeDownKeyTriggered ^ mA11yShortcutChordVolumeUpKeyTriggered) { |
| 3593 | final long now = SystemClock.uptimeMillis(); |
| 3594 | final long timeoutTime = (mScreenshotChordVolumeDownKeyTriggered |
| 3595 | ? mScreenshotChordVolumeDownKeyTime : mA11yShortcutChordVolumeUpKeyTime) |
| 3596 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
| 3597 | if (now < timeoutTime) { |
| 3598 | return timeoutTime - now; |
| 3599 | } |
| 3600 | } |
| 3601 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && mScreenshotChordVolumeDownKeyConsumed) { |
| 3602 | if (!down) { |
| 3603 | mScreenshotChordVolumeDownKeyConsumed = false; |
| 3604 | } |
| 3605 | return -1; |
| 3606 | } |
| 3607 | if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && mA11yShortcutChordVolumeUpKeyConsumed) { |
| 3608 | if (!down) { |
| 3609 | mA11yShortcutChordVolumeUpKeyConsumed = false; |
| 3610 | } |
| 3611 | return -1; |
| 3612 | } |
| 3613 | } |
| 3614 | |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 3615 | // If a ringer toggle chord could be on the way but we're not sure, then tell the dispatcher |
| 3616 | // to wait a little while and try again later before dispatching. |
| 3617 | if (mRingerToggleChord != VOLUME_HUSH_OFF && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3618 | if (mA11yShortcutChordVolumeUpKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
| 3619 | final long now = SystemClock.uptimeMillis(); |
| 3620 | final long timeoutTime = mA11yShortcutChordVolumeUpKeyTime |
| 3621 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
| 3622 | if (now < timeoutTime) { |
| 3623 | return timeoutTime - now; |
| 3624 | } |
| 3625 | } |
| 3626 | if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && mA11yShortcutChordVolumeUpKeyConsumed) { |
| 3627 | if (!down) { |
| 3628 | mA11yShortcutChordVolumeUpKeyConsumed = false; |
| 3629 | } |
| 3630 | return -1; |
| 3631 | } |
| 3632 | } |
| 3633 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3634 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 3635 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 3636 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3637 | mPendingMetaAction = false; |
| 3638 | } |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 3639 | // Any key that is not Alt or Meta cancels Caps Lock combo tracking. |
| 3640 | if (mPendingCapsLockToggle && !KeyEvent.isMetaKey(keyCode) && !KeyEvent.isAltKey(keyCode)) { |
| 3641 | mPendingCapsLockToggle = false; |
| 3642 | } |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3643 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3644 | // First we always handle the home key here, so applications |
| 3645 | // can never break it, although if keyguard is on, we do let |
| 3646 | // it handle it, because that gives us the correct 5 second |
| 3647 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3648 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3649 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3650 | // If we have released the home key, and didn't do anything else |
| 3651 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3652 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3653 | cancelPreloadRecentApps(); |
| 3654 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3655 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3656 | if (mHomeConsumed) { |
| 3657 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3658 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3659 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3660 | |
| 3661 | if (canceled) { |
| 3662 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 3663 | return -1; |
| 3664 | } |
| 3665 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3666 | // Delay handling home if a double-tap is possible. |
| 3667 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 3668 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 3669 | mHomeDoubleTapPending = true; |
| 3670 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 3671 | ViewConfiguration.getDoubleTapTimeout()); |
| 3672 | return -1; |
| 3673 | } |
| 3674 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3675 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3676 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3677 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3678 | |
| 3679 | // If a system window has focus, then it doesn't make sense |
| 3680 | // right now to interact with applications. |
| 3681 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 3682 | if (attrs != null) { |
| 3683 | final int type = attrs.type; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 3684 | if (type == TYPE_KEYGUARD_DIALOG |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3685 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3686 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3687 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3688 | } |
| 3689 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 3690 | for (int i=0; i<typeCount; i++) { |
| 3691 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 3692 | // don't do anything, but also don't pass it to the app |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3693 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3694 | } |
| 3695 | } |
| 3696 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3697 | |
| 3698 | // Remember that home is pressed and handle special actions. |
| 3699 | if (repeatCount == 0) { |
| 3700 | mHomePressed = true; |
| 3701 | if (mHomeDoubleTapPending) { |
| 3702 | mHomeDoubleTapPending = false; |
| 3703 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 3704 | handleDoubleTapOnHome(); |
Sid Soundararajan | ff662fa | 2017-03-15 16:24:24 -0700 | [diff] [blame] | 3705 | } else if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3706 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3707 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3708 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 3709 | if (!keyguardOn) { |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 3710 | handleLongPressOnHome(event.getDeviceId()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3711 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3712 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3713 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3714 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3715 | // Hijack modified menu keys for debugging features |
| 3716 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 3717 | |
| 3718 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3719 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3720 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 3721 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 3722 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3723 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3724 | } |
| 3725 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3726 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3727 | if (down) { |
| 3728 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3729 | mSearchKeyShortcutPending = true; |
| 3730 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3731 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3732 | } else { |
| 3733 | mSearchKeyShortcutPending = false; |
| 3734 | if (mConsumeSearchKeyUp) { |
| 3735 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3736 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3737 | } |
| 3738 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3739 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3740 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 3741 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3742 | if (down && repeatCount == 0) { |
| 3743 | preloadRecentApps(); |
| 3744 | } else if (!down) { |
| 3745 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 3746 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3747 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3748 | return -1; |
Jun Mukai | d21b3c8 | 2015-04-23 14:09:34 -0700 | [diff] [blame] | 3749 | } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) { |
| 3750 | if (down) { |
| 3751 | IStatusBarService service = getStatusBarService(); |
| 3752 | if (service != null) { |
| 3753 | try { |
| 3754 | service.expandNotificationsPanel(); |
| 3755 | } catch (RemoteException e) { |
| 3756 | // do nothing. |
| 3757 | } |
| 3758 | } |
| 3759 | } |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 3760 | } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed() |
| 3761 | && event.isCtrlPressed()) { |
| 3762 | if (down && repeatCount == 0) { |
| 3763 | int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION |
| 3764 | : TAKE_SCREENSHOT_FULLSCREEN; |
| 3765 | mScreenshotRunnable.setScreenshotType(type); |
| 3766 | mHandler.post(mScreenshotRunnable); |
| 3767 | return -1; |
| 3768 | } |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3769 | } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) { |
Andrei Stingaceanu | 002f712 | 2016-03-30 12:22:05 +0100 | [diff] [blame] | 3770 | if (down && repeatCount == 0 && !isKeyguardLocked()) { |
| 3771 | toggleKeyboardShortcutsMenu(event.getDeviceId()); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3772 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3773 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
Siarhei Vishniakou | 191cf1b | 2017-08-17 16:17:22 -0700 | [diff] [blame] | 3774 | Slog.wtf(TAG, "KEYCODE_ASSIST should be handled in interceptKeyBeforeQueueing"); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3775 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3776 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
Siarhei Vishniakou | 191cf1b | 2017-08-17 16:17:22 -0700 | [diff] [blame] | 3777 | Slog.wtf(TAG, "KEYCODE_VOICE_ASSIST should be handled in interceptKeyBeforeQueueing"); |
| 3778 | return -1; |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 3779 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 3780 | if (down && repeatCount == 0) { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 3781 | mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN); |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 3782 | mHandler.post(mScreenshotRunnable); |
| 3783 | } |
| 3784 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 3785 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 3786 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 3787 | if (down) { |
| 3788 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 3789 | |
| 3790 | // Disable autobrightness if it's on |
| 3791 | int auto = Settings.System.getIntForUser( |
| 3792 | mContext.getContentResolver(), |
| 3793 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 3794 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 3795 | UserHandle.USER_CURRENT_OR_SELF); |
| 3796 | if (auto != 0) { |
| 3797 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3798 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 3799 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 3800 | UserHandle.USER_CURRENT_OR_SELF); |
| 3801 | } |
| 3802 | |
| 3803 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 3804 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 3805 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 3806 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 3807 | Settings.System.SCREEN_BRIGHTNESS, |
| 3808 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 3809 | UserHandle.USER_CURRENT_OR_SELF); |
| 3810 | brightness += step; |
| 3811 | // Make sure we don't go beyond the limits. |
| 3812 | brightness = Math.min(max, brightness); |
| 3813 | brightness = Math.max(min, brightness); |
| 3814 | |
| 3815 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3816 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 3817 | UserHandle.USER_CURRENT_OR_SELF); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3818 | startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 3819 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 3820 | } |
| 3821 | return -1; |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 3822 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 3823 | || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 3824 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { |
Karthik Ravi Shankar | 86ecf34 | 2017-04-28 15:35:58 -0700 | [diff] [blame] | 3825 | if (mUseTvRouting || mHandleVolumeKeysInWM) { |
| 3826 | // On TVs or when the configuration is enabled, volume keys never |
| 3827 | // go to the foreground app. |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 3828 | dispatchDirectAudioEvent(event); |
| 3829 | return -1; |
| 3830 | } |
Karthik Ravi Shankar | 86ecf34 | 2017-04-28 15:35:58 -0700 | [diff] [blame] | 3831 | |
Michael Wright | 0a7e2ea7 | 2017-09-05 15:54:13 +0100 | [diff] [blame] | 3832 | // If the device is in VR mode and keys are "internal" (e.g. on the side of the |
| 3833 | // device), then drop the volume keys and don't forward it to the application/dispatch |
| 3834 | // the audio event. |
Karthik Ravi Shankar | 86ecf34 | 2017-04-28 15:35:58 -0700 | [diff] [blame] | 3835 | if (mPersistentVrModeEnabled) { |
Michael Wright | 0a7e2ea7 | 2017-09-05 15:54:13 +0100 | [diff] [blame] | 3836 | final InputDevice d = event.getDevice(); |
| 3837 | if (d != null && !d.isExternal()) { |
| 3838 | return -1; |
| 3839 | } |
Karthik Ravi Shankar | 86ecf34 | 2017-04-28 15:35:58 -0700 | [diff] [blame] | 3840 | } |
Evan Rosky | 516f9e6 | 2017-01-23 16:43:52 -0800 | [diff] [blame] | 3841 | } else if (keyCode == KeyEvent.KEYCODE_TAB && event.isMetaPressed()) { |
| 3842 | // Pass through keyboard navigation keys. |
| 3843 | return 0; |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 3844 | } else if (mHasFeatureLeanback && interceptBugreportGestureTv(keyCode, down)) { |
| 3845 | return -1; |
Zhen Sun | 62e54c2 | 2017-08-17 15:56:20 -0700 | [diff] [blame] | 3846 | } else if (mHasFeatureLeanback && interceptAccessibilityGestureTv(keyCode, down)) { |
| 3847 | return -1; |
Sujith Ramakrishnan | f8942c0 | 2017-07-18 18:35:14 -0700 | [diff] [blame] | 3848 | } else if (keyCode == KeyEvent.KEYCODE_ALL_APPS) { |
| 3849 | if (!down) { |
| 3850 | mHandler.removeMessages(MSG_HANDLE_ALL_APPS); |
| 3851 | Message msg = mHandler.obtainMessage(MSG_HANDLE_ALL_APPS); |
| 3852 | msg.setAsynchronous(true); |
| 3853 | msg.sendToTarget(); |
| 3854 | } |
| 3855 | return -1; |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3856 | } |
| 3857 | |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 3858 | // Toggle Caps Lock on META-ALT. |
| 3859 | boolean actionTriggered = false; |
| 3860 | if (KeyEvent.isModifierKey(keyCode)) { |
| 3861 | if (!mPendingCapsLockToggle) { |
| 3862 | // Start tracking meta state for combo. |
| 3863 | mInitialMetaState = mMetaState; |
| 3864 | mPendingCapsLockToggle = true; |
| 3865 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 3866 | int altOnMask = mMetaState & KeyEvent.META_ALT_MASK; |
| 3867 | int metaOnMask = mMetaState & KeyEvent.META_META_MASK; |
| 3868 | |
| 3869 | // Check for Caps Lock toggle |
| 3870 | if ((metaOnMask != 0) && (altOnMask != 0)) { |
| 3871 | // Check if nothing else is pressed |
| 3872 | if (mInitialMetaState == (mMetaState ^ (altOnMask | metaOnMask))) { |
| 3873 | // Handle Caps Lock Toggle |
| 3874 | mInputManagerInternal.toggleCapsLock(event.getDeviceId()); |
| 3875 | actionTriggered = true; |
| 3876 | } |
| 3877 | } |
| 3878 | |
| 3879 | // Always stop tracking when key goes up. |
| 3880 | mPendingCapsLockToggle = false; |
| 3881 | } |
| 3882 | } |
| 3883 | // Store current meta state to be able to evaluate it later. |
| 3884 | mMetaState = metaState; |
| 3885 | |
| 3886 | if (actionTriggered) { |
| 3887 | return -1; |
| 3888 | } |
| 3889 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3890 | if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3891 | if (down) { |
| 3892 | mPendingMetaAction = true; |
| 3893 | } else if (mPendingMetaAction) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3894 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId()); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3895 | } |
| 3896 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3897 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3898 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3899 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3900 | // Any printing key that is chorded with Search should be consumed |
| 3901 | // even if no shortcut was invoked. This prevents text from being |
| 3902 | // inadvertently inserted when using a keyboard that has built-in macro |
| 3903 | // shortcut keys (that emit Search+x) and some of them are not registered. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3904 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3905 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 3906 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3907 | mConsumeSearchKeyUp = true; |
| 3908 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3909 | if (down && repeatCount == 0 && !keyguardOn) { |
| 3910 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 3911 | if (shortcutIntent != null) { |
| 3912 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3913 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3914 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3915 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3916 | } catch (ActivityNotFoundException ex) { |
| 3917 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3918 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3919 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3920 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3921 | } else { |
| 3922 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3923 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3924 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3925 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3926 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3927 | } |
| 3928 | } |
| 3929 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3930 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3931 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3932 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 3933 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3934 | if (kcm.isPrintingKey(keyCode)) { |
| 3935 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 3936 | metaState & ~(KeyEvent.META_META_ON |
| 3937 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 3938 | if (shortcutIntent != null) { |
| 3939 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3940 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3941 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3942 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3943 | } catch (ActivityNotFoundException ex) { |
| 3944 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3945 | + "the activity to which it is registered was not found: " |
| 3946 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 3947 | } |
| 3948 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3949 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3950 | } |
| 3951 | } |
| 3952 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3953 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3954 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3955 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 3956 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 3957 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3958 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3959 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3960 | startActivityAsUser(intent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3961 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3962 | } catch (ActivityNotFoundException ex) { |
| 3963 | Slog.w(TAG, "Dropping application launch key because " |
| 3964 | + "the activity to which it is registered was not found: " |
| 3965 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 3966 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3967 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3968 | } |
| 3969 | } |
| 3970 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3971 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3972 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Michael Wright | d847ad5 | 2015-10-24 13:24:15 +0100 | [diff] [blame] | 3973 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3974 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3975 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3976 | mRecentAppsHeldModifiers = shiftlessModifiers; |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 3977 | showRecentApps(true); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3978 | return -1; |
| 3979 | } |
| 3980 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3981 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 3982 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 3983 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3984 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3985 | } |
| 3986 | |
Yohei Yukawa | 2d9accb | 2018-03-07 19:15:15 -0800 | [diff] [blame] | 3987 | // Handle keyboard layout switching. |
| 3988 | // TODO: Deprecate this behavior when we fully migrate to IME subtype-based layout rotation. |
| 3989 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_SPACE |
| 3990 | && ((metaState & KeyEvent.META_CTRL_MASK) != 0)) { |
| 3991 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 3992 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 3993 | return -1; |
| 3994 | } |
| 3995 | |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3996 | // Handle input method switching. |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3997 | if (down && repeatCount == 0 |
| 3998 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3999 | || (keyCode == KeyEvent.KEYCODE_SPACE |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 4000 | && (metaState & KeyEvent.META_META_MASK) != 0))) { |
| 4001 | final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0; |
| 4002 | mWindowManagerFuncs.switchInputMethod(forwardDirection); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 4003 | return -1; |
| 4004 | } |
| 4005 | if (mLanguageSwitchKeyPressed && !down |
| 4006 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 4007 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 4008 | mLanguageSwitchKeyPressed = false; |
| 4009 | return -1; |
| 4010 | } |
| 4011 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4012 | if (isValidGlobalKey(keyCode) |
| 4013 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4014 | return -1; |
| 4015 | } |
| 4016 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 4017 | if (down) { |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 4018 | long shortcutCode = keyCode; |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 4019 | if (event.isCtrlPressed()) { |
| 4020 | shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE; |
| 4021 | } |
| 4022 | |
| 4023 | if (event.isAltPressed()) { |
| 4024 | shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE; |
| 4025 | } |
| 4026 | |
| 4027 | if (event.isShiftPressed()) { |
| 4028 | shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE; |
| 4029 | } |
| 4030 | |
| 4031 | if (event.isMetaPressed()) { |
| 4032 | shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE; |
| 4033 | } |
| 4034 | |
| 4035 | IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode); |
| 4036 | if (shortcutService != null) { |
| 4037 | try { |
Muyuan Li | b5dd049 | 2016-04-14 13:22:20 -0700 | [diff] [blame] | 4038 | if (isUserSetupComplete()) { |
| 4039 | shortcutService.notifyShortcutKeyPressed(shortcutCode); |
| 4040 | } |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 4041 | } catch (RemoteException e) { |
| 4042 | mShortcutKeyServices.delete(shortcutCode); |
| 4043 | } |
| 4044 | return -1; |
| 4045 | } |
| 4046 | } |
| 4047 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 4048 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 4049 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 4050 | return -1; |
| 4051 | } |
| 4052 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 4053 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4054 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4055 | } |
| 4056 | |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 4057 | /** |
| 4058 | * TV only: recognizes a remote control gesture for capturing a bug report. |
| 4059 | */ |
| 4060 | private boolean interceptBugreportGestureTv(int keyCode, boolean down) { |
| 4061 | // The bugreport capture chord is a long press on DPAD CENTER and BACK simultaneously. |
| 4062 | if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { |
| 4063 | mBugreportTvKey1Pressed = down; |
| 4064 | } else if (keyCode == KeyEvent.KEYCODE_BACK) { |
| 4065 | mBugreportTvKey2Pressed = down; |
| 4066 | } |
| 4067 | |
| 4068 | if (mBugreportTvKey1Pressed && mBugreportTvKey2Pressed) { |
| 4069 | if (!mBugreportTvScheduled) { |
| 4070 | mBugreportTvScheduled = true; |
| 4071 | Message msg = Message.obtain(mHandler, MSG_BUGREPORT_TV); |
| 4072 | msg.setAsynchronous(true); |
| 4073 | mHandler.sendMessageDelayed(msg, BUGREPORT_TV_GESTURE_TIMEOUT_MILLIS); |
| 4074 | } |
| 4075 | } else if (mBugreportTvScheduled) { |
| 4076 | mHandler.removeMessages(MSG_BUGREPORT_TV); |
| 4077 | mBugreportTvScheduled = false; |
| 4078 | } |
| 4079 | |
| 4080 | return mBugreportTvScheduled; |
| 4081 | } |
| 4082 | |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 4083 | /** |
| 4084 | * TV only: recognizes a remote control gesture as Accessibility shortcut. |
Zhen Sun | 62e54c2 | 2017-08-17 15:56:20 -0700 | [diff] [blame] | 4085 | * Shortcut: Long press (BACK + DPAD_DOWN) |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 4086 | */ |
Zhen Sun | 62e54c2 | 2017-08-17 15:56:20 -0700 | [diff] [blame] | 4087 | private boolean interceptAccessibilityGestureTv(int keyCode, boolean down) { |
| 4088 | if (keyCode == KeyEvent.KEYCODE_BACK) { |
| 4089 | mAccessibilityTvKey1Pressed = down; |
| 4090 | } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { |
| 4091 | mAccessibilityTvKey2Pressed = down; |
| 4092 | } |
| 4093 | |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 4094 | if (mAccessibilityTvKey1Pressed && mAccessibilityTvKey2Pressed) { |
| 4095 | if (!mAccessibilityTvScheduled) { |
| 4096 | mAccessibilityTvScheduled = true; |
| 4097 | Message msg = Message.obtain(mHandler, MSG_ACCESSIBILITY_TV); |
| 4098 | msg.setAsynchronous(true); |
Eugene Susla | 5f19cd3 | 2017-10-19 14:00:59 -0700 | [diff] [blame] | 4099 | mHandler.sendMessageDelayed(msg, getAccessibilityShortcutTimeout()); |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 4100 | } |
| 4101 | } else if (mAccessibilityTvScheduled) { |
| 4102 | mHandler.removeMessages(MSG_ACCESSIBILITY_TV); |
| 4103 | mAccessibilityTvScheduled = false; |
| 4104 | } |
Zhen Sun | 62e54c2 | 2017-08-17 15:56:20 -0700 | [diff] [blame] | 4105 | |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 4106 | return mAccessibilityTvScheduled; |
| 4107 | } |
| 4108 | |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 4109 | private void takeBugreport() { |
| 4110 | if ("1".equals(SystemProperties.get("ro.debuggable")) |
| 4111 | || Settings.Global.getInt(mContext.getContentResolver(), |
| 4112 | Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1) { |
| 4113 | try { |
| 4114 | ActivityManager.getService() |
| 4115 | .requestBugReport(ActivityManager.BUGREPORT_OPTION_INTERACTIVE); |
| 4116 | } catch (RemoteException e) { |
| 4117 | Slog.e(TAG, "Error taking bugreport", e); |
| 4118 | } |
| 4119 | } |
| 4120 | } |
| 4121 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4122 | /** {@inheritDoc} */ |
| 4123 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 4124 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 4125 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4126 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 4127 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 4128 | + ", flags=" + event.getFlags() |
| 4129 | + ", keyCode=" + event.getKeyCode() |
| 4130 | + ", scanCode=" + event.getScanCode() |
| 4131 | + ", metaState=" + event.getMetaState() |
| 4132 | + ", repeatCount=" + event.getRepeatCount() |
| 4133 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4134 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 4135 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 4136 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 4137 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 4138 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 4139 | final int keyCode = event.getKeyCode(); |
| 4140 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 4141 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 4142 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 4143 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 4144 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 4145 | final FallbackAction fallbackAction; |
| 4146 | if (initialDown) { |
| 4147 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 4148 | } else { |
| 4149 | fallbackAction = mFallbackActions.get(keyCode); |
| 4150 | } |
| 4151 | |
| 4152 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4153 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 4154 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 4155 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 4156 | } |
| 4157 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 4158 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 4159 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 4160 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 4161 | event.getAction(), fallbackAction.keyCode, |
| 4162 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 4163 | event.getDeviceId(), event.getScanCode(), |
| 4164 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 4165 | |
| 4166 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 4167 | fallbackEvent.recycle(); |
| 4168 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 4169 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 4170 | |
| 4171 | if (initialDown) { |
| 4172 | mFallbackActions.put(keyCode, fallbackAction); |
| 4173 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 4174 | mFallbackActions.remove(keyCode); |
| 4175 | fallbackAction.recycle(); |
| 4176 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 4177 | } |
| 4178 | } |
| 4179 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4180 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 4181 | if (fallbackEvent == null) { |
| 4182 | Slog.d(TAG, "No fallback."); |
| 4183 | } else { |
| 4184 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 4185 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 4186 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 4187 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4188 | } |
| 4189 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 4190 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4191 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 4192 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 4193 | long delayMillis = interceptKeyBeforeDispatching( |
| 4194 | win, fallbackEvent, policyFlags); |
| 4195 | if (delayMillis == 0) { |
| 4196 | return true; |
| 4197 | } |
| 4198 | } |
| 4199 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 4200 | } |
| 4201 | |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 4202 | @Override |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 4203 | public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService) |
| 4204 | throws RemoteException { |
| 4205 | synchronized (mLock) { |
| 4206 | IShortcutService service = mShortcutKeyServices.get(shortcutCode); |
Muyuan Li | 24d24ac | 2016-03-03 21:15:02 -0800 | [diff] [blame] | 4207 | if (service != null && service.asBinder().pingBinder()) { |
| 4208 | throw new RemoteException("Key already exists."); |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 4209 | } |
| 4210 | |
| 4211 | mShortcutKeyServices.put(shortcutCode, shortcutService); |
| 4212 | } |
| 4213 | } |
| 4214 | |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 4215 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4216 | public void onKeyguardOccludedChangedLw(boolean occluded) { |
| 4217 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
| 4218 | mPendingKeyguardOccluded = occluded; |
| 4219 | mKeyguardOccludedChanged = true; |
| 4220 | } else { |
Jorim Jaggi | 9ba2e10 | 2017-04-04 12:51:03 +0200 | [diff] [blame] | 4221 | setKeyguardOccludedLw(occluded, false /* force */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4222 | } |
| 4223 | } |
| 4224 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 4225 | private int handleStartTransitionForKeyguardLw(int transit, long duration) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4226 | if (mKeyguardOccludedChanged) { |
| 4227 | if (DEBUG_KEYGUARD) Slog.d(TAG, "transition/occluded changed occluded=" |
| 4228 | + mPendingKeyguardOccluded); |
| 4229 | mKeyguardOccludedChanged = false; |
Jorim Jaggi | 9ba2e10 | 2017-04-04 12:51:03 +0200 | [diff] [blame] | 4230 | if (setKeyguardOccludedLw(mPendingKeyguardOccluded, false /* force */)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4231 | return FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4232 | } |
| 4233 | } |
| 4234 | if (AppTransition.isKeyguardGoingAwayTransit(transit)) { |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 4235 | if (DEBUG_KEYGUARD) Slog.d(TAG, "Starting keyguard exit animation"); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 4236 | startKeyguardExitAnimation(SystemClock.uptimeMillis(), duration); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4237 | } |
| 4238 | return 0; |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 4239 | } |
| 4240 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 4241 | private void launchAssistLongPressAction() { |
| 4242 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 4243 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 4244 | |
| 4245 | // launch the search activity |
| 4246 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 4247 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 4248 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4249 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 4250 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 4251 | SearchManager searchManager = getSearchManager(); |
| 4252 | if (searchManager != null) { |
| 4253 | searchManager.stopSearch(); |
| 4254 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 4255 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 4256 | } catch (ActivityNotFoundException e) { |
| 4257 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 4258 | } |
| 4259 | } |
| 4260 | |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 4261 | private void launchAssistAction(String hint, int deviceId) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 4262 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Maurice Lam | 39d1381 | 2015-07-23 20:49:20 -0700 | [diff] [blame] | 4263 | if (!isUserSetupComplete()) { |
| 4264 | // Disable opening assist window during setup |
| 4265 | return; |
| 4266 | } |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 4267 | Bundle args = null; |
| 4268 | if (deviceId > Integer.MIN_VALUE) { |
| 4269 | args = new Bundle(); |
| 4270 | args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 4271 | } |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 4272 | if ((mContext.getResources().getConfiguration().uiMode |
| 4273 | & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) { |
| 4274 | // On TV, use legacy handling until assistants are implemented in the proper way. |
| 4275 | ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
| 4276 | .launchLegacyAssist(hint, UserHandle.myUserId(), args); |
| 4277 | } else { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4278 | if (hint != null) { |
| 4279 | if (args == null) { |
| 4280 | args = new Bundle(); |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 4281 | } |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4282 | args.putBoolean(hint, true); |
| 4283 | } |
| 4284 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4285 | if (statusbar != null) { |
| 4286 | statusbar.startAssist(args); |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 4287 | } |
| 4288 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 4289 | } |
| 4290 | |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 4291 | private void startActivityAsUser(Intent intent, UserHandle handle) { |
| 4292 | if (isUserSetupComplete()) { |
| 4293 | mContext.startActivityAsUser(intent, handle); |
| 4294 | } else { |
| 4295 | Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); |
| 4296 | } |
| 4297 | } |
| 4298 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 4299 | private SearchManager getSearchManager() { |
| 4300 | if (mSearchManager == null) { |
| 4301 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 4302 | } |
| 4303 | return mSearchManager; |
| 4304 | } |
| 4305 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 4306 | private void preloadRecentApps() { |
| 4307 | mPreloadedRecentApps = true; |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4308 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4309 | if (statusbar != null) { |
| 4310 | statusbar.preloadRecentApps(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 4311 | } |
| 4312 | } |
| 4313 | |
| 4314 | private void cancelPreloadRecentApps() { |
| 4315 | if (mPreloadedRecentApps) { |
| 4316 | mPreloadedRecentApps = false; |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4317 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4318 | if (statusbar != null) { |
| 4319 | statusbar.cancelPreloadRecentApps(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 4320 | } |
| 4321 | } |
| 4322 | } |
| 4323 | |
| 4324 | private void toggleRecentApps() { |
| 4325 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4326 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4327 | if (statusbar != null) { |
| 4328 | statusbar.toggleRecentApps(); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 4329 | } |
| 4330 | } |
| 4331 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4332 | @Override |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 4333 | public void showRecentApps() { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4334 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 4335 | mHandler.obtainMessage(MSG_DISPATCH_SHOW_RECENTS).sendToTarget(); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4336 | } |
| 4337 | |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 4338 | private void showRecentApps(boolean triggeredFromAltTab) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 4339 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4340 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4341 | if (statusbar != null) { |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 4342 | statusbar.showRecentApps(triggeredFromAltTab); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 4343 | } |
| 4344 | } |
| 4345 | |
Clara Bayarri | 4e850ff | 2016-03-02 11:12:32 -0800 | [diff] [blame] | 4346 | private void toggleKeyboardShortcutsMenu(int deviceId) { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4347 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4348 | if (statusbar != null) { |
| 4349 | statusbar.toggleKeyboardShortcutsMenu(deviceId); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 4350 | } |
| 4351 | } |
| 4352 | |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 4353 | private void dismissKeyboardShortcutsMenu() { |
| 4354 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4355 | if (statusbar != null) { |
| 4356 | statusbar.dismissKeyboardShortcutsMenu(); |
| 4357 | } |
| 4358 | } |
| 4359 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 4360 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 4361 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4362 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4363 | if (statusbar != null) { |
| 4364 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 4365 | } |
| 4366 | } |
| 4367 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 4368 | void launchHomeFromHotKey() { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4369 | launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 4370 | } |
| 4371 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4372 | /** |
| 4373 | * A home key -> launch home action was detected. Take the appropriate action |
| 4374 | * given the situation with the keyguard. |
| 4375 | */ |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4376 | void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) { |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 4377 | // Abort possibly stuck animations. |
| 4378 | mHandler.post(mWindowManagerFuncs::triggerAnimationFailsafe); |
| 4379 | |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4380 | if (respectKeyguard) { |
| 4381 | if (isKeyguardShowingAndNotOccluded()) { |
| 4382 | // don't launch home if keyguard showing |
| 4383 | return; |
Winson Chung | 2a35e6d | 2018-01-13 14:27:50 -0800 | [diff] [blame] | 4384 | } else if (mKeyguardOccluded && mKeyguardDelegate.isShowing()) { |
| 4385 | mKeyguardDelegate.dismiss(new KeyguardDismissCallback() { |
| 4386 | @Override |
| 4387 | public void onDismissSucceeded() throws RemoteException { |
| 4388 | mHandler.post(() -> { |
| 4389 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
| 4390 | }); |
| 4391 | } |
| 4392 | }, null /* message */); |
| 4393 | return; |
| 4394 | } else if (!mKeyguardOccluded && mKeyguardDelegate.isInputRestricted()) { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4395 | // when in keyguard restricted mode, must first verify unlock |
| 4396 | // before launching home |
| 4397 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
| 4398 | @Override |
| 4399 | public void onKeyguardExitResult(boolean success) { |
| 4400 | if (success) { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4401 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 4402 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4403 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4404 | }); |
| 4405 | return; |
| 4406 | } |
| 4407 | } |
| 4408 | |
| 4409 | // no keyguard stuff to worry about, just launch home! |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4410 | if (mRecentsVisible) { |
Winson Chung | 2a35e6d | 2018-01-13 14:27:50 -0800 | [diff] [blame] | 4411 | try { |
| 4412 | ActivityManager.getService().stopAppSwitches(); |
| 4413 | } catch (RemoteException e) {} |
| 4414 | |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4415 | // Hide Recents and notify it to launch Home |
| 4416 | if (awakenFromDreams) { |
| 4417 | awakenDreams(); |
| 4418 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4419 | hideRecentApps(false, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4420 | } else { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4421 | // Otherwise, just launch Home |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4422 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4423 | } |
| 4424 | } |
| 4425 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4426 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 4427 | @Override |
| 4428 | public void run() { |
| 4429 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 4430 | // Clear flags. |
| 4431 | mForceClearedSystemUiFlags &= |
| 4432 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 4433 | } |
| 4434 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4435 | } |
| 4436 | }; |
| 4437 | |
| 4438 | /** |
| 4439 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 4440 | * to determine when the nav bar should be shown and prevent applications from |
| 4441 | * receiving those touches. |
| 4442 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 4443 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 4444 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 4445 | super(inputChannel, looper); |
| 4446 | } |
| 4447 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4448 | @Override |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 4449 | public void onInputEvent(InputEvent event, int displayId) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4450 | boolean handled = false; |
| 4451 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4452 | if (event instanceof MotionEvent |
| 4453 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 4454 | final MotionEvent motionEvent = (MotionEvent)event; |
| 4455 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4456 | // When the user taps down, we re-show the nav bar. |
| 4457 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4458 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 4459 | if (mInputConsumer == null) { |
| 4460 | return; |
| 4461 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4462 | // Any user activity always causes us to show the |
| 4463 | // navigation controls, if they had been hidden. |
| 4464 | // We also clear the low profile and only content |
| 4465 | // flags so that tapping on the screen will atomically |
| 4466 | // restore all currently hidden screen decorations. |
| 4467 | int newVal = mResettingSystemUiFlags | |
| 4468 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 4469 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 4470 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4471 | if (mResettingSystemUiFlags != newVal) { |
| 4472 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4473 | changed = true; |
| 4474 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4475 | // We don't allow the system's nav bar to be hidden |
| 4476 | // again for 1 second, to prevent applications from |
| 4477 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4478 | newVal = mForceClearedSystemUiFlags | |
| 4479 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4480 | if (mForceClearedSystemUiFlags != newVal) { |
| 4481 | mForceClearedSystemUiFlags = newVal; |
| 4482 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4483 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4484 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4485 | } |
| 4486 | if (changed) { |
| 4487 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 4488 | } |
| 4489 | } |
| 4490 | } |
| 4491 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 4492 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4493 | } |
| 4494 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 4495 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4496 | |
| 4497 | @Override |
Winson | ab21660 | 2016-08-09 14:05:20 -0700 | [diff] [blame] | 4498 | public void setRecentsVisibilityLw(boolean visible) { |
| 4499 | mRecentsVisible = visible; |
| 4500 | } |
| 4501 | |
| 4502 | @Override |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 4503 | public void setPipVisibilityLw(boolean visible) { |
| 4504 | mPictureInPictureVisible = visible; |
Winson | ab21660 | 2016-08-09 14:05:20 -0700 | [diff] [blame] | 4505 | } |
| 4506 | |
| 4507 | @Override |
Matthew Ng | 64543e6 | 2018-02-28 17:35:10 -0800 | [diff] [blame] | 4508 | public void setNavBarVirtualKeyHapticFeedbackEnabledLw(boolean enabled) { |
| 4509 | mNavBarVirtualKeyHapticFeedbackEnabled = enabled; |
| 4510 | } |
| 4511 | |
| 4512 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4513 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 4514 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 4515 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4516 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4517 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 4518 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4519 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4520 | // Clear any bits in the new visibility that are currently being |
| 4521 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4522 | return visibility & ~mResettingSystemUiFlags |
| 4523 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4524 | } |
| 4525 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4526 | @Override |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4527 | // TODO: Should probably be moved into DisplayFrames. |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 4528 | public boolean getLayoutHintLw(WindowManager.LayoutParams attrs, Rect taskBounds, |
| 4529 | DisplayFrames displayFrames, Rect outFrame, Rect outContentInsets, Rect outStableInsets, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 4530 | Rect outOutsets, DisplayCutout.ParcelableWrapper outDisplayCutout) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4531 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
Adrian Roos | f8898ab | 2018-01-22 17:47:28 +0100 | [diff] [blame] | 4532 | final int pfl = attrs.privateFlags; |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 4533 | final int requestedSysUiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 4534 | final int sysUiVis = requestedSysUiVis | getImpliedSysUiFlagsForLayout(attrs); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4535 | final int displayRotation = displayFrames.mRotation; |
| 4536 | final int displayWidth = displayFrames.mDisplayWidth; |
| 4537 | final int displayHeight = displayFrames.mDisplayHeight; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4538 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4539 | final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl); |
| 4540 | if (useOutsets) { |
| 4541 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 4542 | if (outset > 0) { |
| 4543 | if (displayRotation == Surface.ROTATION_0) { |
| 4544 | outOutsets.bottom += outset; |
| 4545 | } else if (displayRotation == Surface.ROTATION_90) { |
| 4546 | outOutsets.right += outset; |
| 4547 | } else if (displayRotation == Surface.ROTATION_180) { |
| 4548 | outOutsets.top += outset; |
| 4549 | } else if (displayRotation == Surface.ROTATION_270) { |
| 4550 | outOutsets.left += outset; |
| 4551 | } |
| 4552 | } |
| 4553 | } |
| 4554 | |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 4555 | final boolean layoutInScreen = (fl & FLAG_LAYOUT_IN_SCREEN) != 0; |
| 4556 | final boolean layoutInScreenAndInsetDecor = layoutInScreen && |
| 4557 | (fl & FLAG_LAYOUT_INSET_DECOR) != 0; |
Adrian Roos | f8898ab | 2018-01-22 17:47:28 +0100 | [diff] [blame] | 4558 | final boolean screenDecor = (pfl & PRIVATE_FLAG_IS_SCREEN_DECOR) != 0; |
| 4559 | |
| 4560 | if (layoutInScreenAndInsetDecor && !screenDecor) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4561 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4562 | if (canHideNavigationBar() && |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 4563 | (sysUiVis & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
| 4564 | outFrame.set(displayFrames.mUnrestricted); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4565 | availRight = displayFrames.mUnrestricted.right; |
| 4566 | availBottom = displayFrames.mUnrestricted.bottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4567 | } else { |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 4568 | outFrame.set(displayFrames.mRestricted); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4569 | availRight = displayFrames.mRestricted.right; |
| 4570 | availBottom = displayFrames.mRestricted.bottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4571 | } |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4572 | outStableInsets.set(displayFrames.mStable.left, displayFrames.mStable.top, |
| 4573 | availRight - displayFrames.mStable.right, |
| 4574 | availBottom - displayFrames.mStable.bottom); |
| 4575 | |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 4576 | if ((sysUiVis & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4577 | if ((fl & FLAG_FULLSCREEN) != 0) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4578 | outContentInsets.set(displayFrames.mStableFullscreen.left, |
| 4579 | displayFrames.mStableFullscreen.top, |
| 4580 | availRight - displayFrames.mStableFullscreen.right, |
| 4581 | availBottom - displayFrames.mStableFullscreen.bottom); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4582 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4583 | outContentInsets.set(outStableInsets); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4584 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4585 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4586 | outContentInsets.setEmpty(); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4587 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4588 | outContentInsets.set(displayFrames.mCurrent.left, displayFrames.mCurrent.top, |
| 4589 | availRight - displayFrames.mCurrent.right, |
| 4590 | availBottom - displayFrames.mCurrent.bottom); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4591 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4592 | |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 4593 | if (taskBounds != null) { |
| 4594 | calculateRelevantTaskInsets(taskBounds, outContentInsets, |
| 4595 | displayWidth, displayHeight); |
| 4596 | calculateRelevantTaskInsets(taskBounds, outStableInsets, |
| 4597 | displayWidth, displayHeight); |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 4598 | outFrame.intersect(taskBounds); |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 4599 | } |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 4600 | outDisplayCutout.set(displayFrames.mDisplayCutout.calculateRelativeTo(outFrame) |
| 4601 | .getDisplayCutout()); |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 4602 | return mForceShowSystemBars; |
| 4603 | } else { |
| 4604 | if (layoutInScreen) { |
| 4605 | outFrame.set(displayFrames.mUnrestricted); |
| 4606 | } else { |
| 4607 | outFrame.set(displayFrames.mStable); |
| 4608 | } |
| 4609 | if (taskBounds != null) { |
| 4610 | outFrame.intersect(taskBounds); |
| 4611 | } |
| 4612 | |
| 4613 | outContentInsets.setEmpty(); |
| 4614 | outStableInsets.setEmpty(); |
| 4615 | outDisplayCutout.set(DisplayCutout.NO_CUTOUT); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 4616 | return mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4617 | } |
| 4618 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4619 | |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 4620 | /** |
| 4621 | * For any given task bounds, the insets relevant for these bounds given the insets relevant |
| 4622 | * for the entire display. |
| 4623 | */ |
| 4624 | private void calculateRelevantTaskInsets(Rect taskBounds, Rect inOutInsets, int displayWidth, |
| 4625 | int displayHeight) { |
| 4626 | mTmpRect.set(0, 0, displayWidth, displayHeight); |
| 4627 | mTmpRect.inset(inOutInsets); |
| 4628 | mTmpRect.intersect(taskBounds); |
| 4629 | int leftInset = mTmpRect.left - taskBounds.left; |
| 4630 | int topInset = mTmpRect.top - taskBounds.top; |
| 4631 | int rightInset = taskBounds.right - mTmpRect.right; |
| 4632 | int bottomInset = taskBounds.bottom - mTmpRect.bottom; |
| 4633 | inOutInsets.set(leftInset, topInset, rightInset, bottomInset); |
| 4634 | } |
| 4635 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4636 | private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) { |
| 4637 | return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 4638 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0; |
| 4639 | } |
| 4640 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4641 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4642 | @Override |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4643 | public void beginLayoutLw(DisplayFrames displayFrames, int uiMode) { |
Adrian Roos | 30f5321 | 2018-01-05 16:14:34 +0100 | [diff] [blame] | 4644 | displayFrames.onBeginLayout(); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4645 | // TODO(multi-display): This doesn't seem right...Maybe only apply to default display? |
| 4646 | mSystemGestures.screenWidth = displayFrames.mUnrestricted.width(); |
| 4647 | mSystemGestures.screenHeight = displayFrames.mUnrestricted.height(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4648 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 4649 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4650 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4651 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 4652 | final Rect pf = mTmpParentFrame; |
| 4653 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4654 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4655 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4656 | final Rect dcf = mTmpDecorFrame; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4657 | vf.set(displayFrames.mDock); |
| 4658 | of.set(displayFrames.mDock); |
| 4659 | df.set(displayFrames.mDock); |
| 4660 | pf.set(displayFrames.mDock); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4661 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4662 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4663 | if (displayFrames.mDisplayId == DEFAULT_DISPLAY) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4664 | // For purposes of putting out fake window up to steal focus, we will |
| 4665 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4666 | final int sysui = mLastSystemUiFlags; |
| 4667 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4668 | boolean navTranslucent = (sysui |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4669 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 4670 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 4671 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 4672 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 4673 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4674 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mKeyguardOccluded; |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 4675 | if (!isKeyguardShowing) { |
| 4676 | navTranslucent &= areTranslucentBarsAllowed(); |
| 4677 | } |
Jaewan Kim | 3328433 | 2016-05-12 18:55:46 +0900 | [diff] [blame] | 4678 | boolean statusBarExpandedNotKeyguard = !isKeyguardShowing && mStatusBar != null |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4679 | && mStatusBar.getAttrs().height == MATCH_PARENT |
| 4680 | && mStatusBar.getAttrs().width == MATCH_PARENT; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4681 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4682 | // When the navigation bar isn't visible, we put up a fake input window to catch all |
| 4683 | // touch events. This way we can detect when the user presses anywhere to bring back the |
| 4684 | // nav bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 4685 | if (navVisible || navAllowedHidden) { |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 4686 | if (mInputConsumer != null) { |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 4687 | mHandler.sendMessage( |
| 4688 | mHandler.obtainMessage(MSG_DISPOSE_INPUT_CONSUMER, mInputConsumer)); |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 4689 | mInputConsumer = null; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4690 | } |
Tun Zheng | 66dc035 | 2018-01-15 16:55:06 +0800 | [diff] [blame] | 4691 | } else if (mInputConsumer == null && mStatusBar != null && canHideNavigationBar()) { |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 4692 | mInputConsumer = mWindowManagerFuncs.createInputConsumer(mHandler.getLooper(), |
| 4693 | INPUT_CONSUMER_NAVIGATION, |
| 4694 | (channel, looper) -> new HideNavInputEventReceiver(channel, looper)); |
Vladislav Kaznacheev | 19dab2d | 2017-02-07 10:12:51 -0800 | [diff] [blame] | 4695 | // As long as mInputConsumer is active, hover events are not dispatched to the app |
| 4696 | // and the pointer icon is likely to become stale. Hide it to avoid confusion. |
| 4697 | InputManager.getInstance().setPointerIconType(PointerIcon.TYPE_NULL); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4698 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4699 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4700 | // For purposes of positioning and showing the nav bar, if we have decided that it can't |
| 4701 | // be hidden (because of the screen aspect ratio), then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4702 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4703 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4704 | boolean updateSysUiVisibility = layoutNavigationBar(displayFrames, uiMode, dcf, |
| 4705 | navVisible, navTranslucent, navAllowedHidden, statusBarExpandedNotKeyguard); |
| 4706 | if (DEBUG_LAYOUT) Slog.i(TAG, "mDock rect:" + displayFrames.mDock); |
| 4707 | updateSysUiVisibility |= layoutStatusBar( |
| 4708 | displayFrames, pf, df, of, vf, dcf, sysui, isKeyguardShowing); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4709 | if (updateSysUiVisibility) { |
| 4710 | updateSystemUiVisibilityLw(); |
| 4711 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4712 | } |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4713 | layoutScreenDecorWindows(displayFrames, pf, df, dcf); |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 4714 | |
| 4715 | if (displayFrames.mDisplayCutoutSafe.top > displayFrames.mUnrestricted.top) { |
| 4716 | // Make sure that the zone we're avoiding for the cutout is at least as tall as the |
| 4717 | // status bar; otherwise fullscreen apps will end up cutting halfway into the status |
| 4718 | // bar. |
| 4719 | displayFrames.mDisplayCutoutSafe.top = Math.max(displayFrames.mDisplayCutoutSafe.top, |
| 4720 | displayFrames.mStable.top); |
| 4721 | } |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 4722 | } |
| 4723 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4724 | private void layoutScreenDecorWindows(DisplayFrames displayFrames, Rect pf, Rect df, Rect dcf) { |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 4725 | if (mScreenDecorWindows.isEmpty()) { |
| 4726 | return; |
| 4727 | } |
| 4728 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4729 | final int displayId = displayFrames.mDisplayId; |
| 4730 | final Rect dockFrame = displayFrames.mDock; |
| 4731 | final int displayHeight = displayFrames.mDisplayHeight; |
| 4732 | final int displayWidth = displayFrames.mDisplayWidth; |
| 4733 | |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 4734 | for (int i = mScreenDecorWindows.size() - 1; i >= 0; --i) { |
| 4735 | final WindowState w = mScreenDecorWindows.valueAt(i); |
| 4736 | if (w.getDisplayId() != displayId || !w.isVisibleLw()) { |
| 4737 | // Skip if not on the same display or not visible. |
| 4738 | continue; |
| 4739 | } |
| 4740 | |
| 4741 | w.computeFrameLw(pf /* parentFrame */, df /* displayFrame */, df /* overlayFrame */, |
| 4742 | df /* contentFrame */, df /* visibleFrame */, dcf /* decorFrame */, |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 4743 | df /* stableFrame */, df /* outsetFrame */, displayFrames.mDisplayCutout, |
| 4744 | false /* parentFrameWasClippedByDisplayCutout */); |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 4745 | final Rect frame = w.getFrameLw(); |
| 4746 | |
| 4747 | if (frame.left <= 0 && frame.top <= 0) { |
| 4748 | // Docked at left or top. |
| 4749 | if (frame.bottom >= displayHeight) { |
| 4750 | // Docked left. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4751 | dockFrame.left = Math.max(frame.right, dockFrame.left); |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 4752 | } else if (frame.right >= displayWidth ) { |
| 4753 | // Docked top. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4754 | dockFrame.top = Math.max(frame.bottom, dockFrame.top); |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 4755 | } else { |
| 4756 | Slog.w(TAG, "layoutScreenDecorWindows: Ignoring decor win=" + w |
| 4757 | + " not docked on left or top of display. frame=" + frame |
| 4758 | + " displayWidth=" + displayWidth + " displayHeight=" + displayHeight); |
| 4759 | } |
| 4760 | } else if (frame.right >= displayWidth && frame.bottom >= displayHeight) { |
| 4761 | // Docked at right or bottom. |
| 4762 | if (frame.top <= 0) { |
| 4763 | // Docked right. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4764 | dockFrame.right = Math.min(frame.left, dockFrame.right); |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 4765 | } else if (frame.left <= 0) { |
| 4766 | // Docked bottom. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4767 | dockFrame.bottom = Math.min(frame.top, dockFrame.bottom); |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 4768 | } else { |
| 4769 | Slog.w(TAG, "layoutScreenDecorWindows: Ignoring decor win=" + w |
| 4770 | + " not docked on right or bottom" + " of display. frame=" + frame |
| 4771 | + " displayWidth=" + displayWidth + " displayHeight=" + displayHeight); |
| 4772 | } |
| 4773 | } else { |
| 4774 | // Screen decor windows are required to be docked on one of the sides of the screen. |
| 4775 | Slog.w(TAG, "layoutScreenDecorWindows: Ignoring decor win=" + w |
| 4776 | + " not docked on one of the sides of the display. frame=" + frame |
| 4777 | + " displayWidth=" + displayWidth + " displayHeight=" + displayHeight); |
| 4778 | } |
| 4779 | } |
| 4780 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4781 | displayFrames.mRestricted.set(dockFrame); |
| 4782 | displayFrames.mCurrent.set(dockFrame); |
| 4783 | displayFrames.mVoiceContent.set(dockFrame); |
| 4784 | displayFrames.mSystem.set(dockFrame); |
| 4785 | displayFrames.mContent.set(dockFrame); |
| 4786 | displayFrames.mRestrictedOverscan.set(dockFrame); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4787 | } |
| 4788 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4789 | private boolean layoutStatusBar(DisplayFrames displayFrames, Rect pf, Rect df, Rect of, Rect vf, |
| 4790 | Rect dcf, int sysui, boolean isKeyguardShowing) { |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4791 | // decide where the status bar goes ahead of time |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4792 | if (mStatusBar == null) { |
| 4793 | return false; |
| 4794 | } |
| 4795 | // apply any navigation bar insets |
| 4796 | of.set(displayFrames.mUnrestricted); |
| 4797 | df.set(displayFrames.mUnrestricted); |
| 4798 | pf.set(displayFrames.mUnrestricted); |
| 4799 | vf.set(displayFrames.mStable); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4800 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4801 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4802 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4803 | // Let the status bar determine its size. |
| 4804 | mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */, |
| 4805 | vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 4806 | dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */, |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 4807 | displayFrames.mDisplayCutout, false /* parentFrameWasClippedByDisplayCutout */); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4808 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4809 | // For layout, the status bar is always at the top with our fixed height. |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 4810 | displayFrames.mStable.top = displayFrames.mUnrestricted.top |
| 4811 | + mStatusBarHeightForRotation[displayFrames.mRotation]; |
Adrian Roos | bc746cd | 2018-04-16 16:56:07 +0200 | [diff] [blame] | 4812 | // Make sure the status bar covers the entire cutout height |
| 4813 | displayFrames.mStable.top = Math.max(displayFrames.mStable.top, |
| 4814 | displayFrames.mDisplayCutoutSafe.top); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4815 | |
Adrian Roos | 23df3a3 | 2018-03-15 15:41:13 +0100 | [diff] [blame] | 4816 | // Tell the bar controller where the collapsed status bar content is |
| 4817 | mTmpRect.set(mStatusBar.getContentFrameLw()); |
| 4818 | mTmpRect.intersect(displayFrames.mDisplayCutoutSafe); |
| 4819 | mTmpRect.top = mStatusBar.getContentFrameLw().top; // Ignore top display cutout inset |
| 4820 | mTmpRect.bottom = displayFrames.mStable.top; // Use collapsed status bar size |
| 4821 | mStatusBarController.setContentFrame(mTmpRect); |
| 4822 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4823 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
| 4824 | boolean statusBarTranslucent = (sysui |
| 4825 | & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0; |
| 4826 | if (!isKeyguardShowing) { |
| 4827 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 4828 | } |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4829 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4830 | // If the status bar is hidden, we don't want to cause windows behind it to scroll. |
| 4831 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
| 4832 | // Status bar may go away, so the screen area it occupies is available to apps but just |
| 4833 | // covering them when the status bar is visible. |
| 4834 | final Rect dockFrame = displayFrames.mDock; |
| 4835 | dockFrame.top = displayFrames.mStable.top; |
| 4836 | displayFrames.mContent.set(dockFrame); |
| 4837 | displayFrames.mVoiceContent.set(dockFrame); |
Wale Ogunwale | b773b6c | 2018-01-09 14:05:36 -0800 | [diff] [blame] | 4838 | displayFrames.mCurrent.set(dockFrame); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4839 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4840 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + String.format( |
| 4841 | "dock=%s content=%s cur=%s", dockFrame.toString(), |
| 4842 | displayFrames.mContent.toString(), displayFrames.mCurrent.toString())); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4843 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4844 | if (!mStatusBar.isAnimatingLw() && !statusBarTranslucent |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4845 | && !mStatusBarController.wasRecentlyTranslucent()) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4846 | // If the opaque status bar is currently requested to be visible, and not in the |
| 4847 | // process of animating on or off, then we can tell the app that it is covered by it. |
| 4848 | displayFrames.mSystem.top = displayFrames.mStable.top; |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4849 | } |
| 4850 | } |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4851 | return mStatusBarController.checkHiddenLw(); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4852 | } |
| 4853 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4854 | private boolean layoutNavigationBar(DisplayFrames displayFrames, int uiMode, Rect dcf, |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4855 | boolean navVisible, boolean navTranslucent, boolean navAllowedHidden, |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4856 | boolean statusBarExpandedNotKeyguard) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4857 | if (mNavigationBar == null) { |
| 4858 | return false; |
| 4859 | } |
| 4860 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
| 4861 | // Force the navigation bar to its appropriate place and size. We need to do this directly, |
| 4862 | // instead of relying on it to bubble up from the nav bar, because this needs to change |
| 4863 | // atomically with screen rotations. |
| 4864 | final int rotation = displayFrames.mRotation; |
| 4865 | final int displayHeight = displayFrames.mDisplayHeight; |
| 4866 | final int displayWidth = displayFrames.mDisplayWidth; |
| 4867 | final Rect dockFrame = displayFrames.mDock; |
| 4868 | mNavigationBarPosition = navigationBarPosition(displayWidth, displayHeight, rotation); |
| 4869 | |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 4870 | final Rect cutoutSafeUnrestricted = mTmpRect; |
| 4871 | cutoutSafeUnrestricted.set(displayFrames.mUnrestricted); |
| 4872 | cutoutSafeUnrestricted.intersectUnchecked(displayFrames.mDisplayCutoutSafe); |
| 4873 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4874 | if (mNavigationBarPosition == NAV_BAR_BOTTOM) { |
| 4875 | // It's a system nav bar or a portrait screen; nav bar goes on bottom. |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 4876 | final int top = cutoutSafeUnrestricted.bottom |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4877 | - getNavigationBarHeight(rotation, uiMode); |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 4878 | mTmpNavigationFrame.set(0, top, displayWidth, displayFrames.mUnrestricted.bottom); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4879 | displayFrames.mStable.bottom = displayFrames.mStableFullscreen.bottom = top; |
| 4880 | if (transientNavBarShowing) { |
| 4881 | mNavigationBarController.setBarShowingLw(true); |
| 4882 | } else if (navVisible) { |
| 4883 | mNavigationBarController.setBarShowingLw(true); |
| 4884 | dockFrame.bottom = displayFrames.mRestricted.bottom |
| 4885 | = displayFrames.mRestrictedOverscan.bottom = top; |
| 4886 | } else { |
| 4887 | // We currently want to hide the navigation UI - unless we expanded the status bar. |
| 4888 | mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4889 | } |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4890 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4891 | && !mNavigationBar.isAnimatingLw() |
| 4892 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4893 | // If the opaque nav bar is currently requested to be visible and not in the process |
| 4894 | // of animating on or off, then we can tell the app that it is covered by it. |
| 4895 | displayFrames.mSystem.bottom = top; |
| 4896 | } |
| 4897 | } else if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
| 4898 | // Landscape screen; nav bar goes to the right. |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 4899 | final int left = cutoutSafeUnrestricted.right |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4900 | - getNavigationBarWidth(rotation, uiMode); |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 4901 | mTmpNavigationFrame.set(left, 0, displayFrames.mUnrestricted.right, displayHeight); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4902 | displayFrames.mStable.right = displayFrames.mStableFullscreen.right = left; |
| 4903 | if (transientNavBarShowing) { |
| 4904 | mNavigationBarController.setBarShowingLw(true); |
| 4905 | } else if (navVisible) { |
| 4906 | mNavigationBarController.setBarShowingLw(true); |
| 4907 | dockFrame.right = displayFrames.mRestricted.right |
| 4908 | = displayFrames.mRestrictedOverscan.right = left; |
| 4909 | } else { |
| 4910 | // We currently want to hide the navigation UI - unless we expanded the status bar. |
| 4911 | mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard); |
| 4912 | } |
| 4913 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4914 | && !mNavigationBar.isAnimatingLw() |
| 4915 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4916 | // If the nav bar is currently requested to be visible, and not in the process of |
| 4917 | // animating on or off, then we can tell the app that it is covered by it. |
| 4918 | displayFrames.mSystem.right = left; |
| 4919 | } |
| 4920 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
| 4921 | // Seascape screen; nav bar goes to the left. |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 4922 | final int right = cutoutSafeUnrestricted.left |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4923 | + getNavigationBarWidth(rotation, uiMode); |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 4924 | mTmpNavigationFrame.set(displayFrames.mUnrestricted.left, 0, right, displayHeight); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4925 | displayFrames.mStable.left = displayFrames.mStableFullscreen.left = right; |
| 4926 | if (transientNavBarShowing) { |
| 4927 | mNavigationBarController.setBarShowingLw(true); |
| 4928 | } else if (navVisible) { |
| 4929 | mNavigationBarController.setBarShowingLw(true); |
| 4930 | dockFrame.left = displayFrames.mRestricted.left = |
| 4931 | displayFrames.mRestrictedOverscan.left = right; |
| 4932 | } else { |
| 4933 | // We currently want to hide the navigation UI - unless we expanded the status bar. |
| 4934 | mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard); |
| 4935 | } |
| 4936 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4937 | && !mNavigationBar.isAnimatingLw() |
| 4938 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4939 | // If the nav bar is currently requested to be visible, and not in the process of |
| 4940 | // animating on or off, then we can tell the app that it is covered by it. |
| 4941 | displayFrames.mSystem.left = right; |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4942 | } |
| 4943 | } |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4944 | |
| 4945 | // Make sure the content and current rectangles are updated to account for the restrictions |
| 4946 | // from the navigation bar. |
| 4947 | displayFrames.mCurrent.set(dockFrame); |
| 4948 | displayFrames.mVoiceContent.set(dockFrame); |
| 4949 | displayFrames.mContent.set(dockFrame); |
| 4950 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 4951 | // And compute the final frame. |
| 4952 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 4953 | mTmpNavigationFrame, displayFrames.mDisplayCutoutSafe, mTmpNavigationFrame, dcf, |
| 4954 | mTmpNavigationFrame, displayFrames.mDisplayCutoutSafe, |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 4955 | displayFrames.mDisplayCutout, false /* parentFrameWasClippedByDisplayCutout */); |
Adrian Roos | 23df3a3 | 2018-03-15 15:41:13 +0100 | [diff] [blame] | 4956 | mNavigationBarController.setContentFrame(mNavigationBar.getContentFrameLw()); |
| 4957 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4958 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
| 4959 | return mNavigationBarController.checkHiddenLw(); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4960 | } |
| 4961 | |
Yohei Yukawa | d0a66b2 | 2018-01-10 13:19:54 -0800 | [diff] [blame] | 4962 | @NavigationBarPosition |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4963 | private int navigationBarPosition(int displayWidth, int displayHeight, int displayRotation) { |
| 4964 | if (mNavigationBarCanMove && displayWidth > displayHeight) { |
| 4965 | if (displayRotation == Surface.ROTATION_270) { |
| 4966 | return NAV_BAR_LEFT; |
| 4967 | } else { |
| 4968 | return NAV_BAR_RIGHT; |
| 4969 | } |
| 4970 | } |
| 4971 | return NAV_BAR_BOTTOM; |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 4972 | } |
| 4973 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 4974 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 4975 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4976 | public int getSystemDecorLayerLw() { |
Bryce Lee | 2ed3e5f | 2015-04-01 22:09:19 +0000 | [diff] [blame] | 4977 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 4978 | return mStatusBar.getSurfaceLayer(); |
| 4979 | } |
| 4980 | |
| 4981 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { |
| 4982 | return mNavigationBar.getSurfaceLayer(); |
| 4983 | } |
| 4984 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 4985 | return 0; |
| 4986 | } |
| 4987 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4988 | private void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 4989 | boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf, |
| 4990 | DisplayFrames displayFrames) { |
Robert Carr | 825581a | 2018-03-30 14:00:53 -0700 | [diff] [blame] | 4991 | if (!win.isInputMethodTarget() && attached.isInputMethodTarget()) { |
| 4992 | // Here's a special case: if the child window is not the 'dock window' |
| 4993 | // or input method target, and the window it is attached to is below |
| 4994 | // the dock window, then the frames we computed for the window it is |
| 4995 | // attached to can not be used because the dock is effectively part |
| 4996 | // of the underlying window and the attached window is floating on top |
| 4997 | // of the whole thing. So, we ignore the attached window and explicitly |
| 4998 | // compute the frames that would be appropriate without the dock. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 4999 | vf.set(displayFrames.mDock); |
| 5000 | cf.set(displayFrames.mDock); |
| 5001 | of.set(displayFrames.mDock); |
| 5002 | df.set(displayFrames.mDock); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5003 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5004 | // The effective display frame of the attached window depends on whether it is taking |
| 5005 | // care of insetting its content. If not, we need to use the parent's content frame so |
| 5006 | // that the entire window is positioned within that content. Otherwise we can use the |
| 5007 | // overscan frame and let the attached window take care of positioning its content |
| 5008 | // appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 5009 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 5010 | // Set the content frame of the attached window to the parent's decor frame |
| 5011 | // (same as content frame when IME isn't present) if specifically requested by |
| 5012 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 5013 | // Otherwise, use the overscan frame. |
| 5014 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
| 5015 | ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5016 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5017 | // If the window is resizing, then we want to base the content frame on our attached |
| 5018 | // content frame to resize...however, things can be tricky if the attached window is |
| 5019 | // NOT in resize mode, in which case its content frame will be larger. |
| 5020 | // Ungh. So to deal with that, make sure the content frame we end up using is not |
| 5021 | // covering the IM dock. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5022 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5023 | if (attached.isVoiceInteraction()) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5024 | cf.intersectUnchecked(displayFrames.mVoiceContent); |
Robert Carr | 825581a | 2018-03-30 14:00:53 -0700 | [diff] [blame] | 5025 | } else if (win.isInputMethodTarget() || attached.isInputMethodTarget()) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5026 | cf.intersectUnchecked(displayFrames.mContent); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5027 | } |
| 5028 | } |
| 5029 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5030 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5031 | vf.set(attached.getVisibleFrameLw()); |
| 5032 | } |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5033 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached window should be |
| 5034 | // positioned relative to its parent or the entire screen. |
| 5035 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 ? attached.getFrameLw() : df); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5036 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 5037 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5038 | private void applyStableConstraints(int sysui, int fl, Rect r, DisplayFrames displayFrames) { |
| 5039 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) == 0) { |
| 5040 | return; |
| 5041 | } |
| 5042 | // If app is requesting a stable layout, don't let the content insets go below the stable |
| 5043 | // values. |
| 5044 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 5045 | r.intersectUnchecked(displayFrames.mStableFullscreen); |
| 5046 | } else { |
| 5047 | r.intersectUnchecked(displayFrames.mStable); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 5048 | } |
| 5049 | } |
| 5050 | |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 5051 | private boolean canReceiveInput(WindowState win) { |
| 5052 | boolean notFocusable = |
| 5053 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0; |
| 5054 | boolean altFocusableIm = |
| 5055 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0; |
| 5056 | boolean notFocusableForIm = notFocusable ^ altFocusableIm; |
| 5057 | return !notFocusableForIm; |
| 5058 | } |
| 5059 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5060 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5061 | @Override |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5062 | public void layoutWindowLw(WindowState win, WindowState attached, DisplayFrames displayFrames) { |
Wale Ogunwale | c0b0f93 | 2017-11-01 12:51:43 -0700 | [diff] [blame] | 5063 | // We've already done the navigation bar, status bar, and all screen decor windows. If the |
| 5064 | // status bar can receive input, we need to layout it again to accommodate for the IME |
| 5065 | // window. |
| 5066 | if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar |
| 5067 | || mScreenDecorWindows.contains(win)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5068 | return; |
| 5069 | } |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 5070 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5071 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 5072 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5073 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 5074 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5075 | if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state"); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5076 | offsetInputMethodWindowLw(mLastInputMethodWindow, displayFrames); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5077 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5078 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5079 | final int type = attrs.type; |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5080 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 5081 | final int pfl = attrs.privateFlags; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5082 | final int sim = attrs.softInputMode; |
Adrian Roos | 7737398 | 2017-11-24 13:24:28 +0100 | [diff] [blame] | 5083 | final int requestedSysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
| 5084 | final int sysUiFl = requestedSysUiFl | getImpliedSysUiFlagsForLayout(attrs); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5085 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5086 | final Rect pf = mTmpParentFrame; |
| 5087 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5088 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5089 | final Rect cf = mTmpContentFrame; |
| 5090 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5091 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5092 | final Rect sf = mTmpStableFrame; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5093 | Rect osf = null; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5094 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5095 | |
| 5096 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 5097 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 5098 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 5099 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 5100 | |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 5101 | final boolean requestedFullscreen = (fl & FLAG_FULLSCREEN) != 0 |
Adrian Roos | 2dfb785 | 2018-01-15 13:41:37 +0100 | [diff] [blame] | 5102 | || (requestedSysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 5103 | |
| 5104 | final boolean layoutInScreen = (fl & FLAG_LAYOUT_IN_SCREEN) == FLAG_LAYOUT_IN_SCREEN; |
| 5105 | final boolean layoutInsetDecor = (fl & FLAG_LAYOUT_INSET_DECOR) == FLAG_LAYOUT_INSET_DECOR; |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 5106 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5107 | sf.set(displayFrames.mStable); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5108 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5109 | if (type == TYPE_INPUT_METHOD) { |
| 5110 | vf.set(displayFrames.mDock); |
| 5111 | cf.set(displayFrames.mDock); |
| 5112 | of.set(displayFrames.mDock); |
| 5113 | df.set(displayFrames.mDock); |
| 5114 | pf.set(displayFrames.mDock); |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 5115 | // IM dock windows layout below the nav bar... |
Adrian Roos | 1f778d5 | 2018-03-09 16:59:29 +0100 | [diff] [blame] | 5116 | pf.bottom = df.bottom = of.bottom = displayFrames.mUnrestricted.bottom; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 5117 | // ...with content insets above the nav bar |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5118 | cf.bottom = vf.bottom = displayFrames.mStable.bottom; |
Adrian Roos | dd654ea | 2016-05-27 11:46:10 -0700 | [diff] [blame] | 5119 | if (mStatusBar != null && mFocusedWindow == mStatusBar && canReceiveInput(mStatusBar)) { |
| 5120 | // The status bar forces the navigation bar while it's visible. Make sure the IME |
| 5121 | // avoids the navigation bar in that case. |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 5122 | if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5123 | pf.right = df.right = of.right = cf.right = vf.right = |
| 5124 | displayFrames.mStable.right; |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 5125 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5126 | pf.left = df.left = of.left = cf.left = vf.left = displayFrames.mStable.left; |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 5127 | } |
Adrian Roos | dd654ea | 2016-05-27 11:46:10 -0700 | [diff] [blame] | 5128 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5129 | // IM dock windows always go to the bottom of the screen. |
| 5130 | attrs.gravity = Gravity.BOTTOM; |
| 5131 | mDockLayer = win.getSurfaceLayer(); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5132 | } else if (type == TYPE_VOICE_INTERACTION) { |
| 5133 | of.set(displayFrames.mUnrestricted); |
| 5134 | df.set(displayFrames.mUnrestricted); |
| 5135 | pf.set(displayFrames.mUnrestricted); |
Jorim Jaggi | 4b74f4d | 2016-04-27 18:44:08 -0700 | [diff] [blame] | 5136 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5137 | cf.set(displayFrames.mDock); |
Jorim Jaggi | 4b74f4d | 2016-04-27 18:44:08 -0700 | [diff] [blame] | 5138 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5139 | cf.set(displayFrames.mContent); |
Jorim Jaggi | 4b74f4d | 2016-04-27 18:44:08 -0700 | [diff] [blame] | 5140 | } |
| 5141 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5142 | vf.set(displayFrames.mCurrent); |
Jorim Jaggi | 4b74f4d | 2016-04-27 18:44:08 -0700 | [diff] [blame] | 5143 | } else { |
| 5144 | vf.set(cf); |
| 5145 | } |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5146 | } else if (type == TYPE_WALLPAPER) { |
| 5147 | layoutWallpaper(displayFrames, pf, df, of, cf); |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 5148 | } else if (win == mStatusBar) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5149 | of.set(displayFrames.mUnrestricted); |
| 5150 | df.set(displayFrames.mUnrestricted); |
| 5151 | pf.set(displayFrames.mUnrestricted); |
| 5152 | cf.set(displayFrames.mStable); |
| 5153 | vf.set(displayFrames.mStable); |
Adrian Roos | dc5b453 | 2016-01-06 20:49:41 +0100 | [diff] [blame] | 5154 | |
| 5155 | if (adjust == SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5156 | cf.bottom = displayFrames.mContent.bottom; |
Adrian Roos | dc5b453 | 2016-01-06 20:49:41 +0100 | [diff] [blame] | 5157 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5158 | cf.bottom = displayFrames.mDock.bottom; |
| 5159 | vf.bottom = displayFrames.mContent.bottom; |
Adrian Roos | dc5b453 | 2016-01-06 20:49:41 +0100 | [diff] [blame] | 5160 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5161 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5162 | dcf.set(displayFrames.mSystem); |
| 5163 | final boolean inheritTranslucentDecor = |
| 5164 | (attrs.privateFlags & PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 5165 | final boolean isAppWindow = |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5166 | type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 5167 | final boolean topAtRest = |
| 5168 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 5169 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5170 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5171 | && (fl & FLAG_FULLSCREEN) == 0 |
| 5172 | && (fl & FLAG_TRANSLUCENT_STATUS) == 0 |
| 5173 | && (fl & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0 |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 5174 | && (pfl & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5175 | // Ensure policy decor includes status bar |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5176 | dcf.top = displayFrames.mStable.top; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5177 | } |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5178 | if ((fl & FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 5179 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5180 | && (fl & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5181 | // Ensure policy decor includes navigation bar |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5182 | dcf.bottom = displayFrames.mStable.bottom; |
| 5183 | dcf.right = displayFrames.mStable.right; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5184 | } |
| 5185 | } |
| 5186 | |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 5187 | if (layoutInScreen && layoutInsetDecor) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5188 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5189 | + "): IN_SCREEN, INSET_DECOR"); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5190 | // This is the case for a normal activity window: we want it to cover all of the |
| 5191 | // screen space, and it can take care of moving its contents to account for screen |
| 5192 | // decorations that intrude into that space. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5193 | if (attached != null) { |
| 5194 | // If this window is attached to another, our display |
| 5195 | // frame is the same as the one we are attached to. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5196 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf, |
| 5197 | displayFrames); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5198 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5199 | if (type == TYPE_STATUS_BAR_PANEL || type == TYPE_STATUS_BAR_SUB_PANEL) { |
| 5200 | // Status bar panels are the only windows who can go on top of the status |
| 5201 | // bar. They are protected by the STATUS_BAR_SERVICE permission, so they |
| 5202 | // have the same privileges as the status bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 5203 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 5204 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 5205 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5206 | pf.left = df.left = of.left = hasNavBar |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5207 | ? displayFrames.mDock.left : displayFrames.mUnrestricted.left; |
| 5208 | pf.top = df.top = of.top = displayFrames.mUnrestricted.top; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5209 | pf.right = df.right = of.right = hasNavBar |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5210 | ? displayFrames.mRestricted.right |
| 5211 | : displayFrames.mUnrestricted.right; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5212 | pf.bottom = df.bottom = of.bottom = hasNavBar |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5213 | ? displayFrames.mRestricted.bottom |
| 5214 | : displayFrames.mUnrestricted.bottom; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 5215 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5216 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 5217 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 5218 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5219 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5220 | && type >= FIRST_APPLICATION_WINDOW && type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 5221 | // Asking to layout into the overscan region, so give it that pure |
| 5222 | // unrestricted area. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5223 | of.set(displayFrames.mOverscan); |
| 5224 | df.set(displayFrames.mOverscan); |
| 5225 | pf.set(displayFrames.mOverscan); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5226 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5227 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 5228 | && (type >= FIRST_APPLICATION_WINDOW && type <= LAST_SUB_WINDOW |
| 5229 | || type == TYPE_VOLUME_OVERLAY)) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5230 | // Asking for layout as if the nav bar is hidden, lets the application |
| 5231 | // extend into the unrestricted overscan screen area. We only do this for |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 5232 | // application windows and certain system windows to ensure no window that |
| 5233 | // can be above the nav bar can do this. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5234 | df.set(displayFrames.mOverscan); |
| 5235 | pf.set(displayFrames.mOverscan); |
| 5236 | // We need to tell the app about where the frame inside the overscan is, so |
| 5237 | // it can inset its content by that amount -- it didn't ask to actually |
| 5238 | // extend itself into the overscan region. |
| 5239 | of.set(displayFrames.mUnrestricted); |
Wale Ogunwale | 7bb06e0 | 2017-11-13 16:49:19 +0000 | [diff] [blame] | 5240 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5241 | df.set(displayFrames.mRestrictedOverscan); |
| 5242 | pf.set(displayFrames.mRestrictedOverscan); |
Wale Ogunwale | 7bb06e0 | 2017-11-13 16:49:19 +0000 | [diff] [blame] | 5243 | // We need to tell the app about where the frame inside the overscan |
| 5244 | // is, so it can inset its content by that amount -- it didn't ask |
| 5245 | // to actually extend itself into the overscan region. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5246 | of.set(displayFrames.mUnrestricted); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 5247 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5248 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5249 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5250 | if (win.isVoiceInteraction()) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5251 | cf.set(displayFrames.mVoiceContent); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5252 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5253 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5254 | cf.set(displayFrames.mDock); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5255 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5256 | cf.set(displayFrames.mContent); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5257 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5258 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5259 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5260 | // Full screen windows are always given a layout that is as if the status |
| 5261 | // bar and other transient decors are gone. This is to avoid bad states when |
| 5262 | // moving from a window that is not hiding the status bar to one that is. |
| 5263 | cf.set(displayFrames.mRestricted); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5264 | } |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5265 | applyStableConstraints(sysUiFl, fl, cf, displayFrames); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 5266 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5267 | vf.set(displayFrames.mCurrent); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 5268 | } else { |
| 5269 | vf.set(cf); |
| 5270 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5271 | } |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 5272 | } else if (layoutInScreen || (sysUiFl |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5273 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 5274 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5275 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
| 5276 | + "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5277 | // A window that has requested to fill the entire screen just |
| 5278 | // gets everything, period. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5279 | if (type == TYPE_STATUS_BAR_PANEL || type == TYPE_STATUS_BAR_SUB_PANEL) { |
| 5280 | cf.set(displayFrames.mUnrestricted); |
| 5281 | of.set(displayFrames.mUnrestricted); |
| 5282 | df.set(displayFrames.mUnrestricted); |
| 5283 | pf.set(displayFrames.mUnrestricted); |
| 5284 | if (hasNavBar) { |
| 5285 | pf.left = df.left = of.left = cf.left = displayFrames.mDock.left; |
| 5286 | pf.right = df.right = of.right = cf.right = displayFrames.mRestricted.right; |
| 5287 | pf.bottom = df.bottom = of.bottom = cf.bottom = |
| 5288 | displayFrames.mRestricted.bottom; |
| 5289 | } |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 5290 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
| 5291 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 5292 | pf.left, pf.top, pf.right, pf.bottom)); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5293 | } else if (type == TYPE_NAVIGATION_BAR || type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 5294 | // The navigation bar has Real Ultimate Power. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5295 | of.set(displayFrames.mUnrestricted); |
| 5296 | df.set(displayFrames.mUnrestricted); |
| 5297 | pf.set(displayFrames.mUnrestricted); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5298 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 5299 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 5300 | pf.left, pf.top, pf.right, pf.bottom)); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5301 | } else if ((type == TYPE_SECURE_SYSTEM_OVERLAY || type == TYPE_SCREENSHOT) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 5302 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 5303 | // Fullscreen secure system overlays get what they ask for. Screenshot region |
| 5304 | // selection overlay should also expand to full screen. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5305 | cf.set(displayFrames.mOverscan); |
| 5306 | of.set(displayFrames.mOverscan); |
| 5307 | df.set(displayFrames.mOverscan); |
| 5308 | pf.set(displayFrames.mOverscan); |
| 5309 | } else if (type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 5310 | // Boot progress screen always covers entire display. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5311 | cf.set(displayFrames.mOverscan); |
| 5312 | of.set(displayFrames.mOverscan); |
| 5313 | df.set(displayFrames.mOverscan); |
| 5314 | pf.set(displayFrames.mOverscan); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5315 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5316 | && type >= FIRST_APPLICATION_WINDOW && type <= LAST_SUB_WINDOW) { |
| 5317 | // Asking to layout into the overscan region, so give it that pure unrestricted |
| 5318 | // area. |
| 5319 | cf.set(displayFrames.mOverscan); |
| 5320 | of.set(displayFrames.mOverscan); |
| 5321 | df.set(displayFrames.mOverscan); |
| 5322 | pf.set(displayFrames.mOverscan); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5323 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5324 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5325 | && (type == TYPE_STATUS_BAR |
| 5326 | || type == TYPE_TOAST |
| 5327 | || type == TYPE_DOCK_DIVIDER |
| 5328 | || type == TYPE_VOICE_INTERACTION_STARTING |
| 5329 | || (type >= FIRST_APPLICATION_WINDOW && type <= LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5330 | // Asking for layout as if the nav bar is hidden, lets the |
| 5331 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5332 | // only do this for application windows (or toasts) to ensure no window that |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5333 | // can be above the nav bar can do this. |
| 5334 | // XXX This assumes that an app asking for this will also |
| 5335 | // ask for layout in only content. We can't currently figure out |
| 5336 | // what the screen would be if only laying out to hide the nav bar. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5337 | cf.set(displayFrames.mUnrestricted); |
| 5338 | of.set(displayFrames.mUnrestricted); |
| 5339 | df.set(displayFrames.mUnrestricted); |
| 5340 | pf.set(displayFrames.mUnrestricted); |
Jorim Jaggi | 9f6798a | 2016-02-10 22:16:06 -0800 | [diff] [blame] | 5341 | } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5342 | of.set(displayFrames.mRestricted); |
| 5343 | df.set(displayFrames.mRestricted); |
| 5344 | pf.set(displayFrames.mRestricted); |
Jorim Jaggi | 9f6798a | 2016-02-10 22:16:06 -0800 | [diff] [blame] | 5345 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5346 | cf.set(displayFrames.mDock); |
Jorim Jaggi | 9f6798a | 2016-02-10 22:16:06 -0800 | [diff] [blame] | 5347 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5348 | cf.set(displayFrames.mContent); |
Jorim Jaggi | 9f6798a | 2016-02-10 22:16:06 -0800 | [diff] [blame] | 5349 | } |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 5350 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5351 | cf.set(displayFrames.mRestricted); |
| 5352 | of.set(displayFrames.mRestricted); |
| 5353 | df.set(displayFrames.mRestricted); |
| 5354 | pf.set(displayFrames.mRestricted); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 5355 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5356 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5357 | applyStableConstraints(sysUiFl, fl, cf,displayFrames); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5358 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 5359 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5360 | vf.set(displayFrames.mCurrent); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 5361 | } else { |
| 5362 | vf.set(cf); |
| 5363 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5364 | } else if (attached != null) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5365 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
| 5366 | + "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5367 | // A child window should be placed inside of the same visible |
| 5368 | // frame that its parent had. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5369 | setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf, |
| 5370 | displayFrames); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5371 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5372 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 5373 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5374 | // Otherwise, a normal window must be placed inside the content |
| 5375 | // of all screen decorations. |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 5376 | if (type == TYPE_STATUS_BAR_PANEL) { |
| 5377 | // Status bar panels can go on |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5378 | // top of the status bar. They are protected by the STATUS_BAR_SERVICE |
| 5379 | // permission, so they have the same privileges as the status bar itself. |
| 5380 | cf.set(displayFrames.mRestricted); |
| 5381 | of.set(displayFrames.mRestricted); |
| 5382 | df.set(displayFrames.mRestricted); |
| 5383 | pf.set(displayFrames.mRestricted); |
| 5384 | } else if (type == TYPE_TOAST || type == TYPE_SYSTEM_ALERT) { |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 5385 | // These dialogs are stable to interim decor changes. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5386 | cf.set(displayFrames.mStable); |
| 5387 | of.set(displayFrames.mStable); |
| 5388 | df.set(displayFrames.mStable); |
| 5389 | pf.set(displayFrames.mStable); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5390 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5391 | pf.set(displayFrames.mContent); |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 5392 | if (win.isVoiceInteraction()) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5393 | cf.set(displayFrames.mVoiceContent); |
| 5394 | of.set(displayFrames.mVoiceContent); |
| 5395 | df.set(displayFrames.mVoiceContent); |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 5396 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5397 | cf.set(displayFrames.mDock); |
| 5398 | of.set(displayFrames.mDock); |
| 5399 | df.set(displayFrames.mDock); |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 5400 | } else { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5401 | cf.set(displayFrames.mContent); |
| 5402 | of.set(displayFrames.mContent); |
| 5403 | df.set(displayFrames.mContent); |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 5404 | } |
| 5405 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5406 | vf.set(displayFrames.mCurrent); |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 5407 | } else { |
| 5408 | vf.set(cf); |
| 5409 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 5410 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5411 | } |
| 5412 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5413 | |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 5414 | boolean parentFrameWasClippedByDisplayCutout = false; |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 5415 | final int cutoutMode = attrs.layoutInDisplayCutoutMode; |
Adrian Roos | a7f9b84 | 2018-02-16 19:35:27 +0100 | [diff] [blame] | 5416 | final boolean attachedInParent = attached != null && !layoutInScreen; |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 5417 | final boolean requestedHideNavigation = |
| 5418 | (requestedSysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
Adrian Roos | c8045bf | 2018-03-29 19:41:30 +0200 | [diff] [blame] | 5419 | |
| 5420 | // TYPE_BASE_APPLICATION windows are never considered floating here because they don't get |
| 5421 | // cropped / shifted to the displayFrame in WindowState. |
| 5422 | final boolean floatingInScreenWindow = !attrs.isFullscreen() && layoutInScreen |
| 5423 | && type != TYPE_BASE_APPLICATION; |
| 5424 | |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 5425 | // Ensure that windows with a DEFAULT or NEVER display cutout mode are laid out in |
| 5426 | // the cutout safe zone. |
Adrian Roos | eb3697c | 2018-02-21 17:32:44 +0100 | [diff] [blame] | 5427 | if (cutoutMode != LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) { |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 5428 | final Rect displayCutoutSafeExceptMaybeBars = mTmpDisplayCutoutSafeExceptMaybeBarsRect; |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 5429 | displayCutoutSafeExceptMaybeBars.set(displayFrames.mDisplayCutoutSafe); |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 5430 | if (layoutInScreen && layoutInsetDecor && !requestedFullscreen |
| 5431 | && cutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT) { |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 5432 | // At the top we have the status bar, so apps that are |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 5433 | // LAYOUT_IN_SCREEN | LAYOUT_INSET_DECOR but not FULLSCREEN |
| 5434 | // already expect that there's an inset there and we don't need to exclude |
| 5435 | // the window from that area. |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 5436 | displayCutoutSafeExceptMaybeBars.top = Integer.MIN_VALUE; |
| 5437 | } |
| 5438 | if (layoutInScreen && layoutInsetDecor && !requestedHideNavigation |
| 5439 | && cutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT) { |
| 5440 | // Same for the navigation bar. |
| 5441 | switch (mNavigationBarPosition) { |
| 5442 | case NAV_BAR_BOTTOM: |
| 5443 | displayCutoutSafeExceptMaybeBars.bottom = Integer.MAX_VALUE; |
| 5444 | break; |
| 5445 | case NAV_BAR_RIGHT: |
| 5446 | displayCutoutSafeExceptMaybeBars.right = Integer.MAX_VALUE; |
| 5447 | break; |
| 5448 | case NAV_BAR_LEFT: |
| 5449 | displayCutoutSafeExceptMaybeBars.left = Integer.MIN_VALUE; |
| 5450 | break; |
| 5451 | } |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 5452 | } |
Adrian Roos | 1f778d5 | 2018-03-09 16:59:29 +0100 | [diff] [blame] | 5453 | if (type == TYPE_INPUT_METHOD && mNavigationBarPosition == NAV_BAR_BOTTOM) { |
| 5454 | // The IME can always extend under the bottom cutout if the navbar is there. |
| 5455 | displayCutoutSafeExceptMaybeBars.bottom = Integer.MAX_VALUE; |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 5456 | } |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 5457 | // Windows that are attached to a parent and laid out in said parent already avoid |
| 5458 | // the cutout according to that parent and don't need to be further constrained. |
Adrian Roos | c8045bf | 2018-03-29 19:41:30 +0200 | [diff] [blame] | 5459 | // Floating IN_SCREEN windows get what they ask for and lay out in the full screen. |
| 5460 | // They will later be cropped or shifted using the displayFrame in WindowState, |
| 5461 | // which prevents overlap with the DisplayCutout. |
| 5462 | if (!attachedInParent && !floatingInScreenWindow) { |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 5463 | mTmpRect.set(pf); |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 5464 | pf.intersectUnchecked(displayCutoutSafeExceptMaybeBars); |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 5465 | parentFrameWasClippedByDisplayCutout |= !mTmpRect.equals(pf); |
Adrian Roos | eb3697c | 2018-02-21 17:32:44 +0100 | [diff] [blame] | 5466 | } |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 5467 | // Make sure that NO_LIMITS windows clipped to the display don't extend under the |
| 5468 | // cutout. |
| 5469 | df.intersectUnchecked(displayCutoutSafeExceptMaybeBars); |
Adrian Roos | dcc92ed | 2017-11-22 14:35:58 +0100 | [diff] [blame] | 5470 | } |
| 5471 | |
| 5472 | // Content should never appear in the cutout. |
| 5473 | cf.intersectUnchecked(displayFrames.mDisplayCutoutSafe); |
| 5474 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 5475 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
Wale Ogunwale | 9185fb0 | 2016-03-11 18:06:14 -0800 | [diff] [blame] | 5476 | // Also, we don't allow windows in multi-window mode to extend out of the screen. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5477 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && type != TYPE_SYSTEM_ERROR |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 5478 | && !win.isInMultiWindowMode()) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 5479 | df.left = df.top = -10000; |
| 5480 | df.right = df.bottom = 10000; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5481 | if (type != TYPE_WALLPAPER) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 5482 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 5483 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 5484 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5485 | } |
| 5486 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5487 | // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we |
| 5488 | // need to provide information to the clients that want to pretend that you can draw there. |
Filip Gruszczynski | b0c673b | 2015-06-05 09:43:06 -0700 | [diff] [blame] | 5489 | // We only want to apply outsets to certain types of windows. For example, we never want to |
| 5490 | // apply the outsets to floating dialogs, because they wouldn't make sense there. |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 5491 | final boolean useOutsets = shouldUseOutsets(attrs, fl); |
Filip Gruszczynski | b0c673b | 2015-06-05 09:43:06 -0700 | [diff] [blame] | 5492 | if (isDefaultDisplay && useOutsets) { |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5493 | osf = mTmpOutsetFrame; |
| 5494 | osf.set(cf.left, cf.top, cf.right, cf.bottom); |
| 5495 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 5496 | if (outset > 0) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5497 | int rotation = displayFrames.mRotation; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5498 | if (rotation == Surface.ROTATION_0) { |
| 5499 | osf.bottom += outset; |
| 5500 | } else if (rotation == Surface.ROTATION_90) { |
| 5501 | osf.right += outset; |
| 5502 | } else if (rotation == Surface.ROTATION_180) { |
| 5503 | osf.top -= outset; |
| 5504 | } else if (rotation == Surface.ROTATION_270) { |
| 5505 | osf.left -= outset; |
| 5506 | } |
| 5507 | if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset |
| 5508 | + " with rotation " + rotation + ", result: " + osf); |
| 5509 | } |
| 5510 | } |
| 5511 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5512 | if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle() |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 5513 | + ": sim=#" + Integer.toHexString(sim) |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5514 | + " attach=" + attached + " type=" + type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 5515 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 5516 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5517 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5518 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5519 | + " dcf=" + dcf.toShortString() |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5520 | + " sf=" + sf.toShortString() |
| 5521 | + " osf=" + (osf == null ? "null" : osf.toShortString())); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5522 | |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 5523 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf, displayFrames.mDisplayCutout, |
| 5524 | parentFrameWasClippedByDisplayCutout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5525 | // Dock windows carve out the bottom of the screen, so normal windows |
| 5526 | // can't appear underneath them. |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5527 | if (type == TYPE_INPUT_METHOD && win.isVisibleLw() |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5528 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5529 | setLastInputMethodWindowLw(null, null); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5530 | offsetInputMethodWindowLw(win, displayFrames); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5531 | } |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5532 | if (type == TYPE_VOICE_INTERACTION && win.isVisibleLw() |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5533 | && !win.getGivenInsetsPendingLw()) { |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5534 | offsetVoiceInputWindowLw(win, displayFrames); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5535 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5536 | } |
| 5537 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5538 | private void layoutWallpaper(DisplayFrames displayFrames, Rect pf, Rect df, Rect of, Rect cf) { |
| 5539 | // The wallpaper has Real Ultimate Power, but we want to tell it about the overscan area. |
| 5540 | df.set(displayFrames.mOverscan); |
| 5541 | pf.set(displayFrames.mOverscan); |
| 5542 | cf.set(displayFrames.mUnrestricted); |
| 5543 | of.set(displayFrames.mUnrestricted); |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 5544 | } |
| 5545 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5546 | private void offsetInputMethodWindowLw(WindowState win, DisplayFrames displayFrames) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 5547 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5548 | top += win.getGivenContentInsetsLw().top; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5549 | displayFrames.mContent.bottom = Math.min(displayFrames.mContent.bottom, top); |
| 5550 | displayFrames.mVoiceContent.bottom = Math.min(displayFrames.mVoiceContent.bottom, top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5551 | top = win.getVisibleFrameLw().top; |
| 5552 | top += win.getGivenVisibleInsetsLw().top; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5553 | displayFrames.mCurrent.bottom = Math.min(displayFrames.mCurrent.bottom, top); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5554 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5555 | + displayFrames.mDock.bottom + " mContentBottom=" |
| 5556 | + displayFrames.mContent.bottom + " mCurBottom=" + displayFrames.mCurrent.bottom); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5557 | } |
| 5558 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5559 | private void offsetVoiceInputWindowLw(WindowState win, DisplayFrames displayFrames) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 5560 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 5561 | top += win.getGivenContentInsetsLw().top; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 5562 | displayFrames.mVoiceContent.bottom = Math.min(displayFrames.mVoiceContent.bottom, top); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5563 | } |
| 5564 | |
| 5565 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5566 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 5567 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5568 | mTopFullscreenOpaqueWindowState = null; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 5569 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5570 | mTopDockedOpaqueWindowState = null; |
| 5571 | mTopDockedOpaqueOrDimmingWindowState = null; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5572 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5573 | mForceStatusBarFromKeyguard = false; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 5574 | mForceStatusBarTransparent = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5575 | mForcingShowNavBar = false; |
| 5576 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5577 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5578 | mAllowLockscreenWhenOn = false; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5579 | mShowingDream = false; |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 5580 | mWindowSleepTokenNeeded = false; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5581 | } |
| 5582 | |
| 5583 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5584 | @Override |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 5585 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs, |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5586 | WindowState attached, WindowState imeTarget) { |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5587 | final boolean affectsSystemUi = win.canAffectSystemUiFlags(); |
| 5588 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": affectsSystemUi=" + affectsSystemUi); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5589 | applyKeyguardPolicyLw(win, imeTarget); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5590 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5591 | if (mTopFullscreenOpaqueWindowState == null && affectsSystemUi |
| 5592 | && attrs.type == TYPE_INPUT_METHOD) { |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 5593 | mForcingShowNavBar = true; |
| 5594 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5595 | } |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 5596 | if (attrs.type == TYPE_STATUS_BAR) { |
| 5597 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 5598 | mForceStatusBarFromKeyguard = true; |
| 5599 | } |
| 5600 | if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) { |
| 5601 | mForceStatusBarTransparent = true; |
| 5602 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 5603 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 5604 | |
| 5605 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 5606 | && attrs.type < FIRST_SYSTEM_WINDOW; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5607 | final int windowingMode = win.getWindowingMode(); |
| 5608 | final boolean inFullScreenOrSplitScreenSecondaryWindowingMode = |
| 5609 | windowingMode == WINDOWING_MODE_FULLSCREEN |
| 5610 | || windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5611 | if (mTopFullscreenOpaqueWindowState == null && affectsSystemUi) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5612 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5613 | mForceStatusBar = true; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5614 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5615 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 5616 | // If the lockscreen was showing when the dream started then wait |
| 5617 | // for the dream to draw before hiding the lockscreen. |
| 5618 | if (!mDreamingLockscreen |
| 5619 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 5620 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 5621 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5622 | } |
| 5623 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 5624 | |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 5625 | // For app windows that are not attached, we decide if all windows in the app they |
| 5626 | // represent should be hidden or if we should hide the lockscreen. For attached app |
| 5627 | // windows we defer the decision to the window it is attached to. |
| 5628 | if (appWindow && attached == null) { |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5629 | if (attrs.isFullscreen() && inFullScreenOrSplitScreenSecondaryWindowingMode) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 5630 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 5631 | mTopFullscreenOpaqueWindowState = win; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 5632 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 5633 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 5634 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 5635 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 5636 | mAllowLockscreenWhenOn = true; |
| 5637 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5638 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 5639 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5640 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5641 | |
Jorim Jaggi | 90859bc | 2016-06-28 16:25:23 -0700 | [diff] [blame] | 5642 | // Voice interaction overrides both top fullscreen and top docked. |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5643 | if (affectsSystemUi && win.getAttrs().type == TYPE_VOICE_INTERACTION) { |
Jorim Jaggi | 90859bc | 2016-06-28 16:25:23 -0700 | [diff] [blame] | 5644 | if (mTopFullscreenOpaqueWindowState == null) { |
| 5645 | mTopFullscreenOpaqueWindowState = win; |
| 5646 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 5647 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 5648 | } |
| 5649 | } |
| 5650 | if (mTopDockedOpaqueWindowState == null) { |
| 5651 | mTopDockedOpaqueWindowState = win; |
| 5652 | if (mTopDockedOpaqueOrDimmingWindowState == null) { |
| 5653 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 5654 | } |
| 5655 | } |
| 5656 | } |
| 5657 | |
| 5658 | // Keep track of the window if it's dimming but not necessarily fullscreen. |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5659 | if (mTopFullscreenOpaqueOrDimmingWindowState == null && affectsSystemUi |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5660 | && win.isDimming() && inFullScreenOrSplitScreenSecondaryWindowingMode) { |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 5661 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 5662 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5663 | |
| 5664 | // We need to keep track of the top "fullscreen" opaque window for the docked stack |
| 5665 | // separately, because both the "real fullscreen" opaque window and the one for the docked |
| 5666 | // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR. |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5667 | if (mTopDockedOpaqueWindowState == null && affectsSystemUi && appWindow && attached == null |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5668 | && attrs.isFullscreen() && windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5669 | mTopDockedOpaqueWindowState = win; |
| 5670 | if (mTopDockedOpaqueOrDimmingWindowState == null) { |
| 5671 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 5672 | } |
| 5673 | } |
| 5674 | |
| 5675 | // Also keep track of any windows that are dimming but not necessarily fullscreen in the |
| 5676 | // docked stack. |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5677 | if (mTopDockedOpaqueOrDimmingWindowState == null && affectsSystemUi && win.isDimming() |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5678 | && windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5679 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 5680 | } |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 5681 | |
| 5682 | // Take note if a window wants to acquire a sleep token. |
| 5683 | if (win.isVisibleLw() && (attrs.privateFlags & PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN) != 0 |
| 5684 | && win.canAcquireSleepToken()) { |
| 5685 | mWindowSleepTokenNeeded = true; |
| 5686 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5687 | } |
| 5688 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5689 | private void applyKeyguardPolicyLw(WindowState win, WindowState imeTarget) { |
| 5690 | if (canBeHiddenByKeyguardLw(win)) { |
| 5691 | if (shouldBeHiddenByKeyguard(win, imeTarget)) { |
| 5692 | win.hideLw(false /* doAnimation */); |
| 5693 | } else { |
| 5694 | win.showLw(false /* doAnimation */); |
| 5695 | } |
| 5696 | } |
| 5697 | } |
| 5698 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5699 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5700 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 5701 | public int finishPostLayoutPolicyLw() { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5702 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5703 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 5704 | |
| 5705 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 5706 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 5707 | : null; |
| 5708 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 5709 | // If we are not currently showing a dream then remember the current |
| 5710 | // lockscreen state. We will use this to determine whether the dream |
| 5711 | // started while the lockscreen was showing and remember this state |
| 5712 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5713 | if (!mShowingDream) { |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 5714 | mDreamingLockscreen = isKeyguardShowingAndNotOccluded(); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 5715 | if (mDreamingSleepTokenNeeded) { |
| 5716 | mDreamingSleepTokenNeeded = false; |
| 5717 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget(); |
| 5718 | } |
| 5719 | } else { |
| 5720 | if (!mDreamingSleepTokenNeeded) { |
| 5721 | mDreamingSleepTokenNeeded = true; |
| 5722 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget(); |
| 5723 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5724 | } |
| 5725 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5726 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5727 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5728 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 5729 | + " top=" + mTopFullscreenOpaqueWindowState); |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 5730 | boolean shouldBeTransparent = mForceStatusBarTransparent |
| 5731 | && !mForceStatusBar |
| 5732 | && !mForceStatusBarFromKeyguard; |
| 5733 | if (!shouldBeTransparent) { |
| 5734 | mStatusBarController.setShowTransparent(false /* transparent */); |
| 5735 | } else if (!mStatusBar.isVisibleLw()) { |
| 5736 | mStatusBarController.setShowTransparent(true /* transparent */); |
| 5737 | } |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 5738 | |
| 5739 | WindowManager.LayoutParams statusBarAttrs = mStatusBar.getAttrs(); |
| 5740 | boolean statusBarExpanded = statusBarAttrs.height == MATCH_PARENT |
| 5741 | && statusBarAttrs.width == MATCH_PARENT; |
Selim Cinek | 3a49ba2 | 2017-08-10 11:17:39 -0700 | [diff] [blame] | 5742 | boolean topAppHidesStatusBar = topAppHidesStatusBar(); |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 5743 | if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent |
| 5744 | || statusBarExpanded) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5745 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5746 | if (mStatusBarController.setBarShowingLw(true)) { |
| 5747 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5748 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 5749 | // Maintain fullscreen layout until incoming animation is complete. |
| 5750 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 5751 | // Transient status bar on the lockscreen is not allowed |
Jorim Jaggi | 2dc47c1 | 2017-05-05 17:39:58 +0200 | [diff] [blame] | 5752 | if ((mForceStatusBarFromKeyguard || statusBarExpanded) |
| 5753 | && mStatusBarController.isTransientShowing()) { |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 5754 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 5755 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 5756 | } |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 5757 | if (statusBarExpanded && mNavigationBar != null) { |
| 5758 | if (mNavigationBarController.setBarShowingLw(true)) { |
| 5759 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5760 | } |
| 5761 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5762 | } else if (mTopFullscreenOpaqueWindowState != null) { |
Selim Cinek | 3a49ba2 | 2017-08-10 11:17:39 -0700 | [diff] [blame] | 5763 | topIsFullscreen = topAppHidesStatusBar; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5764 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 5765 | // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5766 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 5767 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5768 | if (mStatusBarController.isTransientShowing()) { |
| 5769 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5770 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5771 | } |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 5772 | } else if (topIsFullscreen |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5773 | && !mWindowManagerInternal.isStackVisible(WINDOWING_MODE_FREEFORM) |
| 5774 | && !mWindowManagerInternal.isStackVisible( |
| 5775 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5776 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5777 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5778 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5779 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 5780 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 5781 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5782 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5783 | if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5784 | if (mStatusBarController.setBarShowingLw(true)) { |
| 5785 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5786 | } |
Selim Cinek | 3a49ba2 | 2017-08-10 11:17:39 -0700 | [diff] [blame] | 5787 | topAppHidesStatusBar = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5788 | } |
| 5789 | } |
Selim Cinek | 3a49ba2 | 2017-08-10 11:17:39 -0700 | [diff] [blame] | 5790 | mStatusBarController.setTopAppHidesStatusBar(topAppHidesStatusBar); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5791 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 5792 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 5793 | if (mTopIsFullscreen != topIsFullscreen) { |
| 5794 | if (!topIsFullscreen) { |
| 5795 | // Force another layout when status bar becomes fully shown. |
| 5796 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5797 | } |
| 5798 | mTopIsFullscreen = topIsFullscreen; |
| 5799 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 5800 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5801 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5802 | // If the navigation bar has been hidden or shown, we need to do another |
| 5803 | // layout pass to update that window. |
| 5804 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5805 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5806 | |
Jorim Jaggi | 77e1043 | 2016-10-26 17:43:56 -0700 | [diff] [blame] | 5807 | if (mShowingDream != mLastShowingDream) { |
| 5808 | mLastShowingDream = mShowingDream; |
| 5809 | mWindowManagerFuncs.notifyShowingDreamChanged(); |
| 5810 | } |
| 5811 | |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 5812 | updateWindowSleepToken(); |
| 5813 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5814 | // update since mAllowLockscreenWhenOn might have changed |
| 5815 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5816 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5817 | } |
| 5818 | |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 5819 | private void updateWindowSleepToken() { |
| 5820 | if (mWindowSleepTokenNeeded && !mLastWindowSleepTokenNeeded) { |
| 5821 | mHandler.removeCallbacks(mReleaseSleepTokenRunnable); |
| 5822 | mHandler.post(mAcquireSleepTokenRunnable); |
| 5823 | } else if (!mWindowSleepTokenNeeded && mLastWindowSleepTokenNeeded) { |
| 5824 | mHandler.removeCallbacks(mAcquireSleepTokenRunnable); |
| 5825 | mHandler.post(mReleaseSleepTokenRunnable); |
| 5826 | } |
| 5827 | mLastWindowSleepTokenNeeded = mWindowSleepTokenNeeded; |
| 5828 | } |
| 5829 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5830 | /** |
Selim Cinek | 3a49ba2 | 2017-08-10 11:17:39 -0700 | [diff] [blame] | 5831 | * @return Whether the top app should hide the statusbar based on the top fullscreen opaque |
| 5832 | * window. |
| 5833 | */ |
| 5834 | private boolean topAppHidesStatusBar() { |
| 5835 | if (mTopFullscreenOpaqueWindowState == null) { |
| 5836 | return false; |
| 5837 | } |
| 5838 | final int fl = PolicyControl.getWindowFlags(null, |
| 5839 | mTopFullscreenOpaqueWindowState.getAttrs()); |
| 5840 | if (localLOGV) { |
Robert Carr | 217e7cc | 2018-01-31 18:08:39 -0800 | [diff] [blame] | 5841 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()); |
Selim Cinek | 3a49ba2 | 2017-08-10 11:17:39 -0700 | [diff] [blame] | 5842 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
| 5843 | + " lp.flags=0x" + Integer.toHexString(fl)); |
| 5844 | } |
| 5845 | return (fl & LayoutParams.FLAG_FULLSCREEN) != 0 |
| 5846 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
| 5847 | } |
| 5848 | |
| 5849 | /** |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5850 | * Updates the occluded state of the Keyguard. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5851 | * |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5852 | * @return Whether the flags have changed and we have to redo the layout. |
| 5853 | */ |
Jorim Jaggi | 9ba2e10 | 2017-04-04 12:51:03 +0200 | [diff] [blame] | 5854 | private boolean setKeyguardOccludedLw(boolean isOccluded, boolean force) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5855 | if (DEBUG_KEYGUARD) Slog.d(TAG, "setKeyguardOccluded occluded=" + isOccluded); |
Jorim Jaggi | ec7708a | 2017-04-10 18:47:36 -0700 | [diff] [blame] | 5856 | final boolean wasOccluded = mKeyguardOccluded; |
| 5857 | final boolean showing = mKeyguardDelegate.isShowing(); |
| 5858 | final boolean changed = wasOccluded != isOccluded || force; |
| 5859 | if (!isOccluded && changed && showing) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5860 | mKeyguardOccluded = false; |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 5861 | mKeyguardDelegate.setOccluded(false, true /* animate */); |
Jorim Jaggi | 9ba2e10 | 2017-04-04 12:51:03 +0200 | [diff] [blame] | 5862 | if (mStatusBar != null) { |
| 5863 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 5864 | if (!mKeyguardDelegate.hasLockscreenWallpaper()) { |
| 5865 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 5866 | } |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 5867 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5868 | return true; |
Jorim Jaggi | ec7708a | 2017-04-10 18:47:36 -0700 | [diff] [blame] | 5869 | } else if (isOccluded && changed && showing) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5870 | mKeyguardOccluded = true; |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 5871 | mKeyguardDelegate.setOccluded(true, false /* animate */); |
Jorim Jaggi | 9ba2e10 | 2017-04-04 12:51:03 +0200 | [diff] [blame] | 5872 | if (mStatusBar != null) { |
| 5873 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 5874 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 5875 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5876 | return true; |
Jorim Jaggi | ec7708a | 2017-04-10 18:47:36 -0700 | [diff] [blame] | 5877 | } else if (changed) { |
Adrian Roos | 909fe2d | 2016-10-12 12:03:24 -0700 | [diff] [blame] | 5878 | mKeyguardOccluded = isOccluded; |
| 5879 | mKeyguardDelegate.setOccluded(isOccluded, false /* animate */); |
| 5880 | return false; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5881 | } else { |
| 5882 | return false; |
| 5883 | } |
| 5884 | } |
| 5885 | |
| 5886 | private boolean isStatusBarKeyguard() { |
| 5887 | return mStatusBar != null |
| 5888 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 5889 | } |
| 5890 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5891 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5892 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 5893 | return !mShowingDream; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5894 | } |
| 5895 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5896 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5897 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5898 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5899 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5900 | // If the navigation bar has been hidden or shown, we need to do another |
| 5901 | // layout pass to update that window. |
| 5902 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 5903 | } |
| 5904 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5905 | } |
| 5906 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 5907 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5908 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5909 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5910 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5911 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 5912 | if (newLidState == mLidState) { |
| 5913 | return; |
| 5914 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5915 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5916 | mLidState = newLidState; |
| 5917 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5918 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5919 | |
| 5920 | if (lidOpen) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5921 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch, |
| 5922 | "android.policy:LID"); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5923 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 5924 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5925 | } |
| 5926 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5927 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5928 | @Override |
| 5929 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 5930 | int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; |
| 5931 | if (mCameraLensCoverState == lensCoverState) { |
| 5932 | return; |
| 5933 | } |
| 5934 | if (mCameraLensCoverState == CAMERA_LENS_COVERED && |
| 5935 | lensCoverState == CAMERA_LENS_UNCOVERED) { |
| 5936 | Intent intent; |
| 5937 | final boolean keyguardActive = mKeyguardDelegate == null ? false : |
| 5938 | mKeyguardDelegate.isShowing(); |
| 5939 | if (keyguardActive) { |
| 5940 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); |
| 5941 | } else { |
| 5942 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 5943 | } |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5944 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens, |
| 5945 | "android.policy:CAMERA_COVER"); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5946 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5947 | } |
| 5948 | mCameraLensCoverState = lensCoverState; |
| 5949 | } |
| 5950 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5951 | void setHdmiPlugged(boolean plugged) { |
| 5952 | if (mHdmiPlugged != plugged) { |
| 5953 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5954 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5955 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5956 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5957 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 5958 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5959 | } |
| 5960 | } |
| 5961 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5962 | void initializeHdmiState() { |
Jeff Sharkey | 8918298 | 2017-11-01 19:02:56 -0600 | [diff] [blame] | 5963 | final int oldMask = StrictMode.allowThreadDiskReadsMask(); |
| 5964 | try { |
| 5965 | initializeHdmiStateInternal(); |
| 5966 | } finally { |
| 5967 | StrictMode.setThreadPolicyMask(oldMask); |
| 5968 | } |
| 5969 | } |
| 5970 | |
| 5971 | void initializeHdmiStateInternal() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 5972 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5973 | // watch for HDMI plug messages if the hdmi switch exists |
| 5974 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 5975 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 5976 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5977 | final String filename = "/sys/class/switch/hdmi/state"; |
| 5978 | FileReader reader = null; |
| 5979 | try { |
| 5980 | reader = new FileReader(filename); |
| 5981 | char[] buf = new char[15]; |
| 5982 | int n = reader.read(buf); |
| 5983 | if (n > 1) { |
| 5984 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 5985 | } |
| 5986 | } catch (IOException ex) { |
| 5987 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 5988 | } catch (NumberFormatException ex) { |
| 5989 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 5990 | } finally { |
| 5991 | if (reader != null) { |
| 5992 | try { |
| 5993 | reader.close(); |
| 5994 | } catch (IOException ex) { |
| 5995 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5996 | } |
| 5997 | } |
| 5998 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 5999 | // This dance forces the code in setHdmiPlugged to run. |
| 6000 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 6001 | mHdmiPlugged = !plugged; |
| 6002 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 6003 | } |
| 6004 | |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 6005 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6006 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6007 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 6008 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 6009 | if (!mSystemBooted) { |
| 6010 | // If we have not yet booted, don't let key events do anything. |
| 6011 | return 0; |
| 6012 | } |
| 6013 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 6014 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6015 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 6016 | final boolean canceled = event.isCanceled(); |
| 6017 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 6018 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 6019 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 6020 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 6021 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 6022 | // the same as if it were open and in front. |
| 6023 | // This will prevent any keys other than the power button from waking the screen |
| 6024 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6025 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 6026 | (interactive ? |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6027 | isKeyguardShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6028 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6029 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 6030 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6031 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 6032 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 6033 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6034 | } |
| 6035 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 6036 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6037 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 6038 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 6039 | || event.isWakeKey(); |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 6040 | if (interactive || (isInjected && !isWakeKey)) { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 6041 | // When the device is interactive or the key is injected pass the |
| 6042 | // key to the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6043 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6044 | isWakeKey = false; |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 6045 | |
| 6046 | if (interactive) { |
| 6047 | // If the screen is awake, but the button pressed was the one that woke the device |
| 6048 | // then don't pass it to the application |
| 6049 | if (keyCode == mPendingWakeKey && !down) { |
| 6050 | result = 0; |
| 6051 | } |
| 6052 | // Reset the pending key |
| 6053 | mPendingWakeKey = PENDING_KEY_NULL; |
| 6054 | } |
| 6055 | } else if (!interactive && shouldDispatchInputWhenNonInteractive(event)) { |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 6056 | // If we're currently dozing with the screen on and the keyguard showing, pass the key |
| 6057 | // to the application but preserve its wake key status to make sure we still move |
| 6058 | // from dozing to fully interactive if we would normally go from off to fully |
| 6059 | // interactive. |
| 6060 | result = ACTION_PASS_TO_USER; |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 6061 | // Since we're dispatching the input, reset the pending key |
| 6062 | mPendingWakeKey = PENDING_KEY_NULL; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6063 | } else { |
| 6064 | // When the screen is off and the key is not injected, determine whether |
| 6065 | // to wake the device but don't pass the key to the application. |
| 6066 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 6067 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 6068 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6069 | } |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 6070 | // Cache the wake key on down event so we can also avoid sending the up event to the app |
| 6071 | if (isWakeKey && down) { |
| 6072 | mPendingWakeKey = keyCode; |
| 6073 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6074 | } |
| 6075 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 6076 | // If the key would be handled globally, just return the result, don't worry about special |
| 6077 | // key processing. |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6078 | if (isValidGlobalKey(keyCode) |
| 6079 | && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 6080 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6081 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 6082 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 6083 | return result; |
| 6084 | } |
| 6085 | |
Matthew Ng | 64543e6 | 2018-02-28 17:35:10 -0800 | [diff] [blame] | 6086 | // Enable haptics if down and virtual key without multiple repetitions. If this is a hard |
| 6087 | // virtual key such as a navigation bar button, only vibrate if flag is enabled. |
| 6088 | final boolean isNavBarVirtKey = ((event.getFlags() & KeyEvent.FLAG_VIRTUAL_HARD_KEY) != 0); |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 6089 | boolean useHapticFeedback = down |
| 6090 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
Matthew Ng | 64543e6 | 2018-02-28 17:35:10 -0800 | [diff] [blame] | 6091 | && (!isNavBarVirtKey || mNavBarVirtualKeyHapticFeedbackEnabled) |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 6092 | && event.getRepeatCount() == 0; |
| 6093 | |
Winson Chung | 703719b | 2018-04-18 17:53:15 -0700 | [diff] [blame] | 6094 | // Cancel any pending remote recents animations before handling the button itself. In the |
| 6095 | // case where we are going home and the recents animation has already started, just cancel |
| 6096 | // the recents animation, leaving the home stack in place for the pending start activity |
| 6097 | if (isNavBarVirtKey && !down) { |
| 6098 | boolean isHomeKey = keyCode == KeyEvent.KEYCODE_HOME; |
| 6099 | mActivityManagerInternal.cancelRecentsAnimation(!isHomeKey); |
| 6100 | } |
| 6101 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6102 | // Handle special keys. |
| 6103 | switch (keyCode) { |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 6104 | case KeyEvent.KEYCODE_BACK: { |
| 6105 | if (down) { |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 6106 | interceptBackKeyDown(); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 6107 | } else { |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 6108 | boolean handled = interceptBackKeyUp(event); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 6109 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 6110 | // Don't pass back press to app if we've already handled it via long press |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 6111 | if (handled) { |
| 6112 | result &= ~ACTION_PASS_TO_USER; |
| 6113 | } |
| 6114 | } |
| 6115 | break; |
| 6116 | } |
| 6117 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6118 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 6119 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 6120 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 6121 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 6122 | if (down) { |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 6123 | // Any activity on the vol down button stops the ringer toggle shortcut |
| 6124 | cancelPendingRingerToggleChordAction(); |
| 6125 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6126 | if (interactive && !mScreenshotChordVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 6127 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6128 | mScreenshotChordVolumeDownKeyTriggered = true; |
| 6129 | mScreenshotChordVolumeDownKeyTime = event.getDownTime(); |
| 6130 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 6131 | cancelPendingPowerKeyAction(); |
| 6132 | interceptScreenshotChord(); |
Phil Weaver | ce687c5 | 2017-03-15 08:51:52 -0700 | [diff] [blame] | 6133 | interceptAccessibilityShortcutChord(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 6134 | } |
| 6135 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6136 | mScreenshotChordVolumeDownKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 6137 | cancelPendingScreenshotChordAction(); |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 6138 | cancelPendingAccessibilityShortcutAction(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 6139 | } |
| 6140 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 6141 | if (down) { |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 6142 | if (interactive && !mA11yShortcutChordVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 6143 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 6144 | mA11yShortcutChordVolumeUpKeyTriggered = true; |
| 6145 | mA11yShortcutChordVolumeUpKeyTime = event.getDownTime(); |
| 6146 | mA11yShortcutChordVolumeUpKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 6147 | cancelPendingPowerKeyAction(); |
| 6148 | cancelPendingScreenshotChordAction(); |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 6149 | cancelPendingRingerToggleChordAction(); |
| 6150 | |
Phil Weaver | ce687c5 | 2017-03-15 08:51:52 -0700 | [diff] [blame] | 6151 | interceptAccessibilityShortcutChord(); |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 6152 | interceptRingerToggleChord(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 6153 | } |
| 6154 | } else { |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 6155 | mA11yShortcutChordVolumeUpKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 6156 | cancelPendingScreenshotChordAction(); |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 6157 | cancelPendingAccessibilityShortcutAction(); |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 6158 | cancelPendingRingerToggleChordAction(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 6159 | } |
| 6160 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6161 | if (down) { |
Philip Quinn | 4b5b3c6 | 2017-07-20 21:07:58 -0700 | [diff] [blame] | 6162 | sendSystemKeyToStatusBarAsync(event.getKeyCode()); |
| 6163 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 6164 | TelecomManager telecomManager = getTelecommService(); |
| 6165 | if (telecomManager != null) { |
| 6166 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 6167 | // If an incoming call is ringing, either VOLUME key means |
| 6168 | // "silence ringer". We handle these keys here, rather than |
| 6169 | // in the InCallScreen, to make sure we'll respond to them |
| 6170 | // even if the InCallScreen hasn't come to the foreground yet. |
| 6171 | // Look for the DOWN event here, to agree with the "fallback" |
| 6172 | // behavior in the InCallScreen. |
| 6173 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 6174 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6175 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 6176 | // Silence the ringer. (It's safe to call this |
| 6177 | // even if the ringer has already been silenced.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 6178 | telecomManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6179 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 6180 | // And *don't* pass this key thru to the current activity |
| 6181 | // (which is probably the InCallScreen.) |
| 6182 | result &= ~ACTION_PASS_TO_USER; |
| 6183 | break; |
| 6184 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6185 | } |
Eric Laurent | a9a5258 | 2017-05-10 15:16:01 -0700 | [diff] [blame] | 6186 | int audioMode = AudioManager.MODE_NORMAL; |
| 6187 | try { |
| 6188 | audioMode = getAudioService().getMode(); |
| 6189 | } catch (Exception e) { |
| 6190 | Log.e(TAG, "Error getting AudioService in interceptKeyBeforeQueueing.", e); |
| 6191 | } |
| 6192 | boolean isInCall = (telecomManager != null && telecomManager.isInCall()) || |
| 6193 | audioMode == AudioManager.MODE_IN_COMMUNICATION; |
| 6194 | if (isInCall && (result & ACTION_PASS_TO_USER) == 0) { |
| 6195 | // If we are in call but we decided not to pass the key to |
| 6196 | // the application, just pass it to the session service. |
| 6197 | MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent( |
| 6198 | event, AudioManager.USE_DEFAULT_STREAM_TYPE, false); |
| 6199 | break; |
| 6200 | } |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 6201 | } |
Karthik Ravi Shankar | 86ecf34 | 2017-04-28 15:35:58 -0700 | [diff] [blame] | 6202 | if (mUseTvRouting || mHandleVolumeKeysInWM) { |
| 6203 | // Defer special key handlings to |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 6204 | // {@link interceptKeyBeforeDispatching()}. |
| 6205 | result |= ACTION_PASS_TO_USER; |
| 6206 | } else if ((result & ACTION_PASS_TO_USER) == 0) { |
| 6207 | // If we aren't passing to the user and no one else |
| 6208 | // handled it send it to the session manager to |
| 6209 | // figure out. |
Jaewan Kim | 5026936 | 2016-12-23 11:22:02 +0900 | [diff] [blame] | 6210 | MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent( |
David Lin | f52b607 | 2017-04-21 18:52:18 -0700 | [diff] [blame] | 6211 | event, AudioManager.USE_DEFAULT_STREAM_TYPE, true); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6212 | } |
| 6213 | break; |
| 6214 | } |
| 6215 | |
| 6216 | case KeyEvent.KEYCODE_ENDCALL: { |
| 6217 | result &= ~ACTION_PASS_TO_USER; |
| 6218 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 6219 | TelecomManager telecomManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6220 | boolean hungUp = false; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 6221 | if (telecomManager != null) { |
| 6222 | hungUp = telecomManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6223 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6224 | if (interactive && !hungUp) { |
| 6225 | mEndCallKeyHandled = false; |
| 6226 | mHandler.postDelayed(mEndCallLongPress, |
| 6227 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 6228 | } else { |
| 6229 | mEndCallKeyHandled = true; |
| 6230 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6231 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6232 | if (!mEndCallKeyHandled) { |
| 6233 | mHandler.removeCallbacks(mEndCallLongPress); |
| 6234 | if (!canceled) { |
| 6235 | if ((mEndcallBehavior |
| 6236 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 6237 | if (goHome()) { |
| 6238 | break; |
| 6239 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 6240 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6241 | if ((mEndcallBehavior |
| 6242 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
Selim Cinek | ab55ba5 | 2017-08-02 16:45:51 -0700 | [diff] [blame] | 6243 | goToSleep(event.getEventTime(), |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6244 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 6245 | isWakeKey = false; |
| 6246 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6247 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6248 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6249 | } |
| 6250 | break; |
| 6251 | } |
| 6252 | |
| 6253 | case KeyEvent.KEYCODE_POWER: { |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 6254 | // Any activity on the power button stops the accessibility shortcut |
| 6255 | cancelPendingAccessibilityShortcutAction(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6256 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6257 | isWakeKey = false; // wake-up will be handled separately |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6258 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6259 | interceptPowerKeyDown(event, interactive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6260 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6261 | interceptPowerKeyUp(event, interactive, canceled); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6262 | } |
| 6263 | break; |
| 6264 | } |
| 6265 | |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 6266 | case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN: |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6267 | // fall through |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 6268 | case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP: |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6269 | // fall through |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 6270 | case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_LEFT: |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6271 | // fall through |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 6272 | case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_RIGHT: { |
| 6273 | result &= ~ACTION_PASS_TO_USER; |
| 6274 | interceptSystemNavigationKey(event); |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6275 | break; |
| 6276 | } |
| 6277 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 6278 | case KeyEvent.KEYCODE_SLEEP: { |
| 6279 | result &= ~ACTION_PASS_TO_USER; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6280 | isWakeKey = false; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 6281 | if (!mPowerManager.isInteractive()) { |
| 6282 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 6283 | } |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 6284 | if (down) { |
Siarhei Vishniakou | 191cf1b | 2017-08-17 16:17:22 -0700 | [diff] [blame] | 6285 | sleepPress(); |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 6286 | } else { |
| 6287 | sleepRelease(event.getEventTime()); |
| 6288 | } |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 6289 | break; |
| 6290 | } |
| 6291 | |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 6292 | case KeyEvent.KEYCODE_SOFT_SLEEP: { |
| 6293 | result &= ~ACTION_PASS_TO_USER; |
| 6294 | isWakeKey = false; |
| 6295 | if (!down) { |
| 6296 | mPowerManagerInternal.setUserInactiveOverrideFromWindowManager(); |
| 6297 | } |
| 6298 | break; |
| 6299 | } |
| 6300 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 6301 | case KeyEvent.KEYCODE_WAKEUP: { |
| 6302 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6303 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 6304 | break; |
| 6305 | } |
| 6306 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6307 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 6308 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 6309 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6310 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 6311 | case KeyEvent.KEYCODE_MUTE: |
| 6312 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 6313 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 6314 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 6315 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 6316 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 6317 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 6318 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 6319 | if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { |
| 6320 | // If the global session is active pass all media keys to it |
| 6321 | // instead of the active window. |
| 6322 | result &= ~ACTION_PASS_TO_USER; |
| 6323 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6324 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 6325 | // Only do this if we would otherwise not pass it to the user. In that |
| 6326 | // case, the PhoneWindow class will do the same thing, except it will |
| 6327 | // only do it if the showing app doesn't process the key on its own. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 6328 | // Note that we need to make a copy of the key event here because the |
| 6329 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6330 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 6331 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 6332 | new KeyEvent(event)); |
| 6333 | msg.setAsynchronous(true); |
| 6334 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6335 | } |
| 6336 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6337 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6338 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6339 | case KeyEvent.KEYCODE_CALL: { |
| 6340 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 6341 | TelecomManager telecomManager = getTelecommService(); |
| 6342 | if (telecomManager != null) { |
| 6343 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 6344 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 6345 | + " CALL key-down while ringing: Answer the call!"); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 6346 | telecomManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6347 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 6348 | // And *don't* pass this key thru to the current activity |
| 6349 | // (which is presumably the InCallScreen.) |
| 6350 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6351 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6352 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6353 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6354 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6355 | } |
Siarhei Vishniakou | 191cf1b | 2017-08-17 16:17:22 -0700 | [diff] [blame] | 6356 | case KeyEvent.KEYCODE_ASSIST: { |
| 6357 | final boolean longPressed = event.getRepeatCount() > 0; |
| 6358 | if (down && longPressed) { |
| 6359 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_ASSIST_LONG_PRESS); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 6360 | msg.setAsynchronous(true); |
| 6361 | msg.sendToTarget(); |
| 6362 | } |
Siarhei Vishniakou | 191cf1b | 2017-08-17 16:17:22 -0700 | [diff] [blame] | 6363 | if (!down && !longPressed) { |
| 6364 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_ASSIST, event.getDeviceId(), |
| 6365 | 0 /* unused */, null /* hint */); |
| 6366 | msg.setAsynchronous(true); |
| 6367 | msg.sendToTarget(); |
| 6368 | } |
| 6369 | result &= ~ACTION_PASS_TO_USER; |
| 6370 | break; |
| 6371 | } |
| 6372 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 6373 | if (!down) { |
| 6374 | mBroadcastWakeLock.acquire(); |
| 6375 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK); |
| 6376 | msg.setAsynchronous(true); |
| 6377 | msg.sendToTarget(); |
| 6378 | } |
| 6379 | result &= ~ACTION_PASS_TO_USER; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 6380 | break; |
| 6381 | } |
| 6382 | case KeyEvent.KEYCODE_WINDOW: { |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 6383 | if (mShortPressOnWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) { |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 6384 | if (mPictureInPictureVisible) { |
| 6385 | // Consumes the key only if picture-in-picture is visible to show |
| 6386 | // picture-in-picture control menu. This gives a chance to the foreground |
| 6387 | // activity to customize PIP key behavior. |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 6388 | if (!down) { |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 6389 | showPictureInPictureMenu(event); |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 6390 | } |
| 6391 | result &= ~ACTION_PASS_TO_USER; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 6392 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 6393 | } |
| 6394 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 6395 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6396 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 6397 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 6398 | if (useHapticFeedback) { |
| 6399 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 6400 | } |
| 6401 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 6402 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6403 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 6404 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 6405 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6406 | return result; |
| 6407 | } |
| 6408 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 6409 | /** |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6410 | * Handle statusbar expansion events. |
| 6411 | * @param event |
| 6412 | */ |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 6413 | private void interceptSystemNavigationKey(KeyEvent event) { |
Phil Weaver | 27fcd9c | 2017-01-20 15:57:24 -0800 | [diff] [blame] | 6414 | if (event.getAction() == KeyEvent.ACTION_UP) { |
| 6415 | if (!mAccessibilityManager.isEnabled() |
| 6416 | || !mAccessibilityManager.sendFingerprintGesture(event.getKeyCode())) { |
Siarhei Vishniakou | e5e0d9f | 2018-03-05 20:09:08 -0800 | [diff] [blame] | 6417 | if (mSystemNavigationKeysEnabled) { |
Philip Quinn | 4b5b3c6 | 2017-07-20 21:07:58 -0700 | [diff] [blame] | 6418 | sendSystemKeyToStatusBarAsync(event.getKeyCode()); |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6419 | } |
| 6420 | } |
| 6421 | } |
| 6422 | } |
| 6423 | |
| 6424 | /** |
Philip Quinn | 4b5b3c6 | 2017-07-20 21:07:58 -0700 | [diff] [blame] | 6425 | * Notify the StatusBar that a system key was pressed. |
| 6426 | */ |
| 6427 | private void sendSystemKeyToStatusBar(int keyCode) { |
| 6428 | IStatusBarService statusBar = getStatusBarService(); |
| 6429 | if (statusBar != null) { |
| 6430 | try { |
| 6431 | statusBar.handleSystemKey(keyCode); |
| 6432 | } catch (RemoteException e) { |
| 6433 | // Oh well. |
| 6434 | } |
| 6435 | } |
| 6436 | } |
| 6437 | |
| 6438 | /** |
| 6439 | * Notify the StatusBar that a system key was pressed without blocking the current thread. |
| 6440 | */ |
| 6441 | private void sendSystemKeyToStatusBarAsync(int keyCode) { |
| 6442 | Message message = mHandler.obtainMessage(MSG_SYSTEM_KEY_PRESS, keyCode, 0); |
| 6443 | message.setAsynchronous(true); |
| 6444 | mHandler.sendMessage(message); |
| 6445 | } |
| 6446 | |
| 6447 | /** |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 6448 | * Notify the StatusBar that system rotation suggestion has changed. |
| 6449 | */ |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 6450 | private void sendProposedRotationChangeToStatusBarInternal(int rotation, boolean isValid) { |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 6451 | StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); |
| 6452 | if (statusBar != null) { |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 6453 | statusBar.onProposedRotationChanged(rotation, isValid); |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 6454 | } |
| 6455 | } |
| 6456 | |
| 6457 | /** |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6458 | * Returns true if the key can have global actions attached to it. |
| 6459 | * We reserve all power management keys for the system since they require |
| 6460 | * very careful handling. |
| 6461 | */ |
| 6462 | private static boolean isValidGlobalKey(int keyCode) { |
| 6463 | switch (keyCode) { |
| 6464 | case KeyEvent.KEYCODE_POWER: |
| 6465 | case KeyEvent.KEYCODE_WAKEUP: |
| 6466 | case KeyEvent.KEYCODE_SLEEP: |
| 6467 | return false; |
| 6468 | default: |
| 6469 | return true; |
| 6470 | } |
| 6471 | } |
| 6472 | |
| 6473 | /** |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 6474 | * When the screen is off we ignore some keys that might otherwise typically |
| 6475 | * be considered wake keys. We filter them out here. |
| 6476 | * |
| 6477 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 6478 | * is always considered a wake key. |
| 6479 | */ |
| 6480 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 6481 | switch (keyCode) { |
| 6482 | // ignore volume keys unless docked |
| 6483 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 6484 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 6485 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 6486 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 6487 | |
| 6488 | // ignore media and camera keys |
| 6489 | case KeyEvent.KEYCODE_MUTE: |
| 6490 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 6491 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 6492 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 6493 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 6494 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 6495 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 6496 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 6497 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 6498 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 6499 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 6500 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 6501 | case KeyEvent.KEYCODE_CAMERA: |
| 6502 | return false; |
| 6503 | } |
| 6504 | return true; |
| 6505 | } |
| 6506 | |
| 6507 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 6508 | /** {@inheritDoc} */ |
| 6509 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 6510 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 6511 | if ((policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6512 | if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion, |
| 6513 | "android.policy:MOTION")) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6514 | return 0; |
| 6515 | } |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 6516 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6517 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 6518 | if (shouldDispatchInputWhenNonInteractive(null)) { |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 6519 | return ACTION_PASS_TO_USER; |
| 6520 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6521 | |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 6522 | // If we have not passed the action up and we are in theater mode without dreaming, |
| 6523 | // there will be no dream to intercept the touch and wake into ambient. The device should |
| 6524 | // wake up in this case. |
| 6525 | if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6526 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming, |
| 6527 | "android.policy:MOTION"); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 6528 | } |
| 6529 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 6530 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 6531 | } |
| 6532 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 6533 | private boolean shouldDispatchInputWhenNonInteractive(KeyEvent event) { |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 6534 | final boolean displayOff = (mDisplay == null || mDisplay.getState() == STATE_OFF); |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 6535 | |
| 6536 | if (displayOff && !mHasFeatureWatch) { |
| 6537 | return false; |
| 6538 | } |
| 6539 | |
| 6540 | // Send events to keyguard while the screen is on and it's showing. |
| 6541 | if (isKeyguardShowingAndNotOccluded() && !displayOff) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6542 | return true; |
| 6543 | } |
| 6544 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 6545 | // Watches handle BACK specially |
| 6546 | if (mHasFeatureWatch |
| 6547 | && event != null |
| 6548 | && (event.getKeyCode() == KeyEvent.KEYCODE_BACK |
| 6549 | || event.getKeyCode() == KeyEvent.KEYCODE_STEM_PRIMARY)) { |
| 6550 | return false; |
| 6551 | } |
| 6552 | |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6553 | // Send events to a dozing dream even if the screen is off since the dream |
| 6554 | // is in control of the state of the screen. |
| 6555 | IDreamManager dreamManager = getDreamManager(); |
| 6556 | |
| 6557 | try { |
| 6558 | if (dreamManager != null && dreamManager.isDreaming()) { |
| 6559 | return true; |
| 6560 | } |
| 6561 | } catch (RemoteException e) { |
| 6562 | Slog.e(TAG, "RemoteException when checking if dreaming", e); |
| 6563 | } |
| 6564 | |
| 6565 | // Otherwise, consume events since the user can't see what is being |
| 6566 | // interacted with. |
| 6567 | return false; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 6568 | } |
| 6569 | |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6570 | private void dispatchDirectAudioEvent(KeyEvent event) { |
| 6571 | if (event.getAction() != KeyEvent.ACTION_DOWN) { |
| 6572 | return; |
| 6573 | } |
| 6574 | int keyCode = event.getKeyCode(); |
John Spurlock | b94f2d6 | 2015-03-17 14:11:57 -0400 | [diff] [blame] | 6575 | int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND |
| 6576 | | AudioManager.FLAG_FROM_KEY; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6577 | String pkgName = mContext.getOpPackageName(); |
| 6578 | switch (keyCode) { |
| 6579 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 6580 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 6581 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 6582 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
Eric Laurent | a9a5258 | 2017-05-10 15:16:01 -0700 | [diff] [blame] | 6583 | } catch (Exception e) { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6584 | Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e); |
| 6585 | } |
| 6586 | break; |
| 6587 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 6588 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 6589 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 6590 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
Eric Laurent | a9a5258 | 2017-05-10 15:16:01 -0700 | [diff] [blame] | 6591 | } catch (Exception e) { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6592 | Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e); |
| 6593 | } |
| 6594 | break; |
| 6595 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 6596 | try { |
| 6597 | if (event.getRepeatCount() == 0) { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 6598 | getAudioService().adjustSuggestedStreamVolume( |
| 6599 | AudioManager.ADJUST_TOGGLE_MUTE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 6600 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6601 | } |
Eric Laurent | a9a5258 | 2017-05-10 15:16:01 -0700 | [diff] [blame] | 6602 | } catch (Exception e) { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6603 | Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e); |
| 6604 | } |
| 6605 | break; |
| 6606 | } |
| 6607 | } |
| 6608 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 6609 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 6610 | if (DEBUG_INPUT) { |
| 6611 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6612 | } |
| 6613 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 6614 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 6615 | if (DEBUG_INPUT) { |
| 6616 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 6617 | } |
| 6618 | |
| 6619 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 6620 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 6621 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 6622 | } |
| 6623 | |
| 6624 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 6625 | |
| 6626 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 6627 | && event.getRepeatCount() == 0) { |
| 6628 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 6629 | |
| 6630 | Message msg = mHandler.obtainMessage( |
| 6631 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 6632 | msg.setAsynchronous(true); |
| 6633 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 6634 | } else { |
| 6635 | mBroadcastWakeLock.release(); |
| 6636 | } |
| 6637 | } |
| 6638 | |
| 6639 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 6640 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 6641 | |
| 6642 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 6643 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 6644 | if (DEBUG_INPUT) { |
| 6645 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 6646 | } |
| 6647 | |
| 6648 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 6649 | mBroadcastWakeLock.release(); |
| 6650 | } |
| 6651 | |
| 6652 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6653 | if (mActivityManagerInternal.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 6654 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6655 | } |
| 6656 | } |
| 6657 | |
Siarhei Vishniakou | 191cf1b | 2017-08-17 16:17:22 -0700 | [diff] [blame] | 6658 | void launchVoiceAssistWithWakeLock() { |
| 6659 | final Intent voiceIntent; |
| 6660 | if (!keyguardOn()) { |
| 6661 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 6662 | } else { |
| 6663 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 6664 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 6665 | if (dic != null) { |
| 6666 | try { |
| 6667 | dic.exitIdle("voice-search"); |
| 6668 | } catch (RemoteException e) { |
| 6669 | } |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 6670 | } |
Siarhei Vishniakou | 191cf1b | 2017-08-17 16:17:22 -0700 | [diff] [blame] | 6671 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 6672 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 6673 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6674 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 6675 | mBroadcastWakeLock.release(); |
| 6676 | } |
| 6677 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 6678 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 6679 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 6680 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 6681 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 6682 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 6683 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6684 | } else { |
| 6685 | try { |
| 6686 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 6687 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 6688 | mUiMode = uiModeService.getCurrentModeType(); |
| 6689 | } catch (RemoteException e) { |
| 6690 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 6691 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6692 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 6693 | synchronized (mLock) { |
| 6694 | updateOrientationListenerLp(); |
| 6695 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 6696 | } |
| 6697 | }; |
| 6698 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 6699 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 6700 | @Override |
| 6701 | public void onReceive(Context context, Intent intent) { |
| 6702 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6703 | if (mKeyguardDelegate != null) { |
| 6704 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 6705 | } |
| 6706 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6707 | if (mKeyguardDelegate != null) { |
| 6708 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 6709 | } |
| 6710 | } |
| 6711 | } |
| 6712 | }; |
| 6713 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6714 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 6715 | @Override |
| 6716 | public void onReceive(Context context, Intent intent) { |
| 6717 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 6718 | // tickle the settings observer: this first ensures that we're |
| 6719 | // observing the relevant settings for the newly-active user, |
| 6720 | // and then updates our own bookkeeping based on the now- |
| 6721 | // current user. |
| 6722 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 6723 | |
| 6724 | // force a re-application of focused window sysui visibility. |
| 6725 | // the window may never have been shown for this user |
| 6726 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 6727 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 6728 | mLastSystemUiFlags = 0; |
| 6729 | updateSystemUiVisibilityLw(); |
| 6730 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6731 | } |
| 6732 | } |
| 6733 | }; |
| 6734 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6735 | private final Runnable mHiddenNavPanic = new Runnable() { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 6736 | @Override |
| 6737 | public void run() { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6738 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 6739 | if (!isUserSetupComplete()) { |
| 6740 | // Swipe-up for navigation bar is disabled during setup |
| 6741 | return; |
| 6742 | } |
| 6743 | mPendingPanicGestureUptime = SystemClock.uptimeMillis(); |
Adrian Roos | 1f42590 | 2016-07-22 10:37:50 -0700 | [diff] [blame] | 6744 | if (!isNavBarEmpty(mLastSystemUiFlags)) { |
| 6745 | mNavigationBarController.showTransient(); |
| 6746 | } |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6747 | } |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 6748 | } |
| 6749 | }; |
| 6750 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6751 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 6752 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 6753 | if (!isUserSetupComplete()) { |
| 6754 | // Swipe-up for navigation bar is disabled during setup |
| 6755 | return; |
| 6756 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6757 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
Adrian Roos | 1f42590 | 2016-07-22 10:37:50 -0700 | [diff] [blame] | 6758 | boolean nb = mNavigationBarController.checkShowTransientBarLw() |
| 6759 | && !isNavBarEmpty(mLastSystemUiFlags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6760 | if (sb || nb) { |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 6761 | // Don't show status bar when swiping on already visible navigation bar |
| 6762 | if (!nb && swipeTarget == mNavigationBar) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6763 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6764 | return; |
| 6765 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6766 | if (sb) mStatusBarController.showTransient(); |
| 6767 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6768 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6769 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 6770 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6771 | } |
| 6772 | } |
| 6773 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6774 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6775 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6776 | public void startedGoingToSleep(int why) { |
| 6777 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")"); |
Selim Cinek | ab55ba5 | 2017-08-02 16:45:51 -0700 | [diff] [blame] | 6778 | |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6779 | mGoingToSleep = true; |
Selim Cinek | ab55ba5 | 2017-08-02 16:45:51 -0700 | [diff] [blame] | 6780 | mRequestedOrGoingToSleep = true; |
| 6781 | |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 6782 | if (mKeyguardDelegate != null) { |
| 6783 | mKeyguardDelegate.onStartedGoingToSleep(why); |
| 6784 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | // Called on the PowerManager's Notifier thread. |
| 6788 | @Override |
| 6789 | public void finishedGoingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 6790 | EventLog.writeEvent(70000, 0); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6791 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")"); |
Chris Wren | 9bb290b | 2015-06-29 12:02:13 -0400 | [diff] [blame] | 6792 | MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6793 | |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6794 | mGoingToSleep = false; |
Selim Cinek | ab55ba5 | 2017-08-02 16:45:51 -0700 | [diff] [blame] | 6795 | mRequestedOrGoingToSleep = false; |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6796 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6797 | // We must get this work done here because the power manager will drop |
| 6798 | // the wake lock and let the system suspend once this function returns. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6799 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6800 | mAwake = false; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6801 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6802 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6803 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6804 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6805 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6806 | mKeyguardDelegate.onFinishedGoingToSleep(why, |
| 6807 | mCameraGestureTriggeredDuringGoingToSleep); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6808 | } |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6809 | mCameraGestureTriggeredDuringGoingToSleep = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6810 | } |
| 6811 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6812 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6813 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6814 | public void startedWakingUp() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 6815 | EventLog.writeEvent(70000, 1); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6816 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up..."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 6817 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6818 | // Since goToSleep performs these functions synchronously, we must |
| 6819 | // do the same here. We cannot post this work to a handler because |
| 6820 | // that might cause it to become reordered with respect to what |
| 6821 | // may happen in a future call to goToSleep. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6822 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6823 | mAwake = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6824 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6825 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6826 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6827 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6828 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6829 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6830 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6831 | mKeyguardDelegate.onStartedWakingUp(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6832 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6833 | } |
| 6834 | |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6835 | // Called on the PowerManager's Notifier thread. |
| 6836 | @Override |
| 6837 | public void finishedWakingUp() { |
| 6838 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up..."); |
Adrian Roos | 369907f | 2017-07-14 14:53:39 +0200 | [diff] [blame] | 6839 | |
| 6840 | if (mKeyguardDelegate != null) { |
| 6841 | mKeyguardDelegate.onFinishedWakingUp(); |
| 6842 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6843 | } |
| 6844 | |
| 6845 | private void wakeUpFromPowerKey(long eventTime) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6846 | wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER"); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6847 | } |
| 6848 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6849 | private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) { |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 6850 | final boolean theaterModeEnabled = isTheaterModeEnabled(); |
| 6851 | if (!wakeInTheaterMode && theaterModeEnabled) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6852 | return false; |
| 6853 | } |
| 6854 | |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 6855 | if (theaterModeEnabled) { |
| 6856 | Settings.Global.putInt(mContext.getContentResolver(), |
| 6857 | Settings.Global.THEATER_MODE_ON, 0); |
| 6858 | } |
| 6859 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6860 | mPowerManager.wakeUp(wakeTime, reason); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6861 | return true; |
| 6862 | } |
| 6863 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6864 | private void finishKeyguardDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6865 | synchronized (mLock) { |
Jorim Jaggi | f325548 | 2015-07-24 12:32:42 -0700 | [diff] [blame] | 6866 | if (!mScreenOnEarly || mKeyguardDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6867 | return; // We are not awake yet or we have already informed of this event. |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6868 | } |
| 6869 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6870 | mKeyguardDrawComplete = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6871 | if (mKeyguardDelegate != null) { |
| 6872 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 6873 | } |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6874 | mWindowManagerDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6875 | } |
| 6876 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6877 | // ... eventually calls finishWindowsDrawn which will finalize our screen turn on |
| 6878 | // as well as enabling the orientation change logic/sensor. |
| 6879 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, |
| 6880 | WAITING_FOR_DRAWN_TIMEOUT); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6881 | } |
| 6882 | |
| 6883 | // Called on the DisplayManager's DisplayPowerController thread. |
| 6884 | @Override |
| 6885 | public void screenTurnedOff() { |
| 6886 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); |
| 6887 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6888 | updateScreenOffSleepToken(true); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6889 | synchronized (mLock) { |
| 6890 | mScreenOnEarly = false; |
| 6891 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 6892 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6893 | mWindowManagerDrawComplete = false; |
| 6894 | mScreenOnListener = null; |
| 6895 | updateOrientationListenerLp(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 6896 | |
| 6897 | if (mKeyguardDelegate != null) { |
| 6898 | mKeyguardDelegate.onScreenTurnedOff(); |
| 6899 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6900 | } |
Ruben Brunk | fecb615 | 2016-10-28 20:18:57 -0700 | [diff] [blame] | 6901 | reportScreenStateToVrManager(false); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6902 | } |
| 6903 | |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 6904 | private long getKeyguardDrawnTimeout() { |
| 6905 | final boolean bootCompleted = |
| 6906 | LocalServices.getService(SystemServiceManager.class).isBootCompleted(); |
| 6907 | // Set longer timeout if it has not booted yet to prevent showing empty window. |
| 6908 | return bootCompleted ? 1000 : 5000; |
| 6909 | } |
| 6910 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6911 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6912 | @Override |
| 6913 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6914 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6915 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6916 | updateScreenOffSleepToken(false); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6917 | synchronized (mLock) { |
| 6918 | mScreenOnEarly = true; |
| 6919 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 6920 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6921 | mWindowManagerDrawComplete = false; |
| 6922 | mScreenOnListener = screenOnListener; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6923 | |
eddy-sh.chen | 0df686d | 2018-02-22 18:10:21 +0800 | [diff] [blame] | 6924 | if (mKeyguardDelegate != null && mKeyguardDelegate.hasKeyguard()) { |
Jorim Jaggi | a4b51bc | 2015-08-10 18:20:43 -0700 | [diff] [blame] | 6925 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 6926 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, |
| 6927 | getKeyguardDrawnTimeout()); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6928 | mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback); |
| 6929 | } else { |
| 6930 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 6931 | "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
| 6932 | finishKeyguardDrawn(); |
| 6933 | } |
| 6934 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6935 | } |
| 6936 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 6937 | // Called on the DisplayManager's DisplayPowerController thread. |
| 6938 | @Override |
| 6939 | public void screenTurnedOn() { |
| 6940 | synchronized (mLock) { |
| 6941 | if (mKeyguardDelegate != null) { |
| 6942 | mKeyguardDelegate.onScreenTurnedOn(); |
| 6943 | } |
| 6944 | } |
Ruben Brunk | fecb615 | 2016-10-28 20:18:57 -0700 | [diff] [blame] | 6945 | reportScreenStateToVrManager(true); |
| 6946 | } |
| 6947 | |
Jorim Jaggi | 51304d7 | 2017-05-17 17:25:32 +0200 | [diff] [blame] | 6948 | @Override |
| 6949 | public void screenTurningOff(ScreenOffListener screenOffListener) { |
| 6950 | mWindowManagerFuncs.screenTurningOff(screenOffListener); |
Adrian Roos | 369907f | 2017-07-14 14:53:39 +0200 | [diff] [blame] | 6951 | synchronized (mLock) { |
| 6952 | if (mKeyguardDelegate != null) { |
| 6953 | mKeyguardDelegate.onScreenTurningOff(); |
| 6954 | } |
| 6955 | } |
Jorim Jaggi | 51304d7 | 2017-05-17 17:25:32 +0200 | [diff] [blame] | 6956 | } |
| 6957 | |
Ruben Brunk | fecb615 | 2016-10-28 20:18:57 -0700 | [diff] [blame] | 6958 | private void reportScreenStateToVrManager(boolean isScreenOn) { |
Zak Cohen | 732aeb0 | 2017-01-29 14:19:52 -0800 | [diff] [blame] | 6959 | if (mVrManagerInternal == null) { |
Ruben Brunk | fecb615 | 2016-10-28 20:18:57 -0700 | [diff] [blame] | 6960 | return; |
| 6961 | } |
Zak Cohen | 732aeb0 | 2017-01-29 14:19:52 -0800 | [diff] [blame] | 6962 | mVrManagerInternal.onScreenStateChanged(isScreenOn); |
| 6963 | } |
| 6964 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6965 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6966 | synchronized (mLock) { |
| 6967 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6968 | return; // Screen is not turned on or we did already handle this case earlier. |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6969 | } |
| 6970 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6971 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6972 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6973 | |
| 6974 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6975 | } |
| 6976 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 6977 | private void finishScreenTurningOn() { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6978 | synchronized (mLock) { |
| 6979 | // We have just finished drawing screen content. Since the orientation listener |
| 6980 | // gets only installed when all windows are drawn, we try to install it again. |
| 6981 | updateOrientationListenerLp(); |
| 6982 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6983 | final ScreenOnListener listener; |
| 6984 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6985 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6986 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 6987 | "finishScreenTurningOn: mAwake=" + mAwake |
| 6988 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 6989 | + ", mScreenOnFully=" + mScreenOnFully |
| 6990 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 6991 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 6992 | |
| 6993 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 6994 | || (mAwake && !mKeyguardDrawComplete)) { |
| 6995 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6996 | } |
| 6997 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6998 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 6999 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 7000 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7001 | mScreenOnFully = true; |
| 7002 | |
| 7003 | // Remember the first time we draw the keyguard so we know when we're done with |
| 7004 | // the main part of booting and can enable the screen and hide boot messages. |
| 7005 | if (!mKeyguardDrawnOnce && mAwake) { |
| 7006 | mKeyguardDrawnOnce = true; |
| 7007 | enableScreen = true; |
| 7008 | if (mBootMessageNeedsHiding) { |
| 7009 | mBootMessageNeedsHiding = false; |
| 7010 | hideBootMessages(); |
| 7011 | } |
| 7012 | } else { |
| 7013 | enableScreen = false; |
| 7014 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 7015 | } |
| 7016 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7017 | if (listener != null) { |
| 7018 | listener.onScreenOn(); |
| 7019 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 7020 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7021 | if (enableScreen) { |
| 7022 | try { |
| 7023 | mWindowManager.enableScreenIfNeeded(); |
| 7024 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 7025 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 7026 | } |
| 7027 | } |
| 7028 | |
| 7029 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7030 | synchronized (mLock) { |
| 7031 | if (!mKeyguardDrawnOnce) { |
| 7032 | mBootMessageNeedsHiding = true; |
| 7033 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 7034 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 7035 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7036 | |
| 7037 | if (mBootMsgDialog != null) { |
| 7038 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 7039 | mBootMsgDialog.dismiss(); |
| 7040 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 7041 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 7042 | } |
| 7043 | |
| 7044 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7045 | public boolean isScreenOn() { |
Jorim Jaggi | 67b29d5 | 2017-06-09 18:00:00 -0700 | [diff] [blame] | 7046 | synchronized (mLock) { |
| 7047 | return mScreenOnEarly; |
| 7048 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 7049 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 7050 | |
Adrian Roos | e94c15c | 2017-05-09 13:17:54 -0700 | [diff] [blame] | 7051 | @Override |
Adrian Roos | 7c89480 | 2017-07-19 12:25:34 +0200 | [diff] [blame] | 7052 | public boolean okToAnimate() { |
| 7053 | return mAwake && !mGoingToSleep; |
Adrian Roos | e94c15c | 2017-05-09 13:17:54 -0700 | [diff] [blame] | 7054 | } |
| 7055 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 7056 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7057 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7058 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 7059 | if (mKeyguardDelegate != null) { |
| 7060 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 7061 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7062 | } |
| 7063 | |
| 7064 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7065 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7066 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 7067 | if (mKeyguardDelegate != null) { |
| 7068 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 7069 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7070 | } |
| 7071 | |
Tony Mak | 2c0d6dc | 2016-04-29 16:16:54 +0100 | [diff] [blame] | 7072 | @Override |
| 7073 | public boolean isKeyguardShowingAndNotOccluded() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 7074 | if (mKeyguardDelegate == null) return false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 7075 | return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7076 | } |
| 7077 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 7078 | @Override |
| 7079 | public boolean isKeyguardTrustedLw() { |
| 7080 | if (mKeyguardDelegate == null) return false; |
| 7081 | return mKeyguardDelegate.isTrusted(); |
| 7082 | } |
| 7083 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 7084 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7085 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 7086 | public boolean isKeyguardLocked() { |
| 7087 | return keyguardOn(); |
| 7088 | } |
| 7089 | |
| 7090 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7091 | @Override |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 7092 | public boolean isKeyguardSecure(int userId) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 7093 | if (mKeyguardDelegate == null) return false; |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 7094 | return mKeyguardDelegate.isSecure(userId); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 7095 | } |
| 7096 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7097 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7098 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 7099 | public boolean isKeyguardOccluded() { |
| 7100 | if (mKeyguardDelegate == null) return false; |
| 7101 | return mKeyguardOccluded; |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 7102 | } |
| 7103 | |
Siarhei Vishniakou | 35fbb31 | 2017-12-13 13:48:50 -0800 | [diff] [blame] | 7104 | /** {@inheritDoc} */ |
| 7105 | @Override |
| 7106 | public boolean inKeyguardRestrictedKeyInputMode() { |
| 7107 | if (mKeyguardDelegate == null) return false; |
| 7108 | return mKeyguardDelegate.isInputRestricted(); |
| 7109 | } |
| 7110 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7111 | @Override |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 7112 | public void dismissKeyguardLw(IKeyguardDismissCallback callback, CharSequence message) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 7113 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 7114 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 7115 | |
| 7116 | // ask the keyguard to prompt the user to authenticate if necessary |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 7117 | mKeyguardDelegate.dismiss(callback, message); |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 7118 | } else if (callback != null) { |
| 7119 | try { |
| 7120 | callback.onDismissError(); |
| 7121 | } catch (RemoteException e) { |
| 7122 | Slog.w(TAG, "Failed to call callback", e); |
| 7123 | } |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 7124 | } |
| 7125 | } |
| 7126 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 7127 | @Override |
| 7128 | public boolean isKeyguardDrawnLw() { |
| 7129 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7130 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 7131 | } |
| 7132 | } |
| 7133 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 7134 | @Override |
Jorim Jaggi | 77e1043 | 2016-10-26 17:43:56 -0700 | [diff] [blame] | 7135 | public boolean isShowingDreamLw() { |
| 7136 | return mShowingDream; |
| 7137 | } |
| 7138 | |
| 7139 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 7140 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 7141 | if (mKeyguardDelegate != null) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 7142 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 7143 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 7144 | } |
| 7145 | } |
| 7146 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 7147 | @Override |
| 7148 | public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 7149 | DisplayCutout displayCutout, Rect outInsets) { |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 7150 | outInsets.setEmpty(); |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 7151 | |
| 7152 | // Navigation bar and status bar. |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 7153 | getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, displayCutout, outInsets); |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 7154 | outInsets.top = Math.max(outInsets.top, mStatusBarHeightForRotation[displayRotation]); |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 7155 | } |
| 7156 | |
| 7157 | @Override |
| 7158 | public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 7159 | DisplayCutout displayCutout, Rect outInsets) { |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 7160 | outInsets.setEmpty(); |
| 7161 | |
| 7162 | // Only navigation bar |
Matthew Ng | ca4c1a3 | 2016-12-13 16:55:09 -0800 | [diff] [blame] | 7163 | if (mHasNavigationBar) { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 7164 | int position = navigationBarPosition(displayWidth, displayHeight, displayRotation); |
| 7165 | if (position == NAV_BAR_BOTTOM) { |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 7166 | outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode); |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 7167 | } else if (position == NAV_BAR_RIGHT) { |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 7168 | outInsets.right = getNavigationBarWidth(displayRotation, mUiMode); |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 7169 | } else if (position == NAV_BAR_LEFT) { |
| 7170 | outInsets.left = getNavigationBarWidth(displayRotation, mUiMode); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 7171 | } |
| 7172 | } |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 7173 | |
| 7174 | if (displayCutout != null) { |
| 7175 | outInsets.left += displayCutout.getSafeInsetLeft(); |
| 7176 | outInsets.top += displayCutout.getSafeInsetTop(); |
| 7177 | outInsets.right += displayCutout.getSafeInsetRight(); |
| 7178 | outInsets.bottom += displayCutout.getSafeInsetBottom(); |
| 7179 | } |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 7180 | } |
| 7181 | |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 7182 | @Override |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7183 | public boolean isNavBarForcedShownLw(WindowState windowState) { |
Jorim Jaggi | e5638a6 | 2016-03-25 22:57:01 -0700 | [diff] [blame] | 7184 | return mForceShowSystemBars; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7185 | } |
| 7186 | |
| 7187 | @Override |
Andrii Kulian | 3a1619d | 2017-07-07 14:38:09 -0700 | [diff] [blame] | 7188 | public int getNavBarPosition() { |
| 7189 | // TODO(multi-display): Support system decor on secondary displays. |
| 7190 | return mNavigationBarPosition; |
| 7191 | } |
| 7192 | |
| 7193 | @Override |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 7194 | public boolean isDockSideAllowed(int dockSide) { |
| 7195 | |
| 7196 | // We do not allow all dock sides at which the navigation bar touches the docked stack. |
| 7197 | if (!mNavigationBarCanMove) { |
| 7198 | return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT; |
| 7199 | } else { |
| 7200 | return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT; |
| 7201 | } |
| 7202 | } |
| 7203 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7204 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 7205 | PhoneWindow.sendCloseSystemWindows(mContext, null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7206 | } |
| 7207 | |
| 7208 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 7209 | PhoneWindow.sendCloseSystemWindows(mContext, reason); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7210 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 7211 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7212 | @Override |
Andrii Kulian | ef5ce1c | 2018-03-20 19:27:24 -0700 | [diff] [blame] | 7213 | public int rotationForOrientationLw(int orientation, int lastRotation, boolean defaultDisplay) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 7214 | if (false) { |
| 7215 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 7216 | + orientation + ", last=" + lastRotation |
| 7217 | + "); user=" + mUserRotation + " " |
| 7218 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 7219 | ? "USER_ROTATION_LOCKED" : "") |
| 7220 | ); |
| 7221 | } |
| 7222 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 7223 | if (mForceDefaultOrientation) { |
| 7224 | return Surface.ROTATION_0; |
| 7225 | } |
| 7226 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 7227 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7228 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 7229 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 7230 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7231 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7232 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 7233 | final int preferredRotation; |
Andrii Kulian | ef5ce1c | 2018-03-20 19:27:24 -0700 | [diff] [blame] | 7234 | if (!defaultDisplay) { |
| 7235 | // For secondary displays we ignore things like displays sensors, docking mode and |
| 7236 | // rotation lock, and always prefer a default rotation. |
| 7237 | preferredRotation = Surface.ROTATION_0; |
| 7238 | } else if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7239 | // Ignore sensor when lid switch is open and rotation is forced. |
| 7240 | preferredRotation = mLidOpenRotation; |
| 7241 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7242 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7243 | // Ignore sensor when in car dock unless explicitly enabled. |
| 7244 | // This case can override the behavior of NOSENSOR, and can also |
| 7245 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7246 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7247 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 7248 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 7249 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 7250 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7251 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7252 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 7253 | // This case can override the behavior of NOSENSOR, and can also |
| 7254 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7255 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7256 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 7257 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 7258 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 7259 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 7260 | preferredRotation = mDemoHdmiRotation; |
| 7261 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 7262 | && mUndockedHdmiRotation >= 0) { |
| 7263 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 7264 | // been specified in the configuration (only for legacy devices without |
| 7265 | // full multi-display support). |
| 7266 | // Note that the dock orientation overrides the HDMI orientation. |
| 7267 | preferredRotation = mUndockedHdmiRotation; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 7268 | } else if (mDemoRotationLock) { |
| 7269 | // Ignore sensor when demo rotation lock is enabled. |
| 7270 | // Note that the dock orientation and HDMI rotation lock override this. |
| 7271 | preferredRotation = mDemoRotation; |
Santos Cordon | 0b5d969 | 2017-07-21 12:08:53 -0700 | [diff] [blame] | 7272 | } else if (mPersistentVrModeEnabled) { |
| 7273 | // While in VR, apps always prefer a portrait rotation. This does not change |
| 7274 | // any apps that explicitly set landscape, but does cause sensors be ignored, |
| 7275 | // and ignored any orientation lock that the user has set (this conditional |
| 7276 | // should remain above the ORIENTATION_LOCKED conditional below). |
| 7277 | preferredRotation = mPortraitRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 7278 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 7279 | // Application just wants to remain locked in the last rotation. |
| 7280 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 7281 | } else if (!mSupportAutoRotation) { |
| 7282 | // If we don't support auto-rotation then bail out here and ignore |
| 7283 | // the sensor and any rotation lock settings. |
| 7284 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 7285 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7286 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 7287 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 7288 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 7289 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 7290 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7291 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 7292 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 7293 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 7294 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 7295 | // Otherwise, use sensor only if requested by the application or enabled |
| 7296 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 7297 | if (mAllowAllRotations < 0) { |
| 7298 | // Can't read this during init() because the context doesn't |
| 7299 | // have display metrics at that time so we cannot determine |
| 7300 | // tablet vs. phone then. |
| 7301 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 7302 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 7303 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7304 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 7305 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 7306 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 7307 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Santos Cordon | 0b5d969 | 2017-07-21 12:08:53 -0700 | [diff] [blame] | 7308 | preferredRotation = sensorRotation; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7309 | } else { |
| 7310 | preferredRotation = lastRotation; |
| 7311 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 7312 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 7313 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 7314 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 7315 | // The idea is that the user rotation expresses a weak preference for the direction |
| 7316 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 7317 | // NOSENSOR be affected by rotation lock (although it will be affected by docks). |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 7318 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 7319 | } else { |
| 7320 | // No overriding preference. |
| 7321 | // We will do exactly what the application asked us to do. |
| 7322 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7323 | } |
| 7324 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 7325 | switch (orientation) { |
| 7326 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 7327 | // Return portrait unless overridden. |
| 7328 | if (isAnyPortrait(preferredRotation)) { |
| 7329 | return preferredRotation; |
| 7330 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 7331 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 7332 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7333 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 7334 | // Return landscape unless overridden. |
| 7335 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 7336 | return preferredRotation; |
| 7337 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7338 | return mLandscapeRotation; |
| 7339 | |
| 7340 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 7341 | // Return reverse portrait unless overridden. |
| 7342 | if (isAnyPortrait(preferredRotation)) { |
| 7343 | return preferredRotation; |
| 7344 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7345 | return mUpsideDownRotation; |
| 7346 | |
| 7347 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 7348 | // Return seascape unless overridden. |
| 7349 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 7350 | return preferredRotation; |
| 7351 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7352 | return mSeascapeRotation; |
| 7353 | |
| 7354 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 7355 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7356 | // Return either landscape rotation. |
| 7357 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 7358 | return preferredRotation; |
| 7359 | } |
| 7360 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 7361 | return lastRotation; |
| 7362 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7363 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7364 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7365 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 7366 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7367 | // Return either portrait rotation. |
| 7368 | if (isAnyPortrait(preferredRotation)) { |
| 7369 | return preferredRotation; |
| 7370 | } |
| 7371 | if (isAnyPortrait(lastRotation)) { |
| 7372 | return lastRotation; |
| 7373 | } |
| 7374 | return mPortraitRotation; |
| 7375 | |
| 7376 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 7377 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 7378 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7379 | if (preferredRotation >= 0) { |
| 7380 | return preferredRotation; |
| 7381 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 7382 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 7383 | } |
| 7384 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 7385 | } |
| 7386 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7387 | @Override |
| 7388 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 7389 | switch (orientation) { |
| 7390 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 7391 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 7392 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 7393 | return isAnyPortrait(rotation); |
| 7394 | |
| 7395 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 7396 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 7397 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 7398 | return isLandscapeOrSeascape(rotation); |
| 7399 | |
| 7400 | default: |
| 7401 | return true; |
| 7402 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 7403 | } |
| 7404 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7405 | @Override |
| 7406 | public void setRotationLw(int rotation) { |
| 7407 | mOrientationListener.setCurrentRotation(rotation); |
| 7408 | } |
| 7409 | |
Mike Digman | be875db | 2018-01-26 11:13:23 -0800 | [diff] [blame] | 7410 | public boolean isRotationChoicePossible(int orientation) { |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 7411 | // Rotation choice is only shown when the user is in locked mode. |
| 7412 | if (mUserRotationMode != WindowManagerPolicy.USER_ROTATION_LOCKED) return false; |
| 7413 | |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 7414 | // We should only enable rotation choice if the rotation isn't forced by the lid, dock, |
| 7415 | // demo, hdmi, vr, etc mode |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 7416 | |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 7417 | // Determine if the rotation is currently forced |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 7418 | if (mForceDefaultOrientation) { |
| 7419 | return false; // Rotation is forced to default orientation |
| 7420 | |
| 7421 | } else if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
| 7422 | return false; // Rotation is forced mLidOpenRotation |
| 7423 | |
| 7424 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && !mCarDockEnablesAccelerometer) { |
| 7425 | return false; // Rotation forced to mCarDockRotation |
| 7426 | |
| 7427 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 7428 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 7429 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
| 7430 | && !mDeskDockEnablesAccelerometer) { |
| 7431 | return false; // Rotation forced to mDeskDockRotation |
| 7432 | |
| 7433 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 7434 | return false; // Rotation forced to mDemoHdmiRotation |
| 7435 | |
| 7436 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 7437 | && mUndockedHdmiRotation >= 0) { |
| 7438 | return false; // Rotation forced to mUndockedHdmiRotation |
| 7439 | |
| 7440 | } else if (mDemoRotationLock) { |
| 7441 | return false; // Rotation forced to mDemoRotation |
| 7442 | |
| 7443 | } else if (mPersistentVrModeEnabled) { |
| 7444 | return false; // Rotation forced to mPortraitRotation |
| 7445 | |
| 7446 | } else if (!mSupportAutoRotation) { |
| 7447 | return false; |
| 7448 | } |
| 7449 | |
Mike Digman | be875db | 2018-01-26 11:13:23 -0800 | [diff] [blame] | 7450 | // Ensure that some rotation choice is possible for the given orientation |
| 7451 | switch (orientation) { |
| 7452 | case ActivityInfo.SCREEN_ORIENTATION_FULL_USER: |
| 7453 | case ActivityInfo.SCREEN_ORIENTATION_USER: |
| 7454 | case ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED: |
| 7455 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
| 7456 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
| 7457 | // NOSENSOR description is ambiguous, in reality WM ignores user choice |
| 7458 | return true; |
| 7459 | } |
| 7460 | |
| 7461 | // Rotation is forced, should be controlled by system |
| 7462 | return false; |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 7463 | } |
| 7464 | |
| 7465 | public boolean isValidRotationChoice(int orientation, final int preferredRotation) { |
Mike Digman | be875db | 2018-01-26 11:13:23 -0800 | [diff] [blame] | 7466 | // Determine if the given app orientation is compatible with the provided rotation choice |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 7467 | switch (orientation) { |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 7468 | case ActivityInfo.SCREEN_ORIENTATION_FULL_USER: |
| 7469 | // Works with any of the 4 rotations |
| 7470 | return preferredRotation >= 0; |
| 7471 | |
Mike Digman | be875db | 2018-01-26 11:13:23 -0800 | [diff] [blame] | 7472 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
| 7473 | // It's possible for the user pref to be set at 180 because of FULL_USER. This would |
| 7474 | // make switching to USER_PORTRAIT appear at 180. Provide choice to back to portrait |
| 7475 | // but never to go to 180. |
| 7476 | return preferredRotation == mPortraitRotation; |
| 7477 | |
| 7478 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
| 7479 | // Works landscape or seascape |
| 7480 | return isLandscapeOrSeascape(preferredRotation); |
| 7481 | |
| 7482 | case ActivityInfo.SCREEN_ORIENTATION_USER: |
| 7483 | case ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED: |
| 7484 | // Works with any rotation except upside down |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 7485 | return (preferredRotation >= 0) && (preferredRotation != mUpsideDownRotation); |
| 7486 | } |
Mike Digman | be875db | 2018-01-26 11:13:23 -0800 | [diff] [blame] | 7487 | |
| 7488 | return false; |
Mike Digman | e14e663 | 2018-01-11 10:43:08 -0800 | [diff] [blame] | 7489 | } |
| 7490 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7491 | private boolean isLandscapeOrSeascape(int rotation) { |
| 7492 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 7493 | } |
| 7494 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7495 | private boolean isAnyPortrait(int rotation) { |
| 7496 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 7497 | } |
| 7498 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7499 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7500 | public int getUserRotationMode() { |
| 7501 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 7502 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 7503 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 7504 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7505 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7506 | |
| 7507 | // User rotation: to be used when all else fails in assigning an orientation to the device |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7508 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7509 | public void setUserRotationMode(int mode, int rot) { |
| 7510 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 7511 | |
| 7512 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7513 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7514 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7515 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7516 | rot, |
| 7517 | UserHandle.USER_CURRENT); |
| 7518 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 7519 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7520 | 0, |
| 7521 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7522 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7523 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7524 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7525 | 1, |
| 7526 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7527 | } |
| 7528 | } |
| 7529 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7530 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 7531 | public void setSafeMode(boolean safeMode) { |
| 7532 | mSafeMode = safeMode; |
Michael Wright | 33d6c08 | 2017-07-21 16:40:58 +0100 | [diff] [blame] | 7533 | if (safeMode) { |
| 7534 | performHapticFeedbackLw(null, HapticFeedbackConstants.SAFE_MODE_ENABLED, true); |
| 7535 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7536 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7537 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 7538 | static long[] getLongIntArray(Resources r, int resid) { |
Phil Weaver | b9f0612 | 2017-11-30 10:48:17 -0800 | [diff] [blame] | 7539 | return ArrayUtils.convertToLongArray(r.getIntArray(resid)); |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 7540 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7541 | |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 7542 | private void bindKeyguard() { |
| 7543 | synchronized (mLock) { |
| 7544 | if (mKeyguardBound) { |
| 7545 | return; |
| 7546 | } |
| 7547 | mKeyguardBound = true; |
| 7548 | } |
| 7549 | mKeyguardDelegate.bindService(mContext); |
| 7550 | } |
| 7551 | |
| 7552 | @Override |
| 7553 | public void onSystemUiStarted() { |
| 7554 | bindKeyguard(); |
| 7555 | } |
| 7556 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7557 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7558 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7559 | public void systemReady() { |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 7560 | // In normal flow, systemReady is called before other system services are ready. |
| 7561 | // So it is better not to bind keyguard here. |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 7562 | mKeyguardDelegate.onSystemReady(); |
| 7563 | |
Zak Cohen | 732aeb0 | 2017-01-29 14:19:52 -0800 | [diff] [blame] | 7564 | mVrManagerInternal = LocalServices.getService(VrManagerInternal.class); |
Santos Cordon | c09d89c | 2017-04-13 16:12:02 -0700 | [diff] [blame] | 7565 | if (mVrManagerInternal != null) { |
| 7566 | mVrManagerInternal.addPersistentVrModeStateListener(mPersistentVrModeListener); |
| 7567 | } |
Zak Cohen | 732aeb0 | 2017-01-29 14:19:52 -0800 | [diff] [blame] | 7568 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 7569 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 7570 | updateUiMode(); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 7571 | synchronized (mLock) { |
| 7572 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 7573 | mSystemReady = true; |
| 7574 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7575 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 7576 | public void run() { |
| 7577 | updateSettings(); |
| 7578 | } |
| 7579 | }); |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 7580 | // If this happens, for whatever reason, systemReady came later than systemBooted. |
| 7581 | // And keyguard should be already bound from systemBooted |
| 7582 | if (mSystemBooted) { |
| 7583 | mKeyguardDelegate.onBootCompleted(); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 7584 | } |
| 7585 | } |
| 7586 | |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 7587 | mSystemGestures.systemReady(); |
Amith Yamasani | 02a0381 | 2016-04-22 17:32:00 -0700 | [diff] [blame] | 7588 | mImmersiveModeConfirmation.systemReady(); |
Felipe Leme | 5f97880 | 2017-06-08 13:01:13 -0700 | [diff] [blame] | 7589 | |
| 7590 | mAutofillManagerInternal = LocalServices.getService(AutofillManagerInternal.class); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7591 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7592 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7593 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7594 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7595 | public void systemBooted() { |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 7596 | bindKeyguard(); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7597 | synchronized (mLock) { |
| 7598 | mSystemBooted = true; |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 7599 | if (mSystemReady) { |
| 7600 | mKeyguardDelegate.onBootCompleted(); |
| 7601 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7602 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 7603 | startedWakingUp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 7604 | screenTurningOn(null); |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 7605 | screenTurnedOn(); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7606 | } |
| 7607 | |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 7608 | @Override |
| 7609 | public boolean canDismissBootAnimation() { |
| 7610 | synchronized (mLock) { |
| 7611 | return mKeyguardDrawComplete; |
| 7612 | } |
| 7613 | } |
| 7614 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7615 | ProgressDialog mBootMsgDialog = null; |
| 7616 | |
| 7617 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7618 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7619 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 7620 | mHandler.post(new Runnable() { |
| 7621 | @Override public void run() { |
| 7622 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 7623 | int theme; |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 7624 | if (mContext.getPackageManager().hasSystemFeature(FEATURE_LEANBACK)) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 7625 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 7626 | } else { |
| 7627 | theme = 0; |
| 7628 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 7629 | |
| 7630 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 7631 | // This dialog will consume all events coming in to |
| 7632 | // it, to avoid it trying to do things too early in boot. |
| 7633 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 7634 | return true; |
| 7635 | } |
| 7636 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 7637 | return true; |
| 7638 | } |
| 7639 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 7640 | return true; |
| 7641 | } |
| 7642 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 7643 | return true; |
| 7644 | } |
| 7645 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 7646 | return true; |
| 7647 | } |
| 7648 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 7649 | AccessibilityEvent event) { |
| 7650 | return true; |
| 7651 | } |
| 7652 | }; |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 7653 | if (mContext.getPackageManager().isUpgrade()) { |
| 7654 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 7655 | } else { |
| 7656 | mBootMsgDialog.setTitle(R.string.android_start_title); |
| 7657 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7658 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 7659 | mBootMsgDialog.setIndeterminate(true); |
| 7660 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 7661 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7662 | mBootMsgDialog.getWindow().addFlags( |
| 7663 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 7664 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 7665 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 7666 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 7667 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 7668 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7669 | mBootMsgDialog.setCancelable(false); |
| 7670 | mBootMsgDialog.show(); |
| 7671 | } |
| 7672 | mBootMsgDialog.setMessage(msg); |
| 7673 | } |
| 7674 | }); |
| 7675 | } |
| 7676 | |
| 7677 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7678 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7679 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 7680 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7681 | } |
| 7682 | |
Yoshiaki Naka | e1bdfc82 | 2017-09-15 15:24:34 +0900 | [diff] [blame] | 7683 | @Override |
| 7684 | public void requestUserActivityNotification() { |
| 7685 | if (!mNotifyUserActivity && !mHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 7686 | mNotifyUserActivity = true; |
| 7687 | } |
| 7688 | } |
| 7689 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7690 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7691 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7692 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7693 | // *************************************** |
| 7694 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 7695 | // *************************************** |
| 7696 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 7697 | // WITH ITS LOCKS HELD. |
| 7698 | // |
| 7699 | // This code must be VERY careful about the locks |
| 7700 | // it acquires. |
| 7701 | // In fact, the current code acquires way too many, |
| 7702 | // and probably has lurking deadlocks. |
| 7703 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7704 | synchronized (mScreenLockTimeout) { |
| 7705 | if (mLockScreenTimerActive) { |
| 7706 | // reset the timer |
| 7707 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 7708 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 7709 | } |
| 7710 | } |
Yoshiaki Naka | e1bdfc82 | 2017-09-15 15:24:34 +0900 | [diff] [blame] | 7711 | |
| 7712 | if (mAwake && mNotifyUserActivity) { |
| 7713 | mHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 7714 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 7715 | mNotifyUserActivity = false; |
| 7716 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 7717 | } |
| 7718 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7719 | class ScreenLockTimeout implements Runnable { |
| 7720 | Bundle options; |
| 7721 | |
| 7722 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7723 | public void run() { |
| 7724 | synchronized (this) { |
| 7725 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 7726 | if (mKeyguardDelegate != null) { |
| 7727 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 7728 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7729 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7730 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7731 | } |
| 7732 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7733 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7734 | public void setLockOptions(Bundle options) { |
| 7735 | this.options = options; |
| 7736 | } |
| 7737 | } |
| 7738 | |
| 7739 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 7740 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7741 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7742 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 7743 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 7744 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7745 | if (options != null) { |
| 7746 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 7747 | // until the runnable actually executes. |
| 7748 | mScreenLockTimeout.setLockOptions(options); |
| 7749 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 7750 | mHandler.post(mScreenLockTimeout); |
| 7751 | } |
| 7752 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7753 | private void updateLockScreenTimeout() { |
| 7754 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7755 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 7756 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure(mCurrentUserId)); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7757 | if (mLockScreenTimerActive != enable) { |
| 7758 | if (enable) { |
| 7759 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
Jim Miller | 2967f48 | 2016-01-07 15:05:32 -0800 | [diff] [blame] | 7760 | mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7761 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 7762 | } else { |
| 7763 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 7764 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 7765 | } |
| 7766 | mLockScreenTimerActive = enable; |
| 7767 | } |
| 7768 | } |
| 7769 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7770 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 7771 | // TODO (multidisplay): Support multiple displays in WindowManagerPolicy. |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 7772 | private void updateDreamingSleepToken(boolean acquire) { |
| 7773 | if (acquire) { |
| 7774 | if (mDreamingSleepToken == null) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 7775 | mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken( |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 7776 | "Dream", DEFAULT_DISPLAY); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 7777 | } |
| 7778 | } else { |
| 7779 | if (mDreamingSleepToken != null) { |
| 7780 | mDreamingSleepToken.release(); |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 7781 | mDreamingSleepToken = null; |
| 7782 | } |
| 7783 | } |
| 7784 | } |
| 7785 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 7786 | // TODO (multidisplay): Support multiple displays in WindowManagerPolicy. |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 7787 | private void updateScreenOffSleepToken(boolean acquire) { |
| 7788 | if (acquire) { |
| 7789 | if (mScreenOffSleepToken == null) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 7790 | mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken( |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 7791 | "ScreenOff", DEFAULT_DISPLAY); |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 7792 | } |
| 7793 | } else { |
| 7794 | if (mScreenOffSleepToken != null) { |
| 7795 | mScreenOffSleepToken.release(); |
| 7796 | mScreenOffSleepToken = null; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 7797 | } |
| 7798 | } |
| 7799 | } |
| 7800 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7801 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7802 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7803 | public void enableScreenAfterBoot() { |
| 7804 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7805 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7806 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7807 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 7808 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7809 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7810 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Selim Cinek | ab55ba5 | 2017-08-02 16:45:51 -0700 | [diff] [blame] | 7811 | goToSleep(SystemClock.uptimeMillis(), PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7812 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 7813 | } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) { |
| 7814 | mWindowManagerFuncs.lockDeviceNow(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7815 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 7816 | |
| 7817 | synchronized (mLock) { |
| 7818 | updateWakeGestureListenerLp(); |
| 7819 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7820 | } |
| 7821 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 7822 | void updateUiMode() { |
| 7823 | if (mUiModeManager == null) { |
| 7824 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 7825 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 7826 | } |
| 7827 | try { |
| 7828 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 7829 | } catch (RemoteException e) { |
| 7830 | } |
| 7831 | } |
| 7832 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7833 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7834 | try { |
| 7835 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 7836 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 7837 | } catch (RemoteException e) { |
| 7838 | // Ignore |
| 7839 | } |
| 7840 | } |
| 7841 | |
| 7842 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 7843 | try { |
| 7844 | //set orientation on WindowManager |
| 7845 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7846 | } catch (RemoteException e) { |
| 7847 | // Ignore |
| 7848 | } |
| 7849 | } |
| 7850 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7851 | /** |
| 7852 | * Return an Intent to launch the currently active dock app as home. Returns |
| 7853 | * null if the standard home should be launched, which is the case if any of the following is |
| 7854 | * true: |
| 7855 | * <ul> |
| 7856 | * <li>The device is not in either car mode or desk mode |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 7857 | * <li>The device is in car mode but mEnableCarDockHomeCapture is false |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7858 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 7859 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 7860 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 7861 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7862 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7863 | */ |
| 7864 | Intent createHomeDockIntent() { |
| 7865 | Intent intent = null; |
| 7866 | |
| 7867 | // What home does is based on the mode, not the dock state. That |
| 7868 | // is, when in car mode you should be taken to car home regardless |
| 7869 | // of whether we are actually in a car dock. |
| 7870 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 7871 | if (mEnableCarDockHomeCapture) { |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7872 | intent = mCarDockIntent; |
| 7873 | } |
| 7874 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 7875 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 7876 | intent = mDeskDockIntent; |
| 7877 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 7878 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 7879 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 7880 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 7881 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 7882 | // Always launch dock home from home when watch is docked, if it exists. |
| 7883 | intent = mDeskDockIntent; |
Zak Cohen | db6ca49 | 2017-01-26 14:09:00 -0800 | [diff] [blame] | 7884 | } else if (mUiMode == Configuration.UI_MODE_TYPE_VR_HEADSET) { |
| 7885 | if (ENABLE_VR_HEADSET_HOME_CAPTURE) { |
| 7886 | intent = mVrHeadsetHomeIntent; |
| 7887 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7888 | } |
| 7889 | |
| 7890 | if (intent == null) { |
| 7891 | return null; |
| 7892 | } |
| 7893 | |
| 7894 | ActivityInfo ai = null; |
| 7895 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 7896 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 7897 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 7898 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7899 | if (info != null) { |
| 7900 | ai = info.activityInfo; |
| 7901 | } |
| 7902 | if (ai != null |
| 7903 | && ai.metaData != null |
| 7904 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 7905 | intent = new Intent(intent); |
| 7906 | intent.setClassName(ai.packageName, ai.name); |
| 7907 | return intent; |
| 7908 | } |
| 7909 | |
| 7910 | return null; |
| 7911 | } |
| 7912 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 7913 | void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { |
Winson Chung | 2a35e6d | 2018-01-13 14:27:50 -0800 | [diff] [blame] | 7914 | try { |
| 7915 | ActivityManager.getService().stopAppSwitches(); |
| 7916 | } catch (RemoteException e) {} |
| 7917 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 7918 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 7919 | if (awakenFromDreams) { |
| 7920 | awakenDreams(); |
| 7921 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7922 | |
| 7923 | Intent dock = createHomeDockIntent(); |
| 7924 | if (dock != null) { |
| 7925 | try { |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 7926 | if (fromHomeKey) { |
| 7927 | dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 7928 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 7929 | startActivityAsUser(dock, UserHandle.CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7930 | return; |
| 7931 | } catch (ActivityNotFoundException e) { |
| 7932 | } |
| 7933 | } |
| 7934 | |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 7935 | Intent intent; |
| 7936 | |
| 7937 | if (fromHomeKey) { |
| 7938 | intent = new Intent(mHomeIntent); |
| 7939 | intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 7940 | } else { |
| 7941 | intent = mHomeIntent; |
| 7942 | } |
| 7943 | |
Bryce Lee | 9fc0b6f | 2015-03-19 21:37:45 +0000 | [diff] [blame] | 7944 | startActivityAsUser(intent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 7945 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7946 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 7947 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7948 | * goes to the home screen |
| 7949 | * @return whether it did anything |
| 7950 | */ |
| 7951 | boolean goHome() { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 7952 | if (!isUserSetupComplete()) { |
| 7953 | Slog.i(TAG, "Not going home because user setup is in progress."); |
| 7954 | return false; |
| 7955 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7956 | if (false) { |
| 7957 | // This code always brings home to the front. |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 7958 | startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7959 | } else { |
| 7960 | // This code brings home to the front or, if it is already |
| 7961 | // at the front, puts the device to sleep. |
| 7962 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 7963 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 7964 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 7965 | Log.d(TAG, "UTS-TEST-MODE"); |
| 7966 | } else { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7967 | ActivityManager.getService().stopAppSwitches(); |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 7968 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7969 | Intent dock = createHomeDockIntent(); |
| 7970 | if (dock != null) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7971 | int result = ActivityManager.getService() |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7972 | .startActivityAsUser(null, null, dock, |
| 7973 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 7974 | null, null, 0, |
| 7975 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 7976 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7977 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 7978 | return false; |
| 7979 | } |
| 7980 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 7981 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7982 | int result = ActivityManager.getService() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 7983 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7984 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 7985 | null, null, 0, |
| 7986 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 7987 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 7988 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7989 | return false; |
| 7990 | } |
| 7991 | } catch (RemoteException ex) { |
| 7992 | // bummer, the activity manager, which is in this process, is dead |
| 7993 | } |
| 7994 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7995 | return true; |
| 7996 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7997 | |
| 7998 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 7999 | public void setCurrentOrientationLw(int newOrientation) { |
| 8000 | synchronized (mLock) { |
| 8001 | if (newOrientation != mCurrentAppOrientation) { |
| 8002 | mCurrentAppOrientation = newOrientation; |
| 8003 | updateOrientationListenerLp(); |
| 8004 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 8005 | } |
| 8006 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 8007 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 8008 | private boolean isTheaterModeEnabled() { |
| 8009 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 8010 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 8011 | } |
| 8012 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 8013 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 8014 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 8015 | if (!mVibrator.hasVibrator()) { |
| 8016 | return false; |
| 8017 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 8018 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 8019 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 8020 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 8021 | return false; |
| 8022 | } |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 8023 | |
| 8024 | VibrationEffect effect = getVibrationEffect(effectId); |
| 8025 | if (effect == null) { |
| 8026 | return false; |
| 8027 | } |
| 8028 | |
| 8029 | int owningUid; |
| 8030 | String owningPackage; |
| 8031 | if (win != null) { |
| 8032 | owningUid = win.getOwningUid(); |
| 8033 | owningPackage = win.getOwningPackage(); |
| 8034 | } else { |
| 8035 | owningUid = android.os.Process.myUid(); |
| 8036 | owningPackage = mContext.getOpPackageName(); |
| 8037 | } |
| 8038 | mVibrator.vibrate(owningUid, owningPackage, effect, VIBRATION_ATTRIBUTES); |
| 8039 | return true; |
| 8040 | } |
| 8041 | |
| 8042 | private VibrationEffect getVibrationEffect(int effectId) { |
| 8043 | long[] pattern; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 8044 | switch (effectId) { |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 8045 | case HapticFeedbackConstants.CLOCK_TICK: |
Alexey Kuzmin | 6310f40 | 2018-03-20 18:21:51 +0000 | [diff] [blame] | 8046 | case HapticFeedbackConstants.CONTEXT_CLICK: |
Michael Wright | 57d94d9 | 2017-05-31 14:44:45 +0100 | [diff] [blame] | 8047 | return VibrationEffect.get(VibrationEffect.EFFECT_TICK); |
Alexey Kuzmin | 6310f40 | 2018-03-20 18:21:51 +0000 | [diff] [blame] | 8048 | case HapticFeedbackConstants.KEYBOARD_RELEASE: |
| 8049 | case HapticFeedbackConstants.TEXT_HANDLE_MOVE: |
| 8050 | case HapticFeedbackConstants.VIRTUAL_KEY_RELEASE: |
| 8051 | case HapticFeedbackConstants.ENTRY_BUMP: |
| 8052 | case HapticFeedbackConstants.DRAG_CROSSING: |
| 8053 | case HapticFeedbackConstants.GESTURE_END: |
| 8054 | return VibrationEffect.get(VibrationEffect.EFFECT_TICK, false); |
| 8055 | case HapticFeedbackConstants.KEYBOARD_TAP: // == KEYBOARD_PRESS |
| 8056 | case HapticFeedbackConstants.VIRTUAL_KEY: |
| 8057 | case HapticFeedbackConstants.EDGE_RELEASE: |
| 8058 | case HapticFeedbackConstants.CONFIRM: |
| 8059 | case HapticFeedbackConstants.GESTURE_START: |
| 8060 | return VibrationEffect.get(VibrationEffect.EFFECT_CLICK); |
| 8061 | case HapticFeedbackConstants.LONG_PRESS: |
| 8062 | case HapticFeedbackConstants.EDGE_SQUEEZE: |
| 8063 | return VibrationEffect.get(VibrationEffect.EFFECT_HEAVY_CLICK); |
| 8064 | case HapticFeedbackConstants.REJECT: |
| 8065 | return VibrationEffect.get(VibrationEffect.EFFECT_DOUBLE_CLICK); |
| 8066 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 8067 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 8068 | pattern = mCalendarDateVibePattern; |
| 8069 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 8070 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 8071 | pattern = mSafeModeEnabledVibePattern; |
| 8072 | break; |
Alexey Kuzmin | 6310f40 | 2018-03-20 18:21:51 +0000 | [diff] [blame] | 8073 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 8074 | default: |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 8075 | return null; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 8076 | } |
Erik Wolsheimer | 017939e | 2017-05-24 11:18:25 -0700 | [diff] [blame] | 8077 | if (pattern.length == 0) { |
| 8078 | // No vibration |
| 8079 | return null; |
| 8080 | } else if (pattern.length == 1) { |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 8081 | // One-shot vibration |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 8082 | return VibrationEffect.createOneShot(pattern[0], VibrationEffect.DEFAULT_AMPLITUDE); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 8083 | } else { |
| 8084 | // Pattern vibration |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 8085 | return VibrationEffect.createWaveform(pattern, -1); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 8086 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 8087 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 8088 | |
| 8089 | @Override |
| 8090 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 8091 | } |
| 8092 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 8093 | @Override |
| 8094 | public void keepScreenOnStoppedLw() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 8095 | if (isKeyguardShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 8096 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 8097 | } |
| 8098 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 8099 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 8100 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8101 | // If there is no window focused, there will be nobody to handle the events |
| 8102 | // anyway, so just hang on in whatever state we're in until things settle down. |
Adrian Roos | dab1516 | 2016-09-12 15:08:35 -0700 | [diff] [blame] | 8103 | WindowState winCandidate = mFocusedWindow != null ? mFocusedWindow |
Adrian Roos | 53f28ec | 2014-10-29 17:26:12 +0100 | [diff] [blame] | 8104 | : mTopFullscreenOpaqueWindowState; |
Adrian Roos | dab1516 | 2016-09-12 15:08:35 -0700 | [diff] [blame] | 8105 | if (winCandidate == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 8106 | return 0; |
| 8107 | } |
Adrian Roos | dab1516 | 2016-09-12 15:08:35 -0700 | [diff] [blame] | 8108 | if (winCandidate.getAttrs().token == mImmersiveModeConfirmation.getWindowToken()) { |
| 8109 | // The immersive mode confirmation should never affect the system bar visibility, |
| 8110 | // otherwise it will unhide the navigation bar and hide itself. |
| 8111 | winCandidate = isStatusBarKeyguard() ? mStatusBar : mTopFullscreenOpaqueWindowState; |
| 8112 | if (winCandidate == null) { |
| 8113 | return 0; |
| 8114 | } |
| 8115 | } |
| 8116 | final WindowState win = winCandidate; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 8117 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mKeyguardOccluded) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 8118 | // We are updating at a point where the keyguard has gotten |
| 8119 | // focus, but we were last in a state where the top window is |
| 8120 | // hiding it. This is probably because the keyguard as been |
| 8121 | // shown while the top window was displayed, so we want to ignore |
| 8122 | // it here because this is just a very transient change and it |
| 8123 | // will quickly lose focus once it correctly gets hidden. |
| 8124 | return 0; |
| 8125 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 8126 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 8127 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 8128 | & ~mResettingSystemUiFlags |
| 8129 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 8130 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 8131 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 8132 | } |
Thanh Hai Mai | 6c009f5 | 2015-09-01 16:27:32 -0700 | [diff] [blame] | 8133 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 8134 | final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */, |
| 8135 | mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState); |
| 8136 | final int dockedVisibility = updateLightStatusBarLw(0 /* vis */, |
| 8137 | mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 8138 | mWindowManagerFuncs.getStackBounds( |
| 8139 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_HOME, mNonDockedStackBounds); |
| 8140 | mWindowManagerFuncs.getStackBounds( |
| 8141 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, mDockedStackBounds); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 8142 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 8143 | final int diff = visibility ^ mLastSystemUiFlags; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 8144 | final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags; |
| 8145 | final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 8146 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 8147 | if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu |
| 8148 | && mFocusedApp == win.getAppToken() |
| 8149 | && mLastNonDockedStackBounds.equals(mNonDockedStackBounds) |
| 8150 | && mLastDockedStackBounds.equals(mDockedStackBounds)) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 8151 | return 0; |
| 8152 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 8153 | mLastSystemUiFlags = visibility; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 8154 | mLastFullscreenStackSysUiFlags = fullscreenVisibility; |
| 8155 | mLastDockedStackSysUiFlags = dockedVisibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 8156 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 8157 | mFocusedApp = win.getAppToken(); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 8158 | final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds); |
| 8159 | final Rect dockedStackBounds = new Rect(mDockedStackBounds); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 8160 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 8161 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 8162 | public void run() { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 8163 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 8164 | if (statusbar != null) { |
| 8165 | statusbar.setSystemUiVisibility(visibility, fullscreenVisibility, |
| 8166 | dockedVisibility, 0xffffffff, fullscreenStackBounds, |
| 8167 | dockedStackBounds, win.toString()); |
| 8168 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8169 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 8170 | } |
| 8171 | }); |
| 8172 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8173 | } |
| 8174 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 8175 | private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) { |
Jorim Jaggi | ff46d4c | 2017-07-17 16:46:00 +0200 | [diff] [blame] | 8176 | final boolean onKeyguard = isStatusBarKeyguard() && !mKeyguardOccluded; |
| 8177 | final WindowState statusColorWin = onKeyguard ? mStatusBar : opaqueOrDimming; |
| 8178 | if (statusColorWin != null && (statusColorWin == opaque || onKeyguard)) { |
| 8179 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 8180 | // its light flag. |
| 8181 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
Adrian Roos | 0c124c6 | 2018-03-19 17:47:12 +0100 | [diff] [blame] | 8182 | vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) |
| 8183 | & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
Jorim Jaggi | ff46d4c | 2017-07-17 16:46:00 +0200 | [diff] [blame] | 8184 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 8185 | // Otherwise if it's dimming, clear the light flag. |
| 8186 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 8187 | } |
| 8188 | return vis; |
| 8189 | } |
| 8190 | |
Yohei Yukawa | d0a66b2 | 2018-01-10 13:19:54 -0800 | [diff] [blame] | 8191 | @VisibleForTesting |
| 8192 | @Nullable |
| 8193 | static WindowState chooseNavigationColorWindowLw(WindowState opaque, |
| 8194 | WindowState opaqueOrDimming, WindowState imeWindow, |
| 8195 | @NavigationBarPosition int navBarPosition) { |
Yohei Yukawa | 217844e | 2018-01-10 13:19:59 -0800 | [diff] [blame] | 8196 | // If the IME window is visible and FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS is set, then IME |
| 8197 | // window can be navigation color window. |
| 8198 | final boolean imeWindowCanNavColorWindow = imeWindow != null |
| 8199 | && imeWindow.isVisibleLw() |
| 8200 | && navBarPosition == NAV_BAR_BOTTOM |
| 8201 | && (PolicyControl.getWindowFlags(imeWindow, null) |
| 8202 | & WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0; |
| 8203 | |
| 8204 | if (opaque != null && opaqueOrDimming == opaque) { |
| 8205 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect it |
| 8206 | // unless IME window is also eligible, since currently the IME window is always show |
| 8207 | // above the opaque fullscreen app window, regardless of the IME target window. |
| 8208 | // TODO(b/31559891): Maybe we need to revisit this condition once b/31559891 is fixed. |
| 8209 | return imeWindowCanNavColorWindow ? imeWindow : opaque; |
| 8210 | } |
| 8211 | |
| 8212 | if (opaqueOrDimming == null || !opaqueOrDimming.isDimming()) { |
| 8213 | // No dimming window is involved. Determine the result only with the IME window. |
| 8214 | return imeWindowCanNavColorWindow ? imeWindow : null; |
| 8215 | } |
| 8216 | |
| 8217 | if (!imeWindowCanNavColorWindow) { |
| 8218 | // No IME window is involved. Determine the result only with opaqueOrDimming. |
| 8219 | return opaqueOrDimming; |
| 8220 | } |
| 8221 | |
| 8222 | // The IME window and the dimming window are competing. Check if the dimming window can be |
| 8223 | // IME target or not. |
| 8224 | if (LayoutParams.mayUseInputMethod(PolicyControl.getWindowFlags(opaqueOrDimming, null))) { |
| 8225 | // The IME window is above the dimming window. |
Yohei Yukawa | d0a66b2 | 2018-01-10 13:19:54 -0800 | [diff] [blame] | 8226 | return imeWindow; |
Yohei Yukawa | b08669b | 2017-11-09 18:45:13 +0000 | [diff] [blame] | 8227 | } else { |
Yohei Yukawa | 217844e | 2018-01-10 13:19:59 -0800 | [diff] [blame] | 8228 | // The dimming window is above the IME window. |
Yohei Yukawa | d0a66b2 | 2018-01-10 13:19:54 -0800 | [diff] [blame] | 8229 | return opaqueOrDimming; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 8230 | } |
Yohei Yukawa | d0a66b2 | 2018-01-10 13:19:54 -0800 | [diff] [blame] | 8231 | } |
| 8232 | |
| 8233 | @VisibleForTesting |
| 8234 | static int updateLightNavigationBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming, |
| 8235 | WindowState imeWindow, WindowState navColorWin) { |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 8236 | |
Yohei Yukawa | b08669b | 2017-11-09 18:45:13 +0000 | [diff] [blame] | 8237 | if (navColorWin != null) { |
Yohei Yukawa | 217844e | 2018-01-10 13:19:59 -0800 | [diff] [blame] | 8238 | if (navColorWin == imeWindow || navColorWin == opaque) { |
| 8239 | // Respect the light flag. |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 8240 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
Yohei Yukawa | b08669b | 2017-11-09 18:45:13 +0000 | [diff] [blame] | 8241 | vis |= PolicyControl.getSystemUiVisibility(navColorWin, null) |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 8242 | & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
Yohei Yukawa | 217844e | 2018-01-10 13:19:59 -0800 | [diff] [blame] | 8243 | } else if (navColorWin == opaqueOrDimming && navColorWin.isDimming()) { |
| 8244 | // Clear the light flag for dimming window. |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 8245 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 8246 | } |
| 8247 | } |
| 8248 | return vis; |
| 8249 | } |
| 8250 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 8251 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 8252 | final boolean dockedStackVisible = |
| 8253 | mWindowManagerInternal.isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 8254 | final boolean freeformStackVisible = |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 8255 | mWindowManagerInternal.isStackVisible(WINDOWING_MODE_FREEFORM); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 8256 | final boolean resizing = mWindowManagerInternal.isDockedDividerResizing(); |
| 8257 | |
| 8258 | // We need to force system bars when the docked stack is visible, when the freeform stack |
| 8259 | // is visible but also when we are resizing for the transitions when docked stack |
| 8260 | // visibility changes. |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 8261 | mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing; |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 8262 | final boolean forceOpaqueStatusBar = mForceShowSystemBars && !mForceStatusBarFromKeyguard; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 8263 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 8264 | // apply translucent bar vis flags |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 8265 | WindowState fullscreenTransWin = isStatusBarKeyguard() && !mKeyguardOccluded |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 8266 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 8267 | : mTopFullscreenOpaqueWindowState; |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 8268 | vis = mStatusBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); |
| 8269 | vis = mNavigationBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); |
| 8270 | final int dockedVis = mStatusBarController.applyTranslucentFlagLw( |
| 8271 | mTopDockedOpaqueWindowState, 0, 0); |
| 8272 | |
| 8273 | final boolean fullscreenDrawsStatusBarBackground = |
Adrian Roos | 23df3a3 | 2018-03-15 15:41:13 +0100 | [diff] [blame] | 8274 | drawsStatusBarBackground(vis, mTopFullscreenOpaqueWindowState); |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 8275 | final boolean dockedDrawsStatusBarBackground = |
Adrian Roos | 23df3a3 | 2018-03-15 15:41:13 +0100 | [diff] [blame] | 8276 | drawsStatusBarBackground(dockedVis, mTopDockedOpaqueWindowState); |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 8277 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8278 | // prevent status bar interaction from clearing certain flags |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 8279 | int type = win.getAttrs().type; |
| 8280 | boolean statusBarHasFocus = type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 8281 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 8282 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 8283 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 8284 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 73fef8d | 2015-02-16 17:32:28 +0100 | [diff] [blame] | 8285 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 8286 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 8287 | if (mKeyguardOccluded) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 8288 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 8289 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 8290 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 8291 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 8292 | |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 8293 | if (fullscreenDrawsStatusBarBackground && dockedDrawsStatusBarBackground) { |
| 8294 | vis |= View.STATUS_BAR_TRANSPARENT; |
| 8295 | vis &= ~View.STATUS_BAR_TRANSLUCENT; |
| 8296 | } else if ((!areTranslucentBarsAllowed() && fullscreenTransWin != mStatusBar) |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 8297 | || forceOpaqueStatusBar) { |
| 8298 | vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 8299 | } |
| 8300 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 8301 | vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing); |
Yorke Lee | 2e4b732 | 2016-03-02 17:33:06 -0800 | [diff] [blame] | 8302 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8303 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8304 | boolean immersiveSticky = |
| 8305 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 8306 | final boolean hideStatusBarWM = |
| 8307 | mTopFullscreenOpaqueWindowState != null |
| 8308 | && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8309 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 8310 | final boolean hideStatusBarSysui = |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8311 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 8312 | final boolean hideNavBarSysui = |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8313 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 8314 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 8315 | final boolean transientStatusBarAllowed = mStatusBar != null |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 8316 | && (statusBarHasFocus || (!mForceShowSystemBars |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 8317 | && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky)))); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8318 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 8319 | final boolean transientNavBarAllowed = mNavigationBar != null |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 8320 | && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8321 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 8322 | final long now = SystemClock.uptimeMillis(); |
| 8323 | final boolean pendingPanic = mPendingPanicGestureUptime != 0 |
| 8324 | && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION; |
| 8325 | if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) { |
| 8326 | // The user performed the panic gesture recently, we're about to hide the bars, |
| 8327 | // we're no longer on the Keyguard and the screen is ready. We can now request the bars. |
| 8328 | mPendingPanicGestureUptime = 0; |
| 8329 | mStatusBarController.showTransient(); |
Adrian Roos | 1f42590 | 2016-07-22 10:37:50 -0700 | [diff] [blame] | 8330 | if (!isNavBarEmpty(vis)) { |
| 8331 | mNavigationBarController.showTransient(); |
| 8332 | } |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 8333 | } |
| 8334 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 8335 | final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8336 | && !transientStatusBarAllowed && hideStatusBarSysui; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 8337 | final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8338 | && !transientNavBarAllowed; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 8339 | if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8340 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8341 | clearClearableFlagsLw(); |
tiger_huang | c58d756 | 2014-10-23 20:24:19 +0800 | [diff] [blame] | 8342 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 8343 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8344 | |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 8345 | final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 8346 | immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 8347 | final boolean navAllowedHidden = immersive || immersiveSticky; |
| 8348 | |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 8349 | if (hideNavBarSysui && !navAllowedHidden |
| 8350 | && getWindowLayerLw(win) > getWindowLayerFromTypeLw(TYPE_INPUT_CONSUMER)) { |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 8351 | // We can't hide the navbar from this window otherwise the input consumer would not get |
| 8352 | // the input events. |
| 8353 | vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); |
| 8354 | } |
| 8355 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8356 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 8357 | |
| 8358 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8359 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 8360 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 8361 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 8362 | final String pkg = win.getOwningPackage(); |
Amith Yamasani | 02a0381 | 2016-04-22 17:32:00 -0700 | [diff] [blame] | 8363 | mImmersiveModeConfirmation.immersiveModeChangedLw(pkg, newImmersiveMode, |
Adrian Roos | 7aaa551 | 2016-07-12 15:27:24 -0700 | [diff] [blame] | 8364 | isUserSetupComplete(), isNavBarEmpty(win.getSystemUiVisibility())); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 8365 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8366 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8367 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 8368 | |
Yohei Yukawa | d0a66b2 | 2018-01-10 13:19:54 -0800 | [diff] [blame] | 8369 | final WindowState navColorWin = chooseNavigationColorWindowLw( |
| 8370 | mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState, |
| 8371 | mWindowManagerFuncs.getInputMethodWindowLw(), mNavigationBarPosition); |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 8372 | vis = updateLightNavigationBarLw(vis, mTopFullscreenOpaqueWindowState, |
Yohei Yukawa | d0a66b2 | 2018-01-10 13:19:54 -0800 | [diff] [blame] | 8373 | mTopFullscreenOpaqueOrDimmingWindowState, |
| 8374 | mWindowManagerFuncs.getInputMethodWindowLw(), navColorWin); |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 8375 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 8376 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 8377 | } |
| 8378 | |
Adrian Roos | 23df3a3 | 2018-03-15 15:41:13 +0100 | [diff] [blame] | 8379 | private boolean drawsStatusBarBackground(int vis, WindowState win) { |
| 8380 | if (!mStatusBarController.isTransparentAllowed(win)) { |
| 8381 | return false; |
| 8382 | } |
| 8383 | if (win == null) { |
| 8384 | return true; |
| 8385 | } |
| 8386 | |
| 8387 | final boolean drawsSystemBars = |
| 8388 | (win.getAttrs().flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0; |
| 8389 | final boolean forceDrawsSystemBars = |
| 8390 | (win.getAttrs().privateFlags & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) != 0; |
| 8391 | |
| 8392 | return forceDrawsSystemBars || drawsSystemBars && (vis & View.STATUS_BAR_TRANSLUCENT) == 0; |
| 8393 | } |
| 8394 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 8395 | /** |
| 8396 | * @return the current visibility flags with the nav-bar opacity related flags toggled based |
| 8397 | * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}. |
| 8398 | */ |
| 8399 | private int configureNavBarOpacity(int visibility, boolean dockedStackVisible, |
| 8400 | boolean freeformStackVisible, boolean isDockedDividerResizing) { |
Phil Weaver | d755160 | 2018-02-15 15:01:04 -0800 | [diff] [blame] | 8401 | if (mScreenMagnificationActive) { |
| 8402 | // When the screen is magnified, the nav bar should be opaque since its background |
| 8403 | // can vary as the user pans and zooms |
| 8404 | visibility = setNavBarOpaqueFlag(visibility); |
| 8405 | } else if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) { |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 8406 | if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) { |
| 8407 | visibility = setNavBarOpaqueFlag(visibility); |
| 8408 | } |
| 8409 | } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) { |
| 8410 | if (isDockedDividerResizing) { |
| 8411 | visibility = setNavBarOpaqueFlag(visibility); |
| 8412 | } else if (freeformStackVisible) { |
| 8413 | visibility = setNavBarTranslucentFlag(visibility); |
| 8414 | } else { |
| 8415 | visibility = setNavBarOpaqueFlag(visibility); |
| 8416 | } |
| 8417 | } |
| 8418 | |
| 8419 | if (!areTranslucentBarsAllowed()) { |
| 8420 | visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT; |
| 8421 | } |
| 8422 | return visibility; |
| 8423 | } |
| 8424 | |
| 8425 | private int setNavBarOpaqueFlag(int visibility) { |
| 8426 | return visibility &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT); |
| 8427 | } |
| 8428 | |
| 8429 | private int setNavBarTranslucentFlag(int visibility) { |
| 8430 | visibility &= ~View.NAVIGATION_BAR_TRANSPARENT; |
| 8431 | return visibility |= View.NAVIGATION_BAR_TRANSLUCENT; |
| 8432 | } |
| 8433 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8434 | private void clearClearableFlagsLw() { |
| 8435 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 8436 | if (newVal != mResettingSystemUiFlags) { |
| 8437 | mResettingSystemUiFlags = newVal; |
| 8438 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 8439 | } |
| 8440 | } |
| 8441 | |
| 8442 | private boolean isImmersiveMode(int vis) { |
| 8443 | final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 8444 | return mNavigationBar != null |
| 8445 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 8446 | && (vis & flags) != 0 |
| 8447 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 8448 | } |
| 8449 | |
Adrian Roos | 7aaa551 | 2016-07-12 15:27:24 -0700 | [diff] [blame] | 8450 | private static boolean isNavBarEmpty(int systemUiFlags) { |
| 8451 | final int disableNavigationBar = (View.STATUS_BAR_DISABLE_HOME |
| 8452 | | View.STATUS_BAR_DISABLE_BACK |
| 8453 | | View.STATUS_BAR_DISABLE_RECENT); |
| 8454 | |
| 8455 | return (systemUiFlags & disableNavigationBar) == disableNavigationBar; |
| 8456 | } |
| 8457 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 8458 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 8459 | * @return whether the navigation or status bar can be made translucent |
| 8460 | * |
| 8461 | * This should return true unless touch exploration is not enabled or |
| 8462 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 8463 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 8464 | private boolean areTranslucentBarsAllowed() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 8465 | return mTranslucentDecorEnabled; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 8466 | } |
| 8467 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 8468 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 8469 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 8470 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 8471 | public boolean hasNavigationBar() { |
| 8472 | return mHasNavigationBar; |
| 8473 | } |
| 8474 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 8475 | @Override |
| 8476 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 8477 | mLastInputMethodWindow = ime; |
| 8478 | mLastInputMethodTargetWindow = target; |
| 8479 | } |
| 8480 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 8481 | @Override |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 8482 | public void setDismissImeOnBackKeyPressed(boolean newValue) { |
Yohei Yukawa | abbe1ac | 2017-04-18 09:43:05 -0700 | [diff] [blame] | 8483 | mDismissImeOnBackKeyPressed = newValue; |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 8484 | } |
| 8485 | |
| 8486 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 8487 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 8488 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 8489 | if (mKeyguardDelegate != null) { |
| 8490 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 8491 | } |
Phil Weaver | ce687c5 | 2017-03-15 08:51:52 -0700 | [diff] [blame] | 8492 | if (mAccessibilityShortcutController != null) { |
| 8493 | mAccessibilityShortcutController.setCurrentUser(newUserId); |
| 8494 | } |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 8495 | StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); |
Adrian Roos | 2a62910 | 2016-04-15 16:28:03 -0700 | [diff] [blame] | 8496 | if (statusBar != null) { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 8497 | statusBar.setCurrentUser(newUserId); |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 8498 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8499 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 8500 | } |
| 8501 | |
| 8502 | @Override |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 8503 | public void setSwitchingUser(boolean switching) { |
| 8504 | mKeyguardDelegate.setSwitchingUser(switching); |
| 8505 | } |
| 8506 | |
| 8507 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 8508 | public boolean isTopLevelWindow(int windowType) { |
| 8509 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 8510 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 8511 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 8512 | } |
| 8513 | return true; |
| 8514 | } |
| 8515 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 8516 | @Override |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 8517 | public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) { |
| 8518 | // For the upside down rotation we don't rotate seamlessly as the navigation |
| 8519 | // bar moves position. |
| 8520 | // Note most apps (using orientation:sensor or user as opposed to fullSensor) |
| 8521 | // will not enter the reverse portrait orientation, so actually the |
| 8522 | // orientation won't change at all. |
| 8523 | if (oldRotation == mUpsideDownRotation || newRotation == mUpsideDownRotation) { |
| 8524 | return false; |
| 8525 | } |
Robert Carr | 0b9ac5a | 2016-10-26 14:12:14 -0700 | [diff] [blame] | 8526 | // If the navigation bar can't change sides, then it will |
| 8527 | // jump when we change orientations and we don't rotate |
| 8528 | // seamlessly. |
| 8529 | if (!mNavigationBarCanMove) { |
| 8530 | return false; |
| 8531 | } |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 8532 | int delta = newRotation - oldRotation; |
| 8533 | if (delta < 0) delta += 4; |
| 8534 | // Likewise we don't rotate seamlessly for 180 degree rotations |
Geoffrey Pitsch | b2d6ed3 | 2016-08-24 10:37:19 -0400 | [diff] [blame] | 8535 | // in this case the surfaces never resize, and our logic to |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 8536 | // revert the transformations on size change will fail. We could |
| 8537 | // fix this in the future with the "tagged" frames idea. |
| 8538 | if (delta == Surface.ROTATION_180) { |
| 8539 | return false; |
| 8540 | } |
| 8541 | |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 8542 | final WindowState w = mTopFullscreenOpaqueWindowState; |
Robert Carr | 828ec3dc | 2016-08-22 13:32:34 -0700 | [diff] [blame] | 8543 | if (w != mFocusedWindow) { |
| 8544 | return false; |
| 8545 | } |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 8546 | |
Robert Carr | 606f4d5 | 2016-06-30 14:36:27 -0700 | [diff] [blame] | 8547 | // We only enable seamless rotation if the top window has requested |
| 8548 | // it and is in the fullscreen opaque state. Seamless rotation |
| 8549 | // requires freezing various Surface states and won't work well |
| 8550 | // with animations, so we disable it in the animation case for now. |
Robert Carr | 1ccd425 | 2016-08-15 12:05:21 -0700 | [diff] [blame] | 8551 | if (w != null && !w.isAnimatingLw() && |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 8552 | ((w.getAttrs().rotationAnimation == ROTATION_ANIMATION_JUMPCUT) || |
| 8553 | (w.getAttrs().rotationAnimation == ROTATION_ANIMATION_SEAMLESS))) { |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 8554 | return true; |
| 8555 | } |
| 8556 | return false; |
| 8557 | } |
| 8558 | |
| 8559 | @Override |
Phil Weaver | d755160 | 2018-02-15 15:01:04 -0800 | [diff] [blame] | 8560 | public void onScreenMagnificationStateChanged(boolean active) { |
| 8561 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 8562 | mScreenMagnificationActive = active; |
| 8563 | updateSystemUiVisibilityLw(); |
| 8564 | } |
| 8565 | } |
| 8566 | |
| 8567 | @Override |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 8568 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 8569 | final long token = proto.start(fieldId); |
Vishnu Nair | 9a3e406 | 2018-01-11 08:42:54 -0800 | [diff] [blame] | 8570 | proto.write(LAST_SYSTEM_UI_FLAGS, mLastSystemUiFlags); |
| 8571 | proto.write(ROTATION_MODE, mUserRotationMode); |
| 8572 | proto.write(ROTATION, mUserRotation); |
| 8573 | proto.write(ORIENTATION, mCurrentAppOrientation); |
| 8574 | proto.write(SCREEN_ON_FULLY, mScreenOnFully); |
| 8575 | proto.write(KEYGUARD_DRAW_COMPLETE, mKeyguardDrawComplete); |
| 8576 | proto.write(WINDOW_MANAGER_DRAW_COMPLETE, mWindowManagerDrawComplete); |
| 8577 | if (mFocusedApp != null) { |
| 8578 | proto.write(FOCUSED_APP_TOKEN, mFocusedApp.toString()); |
| 8579 | } |
| 8580 | if (mFocusedWindow != null) { |
| 8581 | mFocusedWindow.writeIdentifierToProto(proto, FOCUSED_WINDOW); |
| 8582 | } |
| 8583 | if (mTopFullscreenOpaqueWindowState != null) { |
| 8584 | mTopFullscreenOpaqueWindowState.writeIdentifierToProto( |
| 8585 | proto, TOP_FULLSCREEN_OPAQUE_WINDOW); |
| 8586 | } |
| 8587 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 8588 | mTopFullscreenOpaqueOrDimmingWindowState.writeIdentifierToProto( |
| 8589 | proto, TOP_FULLSCREEN_OPAQUE_OR_DIMMING_WINDOW); |
| 8590 | } |
| 8591 | proto.write(KEYGUARD_OCCLUDED, mKeyguardOccluded); |
| 8592 | proto.write(KEYGUARD_OCCLUDED_CHANGED, mKeyguardOccludedChanged); |
| 8593 | proto.write(KEYGUARD_OCCLUDED_PENDING, mPendingKeyguardOccluded); |
| 8594 | proto.write(FORCE_STATUS_BAR, mForceStatusBar); |
| 8595 | proto.write(FORCE_STATUS_BAR_FROM_KEYGUARD, mForceStatusBarFromKeyguard); |
| 8596 | mStatusBarController.writeToProto(proto, STATUS_BAR); |
| 8597 | mNavigationBarController.writeToProto(proto, NAVIGATION_BAR); |
| 8598 | if (mOrientationListener != null) { |
| 8599 | mOrientationListener.writeToProto(proto, ORIENTATION_LISTENER); |
| 8600 | } |
| 8601 | if (mKeyguardDelegate != null) { |
| 8602 | mKeyguardDelegate.writeToProto(proto, KEYGUARD_DELEGATE); |
| 8603 | } |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 8604 | proto.end(token); |
| 8605 | } |
| 8606 | |
| 8607 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 8608 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8609 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 8610 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 8611 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 8612 | pw.print(prefix); pw.print("mLidState="); |
| 8613 | pw.print(WindowManagerFuncs.lidStateToString(mLidState)); |
| 8614 | pw.print(" mLidOpenRotation="); |
| 8615 | pw.println(Surface.rotationToString(mLidOpenRotation)); |
| 8616 | pw.print(prefix); pw.print("mCameraLensCoverState="); |
| 8617 | pw.print(WindowManagerFuncs.cameraLensStateToString(mCameraLensCoverState)); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8618 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 8619 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 8620 | || mForceClearedSystemUiFlags != 0) { |
| 8621 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 8622 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 8623 | pw.print(" mResettingSystemUiFlags=0x"); |
| 8624 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 8625 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 8626 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 8627 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 8628 | if (mLastFocusNeedsMenu) { |
| 8629 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 8630 | pw.println(mLastFocusNeedsMenu); |
| 8631 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 8632 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 8633 | pw.println(mWakeGestureEnabledSetting); |
| 8634 | |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 8635 | pw.print(prefix); |
| 8636 | pw.print("mSupportAutoRotation="); pw.print(mSupportAutoRotation); |
| 8637 | pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled); |
| 8638 | pw.print(prefix); pw.print("mUiMode="); pw.print(Configuration.uiModeToString(mUiMode)); |
| 8639 | pw.print(" mDockMode="); pw.println(Intent.dockStateToString(mDockMode)); |
| 8640 | pw.print(prefix); pw.print("mEnableCarDockHomeCapture="); |
| 8641 | pw.print(mEnableCarDockHomeCapture); |
| 8642 | pw.print(" mCarDockRotation="); |
| 8643 | pw.print(Surface.rotationToString(mCarDockRotation)); |
| 8644 | pw.print(" mDeskDockRotation="); |
| 8645 | pw.println(Surface.rotationToString(mDeskDockRotation)); |
| 8646 | pw.print(prefix); pw.print("mUserRotationMode="); |
| 8647 | pw.print(WindowManagerPolicy.userRotationModeToString(mUserRotationMode)); |
| 8648 | pw.print(" mUserRotation="); pw.print(Surface.rotationToString(mUserRotation)); |
| 8649 | pw.print(" mAllowAllRotations="); |
| 8650 | pw.println(allowAllRotationsToString(mAllowAllRotations)); |
| 8651 | pw.print(prefix); pw.print("mCurrentAppOrientation="); |
| 8652 | pw.println(ActivityInfo.screenOrientationToString(mCurrentAppOrientation)); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8653 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 8654 | pw.print(mCarDockEnablesAccelerometer); |
| 8655 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 8656 | pw.println(mDeskDockEnablesAccelerometer); |
| 8657 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 8658 | pw.print(mLidKeyboardAccessibility); |
| 8659 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 8660 | pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock); |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 8661 | pw.print(prefix); pw.print("mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 8662 | pw.print(prefix); |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 8663 | pw.print("mLongPressOnBackBehavior="); |
| 8664 | pw.println(longPressOnBackBehaviorToString(mLongPressOnBackBehavior)); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 8665 | pw.print(prefix); |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 8666 | pw.print("mLongPressOnHomeBehavior="); |
| 8667 | pw.println(longPressOnHomeBehaviorToString(mLongPressOnHomeBehavior)); |
| 8668 | pw.print(prefix); |
| 8669 | pw.print("mDoubleTapOnHomeBehavior="); |
| 8670 | pw.println(doubleTapOnHomeBehaviorToString(mDoubleTapOnHomeBehavior)); |
| 8671 | pw.print(prefix); |
| 8672 | pw.print("mShortPressOnPowerBehavior="); |
| 8673 | pw.println(shortPressOnPowerBehaviorToString(mShortPressOnPowerBehavior)); |
| 8674 | pw.print(prefix); |
| 8675 | pw.print("mLongPressOnPowerBehavior="); |
| 8676 | pw.println(longPressOnPowerBehaviorToString(mLongPressOnPowerBehavior)); |
| 8677 | pw.print(prefix); |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 8678 | pw.print("mVeryLongPressOnPowerBehavior="); |
| 8679 | pw.println(veryLongPressOnPowerBehaviorToString(mVeryLongPressOnPowerBehavior)); |
| 8680 | pw.print(prefix); |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 8681 | pw.print("mDoublePressOnPowerBehavior="); |
| 8682 | pw.println(multiPressOnPowerBehaviorToString(mDoublePressOnPowerBehavior)); |
| 8683 | pw.print(prefix); |
| 8684 | pw.print("mTriplePressOnPowerBehavior="); |
| 8685 | pw.println(multiPressOnPowerBehaviorToString(mTriplePressOnPowerBehavior)); |
| 8686 | pw.print(prefix); |
| 8687 | pw.print("mShortPressOnSleepBehavior="); |
| 8688 | pw.println(shortPressOnSleepBehaviorToString(mShortPressOnSleepBehavior)); |
| 8689 | pw.print(prefix); |
| 8690 | pw.print("mShortPressOnWindowBehavior="); |
| 8691 | pw.println(shortPressOnWindowBehaviorToString(mShortPressOnWindowBehavior)); |
| 8692 | pw.print(prefix); |
Michael Kwan | 7f17169 | 2018-04-04 14:00:53 -0700 | [diff] [blame] | 8693 | pw.print("mAllowStartActivityForLongPressOnPowerDuringSetup="); |
| 8694 | pw.println(mAllowStartActivityForLongPressOnPowerDuringSetup); |
| 8695 | pw.print(prefix); |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 8696 | pw.print("mHasSoftInput="); pw.print(mHasSoftInput); |
| 8697 | pw.print(" mDismissImeOnBackKeyPressed="); pw.println(mDismissImeOnBackKeyPressed); |
| 8698 | pw.print(prefix); |
| 8699 | pw.print("mIncallPowerBehavior="); |
| 8700 | pw.print(incallPowerBehaviorToString(mIncallPowerBehavior)); |
| 8701 | pw.print(" mIncallBackBehavior="); |
| 8702 | pw.print(incallBackBehaviorToString(mIncallBackBehavior)); |
| 8703 | pw.print(" mEndcallBehavior="); |
| 8704 | pw.println(endcallBehaviorToString(mEndcallBehavior)); |
| 8705 | pw.print(prefix); pw.print("mHomePressed="); pw.println(mHomePressed); |
| 8706 | pw.print(prefix); |
| 8707 | pw.print("mAwake="); pw.print(mAwake); |
| 8708 | pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 8709 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 8710 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 8711 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 8712 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 8713 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 8714 | pw.print(prefix); pw.print("mShowingDream="); pw.print(mShowingDream); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 8715 | pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); |
| 8716 | pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8717 | if (mLastInputMethodWindow != null) { |
| 8718 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 8719 | pw.println(mLastInputMethodWindow); |
| 8720 | } |
| 8721 | if (mLastInputMethodTargetWindow != null) { |
| 8722 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 8723 | pw.println(mLastInputMethodTargetWindow); |
| 8724 | } |
| 8725 | if (mStatusBar != null) { |
| 8726 | pw.print(prefix); pw.print("mStatusBar="); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 8727 | pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); |
| 8728 | pw.println(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8729 | } |
| 8730 | if (mNavigationBar != null) { |
| 8731 | pw.print(prefix); pw.print("mNavigationBar="); |
| 8732 | pw.println(mNavigationBar); |
| 8733 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8734 | if (mFocusedWindow != null) { |
| 8735 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 8736 | pw.println(mFocusedWindow); |
| 8737 | } |
| 8738 | if (mFocusedApp != null) { |
| 8739 | pw.print(prefix); pw.print("mFocusedApp="); |
| 8740 | pw.println(mFocusedApp); |
| 8741 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8742 | if (mTopFullscreenOpaqueWindowState != null) { |
| 8743 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 8744 | pw.println(mTopFullscreenOpaqueWindowState); |
| 8745 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 8746 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 8747 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 8748 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 8749 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 8750 | if (mForcingShowNavBar) { |
| 8751 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 8752 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 8753 | pw.println(mForcingShowNavBarLayer); |
| 8754 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 8755 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 8756 | pw.print(" mKeyguardOccluded="); pw.println(mKeyguardOccluded); |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 8757 | pw.print(prefix); |
| 8758 | pw.print("mKeyguardOccludedChanged="); pw.print(mKeyguardOccludedChanged); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 8759 | pw.print(" mPendingKeyguardOccluded="); pw.println(mPendingKeyguardOccluded); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 8760 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 8761 | pw.print(" mForceStatusBarFromKeyguard="); |
| 8762 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8763 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 8764 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 8765 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 8766 | pw.print(prefix); pw.print("mLandscapeRotation="); |
| 8767 | pw.print(Surface.rotationToString(mLandscapeRotation)); |
| 8768 | pw.print(" mSeascapeRotation="); |
| 8769 | pw.println(Surface.rotationToString(mSeascapeRotation)); |
| 8770 | pw.print(prefix); pw.print("mPortraitRotation="); |
| 8771 | pw.print(Surface.rotationToString(mPortraitRotation)); |
| 8772 | pw.print(" mUpsideDownRotation="); |
| 8773 | pw.println(Surface.rotationToString(mUpsideDownRotation)); |
| 8774 | pw.print(prefix); pw.print("mDemoHdmiRotation="); |
| 8775 | pw.print(Surface.rotationToString(mDemoHdmiRotation)); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 8776 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 8777 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); |
| 8778 | pw.println(Surface.rotationToString(mUndockedHdmiRotation)); |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 8779 | if (mHasFeatureLeanback) { |
| 8780 | pw.print(prefix); |
| 8781 | pw.print("mAccessibilityTvKey1Pressed="); pw.println(mAccessibilityTvKey1Pressed); |
| 8782 | pw.print(prefix); |
| 8783 | pw.print("mAccessibilityTvKey2Pressed="); pw.println(mAccessibilityTvKey2Pressed); |
| 8784 | pw.print(prefix); |
| 8785 | pw.print("mAccessibilityTvScheduled="); pw.println(mAccessibilityTvScheduled); |
| 8786 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 8787 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 8788 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8789 | mStatusBarController.dump(pw, prefix); |
| 8790 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 8791 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 8792 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 8793 | if (mWakeGestureListener != null) { |
| 8794 | mWakeGestureListener.dump(pw, prefix); |
| 8795 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 8796 | if (mOrientationListener != null) { |
| 8797 | mOrientationListener.dump(pw, prefix); |
| 8798 | } |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 8799 | if (mBurnInProtectionHelper != null) { |
| 8800 | mBurnInProtectionHelper.dump(prefix, pw); |
| 8801 | } |
Jorim Jaggi | 84dc08a | 2015-09-11 17:45:22 -0700 | [diff] [blame] | 8802 | if (mKeyguardDelegate != null) { |
| 8803 | mKeyguardDelegate.dump(prefix, pw); |
| 8804 | } |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 8805 | |
| 8806 | pw.print(prefix); pw.println("Looper state:"); |
| 8807 | mHandler.getLooper().dump(new PrintWriterPrinter(pw), prefix + " "); |
| 8808 | } |
| 8809 | |
| 8810 | private static String allowAllRotationsToString(int allowAll) { |
| 8811 | switch (allowAll) { |
| 8812 | case -1: |
| 8813 | return "unknown"; |
| 8814 | case 0: |
| 8815 | return "false"; |
| 8816 | case 1: |
| 8817 | return "true"; |
| 8818 | default: |
| 8819 | return Integer.toString(allowAll); |
| 8820 | } |
| 8821 | } |
| 8822 | |
| 8823 | private static String endcallBehaviorToString(int behavior) { |
| 8824 | StringBuilder sb = new StringBuilder(); |
| 8825 | if ((behavior & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0 ) { |
| 8826 | sb.append("home|"); |
| 8827 | } |
| 8828 | if ((behavior & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 8829 | sb.append("sleep|"); |
| 8830 | } |
| 8831 | |
| 8832 | final int N = sb.length(); |
| 8833 | if (N == 0) { |
| 8834 | return "<nothing>"; |
| 8835 | } else { |
| 8836 | // Chop off the trailing '|' |
| 8837 | return sb.substring(0, N - 1); |
| 8838 | } |
| 8839 | } |
| 8840 | |
| 8841 | private static String incallPowerBehaviorToString(int behavior) { |
| 8842 | if ((behavior & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0) { |
| 8843 | return "hangup"; |
| 8844 | } else { |
| 8845 | return "sleep"; |
| 8846 | } |
| 8847 | } |
| 8848 | |
| 8849 | private static String incallBackBehaviorToString(int behavior) { |
| 8850 | if ((behavior & Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_HANGUP) != 0) { |
| 8851 | return "hangup"; |
| 8852 | } else { |
| 8853 | return "<nothing>"; |
| 8854 | } |
| 8855 | } |
| 8856 | |
| 8857 | private static String longPressOnBackBehaviorToString(int behavior) { |
| 8858 | switch (behavior) { |
| 8859 | case LONG_PRESS_BACK_NOTHING: |
| 8860 | return "LONG_PRESS_BACK_NOTHING"; |
| 8861 | case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST: |
| 8862 | return "LONG_PRESS_BACK_GO_TO_VOICE_ASSIST"; |
| 8863 | default: |
| 8864 | return Integer.toString(behavior); |
| 8865 | } |
| 8866 | } |
| 8867 | |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 8868 | private static String longPressOnHomeBehaviorToString(int behavior) { |
| 8869 | switch (behavior) { |
| 8870 | case LONG_PRESS_HOME_NOTHING: |
| 8871 | return "LONG_PRESS_HOME_NOTHING"; |
| 8872 | case LONG_PRESS_HOME_ALL_APPS: |
| 8873 | return "LONG_PRESS_HOME_ALL_APPS"; |
| 8874 | case LONG_PRESS_HOME_ASSIST: |
| 8875 | return "LONG_PRESS_HOME_ASSIST"; |
| 8876 | default: |
| 8877 | return Integer.toString(behavior); |
| 8878 | } |
| 8879 | } |
| 8880 | |
| 8881 | private static String doubleTapOnHomeBehaviorToString(int behavior) { |
| 8882 | switch (behavior) { |
| 8883 | case DOUBLE_TAP_HOME_NOTHING: |
| 8884 | return "DOUBLE_TAP_HOME_NOTHING"; |
| 8885 | case DOUBLE_TAP_HOME_RECENT_SYSTEM_UI: |
| 8886 | return "DOUBLE_TAP_HOME_RECENT_SYSTEM_UI"; |
| 8887 | default: |
| 8888 | return Integer.toString(behavior); |
| 8889 | } |
| 8890 | } |
| 8891 | |
| 8892 | private static String shortPressOnPowerBehaviorToString(int behavior) { |
| 8893 | switch (behavior) { |
| 8894 | case SHORT_PRESS_POWER_NOTHING: |
| 8895 | return "SHORT_PRESS_POWER_NOTHING"; |
| 8896 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 8897 | return "SHORT_PRESS_POWER_GO_TO_SLEEP"; |
| 8898 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 8899 | return "SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP"; |
| 8900 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 8901 | return "SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME"; |
| 8902 | case SHORT_PRESS_POWER_GO_HOME: |
| 8903 | return "SHORT_PRESS_POWER_GO_HOME"; |
| 8904 | case SHORT_PRESS_POWER_CLOSE_IME_OR_GO_HOME: |
| 8905 | return "SHORT_PRESS_POWER_CLOSE_IME_OR_GO_HOME"; |
| 8906 | default: |
| 8907 | return Integer.toString(behavior); |
| 8908 | } |
| 8909 | } |
| 8910 | |
| 8911 | private static String longPressOnPowerBehaviorToString(int behavior) { |
| 8912 | switch (behavior) { |
| 8913 | case LONG_PRESS_POWER_NOTHING: |
| 8914 | return "LONG_PRESS_POWER_NOTHING"; |
| 8915 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 8916 | return "LONG_PRESS_POWER_GLOBAL_ACTIONS"; |
| 8917 | case LONG_PRESS_POWER_SHUT_OFF: |
| 8918 | return "LONG_PRESS_POWER_SHUT_OFF"; |
| 8919 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 8920 | return "LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM"; |
| 8921 | default: |
| 8922 | return Integer.toString(behavior); |
| 8923 | } |
| 8924 | } |
Michael Kwan | 57908f0 | 2017-11-14 15:27:53 -0800 | [diff] [blame] | 8925 | |
| 8926 | private static String veryLongPressOnPowerBehaviorToString(int behavior) { |
| 8927 | switch (behavior) { |
| 8928 | case VERY_LONG_PRESS_POWER_NOTHING: |
| 8929 | return "VERY_LONG_PRESS_POWER_NOTHING"; |
| 8930 | case VERY_LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 8931 | return "VERY_LONG_PRESS_POWER_GLOBAL_ACTIONS"; |
| 8932 | default: |
| 8933 | return Integer.toString(behavior); |
| 8934 | } |
| 8935 | } |
| 8936 | |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 8937 | private static String multiPressOnPowerBehaviorToString(int behavior) { |
| 8938 | switch (behavior) { |
| 8939 | case MULTI_PRESS_POWER_NOTHING: |
| 8940 | return "MULTI_PRESS_POWER_NOTHING"; |
| 8941 | case MULTI_PRESS_POWER_THEATER_MODE: |
| 8942 | return "MULTI_PRESS_POWER_THEATER_MODE"; |
| 8943 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
| 8944 | return "MULTI_PRESS_POWER_BRIGHTNESS_BOOST"; |
| 8945 | default: |
| 8946 | return Integer.toString(behavior); |
| 8947 | } |
| 8948 | } |
| 8949 | |
| 8950 | private static String shortPressOnSleepBehaviorToString(int behavior) { |
| 8951 | switch (behavior) { |
| 8952 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
| 8953 | return "SHORT_PRESS_SLEEP_GO_TO_SLEEP"; |
| 8954 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
| 8955 | return "SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME"; |
| 8956 | default: |
| 8957 | return Integer.toString(behavior); |
| 8958 | } |
| 8959 | } |
| 8960 | |
| 8961 | private static String shortPressOnWindowBehaviorToString(int behavior) { |
| 8962 | switch (behavior) { |
| 8963 | case SHORT_PRESS_WINDOW_NOTHING: |
| 8964 | return "SHORT_PRESS_WINDOW_NOTHING"; |
| 8965 | case SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE: |
| 8966 | return "SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE"; |
| 8967 | default: |
| 8968 | return Integer.toString(behavior); |
| 8969 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8970 | } |
Benjamin Franz | 3662b15 | 2018-01-16 17:23:44 +0000 | [diff] [blame] | 8971 | |
| 8972 | @Override |
| 8973 | public void onLockTaskStateChangedLw(int lockTaskState) { |
| 8974 | mImmersiveModeConfirmation.onLockTaskModeChangedLw(lockTaskState); |
| 8975 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 8976 | } |