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 | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 20 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 21 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 22 | import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; |
| 23 | import static android.content.pm.PackageManager.FEATURE_TELEVISION; |
| 24 | import static android.content.pm.PackageManager.FEATURE_WATCH; |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 25 | import static android.content.res.Configuration.EMPTY; |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 26 | import static android.content.res.Configuration.UI_MODE_TYPE_CAR; |
| 27 | import static android.content.res.Configuration.UI_MODE_TYPE_MASK; |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 28 | import static android.view.WindowManager.DOCKED_LEFT; |
| 29 | import static android.view.WindowManager.DOCKED_RIGHT; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 30 | import static android.view.WindowManager.DOCKED_TOP; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 31 | import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 32 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 33 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 34 | import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW; |
| 35 | import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| 36 | import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
| 37 | import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN; |
| 38 | import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN; |
| 39 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR; |
| 40 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR; |
| 41 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN; |
| 42 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
| 43 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
| 44 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 45 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
| 46 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 47 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
| 48 | import static android.view.WindowManager.LayoutParams.LAST_SYSTEM_WINDOW; |
| 49 | import static android.view.WindowManager.LayoutParams.MATCH_PARENT; |
| 50 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND; |
| 51 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT; |
| 52 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 53 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 54 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_TASK_SNAPSHOT; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 55 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR; |
| 56 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE; |
| 57 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT; |
| 58 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE; |
| 59 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS; |
| 60 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; |
| 61 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 62 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 63 | import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; |
| 64 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL; |
| 65 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 66 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; |
| 67 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; |
| 68 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; |
| 69 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 70 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL; |
| 71 | import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; |
| 72 | import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY; |
| 73 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
| 74 | import static android.view.WindowManager.LayoutParams.TYPE_DRAG; |
| 75 | import static android.view.WindowManager.LayoutParams.TYPE_DREAM; |
| 76 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER; |
| 77 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 78 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 79 | import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; |
| 80 | import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY; |
| 81 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
| 82 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; |
| 83 | import static android.view.WindowManager.LayoutParams.TYPE_PHONE; |
| 84 | import static android.view.WindowManager.LayoutParams.TYPE_POINTER; |
Wale Ogunwale | 5b6714c | 2016-11-01 20:54:46 -0700 | [diff] [blame] | 85 | import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 86 | import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE; |
| 87 | import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION; |
| 88 | import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG; |
| 89 | import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT; |
| 90 | import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR; |
| 91 | import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
| 92 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
| 93 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; |
| 94 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; |
| 95 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; |
| 96 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
| 97 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
| 98 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; |
| 99 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
| 100 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; |
| 101 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING; |
| 102 | import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; |
| 103 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 104 | import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN; |
| 105 | import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 106 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 107 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; |
| 108 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 109 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 110 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
| 111 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 112 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 113 | import android.annotation.Nullable; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 114 | import android.app.ActivityManager; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 115 | import android.app.ActivityManager.StackId; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 116 | import android.app.ActivityManagerInternal; |
| 117 | import android.app.ActivityManagerInternal.SleepToken; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 118 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 119 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 120 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 121 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 122 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 123 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 124 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 125 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 126 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 127 | import android.content.ContentResolver; |
| 128 | import android.content.Context; |
| 129 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 130 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 131 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 132 | import android.content.pm.ActivityInfo; |
Svet Ganov | 03f2afc | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 133 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 134 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 135 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 136 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 137 | import android.content.res.Configuration; |
| 138 | import android.content.res.Resources; |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 139 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 140 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 141 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 142 | import android.graphics.Rect; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 143 | import android.hardware.hdmi.HdmiControlManager; |
| 144 | import android.hardware.hdmi.HdmiPlaybackClient; |
| 145 | import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 146 | import android.hardware.input.InputManagerInternal; |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 147 | import android.hardware.power.V1_0.PowerHint; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 148 | import android.media.AudioAttributes; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 149 | import android.media.AudioManager; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 150 | import android.media.AudioSystem; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 151 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 152 | import android.media.Ringtone; |
| 153 | import android.media.RingtoneManager; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 154 | import android.media.session.MediaSessionLegacyHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 155 | import android.os.Binder; |
Svet Ganov | 03f2afc | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 156 | import android.os.Build; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 157 | import android.os.Bundle; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 158 | import android.os.Debug; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 159 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 160 | import android.os.Handler; |
| 161 | import android.os.IBinder; |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 162 | import android.os.IDeviceIdleController; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 163 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 164 | import android.os.Message; |
| 165 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 166 | import android.os.PowerManager; |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 167 | import android.os.PowerManagerInternal; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 168 | import android.os.Process; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 169 | import android.os.RemoteException; |
| 170 | import android.os.ServiceManager; |
| 171 | import android.os.SystemClock; |
| 172 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 173 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 174 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 175 | import android.os.Vibrator; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 176 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 177 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 178 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 179 | import android.service.dreams.DreamService; |
| 180 | import android.service.dreams.IDreamManager; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 181 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 182 | import android.telecom.TelecomManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 183 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 184 | import android.util.EventLog; |
| 185 | import android.util.Log; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 186 | import android.util.LongSparseArray; |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 187 | import android.util.MutableBoolean; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 188 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 189 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 190 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 191 | import android.view.Gravity; |
| 192 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 193 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 194 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 195 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 196 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 197 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 198 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 199 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 200 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 201 | import android.view.KeyEvent; |
| 202 | import android.view.MotionEvent; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 203 | import android.view.Surface; |
| 204 | import android.view.View; |
| 205 | import android.view.ViewConfiguration; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 206 | import android.view.WindowManager; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 207 | import android.view.WindowManager.LayoutParams; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 208 | import android.view.WindowManagerGlobal; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 209 | import android.view.WindowManagerInternal; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 210 | import android.view.WindowManagerInternal.AppTransitionListener; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 211 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 212 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 213 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 214 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 215 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 216 | import android.view.animation.AnimationUtils; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 217 | |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 218 | import com.android.internal.R; |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 219 | import com.android.internal.logging.MetricsLogger; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 220 | import com.android.internal.policy.IKeyguardDismissCallback; |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 221 | import com.android.internal.policy.IShortcutService; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 222 | import com.android.internal.policy.PhoneWindow; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 223 | import com.android.internal.statusbar.IStatusBarService; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 224 | import com.android.internal.util.ScreenShapeHelper; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 225 | import com.android.internal.widget.PointerLocationView; |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 226 | import com.android.server.GestureLauncherService; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 227 | import com.android.server.LocalServices; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 228 | import com.android.server.policy.keyguard.KeyguardServiceDelegate; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 229 | import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener; |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 230 | import com.android.server.policy.keyguard.KeyguardStateMonitor.StateCallback; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 231 | import com.android.server.statusbar.StatusBarManagerInternal; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 232 | import com.android.server.wm.AppTransition; |
Ruben Brunk | fecb615 | 2016-10-28 20:18:57 -0700 | [diff] [blame] | 233 | import com.android.server.vr.VrManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 234 | |
| 235 | import java.io.File; |
| 236 | import java.io.FileReader; |
| 237 | import java.io.IOException; |
| 238 | import java.io.PrintWriter; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 239 | import java.util.List; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 240 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 241 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 242 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 243 | * introduces a new method suffix, Lp, for an internal lock of the |
| 244 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 245 | * 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] | 246 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 247 | */ |
| 248 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 249 | static final String TAG = "WindowManager"; |
| 250 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 251 | static final boolean localLOGV = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 252 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 253 | static final boolean DEBUG_KEYGUARD = false; |
| 254 | static final boolean DEBUG_LAYOUT = false; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 255 | static final boolean DEBUG_SPLASH_SCREEN = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 256 | static final boolean DEBUG_WAKEUP = false; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 257 | static final boolean SHOW_SPLASH_SCREENS = true; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 258 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 259 | // 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] | 260 | // No longer recommended for desk docks; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 261 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 262 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 263 | static final boolean ALTERNATE_CAR_MODE_NAV_SIZE = false; |
| 264 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 265 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 266 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 267 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 268 | 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] | 269 | static final int SHORT_PRESS_POWER_GO_HOME = 4; |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 270 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 271 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 272 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 273 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 274 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 275 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 276 | static final int LONG_PRESS_BACK_NOTHING = 0; |
| 277 | static final int LONG_PRESS_BACK_GO_TO_VOICE_ASSIST = 1; |
| 278 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 279 | static final int MULTI_PRESS_POWER_NOTHING = 0; |
| 280 | static final int MULTI_PRESS_POWER_THEATER_MODE = 1; |
| 281 | static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2; |
| 282 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 283 | // Number of presses needed before we induce panic press behavior on the back button |
| 284 | static final int PANIC_PRESS_BACK_COUNT = 4; |
| 285 | static final int PANIC_PRESS_BACK_NOTHING = 0; |
| 286 | static final int PANIC_PRESS_BACK_HOME = 1; |
| 287 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 288 | // These need to match the documentation/constant in |
| 289 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 290 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 291 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 292 | static final int LONG_PRESS_HOME_ASSIST = 2; |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 293 | static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 294 | |
| 295 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 296 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 297 | |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 298 | static final int SHORT_PRESS_WINDOW_NOTHING = 0; |
| 299 | static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1; |
| 300 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 301 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0; |
| 302 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1; |
| 303 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 304 | static final int PENDING_KEY_NULL = -1; |
| 305 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 306 | // Controls navigation bar opacity depending on which workspace stacks are currently |
| 307 | // visible. |
| 308 | // Nav bar is always opaque when either the freeform stack or docked stack is visible. |
| 309 | static final int NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED = 0; |
| 310 | // Nav bar is always translucent when the freeform stack is visible, otherwise always opaque. |
| 311 | static final int NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE = 1; |
| 312 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 313 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 314 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 315 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 316 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 317 | static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 318 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 319 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 320 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 321 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 322 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 323 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 324 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 325 | /** |
| 326 | * These are the system UI flags that, when changing, can cause the layout |
| 327 | * of the screen to change. |
| 328 | */ |
| 329 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 330 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 331 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 332 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 333 | | View.NAVIGATION_BAR_TRANSLUCENT |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 334 | | View.STATUS_BAR_TRANSPARENT |
| 335 | | View.NAVIGATION_BAR_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 336 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 337 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 338 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 339 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 340 | .build(); |
| 341 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 342 | // The panic gesture may become active only after the keyguard is dismissed and the immersive |
| 343 | // app shows again. If that doesn't happen for 30s we drop the gesture. |
| 344 | private static final long PANIC_GESTURE_EXPIRATION = 30000; |
| 345 | |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 346 | private static final String SYSUI_PACKAGE = "com.android.systemui"; |
| 347 | private static final String SYSUI_SCREENSHOT_SERVICE = |
| 348 | "com.android.systemui.screenshot.TakeScreenshotService"; |
| 349 | private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER = |
| 350 | "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver"; |
| 351 | |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 352 | private static final int NAV_BAR_BOTTOM = 0; |
| 353 | private static final int NAV_BAR_RIGHT = 1; |
| 354 | private static final int NAV_BAR_LEFT = 2; |
| 355 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 356 | /** |
| 357 | * Keyguard stuff |
| 358 | */ |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 359 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 360 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 361 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 362 | * |
| 363 | * These are special keys that are used to launch particular kinds of applications, |
| 364 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 365 | * usage page. We don't support quite that many yet... |
| 366 | */ |
| 367 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 368 | static { |
| 369 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 370 | sApplicationLaunchKeyCategories.append( |
| 371 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 372 | sApplicationLaunchKeyCategories.append( |
| 373 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 374 | sApplicationLaunchKeyCategories.append( |
| 375 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 376 | sApplicationLaunchKeyCategories.append( |
| 377 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 378 | sApplicationLaunchKeyCategories.append( |
| 379 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 380 | sApplicationLaunchKeyCategories.append( |
| 381 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 382 | } |
| 383 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 384 | /** 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] | 385 | static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 386 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 387 | /** Amount of time (in milliseconds) a toast window can be shown. */ |
| 388 | public static final int TOAST_WINDOW_TIMEOUT = 3500; // 3.5 seconds |
| 389 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 390 | /** |
| 391 | * Lock protecting internal state. Must not call out into window |
| 392 | * manager with lock held. (This lock will be acquired in places |
| 393 | * where the window manager is calling in with its own lock held.) |
| 394 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 395 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 396 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 397 | Context mContext; |
| 398 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 399 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 400 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 401 | PowerManager mPowerManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 402 | ActivityManagerInternal mActivityManagerInternal; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 403 | InputManagerInternal mInputManagerInternal; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 404 | DreamManagerInternal mDreamManagerInternal; |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 405 | PowerManagerInternal mPowerManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 406 | IStatusBarService mStatusBarService; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 407 | StatusBarManagerInternal mStatusBarManagerInternal; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 408 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 409 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 410 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 411 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 412 | AccessibilityManager mAccessibilityManager; |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 413 | BurnInProtectionHelper mBurnInProtectionHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 414 | AppOpsManager mAppOpsManager; |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 415 | private boolean mHasFeatureWatch; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 416 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 417 | // Vibrator pattern for haptic feedback of a long press. |
| 418 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 419 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 420 | // Vibrator pattern for haptic feedback of virtual key press. |
| 421 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 422 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 423 | // Vibrator pattern for a short vibration. |
| 424 | long[] mKeyboardTapVibePattern; |
| 425 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 426 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 427 | long[] mClockTickVibePattern; |
| 428 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 429 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 430 | long[] mCalendarDateVibePattern; |
| 431 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 432 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 433 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 434 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 435 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 436 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 437 | |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 438 | // Vibrator pattern for haptic feedback of a context click. |
| 439 | long[] mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 440 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 441 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 442 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 443 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 444 | boolean mSafeMode; |
| 445 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 446 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 447 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 448 | boolean mHasNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 449 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 450 | int mNavigationBarPosition = NAV_BAR_BOTTOM; |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 451 | int[] mNavigationBarHeightForRotationDefault = new int[4]; |
| 452 | int[] mNavigationBarWidthForRotationDefault = new int[4]; |
| 453 | int[] mNavigationBarHeightForRotationInCarMode = new int[4]; |
| 454 | int[] mNavigationBarWidthForRotationInCarMode = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 455 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 456 | private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>(); |
| 457 | |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 458 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 459 | // This is for car dock and this is updated from resource. |
| 460 | private boolean mEnableCarDockHomeCapture = true; |
| 461 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 462 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 463 | KeyguardServiceDelegate mKeyguardDelegate; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 464 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 465 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 466 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 467 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 468 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 469 | } |
| 470 | }; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 471 | final DrawnListener mKeyguardDrawnCallback = new DrawnListener() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 472 | @Override |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 473 | public void onDrawn() { |
| 474 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 475 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 476 | } |
| 477 | }; |
| 478 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 479 | GlobalActions mGlobalActions; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 480 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 481 | WindowState mLastInputMethodWindow = null; |
| 482 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 483 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 484 | // FIXME This state is shared between the input reader and handler thread. |
| 485 | // Technically it's broken and buggy but it has been like this for many years |
| 486 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 487 | // so that only one thread is involved in handling input policy. Unfortunately |
| 488 | // it's on a critical path for power management so we can't just post the work to the |
| 489 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 490 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 491 | volatile boolean mPowerKeyHandled; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 492 | volatile boolean mBackKeyHandled; |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 493 | volatile boolean mBeganFromNonInteractive; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 494 | volatile int mPowerKeyPressCounter; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 495 | volatile int mBackKeyPressCounter; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 496 | volatile boolean mEndCallKeyHandled; |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 497 | volatile boolean mCameraGestureTriggeredDuringGoingToSleep; |
| 498 | volatile boolean mGoingToSleep; |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 499 | volatile boolean mRecentsVisible; |
| 500 | volatile boolean mTvPictureInPictureVisible; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 501 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 502 | // Used to hold the last user key used to wake the device. This helps us prevent up events |
| 503 | // from being passed to the foregrounded app without a corresponding down event |
| 504 | volatile int mPendingWakeKey = PENDING_KEY_NULL; |
| 505 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 506 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 507 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 508 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 509 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 510 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 511 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 512 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 513 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 514 | boolean mSystemBooted; |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 515 | private boolean mDeferBindKeyguard; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 516 | boolean mHdmiPlugged; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 517 | HdmiControl mHdmiControl; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 518 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 519 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 520 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 521 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 522 | int mCarDockRotation; |
| 523 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 524 | int mUndockedHdmiRotation; |
| 525 | int mDemoHdmiRotation; |
| 526 | boolean mDemoHdmiRotationLock; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 527 | int mDemoRotation; |
| 528 | boolean mDemoRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 529 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 530 | boolean mWakeGestureEnabledSetting; |
| 531 | MyWakeGestureListener mWakeGestureListener; |
| 532 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 533 | // Default display does not rotate, apps that require non-default orientation will have to |
| 534 | // have the orientation emulated. |
| 535 | private boolean mForceDefaultOrientation = false; |
| 536 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 537 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 538 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 539 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 540 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 541 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 542 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 543 | boolean mCarDockEnablesAccelerometer; |
| 544 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 545 | int mLidKeyboardAccessibility; |
| 546 | int mLidNavigationAccessibility; |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 547 | boolean mLidControlsScreenLock; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 548 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 549 | int mShortPressOnPowerBehavior; |
| 550 | int mLongPressOnPowerBehavior; |
| 551 | int mDoublePressOnPowerBehavior; |
| 552 | int mTriplePressOnPowerBehavior; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 553 | int mLongPressOnBackBehavior; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 554 | int mPanicPressOnBackBehavior; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 555 | int mShortPressOnSleepBehavior; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 556 | int mShortPressWindowBehavior; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 557 | boolean mAwake; |
| 558 | boolean mScreenOnEarly; |
| 559 | boolean mScreenOnFully; |
| 560 | ScreenOnListener mScreenOnListener; |
| 561 | boolean mKeyguardDrawComplete; |
| 562 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 563 | boolean mOrientationSensorEnabled = false; |
| 564 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 565 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 566 | boolean mTranslucentDecorEnabled = true; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 567 | boolean mUseTvRouting; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 568 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 569 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 570 | |
| 571 | // The last window we were told about in focusChanged. |
| 572 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 573 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 574 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 575 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 576 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 577 | // The current size of the screen; really; extends into the overscan area of |
| 578 | // the screen and doesn't account for any system elements like the status bar. |
| 579 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 580 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 581 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 582 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 583 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 584 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 585 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 586 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 587 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 588 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 589 | // if the status bar can't be hidden; in that case it effectively carves out |
| 590 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 591 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 592 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 593 | // During layout, the current screen borders accounting for any currently |
| 594 | // visible system UI elements. |
| 595 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 596 | // For applications requesting stable content insets, these are them. |
| 597 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 598 | // For applications requesting stable content insets but have also set the |
| 599 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 600 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 601 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 602 | // During layout, the current screen borders with all outer decoration |
| 603 | // (status bar, input method dock) accounted for. |
| 604 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 605 | // During layout, the frame in which content should be displayed |
| 606 | // to the user, accounting for all screen decoration except for any |
| 607 | // space they deem as available for other content. This is usually |
| 608 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 609 | // content insets. |
| 610 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 611 | // During layout, the frame in which voice content should be displayed |
| 612 | // to the user, accounting for all screen decoration except for any |
| 613 | // space they deem as available for other content. |
| 614 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 615 | // During layout, the current screen borders along which input method |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 616 | // windows are placed. |
| 617 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 618 | // During layout, the layer at which the doc window is placed. |
| 619 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 620 | // During layout, this is the layer of the status bar. |
| 621 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 622 | int mLastSystemUiFlags; |
| 623 | // Bits that we are in the process of clearing, so we want to prevent |
| 624 | // them from being set by applications until everything has been updated |
| 625 | // to have them clear. |
| 626 | int mResettingSystemUiFlags = 0; |
| 627 | // Bits that we are currently always keeping cleared. |
| 628 | int mForceClearedSystemUiFlags = 0; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 629 | int mLastFullscreenStackSysUiFlags; |
| 630 | int mLastDockedStackSysUiFlags; |
| 631 | final Rect mNonDockedStackBounds = new Rect(); |
| 632 | final Rect mDockedStackBounds = new Rect(); |
| 633 | final Rect mLastNonDockedStackBounds = new Rect(); |
| 634 | final Rect mLastDockedStackBounds = new Rect(); |
| 635 | |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 636 | // What we last reported to system UI about whether the compatibility |
| 637 | // menu needs to be displayed. |
| 638 | boolean mLastFocusNeedsMenu = false; |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 639 | // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending. |
| 640 | private long mPendingPanicGestureUptime; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 641 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 642 | InputConsumer mInputConsumer = null; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 643 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 644 | static final Rect mTmpParentFrame = new Rect(); |
| 645 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 646 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 647 | static final Rect mTmpContentFrame = new Rect(); |
| 648 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 649 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 650 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 651 | static final Rect mTmpNavigationFrame = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 652 | static final Rect mTmpOutsetFrame = new Rect(); |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 653 | private static final Rect mTmpRect = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 654 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 655 | WindowState mTopFullscreenOpaqueWindowState; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 656 | WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 657 | WindowState mTopDockedOpaqueWindowState; |
| 658 | WindowState mTopDockedOpaqueOrDimmingWindowState; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 659 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 660 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 661 | boolean mForceStatusBarFromKeyguard; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 662 | private boolean mForceStatusBarTransparent; |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 663 | int mNavBarOpacityMode = NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 664 | boolean mForcingShowNavBar; |
| 665 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 666 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 667 | private boolean mPendingKeyguardOccluded; |
| 668 | private boolean mKeyguardOccludedChanged; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 669 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 670 | boolean mShowingDream; |
Jorim Jaggi | 77e1043 | 2016-10-26 17:43:56 -0700 | [diff] [blame] | 671 | private boolean mLastShowingDream; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 672 | boolean mDreamingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 673 | boolean mDreamingSleepTokenNeeded; |
| 674 | SleepToken mDreamingSleepToken; |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 675 | SleepToken mScreenOffSleepToken; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 676 | volatile boolean mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 677 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 678 | boolean mHomeConsumed; |
| 679 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 680 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 681 | Intent mCarDockIntent; |
| 682 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 683 | boolean mSearchKeyShortcutPending; |
| 684 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 685 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 686 | boolean mPendingMetaAction; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 687 | boolean mPendingCapsLockToggle; |
| 688 | int mMetaState; |
| 689 | int mInitialMetaState; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 690 | boolean mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 691 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 692 | // support for activating the lock screen while the screen is on |
| 693 | boolean mAllowLockscreenWhenOn; |
| 694 | int mLockScreenTimeout; |
| 695 | boolean mLockScreenTimerActive; |
| 696 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 697 | // 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] | 698 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 699 | |
| 700 | // Behavior of POWER button while in-call and screen on. |
| 701 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 702 | int mIncallPowerBehavior; |
| 703 | |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 704 | // Behavior of Back button while in-call and screen on |
| 705 | int mIncallBackBehavior; |
| 706 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 707 | Display mDisplay; |
| 708 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 709 | private int mDisplayRotation; |
| 710 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 711 | int mLandscapeRotation = 0; // default landscape rotation |
| 712 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 713 | int mPortraitRotation = 0; // default portrait rotation |
| 714 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 715 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 716 | int mOverscanLeft = 0; |
| 717 | int mOverscanTop = 0; |
| 718 | int mOverscanRight = 0; |
| 719 | int mOverscanBottom = 0; |
| 720 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 721 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 722 | private int mLongPressOnHomeBehavior; |
| 723 | |
| 724 | // What we do when the user double-taps on home |
| 725 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 726 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 727 | // Allowed theater mode wake actions |
| 728 | private boolean mAllowTheaterModeWakeFromKey; |
| 729 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 730 | private boolean mAllowTheaterModeWakeFromMotion; |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 731 | private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 732 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 733 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 734 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 735 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 736 | // Whether to support long press from power button in non-interactive mode |
| 737 | private boolean mSupportLongPressPowerWhenNonInteractive; |
| 738 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 739 | // Whether to go to sleep entering theater mode from power button |
| 740 | private boolean mGoToSleepOnButtonPressTheaterMode; |
| 741 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 742 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 743 | // Time to volume and power must be pressed within this interval of each other. |
| 744 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 745 | // Increase the chord delay when taking a screenshot from the keyguard |
| 746 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 747 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 748 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 749 | private long mScreenshotChordVolumeDownKeyTime; |
| 750 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
| 751 | private boolean mScreenshotChordVolumeUpKeyTriggered; |
| 752 | private boolean mScreenshotChordPowerKeyTriggered; |
| 753 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 754 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 755 | /* The number of steps between min and max brightness */ |
| 756 | private static final int BRIGHTNESS_STEPS = 10; |
| 757 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 758 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 759 | ShortcutManager mShortcutManager; |
| 760 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 761 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 762 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 763 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 764 | private int mCurrentUserId; |
| 765 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 766 | // Maps global key codes to the components that will handle them. |
| 767 | private GlobalKeyManager mGlobalKeyManager; |
| 768 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 769 | // Fallback actions by key code. |
| 770 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 771 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 772 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 773 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 774 | = new LogDecelerateInterpolator(100, 0); |
| 775 | |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 776 | private final MutableBoolean mTmpBoolean = new MutableBoolean(false); |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 777 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 778 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 779 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 780 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 781 | 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] | 782 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 783 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 784 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 785 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 786 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 787 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 788 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 789 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 790 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 791 | private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 792 | private static final int MSG_REQUEST_TRANSIENT_BARS = 16; |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 793 | private static final int MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU = 17; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 794 | private static final int MSG_BACK_LONG_PRESS = 18; |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 795 | private static final int MSG_DISPOSE_INPUT_CONSUMER = 19; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 796 | private static final int MSG_BACK_DELAYED_PRESS = 20; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 797 | |
| 798 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0; |
| 799 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 800 | |
| 801 | private class PolicyHandler extends Handler { |
| 802 | @Override |
| 803 | public void handleMessage(Message msg) { |
| 804 | switch (msg.what) { |
| 805 | case MSG_ENABLE_POINTER_LOCATION: |
| 806 | enablePointerLocation(); |
| 807 | break; |
| 808 | case MSG_DISABLE_POINTER_LOCATION: |
| 809 | disablePointerLocation(); |
| 810 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 811 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 812 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 813 | break; |
| 814 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 815 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 816 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 817 | case MSG_DISPATCH_SHOW_RECENTS: |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 818 | showRecentApps(false, msg.arg1 != 0); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 819 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 820 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 821 | showGlobalActionsInternal(); |
| 822 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 823 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 824 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 825 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 826 | break; |
| 827 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 828 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 829 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 830 | break; |
| 831 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 832 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 833 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 834 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 835 | case MSG_HIDE_BOOT_MESSAGE: |
| 836 | handleHideBootMessage(); |
| 837 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 838 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 839 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 840 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 841 | case MSG_POWER_DELAYED_PRESS: |
| 842 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 843 | finishPowerKeyPress(); |
| 844 | break; |
| 845 | case MSG_POWER_LONG_PRESS: |
| 846 | powerLongPress(); |
| 847 | break; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 848 | case MSG_UPDATE_DREAMING_SLEEP_TOKEN: |
| 849 | updateDreamingSleepToken(msg.arg1 != 0); |
| 850 | break; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 851 | case MSG_REQUEST_TRANSIENT_BARS: |
| 852 | WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ? |
| 853 | mStatusBar : mNavigationBar; |
| 854 | if (targetBar != null) { |
| 855 | requestTransientBars(targetBar); |
| 856 | } |
| 857 | break; |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 858 | case MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU: |
| 859 | showTvPictureInPictureMenuInternal(); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 860 | break; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 861 | case MSG_BACK_LONG_PRESS: |
| 862 | backLongPress(); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 863 | finishBackKeyPress(); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 864 | break; |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 865 | case MSG_DISPOSE_INPUT_CONSUMER: |
| 866 | disposeInputConsumer((InputConsumer) msg.obj); |
| 867 | break; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 868 | case MSG_BACK_DELAYED_PRESS: |
| 869 | backMultiPressAction((Long) msg.obj, msg.arg1); |
| 870 | finishBackKeyPress(); |
| 871 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | } |
| 875 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 876 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 877 | @Override |
| 878 | public void onUEvent(UEventObserver.UEvent event) { |
| 879 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 880 | } |
| 881 | }; |
| 882 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 883 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 884 | SettingsObserver(Handler handler) { |
| 885 | super(handler); |
| 886 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 887 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 888 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 889 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 890 | ContentResolver resolver = mContext.getContentResolver(); |
| 891 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 892 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 893 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 894 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 895 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 896 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 897 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 898 | Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR), false, this, |
| 899 | UserHandle.USER_ALL); |
| 900 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 901 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 902 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 903 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 904 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 905 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 906 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 907 | Settings.System.USER_ROTATION), false, this, |
| 908 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 909 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 910 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 911 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 912 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 913 | Settings.System.POINTER_LOCATION), false, this, |
| 914 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 915 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 916 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 917 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 918 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 919 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 920 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 921 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 922 | Settings.Global.POLICY_CONTROL), false, this, |
| 923 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 924 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 928 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 929 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 930 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 931 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 932 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 933 | class MyWakeGestureListener extends WakeGestureListener { |
| 934 | MyWakeGestureListener(Context context, Handler handler) { |
| 935 | super(context, handler); |
| 936 | } |
| 937 | |
| 938 | @Override |
| 939 | public void onWakeUp() { |
| 940 | synchronized (mLock) { |
| 941 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 942 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 943 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture, |
| 944 | "android.policy:GESTURE"); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 950 | class MyOrientationListener extends WindowOrientationListener { |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 951 | private final Runnable mUpdateRotationRunnable = new Runnable() { |
| 952 | @Override |
| 953 | public void run() { |
Tim Murray | 1f40764 | 2015-10-01 17:07:12 -0700 | [diff] [blame] | 954 | // send interaction hint to improve redraw performance |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 955 | mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 956 | updateRotation(false); |
| 957 | } |
| 958 | }; |
| 959 | |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 960 | MyOrientationListener(Context context, Handler handler) { |
| 961 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 962 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 963 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 964 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 965 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 966 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 967 | mHandler.post(mUpdateRotationRunnable); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 968 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 969 | } |
| 970 | MyOrientationListener mOrientationListener; |
| 971 | |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 972 | private final StatusBarController mStatusBarController = new StatusBarController(); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 973 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 974 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 975 | View.NAVIGATION_BAR_TRANSIENT, |
| 976 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 977 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 978 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 979 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, |
| 980 | View.NAVIGATION_BAR_TRANSPARENT); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 981 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 982 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 983 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 984 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 985 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 986 | IStatusBarService getStatusBarService() { |
| 987 | synchronized (mServiceAquireLock) { |
| 988 | if (mStatusBarService == null) { |
| 989 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 990 | ServiceManager.getService("statusbar")); |
| 991 | } |
| 992 | return mStatusBarService; |
| 993 | } |
| 994 | } |
| 995 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 996 | StatusBarManagerInternal getStatusBarManagerInternal() { |
| 997 | synchronized (mServiceAquireLock) { |
| 998 | if (mStatusBarManagerInternal == null) { |
| 999 | mStatusBarManagerInternal = |
| 1000 | LocalServices.getService(StatusBarManagerInternal.class); |
| 1001 | } |
| 1002 | return mStatusBarManagerInternal; |
| 1003 | } |
| 1004 | } |
| 1005 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 1006 | /* |
| 1007 | * We always let the sensor be switched on by default except when |
| 1008 | * the user has explicitly disabled sensor based rotation or when the |
| 1009 | * screen is switched off. |
| 1010 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1011 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1012 | if (mSupportAutoRotation) { |
| 1013 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 1014 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 1015 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 1016 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 1017 | // If the application has explicitly requested to follow the |
| 1018 | // orientation, then we need to turn the sensor on. |
| 1019 | return true; |
| 1020 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1021 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1022 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 1023 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 1024 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 1025 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1026 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 1027 | // orientation management, |
| 1028 | return true; |
| 1029 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1030 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1031 | // If the setting for using the sensor by default is enabled, then |
| 1032 | // we will always leave it on. Note that the user could go to |
| 1033 | // a window that forces an orientation that does not use the |
| 1034 | // sensor and in theory we could turn it off... however, when next |
| 1035 | // turning it on we won't have a good value for the current |
| 1036 | // orientation for a little bit, which can cause orientation |
| 1037 | // changes to lag, so we'd like to keep it always on. (It will |
| 1038 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 1039 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1040 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1041 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1042 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1043 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1044 | /* |
| 1045 | * Various use cases for invoking this function |
| 1046 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1047 | * 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] | 1048 | * if not already enabled |
| 1049 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 1050 | * already enabled |
| 1051 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 1052 | * screen turning on and current app has nosensor based orientation, do nothing |
| 1053 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1054 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1055 | if (!mOrientationListener.canDetectOrientation()) { |
| 1056 | // If sensor is turned off or nonexistent for some reason |
| 1057 | return; |
| 1058 | } |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 1059 | // Could have been invoked due to screen turning on or off or |
| 1060 | // change of the currently visible window's orientation. |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1061 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 1062 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 1063 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled |
| 1064 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 1065 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1066 | boolean disable = true; |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 1067 | // Note: We postpone the rotating of the screen until the keyguard as well as the |
| 1068 | // window manager have reported a draw complete. |
| 1069 | if (mScreenOnEarly && mAwake && |
| 1070 | mKeyguardDrawComplete && mWindowManagerDrawComplete) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1071 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1072 | disable = false; |
| 1073 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1074 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1075 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1076 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1077 | mOrientationSensorEnabled = true; |
| 1078 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1079 | } |
| 1080 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1081 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1082 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1083 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1084 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1085 | mOrientationSensorEnabled = false; |
| 1086 | } |
| 1087 | } |
| 1088 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1089 | private void interceptBackKeyDown() { |
Nimrod Gileadi | 580135c | 2016-10-31 20:42:19 +0000 | [diff] [blame] | 1090 | MetricsLogger.count(mContext, "key_back_down", 1); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1091 | // Reset back key state for long press |
| 1092 | mBackKeyHandled = false; |
| 1093 | |
| 1094 | // Cancel multi-press detection timeout. |
| 1095 | if (hasPanicPressOnBackBehavior()) { |
| 1096 | if (mBackKeyPressCounter != 0 |
| 1097 | && mBackKeyPressCounter < PANIC_PRESS_BACK_COUNT) { |
| 1098 | mHandler.removeMessages(MSG_BACK_DELAYED_PRESS); |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | if (hasLongPressOnBackBehavior()) { |
| 1103 | Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS); |
| 1104 | msg.setAsynchronous(true); |
| 1105 | mHandler.sendMessageDelayed(msg, |
| 1106 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | // returns true if the key was handled and should not be passed to the user |
| 1111 | private boolean interceptBackKeyUp(KeyEvent event) { |
| 1112 | // Cache handled state |
| 1113 | boolean handled = mBackKeyHandled; |
| 1114 | |
| 1115 | if (hasPanicPressOnBackBehavior()) { |
| 1116 | // Check for back key panic press |
| 1117 | ++mBackKeyPressCounter; |
| 1118 | |
| 1119 | final long eventTime = event.getDownTime(); |
| 1120 | |
| 1121 | if (mBackKeyPressCounter <= PANIC_PRESS_BACK_COUNT) { |
| 1122 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 1123 | Message msg = mHandler.obtainMessage(MSG_BACK_DELAYED_PRESS, |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 1124 | mBackKeyPressCounter, 0, eventTime); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1125 | msg.setAsynchronous(true); |
| 1126 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getMultiPressTimeout()); |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | // Reset back long press state |
| 1131 | cancelPendingBackKeyAction(); |
| 1132 | |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 1133 | if (mHasFeatureWatch) { |
| 1134 | TelecomManager telecomManager = getTelecommService(); |
| 1135 | |
| 1136 | if (telecomManager != null) { |
| 1137 | if (telecomManager.isRinging()) { |
| 1138 | // Pressing back while there's a ringing incoming |
| 1139 | // call should silence the ringer. |
| 1140 | telecomManager.silenceRinger(); |
| 1141 | |
| 1142 | // It should not prevent navigating away |
| 1143 | return false; |
| 1144 | } else if ( |
| 1145 | (mIncallBackBehavior & Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 1146 | && telecomManager.isInCall()) { |
| 1147 | // Otherwise, if "Back button ends call" is enabled, |
| 1148 | // the Back button will hang up any current active call. |
| 1149 | return telecomManager.endCall(); |
| 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1154 | return handled; |
| 1155 | } |
| 1156 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1157 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 1158 | // Hold a wake lock until the power key is released. |
| 1159 | if (!mPowerKeyWakeLock.isHeld()) { |
| 1160 | mPowerKeyWakeLock.acquire(); |
| 1161 | } |
| 1162 | |
| 1163 | // Cancel multi-press detection timeout. |
| 1164 | if (mPowerKeyPressCounter != 0) { |
| 1165 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 1166 | } |
| 1167 | |
| 1168 | // Detect user pressing the power button in panic when an application has |
| 1169 | // taken over the whole screen. |
| 1170 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
Adrian Roos | 7aaa551 | 2016-07-12 15:27:24 -0700 | [diff] [blame] | 1171 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags), |
| 1172 | isNavBarEmpty(mLastSystemUiFlags)); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1173 | if (panic) { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 1174 | mHandler.post(mHiddenNavPanic); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | // Latch power key state to detect screenshot chord. |
| 1178 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 1179 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 1180 | mScreenshotChordPowerKeyTriggered = true; |
| 1181 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 1182 | interceptScreenshotChord(); |
| 1183 | } |
| 1184 | |
| 1185 | // Stop ringing or end call if configured to do so when power is pressed. |
| 1186 | TelecomManager telecomManager = getTelecommService(); |
| 1187 | boolean hungUp = false; |
| 1188 | if (telecomManager != null) { |
| 1189 | if (telecomManager.isRinging()) { |
| 1190 | // Pressing Power while there's a ringing incoming |
| 1191 | // call should silence the ringer. |
| 1192 | telecomManager.silenceRinger(); |
| 1193 | } else if ((mIncallPowerBehavior |
| 1194 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 1195 | && telecomManager.isInCall() && interactive) { |
| 1196 | // Otherwise, if "Power button ends call" is enabled, |
| 1197 | // the Power button will hang up any current active call. |
| 1198 | hungUp = telecomManager.endCall(); |
| 1199 | } |
| 1200 | } |
| 1201 | |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1202 | GestureLauncherService gestureService = LocalServices.getService( |
| 1203 | GestureLauncherService.class); |
| 1204 | boolean gesturedServiceIntercepted = false; |
| 1205 | if (gestureService != null) { |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 1206 | gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive, |
| 1207 | mTmpBoolean); |
| 1208 | if (mTmpBoolean.value && mGoingToSleep) { |
| 1209 | mCameraGestureTriggeredDuringGoingToSleep = true; |
| 1210 | } |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1213 | // If the power key has still not yet been handled, then detect short |
| 1214 | // press, long press, or multi press and decide what to do. |
| 1215 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1216 | || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1217 | if (!mPowerKeyHandled) { |
| 1218 | if (interactive) { |
| 1219 | // When interactive, we're already awake. |
| 1220 | // Wait for a long press or for the button to be released to decide what to do. |
| 1221 | if (hasLongPressOnPowerBehavior()) { |
| 1222 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 1223 | msg.setAsynchronous(true); |
| 1224 | mHandler.sendMessageDelayed(msg, |
| 1225 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 1226 | } |
| 1227 | } else { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1228 | wakeUpFromPowerKey(event.getDownTime()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1229 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1230 | if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { |
| 1231 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 1232 | msg.setAsynchronous(true); |
| 1233 | mHandler.sendMessageDelayed(msg, |
| 1234 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1235 | mBeganFromNonInteractive = true; |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1236 | } else { |
| 1237 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1238 | |
| 1239 | if (maxCount <= 1) { |
| 1240 | mPowerKeyHandled = true; |
| 1241 | } else { |
| 1242 | mBeganFromNonInteractive = true; |
| 1243 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1244 | } |
| 1245 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1246 | } |
| 1247 | } |
| 1248 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1249 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 1250 | final boolean handled = canceled || mPowerKeyHandled; |
| 1251 | mScreenshotChordPowerKeyTriggered = false; |
| 1252 | cancelPendingScreenshotChordAction(); |
| 1253 | cancelPendingPowerKeyAction(); |
| 1254 | |
| 1255 | if (!handled) { |
| 1256 | // Figure out how to handle the key now that it has been released. |
| 1257 | mPowerKeyPressCounter += 1; |
| 1258 | |
| 1259 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1260 | final long eventTime = event.getDownTime(); |
| 1261 | if (mPowerKeyPressCounter < maxCount) { |
| 1262 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 1263 | // Continue holding the wake lock. |
| 1264 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 1265 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 1266 | msg.setAsynchronous(true); |
| 1267 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout()); |
| 1268 | return; |
| 1269 | } |
| 1270 | |
| 1271 | // No other actions. Handle it immediately. |
| 1272 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1273 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1274 | |
| 1275 | // Done. Reset our state. |
| 1276 | finishPowerKeyPress(); |
| 1277 | } |
| 1278 | |
| 1279 | private void finishPowerKeyPress() { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1280 | mBeganFromNonInteractive = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1281 | mPowerKeyPressCounter = 0; |
| 1282 | if (mPowerKeyWakeLock.isHeld()) { |
| 1283 | mPowerKeyWakeLock.release(); |
| 1284 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1287 | private void finishBackKeyPress() { |
| 1288 | mBackKeyPressCounter = 0; |
| 1289 | } |
| 1290 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1291 | private void cancelPendingPowerKeyAction() { |
| 1292 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1293 | mPowerKeyHandled = true; |
| 1294 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1295 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1298 | private void cancelPendingBackKeyAction() { |
| 1299 | if (!mBackKeyHandled) { |
| 1300 | mBackKeyHandled = true; |
| 1301 | mHandler.removeMessages(MSG_BACK_LONG_PRESS); |
| 1302 | } |
| 1303 | } |
| 1304 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1305 | private void backMultiPressAction(long eventTime, int count) { |
| 1306 | if (count >= PANIC_PRESS_BACK_COUNT) { |
| 1307 | switch (mPanicPressOnBackBehavior) { |
| 1308 | case PANIC_PRESS_BACK_NOTHING: |
| 1309 | break; |
| 1310 | case PANIC_PRESS_BACK_HOME: |
| 1311 | launchHomeFromHotKey(); |
| 1312 | break; |
| 1313 | } |
| 1314 | } |
| 1315 | } |
| 1316 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1317 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 1318 | if (mScreenOnEarly && !mScreenOnFully) { |
| 1319 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 1320 | + "already in the process of turning the screen on."); |
| 1321 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 1322 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1323 | |
| 1324 | if (count == 2) { |
| 1325 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 1326 | } else if (count == 3) { |
| 1327 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1328 | } else if (interactive && !mBeganFromNonInteractive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1329 | switch (mShortPressOnPowerBehavior) { |
| 1330 | case SHORT_PRESS_POWER_NOTHING: |
| 1331 | break; |
| 1332 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 1333 | mPowerManager.goToSleep(eventTime, |
| 1334 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1335 | break; |
| 1336 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 1337 | mPowerManager.goToSleep(eventTime, |
| 1338 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1339 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1340 | break; |
| 1341 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 1342 | mPowerManager.goToSleep(eventTime, |
| 1343 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1344 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1345 | launchHomeFromHotKey(); |
| 1346 | break; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1347 | case SHORT_PRESS_POWER_GO_HOME: |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 1348 | launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/); |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1349 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1350 | } |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 1355 | switch (behavior) { |
| 1356 | case MULTI_PRESS_POWER_NOTHING: |
| 1357 | break; |
| 1358 | case MULTI_PRESS_POWER_THEATER_MODE: |
Bryce Lee | 3ae447e | 2015-06-30 12:31:41 -0700 | [diff] [blame] | 1359 | if (!isUserSetupComplete()) { |
| 1360 | Slog.i(TAG, "Ignoring toggling theater mode - device not setup."); |
| 1361 | break; |
| 1362 | } |
| 1363 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1364 | if (isTheaterModeEnabled()) { |
| 1365 | Slog.i(TAG, "Toggling theater mode off."); |
| 1366 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1367 | Settings.Global.THEATER_MODE_ON, 0); |
| 1368 | if (!interactive) { |
| 1369 | wakeUpFromPowerKey(eventTime); |
| 1370 | } |
| 1371 | } else { |
| 1372 | Slog.i(TAG, "Toggling theater mode on."); |
| 1373 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1374 | Settings.Global.THEATER_MODE_ON, 1); |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1375 | |
| 1376 | if (mGoToSleepOnButtonPressTheaterMode && interactive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1377 | mPowerManager.goToSleep(eventTime, |
| 1378 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1379 | } |
| 1380 | } |
| 1381 | break; |
| 1382 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
Jeff Brown | 7b5be5e | 2014-11-12 18:45:31 -0800 | [diff] [blame] | 1383 | Slog.i(TAG, "Starting brightness boost."); |
| 1384 | if (!interactive) { |
| 1385 | wakeUpFromPowerKey(eventTime); |
| 1386 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1387 | mPowerManager.boostScreenBrightness(eventTime); |
| 1388 | break; |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | private int getMaxMultiPressPowerCount() { |
| 1393 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1394 | return 3; |
| 1395 | } |
| 1396 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1397 | return 2; |
| 1398 | } |
| 1399 | return 1; |
| 1400 | } |
| 1401 | |
| 1402 | private void powerLongPress() { |
| 1403 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1404 | switch (behavior) { |
| 1405 | case LONG_PRESS_POWER_NOTHING: |
| 1406 | break; |
| 1407 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1408 | mPowerKeyHandled = true; |
| 1409 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1410 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 1411 | } |
| 1412 | showGlobalActionsInternal(); |
| 1413 | break; |
| 1414 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1415 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1416 | mPowerKeyHandled = true; |
| 1417 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1418 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1419 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1420 | break; |
| 1421 | } |
| 1422 | } |
| 1423 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1424 | private void backLongPress() { |
| 1425 | mBackKeyHandled = true; |
| 1426 | |
| 1427 | switch (mLongPressOnBackBehavior) { |
| 1428 | case LONG_PRESS_BACK_NOTHING: |
| 1429 | break; |
| 1430 | case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST: |
Nancy Zheng | 0d85ee2 | 2016-09-29 09:15:56 -0700 | [diff] [blame] | 1431 | final boolean keyguardActive = mKeyguardDelegate == null |
| 1432 | ? false |
| 1433 | : mKeyguardDelegate.isShowing(); |
| 1434 | if (!keyguardActive) { |
| 1435 | Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST); |
| 1436 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
| 1437 | } |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1438 | break; |
| 1439 | } |
| 1440 | } |
| 1441 | |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 1442 | private void disposeInputConsumer(InputConsumer inputConsumer) { |
| 1443 | if (inputConsumer != null) { |
| 1444 | inputConsumer.dismiss(); |
| 1445 | } |
| 1446 | } |
| 1447 | |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1448 | private void sleepPress(long eventTime) { |
| 1449 | if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) { |
| 1450 | launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | private void sleepRelease(long eventTime) { |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1455 | switch (mShortPressOnSleepBehavior) { |
| 1456 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1457 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1458 | Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)"); |
| 1459 | mPowerManager.goToSleep(eventTime, |
| 1460 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1461 | break; |
| 1462 | } |
| 1463 | } |
| 1464 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1465 | private int getResolvedLongPressOnPowerBehavior() { |
| 1466 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1467 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1468 | } |
| 1469 | return mLongPressOnPowerBehavior; |
| 1470 | } |
| 1471 | |
| 1472 | private boolean hasLongPressOnPowerBehavior() { |
| 1473 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1476 | private boolean hasLongPressOnBackBehavior() { |
| 1477 | return mLongPressOnBackBehavior != LONG_PRESS_BACK_NOTHING; |
| 1478 | } |
| 1479 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1480 | private boolean hasPanicPressOnBackBehavior() { |
| 1481 | return mPanicPressOnBackBehavior != PANIC_PRESS_BACK_NOTHING; |
| 1482 | } |
| 1483 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1484 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1485 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1486 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
| 1487 | && !mScreenshotChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1488 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1489 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1490 | && now <= mScreenshotChordPowerKeyTime |
| 1491 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1492 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1493 | cancelPendingPowerKeyAction(); |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1494 | mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN); |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1495 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1496 | } |
| 1497 | } |
| 1498 | } |
| 1499 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1500 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1501 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1502 | // Double the time it takes to take a screenshot from the keyguard |
| 1503 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1504 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1505 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1506 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1509 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1510 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1513 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1514 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1515 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1516 | mEndCallKeyHandled = true; |
| 1517 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1518 | performAuditoryFeedbackForAccessibilityIfNeed(); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 1519 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1520 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1521 | } |
| 1522 | }; |
| 1523 | |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1524 | private class ScreenshotRunnable implements Runnable { |
| 1525 | private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN; |
| 1526 | |
| 1527 | public void setScreenshotType(int screenshotType) { |
| 1528 | mScreenshotType = screenshotType; |
| 1529 | } |
| 1530 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1531 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1532 | public void run() { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1533 | takeScreenshot(mScreenshotType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1534 | } |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1538 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1539 | @Override |
| 1540 | public void showGlobalActions() { |
| 1541 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1542 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1543 | } |
| 1544 | |
| 1545 | void showGlobalActionsInternal() { |
| 1546 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1547 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1548 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1549 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1550 | final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1551 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1552 | if (keyguardShowing) { |
| 1553 | // since it took two seconds of long press to bring this up, |
| 1554 | // 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] | 1555 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1560 | return Settings.Global.getInt( |
| 1561 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1562 | } |
| 1563 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1564 | boolean isUserSetupComplete() { |
| 1565 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1566 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 1567 | } |
| 1568 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1569 | private void handleShortPressOnHome() { |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1570 | // 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] | 1571 | final HdmiControl hdmiControl = getHdmiControl(); |
| 1572 | if (hdmiControl != null) { |
| 1573 | hdmiControl.turnOnTv(); |
| 1574 | } |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1575 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1576 | // If there's a dream running then use home to escape the dream |
| 1577 | // but don't actually go home. |
| 1578 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1579 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1580 | return; |
| 1581 | } |
| 1582 | |
| 1583 | // Go home! |
| 1584 | launchHomeFromHotKey(); |
| 1585 | } |
| 1586 | |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1587 | /** |
| 1588 | * Creates an accessor to HDMI control service that performs the operation of |
| 1589 | * turning on TV (optional) and switching input to us. If HDMI control service |
| 1590 | * 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] | 1591 | * @return {@link HdmiControl} instance if available, null otherwise. |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1592 | */ |
| 1593 | private HdmiControl getHdmiControl() { |
| 1594 | if (null == mHdmiControl) { |
Andrii Kulian | eb4a794 | 2016-12-21 12:18:05 -0800 | [diff] [blame] | 1595 | if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) { |
| 1596 | return null; |
| 1597 | } |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1598 | HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService( |
| 1599 | Context.HDMI_CONTROL_SERVICE); |
| 1600 | HdmiPlaybackClient client = null; |
| 1601 | if (manager != null) { |
| 1602 | client = manager.getPlaybackClient(); |
| 1603 | } |
| 1604 | mHdmiControl = new HdmiControl(client); |
| 1605 | } |
| 1606 | return mHdmiControl; |
| 1607 | } |
| 1608 | |
| 1609 | private static class HdmiControl { |
| 1610 | private final HdmiPlaybackClient mClient; |
| 1611 | |
| 1612 | private HdmiControl(HdmiPlaybackClient client) { |
| 1613 | mClient = client; |
| 1614 | } |
| 1615 | |
| 1616 | public void turnOnTv() { |
| 1617 | if (mClient == null) { |
| 1618 | return; |
| 1619 | } |
| 1620 | mClient.oneTouchPlay(new OneTouchPlayCallback() { |
| 1621 | @Override |
| 1622 | public void onComplete(int result) { |
| 1623 | if (result != HdmiControlManager.RESULT_SUCCESS) { |
| 1624 | Log.w(TAG, "One touch play failed: " + result); |
| 1625 | } |
| 1626 | } |
| 1627 | }); |
| 1628 | } |
| 1629 | } |
| 1630 | |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 1631 | private void handleLongPressOnHome(int deviceId) { |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1632 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) { |
| 1633 | return; |
| 1634 | } |
| 1635 | mHomeConsumed = true; |
| 1636 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1637 | |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1638 | switch (mLongPressOnHomeBehavior) { |
| 1639 | case LONG_PRESS_HOME_RECENT_SYSTEM_UI: |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1640 | toggleRecentApps(); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1641 | break; |
| 1642 | case LONG_PRESS_HOME_ASSIST: |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 1643 | launchAssistAction(null, deviceId); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1644 | break; |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1645 | default: |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 1646 | Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1647 | break; |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1648 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1649 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1650 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1651 | private void handleDoubleTapOnHome() { |
| 1652 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1653 | mHomeConsumed = true; |
| 1654 | toggleRecentApps(); |
| 1655 | } |
| 1656 | } |
| 1657 | |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 1658 | private void showTvPictureInPictureMenu(KeyEvent event) { |
| 1659 | if (DEBUG_INPUT) Log.d(TAG, "showTvPictureInPictureMenu event=" + event); |
| 1660 | mHandler.removeMessages(MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU); |
| 1661 | Message msg = mHandler.obtainMessage(MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1662 | msg.setAsynchronous(true); |
| 1663 | msg.sendToTarget(); |
| 1664 | } |
| 1665 | |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 1666 | private void showTvPictureInPictureMenuInternal() { |
| 1667 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 1668 | if (statusbar != null) { |
| 1669 | statusbar.showTvPictureInPictureMenu(); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1670 | } |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1671 | } |
| 1672 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1673 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1674 | @Override |
| 1675 | public void run() { |
| 1676 | if (mHomeDoubleTapPending) { |
| 1677 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1678 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1679 | } |
| 1680 | } |
| 1681 | }; |
| 1682 | |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1683 | private boolean isRoundWindow() { |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1684 | return mContext.getResources().getConfiguration().isScreenRound(); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1685 | } |
| 1686 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1687 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1688 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1689 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1690 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1691 | mContext = context; |
| 1692 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1693 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1694 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 1695 | mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 1696 | mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1697 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1698 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1699 | mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 1700 | mHasFeatureWatch = mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1701 | |
| 1702 | // Init display burn-in protection |
| 1703 | boolean burnInProtectionEnabled = context.getResources().getBoolean( |
| 1704 | com.android.internal.R.bool.config_enableBurnInProtection); |
| 1705 | // Allow a system property to override this. Used by developer settings. |
| 1706 | boolean burnInProtectionDevMode = |
| 1707 | SystemProperties.getBoolean("persist.debug.force_burn_in", false); |
| 1708 | if (burnInProtectionEnabled || burnInProtectionDevMode) { |
| 1709 | final int minHorizontal; |
| 1710 | final int maxHorizontal; |
| 1711 | final int minVertical; |
| 1712 | final int maxVertical; |
| 1713 | final int maxRadius; |
| 1714 | if (burnInProtectionDevMode) { |
| 1715 | minHorizontal = -8; |
| 1716 | maxHorizontal = 8; |
| 1717 | minVertical = -8; |
| 1718 | maxVertical = -4; |
| 1719 | maxRadius = (isRoundWindow()) ? 6 : -1; |
| 1720 | } else { |
| 1721 | Resources resources = context.getResources(); |
| 1722 | minHorizontal = resources.getInteger( |
| 1723 | com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); |
| 1724 | maxHorizontal = resources.getInteger( |
| 1725 | com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); |
| 1726 | minVertical = resources.getInteger( |
| 1727 | com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); |
| 1728 | maxVertical = resources.getInteger( |
| 1729 | com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); |
| 1730 | maxRadius = resources.getInteger( |
| 1731 | com.android.internal.R.integer.config_burnInProtectionMaxRadius); |
| 1732 | } |
| 1733 | mBurnInProtectionHelper = new BurnInProtectionHelper( |
| 1734 | context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 1735 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1736 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1737 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1738 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1739 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1740 | try { |
| 1741 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 1742 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1743 | mSettingsObserver = new SettingsObserver(mHandler); |
| 1744 | mSettingsObserver.observe(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1745 | mShortcutManager = new ShortcutManager(context); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 1746 | mUiMode = context.getResources().getInteger( |
| 1747 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1748 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1749 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 1750 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1751 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 1752 | mEnableCarDockHomeCapture = context.getResources().getBoolean( |
| 1753 | com.android.internal.R.bool.config_enableCarDockHomeLaunch); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1754 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1755 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 1756 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1757 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1758 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1759 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1760 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1761 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1762 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1763 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1764 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1765 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1766 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1767 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1768 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1769 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1770 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1771 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1772 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1773 | mCarDockRotation = readRotation( |
| 1774 | com.android.internal.R.integer.config_carDockRotation); |
| 1775 | mDeskDockRotation = readRotation( |
| 1776 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1777 | mUndockedHdmiRotation = readRotation( |
| 1778 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1779 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1780 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1781 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1782 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1783 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1784 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1785 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1786 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 1787 | mLidControlsScreenLock = mContext.getResources().getBoolean( |
| 1788 | com.android.internal.R.bool.config_lidControlsScreenLock); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1789 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1790 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1791 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1792 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1793 | |
| 1794 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 1795 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 1796 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 1797 | || mContext.getResources().getBoolean( |
| 1798 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 1799 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 1800 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 1801 | mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( |
| 1802 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1803 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 1804 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 1805 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 1806 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 1807 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 1808 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 1809 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1810 | mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( |
| 1811 | com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); |
| 1812 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1813 | mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( |
| 1814 | com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); |
| 1815 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1816 | mLongPressOnBackBehavior = mContext.getResources().getInteger( |
| 1817 | com.android.internal.R.integer.config_longPressOnBackBehavior); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1818 | mPanicPressOnBackBehavior = mContext.getResources().getInteger( |
| 1819 | com.android.internal.R.integer.config_backPanicBehavior); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1820 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1821 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1822 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 1823 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1824 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 1825 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1826 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 1827 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1828 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1829 | mShortPressOnSleepBehavior = mContext.getResources().getInteger( |
| 1830 | com.android.internal.R.integer.config_shortPressOnSleepBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1831 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 1832 | mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 1833 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1834 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1835 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1836 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1837 | Context.ACCESSIBILITY_SERVICE); |
| 1838 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1839 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1840 | IntentFilter filter = new IntentFilter(); |
| 1841 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1842 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1843 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1844 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1845 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1846 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1847 | if (intent != null) { |
| 1848 | // Retrieve current sticky dock event broadcast. |
| 1849 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1850 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1851 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1852 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1853 | // register for dream-related broadcasts |
| 1854 | filter = new IntentFilter(); |
| 1855 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1856 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1857 | context.registerReceiver(mDreamReceiver, filter); |
| 1858 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1859 | // register for multiuser-relevant broadcasts |
| 1860 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1861 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1862 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1863 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1864 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1865 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1866 | @Override |
| 1867 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1868 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1869 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1870 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1871 | } |
| 1872 | @Override |
| 1873 | public void onSwipeFromBottom() { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 1874 | if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_BOTTOM) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1875 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1876 | } |
| 1877 | } |
| 1878 | @Override |
| 1879 | public void onSwipeFromRight() { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 1880 | if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_RIGHT) { |
| 1881 | requestTransientBars(mNavigationBar); |
| 1882 | } |
| 1883 | } |
| 1884 | @Override |
| 1885 | public void onSwipeFromLeft() { |
| 1886 | if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_LEFT) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1887 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1888 | } |
| 1889 | } |
| 1890 | @Override |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1891 | public void onFling(int duration) { |
| 1892 | if (mPowerManagerInternal != null) { |
| 1893 | mPowerManagerInternal.powerHint( |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 1894 | PowerHint.INTERACTION, duration); |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1895 | } |
| 1896 | } |
| 1897 | @Override |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1898 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1899 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1900 | } |
Adrian Roos | 3595be4 | 2015-03-05 16:31:15 +0100 | [diff] [blame] | 1901 | @Override |
| 1902 | public void onDown() { |
| 1903 | mOrientationListener.onTouchStart(); |
| 1904 | } |
| 1905 | @Override |
| 1906 | public void onUpOrCancel() { |
| 1907 | mOrientationListener.onTouchEnd(); |
| 1908 | } |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 1909 | @Override |
| 1910 | public void onMouseHoverAtTop() { |
| 1911 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1912 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 1913 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS; |
| 1914 | mHandler.sendMessageDelayed(msg, 500); |
| 1915 | } |
| 1916 | @Override |
| 1917 | public void onMouseHoverAtBottom() { |
| 1918 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1919 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 1920 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION; |
| 1921 | mHandler.sendMessageDelayed(msg, 500); |
| 1922 | } |
| 1923 | @Override |
| 1924 | public void onMouseLeaveFromEdge() { |
| 1925 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1926 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1927 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1928 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1929 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1930 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1931 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1932 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1933 | com.android.internal.R.array.config_longPressVibePattern); |
| 1934 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1935 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1936 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1937 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1938 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1939 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1940 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1941 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1942 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1943 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1944 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1945 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 1946 | mContextClickVibePattern = getLongIntArray(mContext.getResources(), |
| 1947 | com.android.internal.R.array.config_contextClickVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1948 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1949 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1950 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 1951 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1952 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1953 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1954 | // Controls rotation and the like. |
| 1955 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1956 | |
| 1957 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1958 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 1959 | startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 1960 | finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1961 | } |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 1962 | |
| 1963 | mWindowManagerInternal.registerAppTransitionListener( |
| 1964 | mStatusBarController.getAppTransitionListener()); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1965 | mWindowManagerInternal.registerAppTransitionListener(new AppTransitionListener() { |
| 1966 | @Override |
| 1967 | public int onAppTransitionStartingLocked(int transit, IBinder openToken, |
| 1968 | IBinder closeToken, |
| 1969 | Animation openAnimation, Animation closeAnimation) { |
| 1970 | return handleStartTransitionForKeyguardLw(transit, openAnimation); |
| 1971 | } |
| 1972 | |
| 1973 | @Override |
| 1974 | public void onAppTransitionCancelledLocked(int transit) { |
| 1975 | handleStartTransitionForKeyguardLw(transit, null /* transit */); |
| 1976 | } |
| 1977 | }); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1980 | /** |
| 1981 | * Read values from config.xml that may be overridden depending on |
| 1982 | * the configuration of the device. |
| 1983 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1984 | */ |
| 1985 | private void readConfigurationDependentBehaviors() { |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1986 | final Resources res = mContext.getResources(); |
| 1987 | |
| 1988 | mLongPressOnHomeBehavior = res.getInteger( |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1989 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1990 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1991 | mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) { |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1992 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1993 | } |
| 1994 | |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1995 | mDoubleTapOnHomeBehavior = res.getInteger( |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1996 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1997 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1998 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1999 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 2000 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 2001 | |
| 2002 | mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING; |
| 2003 | if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) { |
| 2004 | mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE; |
| 2005 | } |
Yorke Lee | 2e4b732 | 2016-03-02 17:33:06 -0800 | [diff] [blame] | 2006 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 2007 | mNavBarOpacityMode = res.getInteger( |
| 2008 | com.android.internal.R.integer.config_navBarOpacityMode); |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 2011 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 2012 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 2013 | // This method might be called before the policy has been fully initialized |
| 2014 | // or for other displays we don't care about. |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 2015 | // TODO(multi-display): Define policy for secondary displays. |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 2016 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 2017 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2018 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2019 | mDisplay = display; |
| 2020 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2021 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2022 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2023 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 2024 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2025 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2026 | mLandscapeRotation = Surface.ROTATION_0; |
| 2027 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2028 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2029 | mPortraitRotation = Surface.ROTATION_90; |
| 2030 | mUpsideDownRotation = Surface.ROTATION_270; |
| 2031 | } else { |
| 2032 | mPortraitRotation = Surface.ROTATION_270; |
| 2033 | mUpsideDownRotation = Surface.ROTATION_90; |
| 2034 | } |
| 2035 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 2036 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2037 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2038 | mPortraitRotation = Surface.ROTATION_0; |
| 2039 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2040 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2041 | mLandscapeRotation = Surface.ROTATION_270; |
| 2042 | mSeascapeRotation = Surface.ROTATION_90; |
| 2043 | } else { |
| 2044 | mLandscapeRotation = Surface.ROTATION_90; |
| 2045 | mSeascapeRotation = Surface.ROTATION_270; |
| 2046 | } |
| 2047 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 2048 | |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2049 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 2050 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2051 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2052 | |
Devin Kim | d7b12b4 | 2014-05-05 14:34:58 -0700 | [diff] [blame] | 2053 | // Allow the navigation bar to move on non-square small devices (phones). |
| 2054 | mNavigationBarCanMove = width != height && shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 2055 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2056 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2057 | |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2058 | // Allow a system property to override this. Used by the emulator. |
| 2059 | // See also hasNavigationBar(). |
| 2060 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 2061 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2062 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2063 | } else if ("0".equals(navBarOverride)) { |
| 2064 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 2065 | } |
| 2066 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 2067 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 2068 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 2069 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 2070 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 2071 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 2072 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 2073 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 2074 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2075 | |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 2076 | // For demo purposes, allow the rotation of the remote display to be controlled. |
| 2077 | // By default, remote display locks rotation to landscape. |
| 2078 | if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { |
| 2079 | mDemoRotation = mPortraitRotation; |
| 2080 | } else { |
| 2081 | mDemoRotation = mLandscapeRotation; |
| 2082 | } |
| 2083 | mDemoRotationLock = SystemProperties.getBoolean( |
| 2084 | "persist.demo.rotationlock", false); |
| 2085 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2086 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 2087 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 2088 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 2089 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 2090 | // For debug purposes the next line turns this feature off with: |
| 2091 | // $ adb shell setprop config.override_forced_orient true |
| 2092 | // $ adb shell wm size reset |
| 2093 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 2094 | } |
| 2095 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2096 | /** |
| 2097 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 2098 | * navigation bar and touch exploration is not enabled |
| 2099 | */ |
| 2100 | private boolean canHideNavigationBar() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 2101 | return mHasNavigationBar; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2102 | } |
| 2103 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2104 | @Override |
| 2105 | public boolean isDefaultOrientationForced() { |
| 2106 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2109 | @Override |
| 2110 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 2111 | // TODO(multi-display): Define policy for secondary displays. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2112 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 2113 | mOverscanLeft = left; |
| 2114 | mOverscanTop = top; |
| 2115 | mOverscanRight = right; |
| 2116 | mOverscanBottom = bottom; |
| 2117 | } |
| 2118 | } |
| 2119 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2120 | public void updateSettings() { |
| 2121 | ContentResolver resolver = mContext.getContentResolver(); |
| 2122 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2123 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2124 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 2125 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2126 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 2127 | UserHandle.USER_CURRENT); |
| 2128 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 2129 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2130 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 2131 | UserHandle.USER_CURRENT); |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 2132 | mIncallBackBehavior = Settings.Secure.getIntForUser(resolver, |
| 2133 | Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR, |
| 2134 | Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_DEFAULT, |
| 2135 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 2136 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 2137 | // Configure wake gesture. |
| 2138 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 2139 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 2140 | UserHandle.USER_CURRENT) != 0; |
| 2141 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 2142 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 2143 | updateWakeGestureListenerLp(); |
| 2144 | } |
| 2145 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 2146 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2147 | int userRotation = Settings.System.getIntForUser(resolver, |
| 2148 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 2149 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 2150 | if (mUserRotation != userRotation) { |
| 2151 | mUserRotation = userRotation; |
| 2152 | updateRotation = true; |
| 2153 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2154 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 2155 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 2156 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 2157 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 2158 | if (mUserRotationMode != userRotationMode) { |
| 2159 | mUserRotationMode = userRotationMode; |
| 2160 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2161 | updateOrientationListenerLp(); |
| 2162 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 2163 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2164 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2165 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 2166 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2167 | if (mPointerLocationMode != pointerLocation) { |
| 2168 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2169 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 2170 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2171 | } |
| 2172 | } |
| 2173 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2174 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 2175 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 2176 | String imId = Settings.Secure.getStringForUser(resolver, |
| 2177 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2178 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 2179 | if (mHasSoftInput != hasSoftInput) { |
| 2180 | mHasSoftInput = hasSoftInput; |
| 2181 | updateRotation = true; |
| 2182 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2183 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 2184 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 2185 | } |
tiger_huang | cc6366d | 2015-06-29 17:17:30 +0800 | [diff] [blame] | 2186 | } |
| 2187 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 2188 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2189 | } |
| 2190 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 2191 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2192 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 2195 | private void updateWakeGestureListenerLp() { |
| 2196 | if (shouldEnableWakeGestureLp()) { |
| 2197 | mWakeGestureListener.requestWakeUpTrigger(); |
| 2198 | } else { |
| 2199 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 2200 | } |
| 2201 | } |
| 2202 | |
| 2203 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 2204 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 2205 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 2206 | && mWakeGestureListener.isSupported(); |
| 2207 | } |
| 2208 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2209 | private void enablePointerLocation() { |
| 2210 | if (mPointerLocationView == null) { |
| 2211 | mPointerLocationView = new PointerLocationView(mContext); |
| 2212 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2213 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 2214 | WindowManager.LayoutParams.MATCH_PARENT, |
| 2215 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 2216 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 2217 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 2218 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 2219 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 2220 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 2221 | if (ActivityManager.isHighEndGfx()) { |
| 2222 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 2223 | lp.privateFlags |= |
| 2224 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 2225 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2226 | lp.format = PixelFormat.TRANSLUCENT; |
| 2227 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2228 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2229 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2230 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2231 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 2232 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2233 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2234 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2235 | |
| 2236 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2237 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 2238 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 2239 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2240 | wm.removeView(mPointerLocationView); |
| 2241 | mPointerLocationView = null; |
| 2242 | } |
| 2243 | } |
| 2244 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2245 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2246 | try { |
| 2247 | int rotation = mContext.getResources().getInteger(resID); |
| 2248 | switch (rotation) { |
| 2249 | case 0: |
| 2250 | return Surface.ROTATION_0; |
| 2251 | case 90: |
| 2252 | return Surface.ROTATION_90; |
| 2253 | case 180: |
| 2254 | return Surface.ROTATION_180; |
| 2255 | case 270: |
| 2256 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2257 | } |
| 2258 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2259 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2260 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2261 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2265 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2266 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2267 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2268 | |
| 2269 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 2270 | |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 2271 | if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) |
| 2272 | || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) |
| 2273 | || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { |
| 2274 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
| 2275 | } |
| 2276 | |
| 2277 | if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { |
| 2278 | // Window manager will make sure these are okay. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2279 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2280 | } |
| 2281 | String permission = null; |
| 2282 | switch (type) { |
| 2283 | case TYPE_TOAST: |
| 2284 | // XXX right now the app process has complete control over |
| 2285 | // this... should introduce a token to let the system |
| 2286 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2287 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2288 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2289 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2290 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 2291 | case TYPE_WALLPAPER: |
Wale Ogunwale | 5b6714c | 2016-11-01 20:54:46 -0700 | [diff] [blame] | 2292 | case TYPE_PRESENTATION: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2293 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2294 | case TYPE_VOICE_INTERACTION: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2295 | case TYPE_ACCESSIBILITY_OVERLAY: |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 2296 | case TYPE_QS_DIALOG: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 2297 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2298 | break; |
| 2299 | case TYPE_PHONE: |
| 2300 | case TYPE_PRIORITY_PHONE: |
| 2301 | case TYPE_SYSTEM_ALERT: |
| 2302 | case TYPE_SYSTEM_ERROR: |
| 2303 | case TYPE_SYSTEM_OVERLAY: |
| 2304 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2305 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2306 | break; |
| 2307 | default: |
| 2308 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 2309 | } |
| 2310 | if (permission != null) { |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 2311 | if (android.Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permission)) { |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2312 | final int callingUid = Binder.getCallingUid(); |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2313 | // system processes will be automatically allowed privilege to draw |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2314 | if (callingUid == Process.SYSTEM_UID) { |
| 2315 | return WindowManagerGlobal.ADD_OKAY; |
| 2316 | } |
| 2317 | |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2318 | // check if user has enabled this operation. SecurityException will be thrown if |
| 2319 | // this app has not been allowed by the user |
Svet Ganov | 03f2afc | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 2320 | final int mode = mAppOpsManager.checkOpNoThrow(outAppOp[0], callingUid, |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2321 | attrs.packageName); |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2322 | switch (mode) { |
| 2323 | case AppOpsManager.MODE_ALLOWED: |
| 2324 | case AppOpsManager.MODE_IGNORED: |
| 2325 | // although we return ADD_OKAY for MODE_IGNORED, the added window will |
| 2326 | // actually be hidden in WindowManagerService |
| 2327 | return WindowManagerGlobal.ADD_OKAY; |
| 2328 | case AppOpsManager.MODE_ERRORED: |
Svet Ganov | 03f2afc | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 2329 | try { |
| 2330 | ApplicationInfo appInfo = mContext.getPackageManager() |
| 2331 | .getApplicationInfo(attrs.packageName, |
| 2332 | UserHandle.getUserId(callingUid)); |
| 2333 | // Don't crash legacy apps |
| 2334 | if (appInfo.targetSdkVersion < Build.VERSION_CODES.M) { |
| 2335 | return WindowManagerGlobal.ADD_OKAY; |
| 2336 | } |
| 2337 | } catch (PackageManager.NameNotFoundException e) { |
| 2338 | /* ignore */ |
| 2339 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2340 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2341 | default: |
| 2342 | // in the default mode, we will make a decision here based on |
| 2343 | // checkCallingPermission() |
| 2344 | if (mContext.checkCallingPermission(permission) != |
| 2345 | PackageManager.PERMISSION_GRANTED) { |
| 2346 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
| 2347 | } else { |
| 2348 | return WindowManagerGlobal.ADD_OKAY; |
| 2349 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2350 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2351 | } |
| 2352 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2353 | if (mContext.checkCallingOrSelfPermission(permission) |
| 2354 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2355 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2356 | } |
| 2357 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2358 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2359 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2360 | |
| 2361 | @Override |
| 2362 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 2363 | |
| 2364 | // If this switch statement is modified, modify the comment in the declarations of |
| 2365 | // the type in {@link WindowManager.LayoutParams} as well. |
| 2366 | switch (attrs.type) { |
| 2367 | default: |
| 2368 | // These are the windows that by default are shown only to the user that created |
| 2369 | // them. If this needs to be overridden, set |
| 2370 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 2371 | // {@link WindowManager.LayoutParams}. Note that permission |
| 2372 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 2373 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 2374 | return true; |
| 2375 | } |
| 2376 | break; |
| 2377 | |
| 2378 | // These are the windows that by default are shown to all users. However, to |
| 2379 | // protect against spoofing, check permissions below. |
| 2380 | case TYPE_APPLICATION_STARTING: |
| 2381 | case TYPE_BOOT_PROGRESS: |
| 2382 | case TYPE_DISPLAY_OVERLAY: |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2383 | case TYPE_INPUT_CONSUMER: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2384 | case TYPE_KEYGUARD_DIALOG: |
| 2385 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2386 | case TYPE_NAVIGATION_BAR: |
| 2387 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2388 | case TYPE_PHONE: |
| 2389 | case TYPE_POINTER: |
| 2390 | case TYPE_PRIORITY_PHONE: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2391 | case TYPE_SEARCH_BAR: |
| 2392 | case TYPE_STATUS_BAR: |
| 2393 | case TYPE_STATUS_BAR_PANEL: |
| 2394 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 2395 | case TYPE_SYSTEM_DIALOG: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2396 | case TYPE_VOLUME_OVERLAY: |
Wale Ogunwale | 5b6714c | 2016-11-01 20:54:46 -0700 | [diff] [blame] | 2397 | case TYPE_PRESENTATION: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2398 | case TYPE_PRIVATE_PRESENTATION: |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2399 | case TYPE_DOCK_DIVIDER: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2400 | break; |
| 2401 | } |
| 2402 | |
| 2403 | // Check if third party app has set window to system window type. |
| 2404 | return mContext.checkCallingOrSelfPermission( |
| 2405 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 2406 | != PackageManager.PERMISSION_GRANTED; |
| 2407 | } |
| 2408 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2409 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2410 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 2411 | switch (attrs.type) { |
| 2412 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 2413 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2414 | // These types of windows can't receive input events. |
| 2415 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 2416 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 2417 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2418 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2419 | case TYPE_STATUS_BAR: |
| 2420 | |
| 2421 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 2422 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 2423 | // the keyguard as occluded wouldn't set these flags again. |
| 2424 | // See {@link #processKeyguardSetHiddenResultLw}. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2425 | if (mKeyguardOccluded) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2426 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 2427 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2428 | } |
| 2429 | break; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2430 | |
Muyuan Li | 36ca72c | 2016-08-06 20:24:06 -0700 | [diff] [blame] | 2431 | case TYPE_SCREENSHOT: |
| 2432 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 2433 | break; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2434 | |
| 2435 | case TYPE_TOAST: |
| 2436 | // While apps should use the dedicated toast APIs to add such windows |
| 2437 | // it possible legacy apps to add the window directly. Therefore, we |
| 2438 | // make windows added directly by the app behave as a toast as much |
| 2439 | // as possible in terms of timeout and animation. |
| 2440 | if (attrs.hideTimeoutMilliseconds < 0 |
| 2441 | || attrs.hideTimeoutMilliseconds > TOAST_WINDOW_TIMEOUT) { |
| 2442 | attrs.hideTimeoutMilliseconds = TOAST_WINDOW_TIMEOUT; |
| 2443 | } |
| 2444 | attrs.windowAnimations = com.android.internal.R.style.Animation_Toast; |
| 2445 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2446 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 2447 | |
| 2448 | if (attrs.type != TYPE_STATUS_BAR) { |
| 2449 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 2450 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2451 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2452 | |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2453 | if (ActivityManager.isHighEndGfx()) { |
| 2454 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
| 2455 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 2456 | } |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 2457 | final boolean forceWindowDrawsStatusBarBackground = |
| 2458 | (attrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) |
| 2459 | != 0; |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2460 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 2461 | || forceWindowDrawsStatusBarBackground |
| 2462 | && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT) { |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2463 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 2464 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2465 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2466 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2467 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2468 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 2469 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2470 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2471 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 2472 | private void readCameraLensCoverState() { |
| 2473 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 2474 | } |
| 2475 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2476 | private boolean isHidden(int accessibilityMode) { |
| 2477 | switch (accessibilityMode) { |
| 2478 | case 1: |
| 2479 | return mLidState == LID_CLOSED; |
| 2480 | case 2: |
| 2481 | return mLidState == LID_OPEN; |
| 2482 | default: |
| 2483 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2484 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2485 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2486 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2487 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2488 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2489 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 2490 | int navigationPresence) { |
| 2491 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 2492 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2493 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2494 | readLidState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2495 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2496 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 2497 | || (keyboardPresence == PRESENCE_INTERNAL |
| 2498 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2499 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2500 | if (!mHasSoftInput) { |
| 2501 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 2502 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2503 | } |
| 2504 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2505 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 2506 | || (navigationPresence == PRESENCE_INTERNAL |
| 2507 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2508 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2509 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2510 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2511 | |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2512 | @Override |
| 2513 | public void onConfigurationChanged() { |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 2514 | // TODO(multi-display): Define policy for secondary displays. |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2515 | final Resources res = mContext.getResources(); |
| 2516 | |
| 2517 | mStatusBarHeight = |
| 2518 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
| 2519 | |
| 2520 | // Height of the navigation bar when presented horizontally at bottom |
| 2521 | mNavigationBarHeightForRotationDefault[mPortraitRotation] = |
| 2522 | mNavigationBarHeightForRotationDefault[mUpsideDownRotation] = |
| 2523 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
| 2524 | mNavigationBarHeightForRotationDefault[mLandscapeRotation] = |
| 2525 | mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize( |
| 2526 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
| 2527 | |
| 2528 | // Width of the navigation bar when presented vertically along one side |
| 2529 | mNavigationBarWidthForRotationDefault[mPortraitRotation] = |
| 2530 | mNavigationBarWidthForRotationDefault[mUpsideDownRotation] = |
| 2531 | mNavigationBarWidthForRotationDefault[mLandscapeRotation] = |
| 2532 | mNavigationBarWidthForRotationDefault[mSeascapeRotation] = |
| 2533 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
| 2534 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2535 | if (ALTERNATE_CAR_MODE_NAV_SIZE) { |
| 2536 | // Height of the navigation bar when presented horizontally at bottom |
| 2537 | mNavigationBarHeightForRotationInCarMode[mPortraitRotation] = |
| 2538 | mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] = |
| 2539 | res.getDimensionPixelSize( |
| 2540 | com.android.internal.R.dimen.navigation_bar_height_car_mode); |
| 2541 | mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] = |
| 2542 | mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize( |
| 2543 | com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2544 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2545 | // Width of the navigation bar when presented vertically along one side |
| 2546 | mNavigationBarWidthForRotationInCarMode[mPortraitRotation] = |
| 2547 | mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] = |
| 2548 | mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] = |
| 2549 | mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] = |
| 2550 | res.getDimensionPixelSize( |
| 2551 | com.android.internal.R.dimen.navigation_bar_width_car_mode); |
| 2552 | } |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2555 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2556 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2557 | public int windowTypeToLayerLw(int type) { |
| 2558 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2559 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2560 | } |
| 2561 | switch (type) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2562 | case TYPE_WALLPAPER: |
| 2563 | // wallpaper is at the bottom, though the window manager may move it. |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 2564 | return 1; |
| 2565 | case TYPE_PRESENTATION: |
| 2566 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2567 | return 2; |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2568 | case TYPE_DOCK_DIVIDER: |
| 2569 | return 2; |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 2570 | case TYPE_QS_DIALOG: |
| 2571 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2572 | case TYPE_PHONE: |
| 2573 | return 3; |
| 2574 | case TYPE_SEARCH_BAR: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2575 | case TYPE_VOICE_INTERACTION_STARTING: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2576 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2577 | case TYPE_VOICE_INTERACTION: |
| 2578 | // voice interaction layer is almost immediately above apps. |
| 2579 | return 5; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2580 | case TYPE_INPUT_CONSUMER: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2581 | return 6; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2582 | case TYPE_SYSTEM_DIALOG: |
| 2583 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2584 | case TYPE_TOAST: |
| 2585 | // toasts and the plugged-in battery thing |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2586 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2587 | case TYPE_PRIORITY_PHONE: |
| 2588 | // SIM errors and unlock. Not sure if this really should be in a high layer. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2589 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2590 | case TYPE_DREAM: |
| 2591 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2592 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2593 | case TYPE_SYSTEM_ALERT: |
| 2594 | // like the ANR / app crashed dialogs |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2595 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2596 | case TYPE_INPUT_METHOD: |
| 2597 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2598 | return 12; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2599 | case TYPE_INPUT_METHOD_DIALOG: |
| 2600 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2601 | return 13; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2602 | case TYPE_STATUS_BAR_SUB_PANEL: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2603 | return 15; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2604 | case TYPE_STATUS_BAR: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2605 | return 16; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2606 | case TYPE_STATUS_BAR_PANEL: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2607 | return 17; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2608 | case TYPE_KEYGUARD_DIALOG: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2609 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2610 | case TYPE_VOLUME_OVERLAY: |
| 2611 | // the on-screen volume indicator and controller shown when the user |
| 2612 | // changes the device volume |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2613 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2614 | case TYPE_SYSTEM_OVERLAY: |
| 2615 | // the on-screen volume indicator and controller shown when the user |
| 2616 | // changes the device volume |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2617 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2618 | case TYPE_NAVIGATION_BAR: |
| 2619 | // the navigation bar, if available, shows atop most things |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2620 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2621 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2622 | // some panels (e.g. search) need to show on top of the navigation bar |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2623 | return 22; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2624 | case TYPE_SCREENSHOT: |
| 2625 | // screenshot selection layer shouldn't go above system error, but it should cover |
| 2626 | // navigation bars at the very least. |
| 2627 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2628 | case TYPE_SYSTEM_ERROR: |
| 2629 | // system-level error dialogs |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2630 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2631 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2632 | // used to highlight the magnified portion of a display |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2633 | return 25; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2634 | case TYPE_DISPLAY_OVERLAY: |
| 2635 | // used to simulate secondary display devices |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2636 | return 26; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2637 | case TYPE_DRAG: |
| 2638 | // the drag layer: input for drag-and-drop is associated with this window, |
| 2639 | // which sits above all other focusable windows |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2640 | return 27; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2641 | case TYPE_ACCESSIBILITY_OVERLAY: |
| 2642 | // overlay put by accessibility services to intercept user interaction |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2643 | return 28; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2644 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2645 | return 29; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2646 | case TYPE_BOOT_PROGRESS: |
| 2647 | return 30; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2648 | case TYPE_POINTER: |
| 2649 | // the (mouse) pointer layer |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2650 | return 31; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2651 | } |
| 2652 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2653 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2657 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2658 | public int subWindowTypeToLayerLw(int type) { |
| 2659 | switch (type) { |
| 2660 | case TYPE_APPLICATION_PANEL: |
| 2661 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 2662 | return APPLICATION_PANEL_SUBLAYER; |
| 2663 | case TYPE_APPLICATION_MEDIA: |
| 2664 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 2665 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 2666 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2667 | case TYPE_APPLICATION_SUB_PANEL: |
| 2668 | return APPLICATION_SUB_PANEL_SUBLAYER; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 2669 | case TYPE_APPLICATION_ABOVE_SUB_PANEL: |
| 2670 | return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2671 | } |
| 2672 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 2673 | return 0; |
| 2674 | } |
| 2675 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2676 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2677 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2678 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2679 | } |
| 2680 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2681 | private int getNavigationBarWidth(int rotation, int uiMode) { |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2682 | 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] | 2683 | return mNavigationBarWidthForRotationInCarMode[rotation]; |
| 2684 | } else { |
| 2685 | return mNavigationBarWidthForRotationDefault[rotation]; |
| 2686 | } |
| 2687 | } |
| 2688 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2689 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2690 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2691 | int displayId) { |
| 2692 | // TODO(multi-display): Support navigation bar on secondary displays. |
| 2693 | if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2694 | // For a basic navigation bar, when we are in landscape mode we place |
| 2695 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2696 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2697 | return fullWidth - getNavigationBarWidth(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2698 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2699 | } |
| 2700 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2701 | } |
| 2702 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2703 | private int getNavigationBarHeight(int rotation, int uiMode) { |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2704 | 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] | 2705 | return mNavigationBarHeightForRotationInCarMode[rotation]; |
| 2706 | } else { |
| 2707 | return mNavigationBarHeightForRotationDefault[rotation]; |
| 2708 | } |
| 2709 | } |
| 2710 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2711 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2712 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2713 | int displayId) { |
| 2714 | // TODO(multi-display): Support navigation bar on secondary displays. |
| 2715 | if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2716 | // For a basic navigation bar, when we are in portrait mode we place |
| 2717 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2718 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2719 | return fullHeight - getNavigationBarHeight(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2720 | } |
| 2721 | } |
| 2722 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2725 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2726 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2727 | int displayId) { |
| 2728 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode, displayId); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2729 | } |
| 2730 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2731 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2732 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2733 | int displayId) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2734 | // There is a separate status bar at the top of the display. We don't count that as part |
| 2735 | // 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] | 2736 | // we do want to exclude it since applications can't generally use that part |
| 2737 | // of the screen. |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2738 | // TODO(multi-display): Support status bars on secondary displays. |
| 2739 | if (displayId == Display.DEFAULT_DISPLAY) { |
| 2740 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation, uiMode, displayId) |
| 2741 | - mStatusBarHeight; |
| 2742 | } |
| 2743 | return fullHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2744 | } |
| 2745 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2746 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2747 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 2748 | return attrs.type == TYPE_STATUS_BAR; |
| 2749 | } |
| 2750 | |
| 2751 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2752 | public boolean canBeHiddenByKeyguardLw(WindowState win) { |
| 2753 | switch (win.getAttrs().type) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2754 | case TYPE_STATUS_BAR: |
| 2755 | case TYPE_NAVIGATION_BAR: |
| 2756 | case TYPE_WALLPAPER: |
| 2757 | case TYPE_DREAM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2758 | return false; |
| 2759 | default: |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 2760 | // Hide only windows below the keyguard host window. |
| 2761 | return windowTypeToLayerLw(win.getBaseType()) |
| 2762 | < windowTypeToLayerLw(TYPE_STATUS_BAR); |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2763 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2764 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2765 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2766 | private boolean shouldBeHiddenByKeyguard(WindowState win, WindowState imeTarget) { |
| 2767 | |
| 2768 | // Keyguard visibility of window from activities are determined over activity visibility. |
| 2769 | if (win.getAppToken() != null) { |
| 2770 | return false; |
| 2771 | } |
| 2772 | |
| 2773 | final LayoutParams attrs = win.getAttrs(); |
| 2774 | final boolean showImeOverKeyguard = imeTarget != null && imeTarget.isVisibleLw() && |
| 2775 | ((imeTarget.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0 |
| 2776 | || !canBeHiddenByKeyguardLw(imeTarget)); |
| 2777 | |
| 2778 | // Show IME over the keyguard if the target allows it |
| 2779 | boolean allowWhenLocked = (win.isInputMethodWindow() || imeTarget == this) |
| 2780 | && showImeOverKeyguard;; |
| 2781 | |
| 2782 | if (isKeyguardLocked() && isKeyguardOccluded()) { |
| 2783 | // Show SHOW_WHEN_LOCKED windows if Keyguard is occluded. |
| 2784 | allowWhenLocked |= (attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0 |
| 2785 | // Show error dialogs over apps that are shown on lockscreen |
| 2786 | || (attrs.privateFlags & PRIVATE_FLAG_SYSTEM_ERROR) != 0; |
| 2787 | } |
| 2788 | |
| 2789 | boolean keyguardLocked = isKeyguardLocked(); |
| 2790 | boolean hideDockDivider = attrs.type == TYPE_DOCK_DIVIDER |
| 2791 | && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID); |
| 2792 | return (keyguardLocked && !allowWhenLocked && win.getDisplayId() == Display.DEFAULT_DISPLAY) |
| 2793 | || hideDockDivider; |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 2794 | } |
| 2795 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2796 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2797 | @Override |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 2798 | public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme, |
| 2799 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 2800 | int logo, int windowFlags, Configuration overrideConfig) { |
| 2801 | if (!SHOW_SPLASH_SCREENS) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2802 | return null; |
| 2803 | } |
| 2804 | if (packageName == null) { |
| 2805 | return null; |
| 2806 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2807 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2808 | WindowManager wm = null; |
| 2809 | View view = null; |
| 2810 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2811 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2812 | Context context = mContext; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 2813 | if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen " + packageName |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2814 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 2815 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2816 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2817 | try { |
| 2818 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2819 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2820 | } catch (PackageManager.NameNotFoundException e) { |
| 2821 | // Ignore |
| 2822 | } |
| 2823 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2824 | |
Andrii Kulian | a8a9bc5 | 2016-10-14 11:00:13 -0700 | [diff] [blame] | 2825 | if (overrideConfig != null && !overrideConfig.equals(EMPTY)) { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 2826 | if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen: creating context based" |
| 2827 | + " on overrideConfig" + overrideConfig + " for splash screen"); |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2828 | final Context overrideContext = context.createConfigurationContext(overrideConfig); |
| 2829 | overrideContext.setTheme(theme); |
| 2830 | final TypedArray typedArray = overrideContext.obtainStyledAttributes( |
| 2831 | com.android.internal.R.styleable.Window); |
| 2832 | final int resId = typedArray.getResourceId(R.styleable.Window_windowBackground, 0); |
| 2833 | if (resId != 0 && overrideContext.getDrawable(resId) != null) { |
| 2834 | // We want to use the windowBackground for the override context if it is |
| 2835 | // available, otherwise we use the default one to make sure a themed starting |
| 2836 | // window is displayed for the app. |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 2837 | if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen: apply overrideConfig" |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2838 | + overrideConfig + " to starting window resId=" + resId); |
| 2839 | context = overrideContext; |
| 2840 | } |
| 2841 | } |
| 2842 | |
| 2843 | final PhoneWindow win = new PhoneWindow(context); |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 2844 | win.setIsStartingWindow(true); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2845 | |
Phil Weaver | 155edc6 | 2016-06-09 10:24:53 -0700 | [diff] [blame] | 2846 | CharSequence label = context.getResources().getText(labelRes, null); |
| 2847 | // Only change the accessibility title if the label is localized |
| 2848 | if (label != null) { |
| 2849 | win.setTitle(label, true); |
| 2850 | } else { |
| 2851 | win.setTitle(nonLocalizedLabel, false); |
| 2852 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2853 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2854 | win.setType( |
| 2855 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2856 | |
| 2857 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2858 | // Assumes it's safe to show starting windows of launched apps while |
| 2859 | // the keyguard is being hidden. This is okay because starting windows never show |
| 2860 | // secret information. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2861 | if (mKeyguardOccluded) { |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2862 | windowFlags |= FLAG_SHOW_WHEN_LOCKED; |
| 2863 | } |
| 2864 | } |
| 2865 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2866 | // Force the window flags: this is a fake window, so it is not really |
| 2867 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 2868 | // flag because we do know that the next window will take input |
| 2869 | // focus, so we want to get the IME window up on top of us right away. |
| 2870 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2871 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2872 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2873 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2874 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2875 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2876 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2877 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2878 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2879 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2880 | win.setDefaultIcon(icon); |
| 2881 | win.setDefaultLogo(logo); |
| 2882 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2883 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2884 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2885 | |
Phil Weaver | 266ed9a | 2016-06-08 00:34:40 +0000 | [diff] [blame] | 2886 | final WindowManager.LayoutParams params = win.getAttributes(); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2887 | params.token = appToken; |
| 2888 | params.packageName = packageName; |
| 2889 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 2890 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2891 | params.privateFlags |= |
| 2892 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2893 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2894 | |
| 2895 | if (!compatInfo.supportsScreen()) { |
| 2896 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 2897 | } |
| 2898 | |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 2899 | params.setTitle("Splash Screen " + packageName); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2900 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2901 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 2902 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2903 | |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 2904 | if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "Adding splash screen window for " |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2905 | + packageName + " / " + appToken + ": " + (view.getParent() != null ? view : null)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2906 | |
| 2907 | wm.addView(view, params); |
| 2908 | |
| 2909 | // Only return the view if it was successfully added to the |
| 2910 | // window manager... which we can tell by it having a parent. |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2911 | return view.getParent() != null ? new SplashScreenSurface(view, appToken) : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2912 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2913 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 2914 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 2915 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2916 | } catch (RuntimeException e) { |
| 2917 | // don't crash if something else bad happens, for example a |
| 2918 | // failure loading resources because we are loading from an app |
| 2919 | // on external storage that has been unmounted. |
| 2920 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2921 | } finally { |
| 2922 | if (view != null && view.getParent() == null) { |
| 2923 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 2924 | wm.removeViewImmediate(view); |
| 2925 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | return null; |
| 2929 | } |
| 2930 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2931 | /** |
| 2932 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2933 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2934 | * Currently enforces that three window types are singletons: |
| 2935 | * <ul> |
| 2936 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2937 | * <li>KEYGUARD_TYPE</li> |
| 2938 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2939 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2940 | * @param win The window to be added |
| 2941 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2942 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2943 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 2944 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2945 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2946 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2947 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 2948 | switch (attrs.type) { |
| 2949 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 2950 | mContext.enforceCallingOrSelfPermission( |
| 2951 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2952 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2953 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2954 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2955 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2956 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2957 | } |
| 2958 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2959 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2960 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2961 | case TYPE_NAVIGATION_BAR: |
| 2962 | mContext.enforceCallingOrSelfPermission( |
| 2963 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2964 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2965 | if (mNavigationBar != null) { |
| 2966 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2967 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2968 | } |
| 2969 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2970 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2971 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2972 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2973 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 2974 | case TYPE_NAVIGATION_BAR_PANEL: |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2975 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2976 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2977 | case TYPE_VOICE_INTERACTION_STARTING: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2978 | mContext.enforceCallingOrSelfPermission( |
| 2979 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2980 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2981 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2982 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2983 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2987 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2988 | public void removeWindowLw(WindowState win) { |
| 2989 | if (mStatusBar == win) { |
| 2990 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2991 | mStatusBarController.setWindow(null); |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 2992 | } else if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2993 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2994 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2995 | } |
| 2996 | } |
| 2997 | |
| 2998 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2999 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3000 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3001 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3002 | public int selectAnimationLw(WindowState win, int transit) { |
| 3003 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 3004 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3005 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3006 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3007 | if (transit == TRANSIT_EXIT |
| 3008 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3009 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3010 | } else if (transit == TRANSIT_ENTER |
| 3011 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3012 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3013 | } |
| 3014 | } else if (win == mNavigationBar) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 3015 | if (win.getAttrs().windowAnimations != 0) { |
| 3016 | return 0; |
| 3017 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3018 | // This can be on either the bottom or the right or the left. |
| 3019 | if (mNavigationBarPosition == NAV_BAR_BOTTOM) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3020 | if (transit == TRANSIT_EXIT |
| 3021 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 4883281 | 2016-09-06 12:38:23 -0700 | [diff] [blame] | 3022 | if (isKeyguardShowingAndNotOccluded()) { |
| 3023 | return R.anim.dock_bottom_exit_keyguard; |
| 3024 | } else { |
| 3025 | return R.anim.dock_bottom_exit; |
| 3026 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3027 | } else if (transit == TRANSIT_ENTER |
| 3028 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3029 | return R.anim.dock_bottom_enter; |
| 3030 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3031 | } else if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3032 | if (transit == TRANSIT_EXIT |
| 3033 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3034 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3035 | } else if (transit == TRANSIT_ENTER |
| 3036 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3037 | return R.anim.dock_right_enter; |
| 3038 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3039 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
| 3040 | if (transit == TRANSIT_EXIT |
| 3041 | || transit == TRANSIT_HIDE) { |
| 3042 | return R.anim.dock_left_exit; |
| 3043 | } else if (transit == TRANSIT_ENTER |
| 3044 | || transit == TRANSIT_SHOW) { |
| 3045 | return R.anim.dock_left_enter; |
| 3046 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3047 | } |
Filip Gruszczynski | 57f76f1 | 2015-11-04 16:10:54 -0800 | [diff] [blame] | 3048 | } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) { |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 3049 | return selectDockedDividerAnimationLw(win, transit); |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3053 | if (win.hasAppShownWindows()) { |
| 3054 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 3055 | return com.android.internal.R.anim.app_starting_exit; |
| 3056 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3057 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3058 | && transit == TRANSIT_ENTER) { |
| 3059 | // Special case: we are animating in a dream, while the keyguard |
| 3060 | // is shown. We don't want an animation on the dream, because |
| 3061 | // we need it shown immediately with the keyguard animating away |
| 3062 | // to reveal it. |
| 3063 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3064 | } |
| 3065 | |
| 3066 | return 0; |
| 3067 | } |
| 3068 | |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 3069 | private int selectDockedDividerAnimationLw(WindowState win, int transit) { |
| 3070 | int insets = mWindowManagerFuncs.getDockedDividerInsetsLw(); |
| 3071 | |
| 3072 | // If the divider is behind the navigation bar, don't animate. |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 3073 | final Rect frame = win.getFrameLw(); |
| 3074 | final boolean behindNavBar = mNavigationBar != null |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3075 | && ((mNavigationBarPosition == NAV_BAR_BOTTOM |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 3076 | && frame.top + insets >= mNavigationBar.getFrameLw().top) |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3077 | || (mNavigationBarPosition == NAV_BAR_RIGHT |
| 3078 | && frame.left + insets >= mNavigationBar.getFrameLw().left) |
| 3079 | || (mNavigationBarPosition == NAV_BAR_LEFT |
| 3080 | && frame.right - insets <= mNavigationBar.getFrameLw().right)); |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 3081 | final boolean landscape = frame.height() > frame.width(); |
| 3082 | final boolean offscreenLandscape = landscape && (frame.right - insets <= 0 |
| 3083 | || frame.left + insets >= win.getDisplayFrameLw().right); |
| 3084 | final boolean offscreenPortrait = !landscape && (frame.top - insets <= 0 |
| 3085 | || frame.bottom + insets >= win.getDisplayFrameLw().bottom); |
| 3086 | final boolean offscreen = offscreenLandscape || offscreenPortrait; |
| 3087 | if (behindNavBar || offscreen) { |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 3088 | return 0; |
| 3089 | } |
| 3090 | if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) { |
| 3091 | return R.anim.fade_in; |
| 3092 | } else if (transit == TRANSIT_EXIT) { |
| 3093 | return R.anim.fade_out; |
| 3094 | } else { |
| 3095 | return 0; |
| 3096 | } |
| 3097 | } |
| 3098 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3099 | @Override |
| 3100 | public void selectRotationAnimationLw(int anim[]) { |
| 3101 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 3102 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 3103 | + (mTopFullscreenOpaqueWindowState == null ? |
| 3104 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 3105 | if (mTopFullscreenOpaqueWindowState != null) { |
| 3106 | int animationHint = mTopFullscreenOpaqueWindowState.getRotationAnimationHint(); |
| 3107 | if (animationHint < 0 && mTopIsFullscreen) { |
| 3108 | animationHint = mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation; |
| 3109 | } |
| 3110 | switch (animationHint) { |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3111 | case ROTATION_ANIMATION_CROSSFADE: |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 3112 | case ROTATION_ANIMATION_SEAMLESS: // Crossfade is fallback for seamless. |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3113 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 3114 | anim[1] = R.anim.rotation_animation_enter; |
| 3115 | break; |
| 3116 | case ROTATION_ANIMATION_JUMPCUT: |
| 3117 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 3118 | anim[1] = R.anim.rotation_animation_enter; |
| 3119 | break; |
| 3120 | case ROTATION_ANIMATION_ROTATE: |
| 3121 | default: |
| 3122 | anim[0] = anim[1] = 0; |
| 3123 | break; |
| 3124 | } |
| 3125 | } else { |
| 3126 | anim[0] = anim[1] = 0; |
| 3127 | } |
| 3128 | } |
| 3129 | |
| 3130 | @Override |
| 3131 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 3132 | boolean forceDefault) { |
| 3133 | switch (exitAnimId) { |
| 3134 | case R.anim.rotation_animation_xfade_exit: |
| 3135 | case R.anim.rotation_animation_jump_exit: |
| 3136 | // These are the only cases that matter. |
| 3137 | if (forceDefault) { |
| 3138 | return false; |
| 3139 | } |
| 3140 | int anim[] = new int[2]; |
| 3141 | selectRotationAnimationLw(anim); |
| 3142 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 3143 | default: |
| 3144 | return true; |
| 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3149 | public Animation createHiddenByKeyguardExit(boolean onWallpaper, |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 3150 | boolean goingToNotificationShade) { |
| 3151 | if (goingToNotificationShade) { |
| 3152 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
Craig Mautner | b834080 | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 3153 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 3154 | |
| 3155 | AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? |
| 3156 | R.anim.lock_screen_behind_enter_wallpaper : |
| 3157 | R.anim.lock_screen_behind_enter); |
| 3158 | |
| 3159 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 3160 | final List<Animation> animations = set.getAnimations(); |
| 3161 | for (int i = animations.size() - 1; i >= 0; --i) { |
| 3162 | animations.get(i).setInterpolator(mLogDecelerateInterpolator); |
| 3163 | } |
| 3164 | |
| 3165 | return set; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | |
| 3169 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3170 | public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) { |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 3171 | if (goingToNotificationShade) { |
| 3172 | return null; |
| 3173 | } else { |
| 3174 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 3175 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 3176 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 3177 | |
| 3178 | private static void awakenDreams() { |
| 3179 | IDreamManager dreamManager = getDreamManager(); |
| 3180 | if (dreamManager != null) { |
| 3181 | try { |
| 3182 | dreamManager.awaken(); |
| 3183 | } catch (RemoteException e) { |
| 3184 | // fine, stay asleep then |
| 3185 | } |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | static IDreamManager getDreamManager() { |
| 3190 | return IDreamManager.Stub.asInterface( |
| 3191 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 3192 | } |
| 3193 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 3194 | TelecomManager getTelecommService() { |
| 3195 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3196 | } |
| 3197 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3198 | static IAudioService getAudioService() { |
| 3199 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 3200 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 3201 | if (audioService == null) { |
| 3202 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 3203 | } |
| 3204 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3205 | } |
| 3206 | |
| 3207 | boolean keyguardOn() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 3208 | return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 3212 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 3213 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 3214 | }; |
| 3215 | |
| 3216 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3217 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3218 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3219 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3220 | final int keyCode = event.getKeyCode(); |
| 3221 | final int repeatCount = event.getRepeatCount(); |
| 3222 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3223 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3224 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 3225 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3226 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3227 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3228 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3229 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 3230 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3231 | } |
| 3232 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3233 | // If we think we might have a volume down & power key chord on the way |
| 3234 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 3235 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 3236 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3237 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3238 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3239 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 3240 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3241 | if (now < timeoutTime) { |
| 3242 | return timeoutTime - now; |
| 3243 | } |
| 3244 | } |
| 3245 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3246 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3247 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3248 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3249 | } |
| 3250 | return -1; |
| 3251 | } |
| 3252 | } |
| 3253 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3254 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 3255 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 3256 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3257 | mPendingMetaAction = false; |
| 3258 | } |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 3259 | // Any key that is not Alt or Meta cancels Caps Lock combo tracking. |
| 3260 | if (mPendingCapsLockToggle && !KeyEvent.isMetaKey(keyCode) && !KeyEvent.isAltKey(keyCode)) { |
| 3261 | mPendingCapsLockToggle = false; |
| 3262 | } |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3263 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3264 | // First we always handle the home key here, so applications |
| 3265 | // can never break it, although if keyguard is on, we do let |
| 3266 | // it handle it, because that gives us the correct 5 second |
| 3267 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3268 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3269 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3270 | // If we have released the home key, and didn't do anything else |
| 3271 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3272 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3273 | cancelPreloadRecentApps(); |
| 3274 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3275 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3276 | if (mHomeConsumed) { |
| 3277 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3278 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3279 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3280 | |
| 3281 | if (canceled) { |
| 3282 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 3283 | return -1; |
| 3284 | } |
| 3285 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3286 | // Delay handling home if a double-tap is possible. |
| 3287 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 3288 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 3289 | mHomeDoubleTapPending = true; |
| 3290 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 3291 | ViewConfiguration.getDoubleTapTimeout()); |
| 3292 | return -1; |
| 3293 | } |
| 3294 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3295 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3296 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3297 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3298 | |
| 3299 | // If a system window has focus, then it doesn't make sense |
| 3300 | // right now to interact with applications. |
| 3301 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 3302 | if (attrs != null) { |
| 3303 | final int type = attrs.type; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 3304 | if (type == TYPE_KEYGUARD_DIALOG |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3305 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3306 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3307 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3308 | } |
| 3309 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 3310 | for (int i=0; i<typeCount; i++) { |
| 3311 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 3312 | // 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] | 3313 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3314 | } |
| 3315 | } |
| 3316 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3317 | |
| 3318 | // Remember that home is pressed and handle special actions. |
| 3319 | if (repeatCount == 0) { |
| 3320 | mHomePressed = true; |
| 3321 | if (mHomeDoubleTapPending) { |
| 3322 | mHomeDoubleTapPending = false; |
| 3323 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 3324 | handleDoubleTapOnHome(); |
| 3325 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 3326 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 3327 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3328 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3329 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 3330 | if (!keyguardOn) { |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 3331 | handleLongPressOnHome(event.getDeviceId()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3332 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3333 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3334 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3335 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3336 | // Hijack modified menu keys for debugging features |
| 3337 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 3338 | |
| 3339 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3340 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3341 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 3342 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 3343 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3344 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3345 | } |
| 3346 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3347 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3348 | if (down) { |
| 3349 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3350 | mSearchKeyShortcutPending = true; |
| 3351 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3352 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3353 | } else { |
| 3354 | mSearchKeyShortcutPending = false; |
| 3355 | if (mConsumeSearchKeyUp) { |
| 3356 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3357 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3358 | } |
| 3359 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3360 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3361 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 3362 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3363 | if (down && repeatCount == 0) { |
| 3364 | preloadRecentApps(); |
| 3365 | } else if (!down) { |
| 3366 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 3367 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3368 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3369 | return -1; |
Jun Mukai | d21b3c8 | 2015-04-23 14:09:34 -0700 | [diff] [blame] | 3370 | } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) { |
| 3371 | if (down) { |
| 3372 | IStatusBarService service = getStatusBarService(); |
| 3373 | if (service != null) { |
| 3374 | try { |
| 3375 | service.expandNotificationsPanel(); |
| 3376 | } catch (RemoteException e) { |
| 3377 | // do nothing. |
| 3378 | } |
| 3379 | } |
| 3380 | } |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 3381 | } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed() |
| 3382 | && event.isCtrlPressed()) { |
| 3383 | if (down && repeatCount == 0) { |
| 3384 | int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION |
| 3385 | : TAKE_SCREENSHOT_FULLSCREEN; |
| 3386 | mScreenshotRunnable.setScreenshotType(type); |
| 3387 | mHandler.post(mScreenshotRunnable); |
| 3388 | return -1; |
| 3389 | } |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3390 | } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) { |
Andrei Stingaceanu | 002f712 | 2016-03-30 12:22:05 +0100 | [diff] [blame] | 3391 | if (down && repeatCount == 0 && !isKeyguardLocked()) { |
| 3392 | toggleKeyboardShortcutsMenu(event.getDeviceId()); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3393 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3394 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 3395 | if (down) { |
| 3396 | if (repeatCount == 0) { |
| 3397 | mAssistKeyLongPressed = false; |
| 3398 | } else if (repeatCount == 1) { |
| 3399 | mAssistKeyLongPressed = true; |
| 3400 | if (!keyguardOn) { |
| 3401 | launchAssistLongPressAction(); |
| 3402 | } |
| 3403 | } |
| 3404 | } else { |
| 3405 | if (mAssistKeyLongPressed) { |
| 3406 | mAssistKeyLongPressed = false; |
| 3407 | } else { |
| 3408 | if (!keyguardOn) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3409 | launchAssistAction(null, event.getDeviceId()); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3410 | } |
| 3411 | } |
| 3412 | } |
| 3413 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3414 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 3415 | if (!down) { |
| 3416 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 3417 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3418 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3419 | } else { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 3420 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 3421 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 3422 | if (dic != null) { |
| 3423 | try { |
| 3424 | dic.exitIdle("voice-search"); |
| 3425 | } catch (RemoteException e) { |
| 3426 | } |
| 3427 | } |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3428 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 3429 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3430 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3431 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3432 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 3433 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 3434 | if (down && repeatCount == 0) { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 3435 | mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN); |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 3436 | mHandler.post(mScreenshotRunnable); |
| 3437 | } |
| 3438 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 3439 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 3440 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 3441 | if (down) { |
| 3442 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 3443 | |
| 3444 | // Disable autobrightness if it's on |
| 3445 | int auto = Settings.System.getIntForUser( |
| 3446 | mContext.getContentResolver(), |
| 3447 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 3448 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 3449 | UserHandle.USER_CURRENT_OR_SELF); |
| 3450 | if (auto != 0) { |
| 3451 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3452 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 3453 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 3454 | UserHandle.USER_CURRENT_OR_SELF); |
| 3455 | } |
| 3456 | |
| 3457 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 3458 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 3459 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 3460 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 3461 | Settings.System.SCREEN_BRIGHTNESS, |
| 3462 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 3463 | UserHandle.USER_CURRENT_OR_SELF); |
| 3464 | brightness += step; |
| 3465 | // Make sure we don't go beyond the limits. |
| 3466 | brightness = Math.min(max, brightness); |
| 3467 | brightness = Math.max(min, brightness); |
| 3468 | |
| 3469 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3470 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 3471 | UserHandle.USER_CURRENT_OR_SELF); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3472 | startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 3473 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 3474 | } |
| 3475 | return -1; |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 3476 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 3477 | || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 3478 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { |
| 3479 | if (mUseTvRouting) { |
| 3480 | // On TVs volume keys never go to the foreground app. |
| 3481 | dispatchDirectAudioEvent(event); |
| 3482 | return -1; |
| 3483 | } |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3484 | } |
| 3485 | |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 3486 | // Toggle Caps Lock on META-ALT. |
| 3487 | boolean actionTriggered = false; |
| 3488 | if (KeyEvent.isModifierKey(keyCode)) { |
| 3489 | if (!mPendingCapsLockToggle) { |
| 3490 | // Start tracking meta state for combo. |
| 3491 | mInitialMetaState = mMetaState; |
| 3492 | mPendingCapsLockToggle = true; |
| 3493 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 3494 | int altOnMask = mMetaState & KeyEvent.META_ALT_MASK; |
| 3495 | int metaOnMask = mMetaState & KeyEvent.META_META_MASK; |
| 3496 | |
| 3497 | // Check for Caps Lock toggle |
| 3498 | if ((metaOnMask != 0) && (altOnMask != 0)) { |
| 3499 | // Check if nothing else is pressed |
| 3500 | if (mInitialMetaState == (mMetaState ^ (altOnMask | metaOnMask))) { |
| 3501 | // Handle Caps Lock Toggle |
| 3502 | mInputManagerInternal.toggleCapsLock(event.getDeviceId()); |
| 3503 | actionTriggered = true; |
| 3504 | } |
| 3505 | } |
| 3506 | |
| 3507 | // Always stop tracking when key goes up. |
| 3508 | mPendingCapsLockToggle = false; |
| 3509 | } |
| 3510 | } |
| 3511 | // Store current meta state to be able to evaluate it later. |
| 3512 | mMetaState = metaState; |
| 3513 | |
| 3514 | if (actionTriggered) { |
| 3515 | return -1; |
| 3516 | } |
| 3517 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3518 | if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3519 | if (down) { |
| 3520 | mPendingMetaAction = true; |
| 3521 | } else if (mPendingMetaAction) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3522 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId()); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3523 | } |
| 3524 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3525 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3526 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3527 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3528 | // Any printing key that is chorded with Search should be consumed |
| 3529 | // even if no shortcut was invoked. This prevents text from being |
| 3530 | // inadvertently inserted when using a keyboard that has built-in macro |
| 3531 | // 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] | 3532 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3533 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 3534 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3535 | mConsumeSearchKeyUp = true; |
| 3536 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3537 | if (down && repeatCount == 0 && !keyguardOn) { |
| 3538 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 3539 | if (shortcutIntent != null) { |
| 3540 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3541 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3542 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3543 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3544 | } catch (ActivityNotFoundException ex) { |
| 3545 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3546 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3547 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3548 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3549 | } else { |
| 3550 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3551 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3552 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3553 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3554 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3555 | } |
| 3556 | } |
| 3557 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3558 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3559 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3560 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 3561 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3562 | if (kcm.isPrintingKey(keyCode)) { |
| 3563 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 3564 | metaState & ~(KeyEvent.META_META_ON |
| 3565 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 3566 | if (shortcutIntent != null) { |
| 3567 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3568 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3569 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3570 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3571 | } catch (ActivityNotFoundException ex) { |
| 3572 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3573 | + "the activity to which it is registered was not found: " |
| 3574 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 3575 | } |
| 3576 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3577 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3578 | } |
| 3579 | } |
| 3580 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3581 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3582 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3583 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 3584 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 3585 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3586 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3587 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3588 | startActivityAsUser(intent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3589 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3590 | } catch (ActivityNotFoundException ex) { |
| 3591 | Slog.w(TAG, "Dropping application launch key because " |
| 3592 | + "the activity to which it is registered was not found: " |
| 3593 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 3594 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3595 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3596 | } |
| 3597 | } |
| 3598 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3599 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3600 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Michael Wright | d847ad5 | 2015-10-24 13:24:15 +0100 | [diff] [blame] | 3601 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3602 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3603 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3604 | mRecentAppsHeldModifiers = shiftlessModifiers; |
Winson | 14db362 | 2016-05-09 13:34:07 -0700 | [diff] [blame] | 3605 | showRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3606 | return -1; |
| 3607 | } |
| 3608 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3609 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 3610 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 3611 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3612 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3613 | } |
| 3614 | |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3615 | // Handle input method switching. |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3616 | if (down && repeatCount == 0 |
| 3617 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3618 | || (keyCode == KeyEvent.KEYCODE_SPACE |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3619 | && (metaState & KeyEvent.META_META_MASK) != 0))) { |
| 3620 | final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0; |
| 3621 | mWindowManagerFuncs.switchInputMethod(forwardDirection); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3622 | return -1; |
| 3623 | } |
| 3624 | if (mLanguageSwitchKeyPressed && !down |
| 3625 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3626 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 3627 | mLanguageSwitchKeyPressed = false; |
| 3628 | return -1; |
| 3629 | } |
| 3630 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3631 | if (isValidGlobalKey(keyCode) |
| 3632 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 3633 | return -1; |
| 3634 | } |
| 3635 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3636 | if (down) { |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 3637 | long shortcutCode = keyCode; |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3638 | if (event.isCtrlPressed()) { |
| 3639 | shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE; |
| 3640 | } |
| 3641 | |
| 3642 | if (event.isAltPressed()) { |
| 3643 | shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE; |
| 3644 | } |
| 3645 | |
| 3646 | if (event.isShiftPressed()) { |
| 3647 | shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE; |
| 3648 | } |
| 3649 | |
| 3650 | if (event.isMetaPressed()) { |
| 3651 | shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE; |
| 3652 | } |
| 3653 | |
| 3654 | IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode); |
| 3655 | if (shortcutService != null) { |
| 3656 | try { |
Muyuan Li | b5dd049 | 2016-04-14 13:22:20 -0700 | [diff] [blame] | 3657 | if (isUserSetupComplete()) { |
| 3658 | shortcutService.notifyShortcutKeyPressed(shortcutCode); |
| 3659 | } |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3660 | } catch (RemoteException e) { |
| 3661 | mShortcutKeyServices.delete(shortcutCode); |
| 3662 | } |
| 3663 | return -1; |
| 3664 | } |
| 3665 | } |
| 3666 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3667 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 3668 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3669 | return -1; |
| 3670 | } |
| 3671 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3672 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3673 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3674 | } |
| 3675 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3676 | /** {@inheritDoc} */ |
| 3677 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3678 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3679 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3680 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3681 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 3682 | + ", flags=" + event.getFlags() |
| 3683 | + ", keyCode=" + event.getKeyCode() |
| 3684 | + ", scanCode=" + event.getScanCode() |
| 3685 | + ", metaState=" + event.getMetaState() |
| 3686 | + ", repeatCount=" + event.getRepeatCount() |
| 3687 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3688 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3689 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3690 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3691 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3692 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3693 | final int keyCode = event.getKeyCode(); |
| 3694 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3695 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 3696 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3697 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3698 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3699 | final FallbackAction fallbackAction; |
| 3700 | if (initialDown) { |
| 3701 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 3702 | } else { |
| 3703 | fallbackAction = mFallbackActions.get(keyCode); |
| 3704 | } |
| 3705 | |
| 3706 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3707 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3708 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 3709 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3710 | } |
| 3711 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3712 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 3713 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3714 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3715 | event.getAction(), fallbackAction.keyCode, |
| 3716 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3717 | event.getDeviceId(), event.getScanCode(), |
| 3718 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3719 | |
| 3720 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 3721 | fallbackEvent.recycle(); |
| 3722 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3723 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3724 | |
| 3725 | if (initialDown) { |
| 3726 | mFallbackActions.put(keyCode, fallbackAction); |
| 3727 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 3728 | mFallbackActions.remove(keyCode); |
| 3729 | fallbackAction.recycle(); |
| 3730 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3731 | } |
| 3732 | } |
| 3733 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3734 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3735 | if (fallbackEvent == null) { |
| 3736 | Slog.d(TAG, "No fallback."); |
| 3737 | } else { |
| 3738 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 3739 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3740 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3741 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3742 | } |
| 3743 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3744 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3745 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3746 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 3747 | long delayMillis = interceptKeyBeforeDispatching( |
| 3748 | win, fallbackEvent, policyFlags); |
| 3749 | if (delayMillis == 0) { |
| 3750 | return true; |
| 3751 | } |
| 3752 | } |
| 3753 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3754 | } |
| 3755 | |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 3756 | @Override |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3757 | public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService) |
| 3758 | throws RemoteException { |
| 3759 | synchronized (mLock) { |
| 3760 | IShortcutService service = mShortcutKeyServices.get(shortcutCode); |
Muyuan Li | 24d24ac | 2016-03-03 21:15:02 -0800 | [diff] [blame] | 3761 | if (service != null && service.asBinder().pingBinder()) { |
| 3762 | throw new RemoteException("Key already exists."); |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3763 | } |
| 3764 | |
| 3765 | mShortcutKeyServices.put(shortcutCode, shortcutService); |
| 3766 | } |
| 3767 | } |
| 3768 | |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 3769 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3770 | public void onKeyguardOccludedChangedLw(boolean occluded) { |
| 3771 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
| 3772 | mPendingKeyguardOccluded = occluded; |
| 3773 | mKeyguardOccludedChanged = true; |
| 3774 | } else { |
| 3775 | setKeyguardOccludedLw(occluded); |
| 3776 | } |
| 3777 | } |
| 3778 | |
| 3779 | private int handleStartTransitionForKeyguardLw(int transit, @Nullable Animation anim) { |
| 3780 | if (mKeyguardOccludedChanged) { |
| 3781 | if (DEBUG_KEYGUARD) Slog.d(TAG, "transition/occluded changed occluded=" |
| 3782 | + mPendingKeyguardOccluded); |
| 3783 | mKeyguardOccludedChanged = false; |
| 3784 | if (setKeyguardOccludedLw(mPendingKeyguardOccluded)) { |
| 3785 | return FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3786 | } |
| 3787 | } |
| 3788 | if (AppTransition.isKeyguardGoingAwayTransit(transit)) { |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 3789 | if (DEBUG_KEYGUARD) Slog.d(TAG, "Starting keyguard exit animation"); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3790 | final long startTime = anim != null |
| 3791 | ? SystemClock.uptimeMillis() + anim.getStartOffset() |
| 3792 | : SystemClock.uptimeMillis(); |
| 3793 | final long duration = anim != null |
| 3794 | ? anim.getDuration() |
| 3795 | : 0; |
| 3796 | startKeyguardExitAnimation(startTime, duration); |
| 3797 | } |
| 3798 | return 0; |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 3799 | } |
| 3800 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3801 | private void launchAssistLongPressAction() { |
| 3802 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 3803 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 3804 | |
| 3805 | // launch the search activity |
| 3806 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 3807 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3808 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3809 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 3810 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3811 | SearchManager searchManager = getSearchManager(); |
| 3812 | if (searchManager != null) { |
| 3813 | searchManager.stopSearch(); |
| 3814 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3815 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3816 | } catch (ActivityNotFoundException e) { |
| 3817 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 3818 | } |
| 3819 | } |
| 3820 | |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3821 | private void launchAssistAction(String hint, int deviceId) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3822 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Maurice Lam | 39d1381 | 2015-07-23 20:49:20 -0700 | [diff] [blame] | 3823 | if (!isUserSetupComplete()) { |
| 3824 | // Disable opening assist window during setup |
| 3825 | return; |
| 3826 | } |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3827 | Bundle args = null; |
| 3828 | if (deviceId > Integer.MIN_VALUE) { |
| 3829 | args = new Bundle(); |
| 3830 | args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3831 | } |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 3832 | if ((mContext.getResources().getConfiguration().uiMode |
| 3833 | & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) { |
| 3834 | // On TV, use legacy handling until assistants are implemented in the proper way. |
| 3835 | ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
| 3836 | .launchLegacyAssist(hint, UserHandle.myUserId(), args); |
| 3837 | } else { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3838 | if (hint != null) { |
| 3839 | if (args == null) { |
| 3840 | args = new Bundle(); |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 3841 | } |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3842 | args.putBoolean(hint, true); |
| 3843 | } |
| 3844 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3845 | if (statusbar != null) { |
| 3846 | statusbar.startAssist(args); |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 3847 | } |
| 3848 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3849 | } |
| 3850 | |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3851 | private void startActivityAsUser(Intent intent, UserHandle handle) { |
| 3852 | if (isUserSetupComplete()) { |
| 3853 | mContext.startActivityAsUser(intent, handle); |
| 3854 | } else { |
| 3855 | Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); |
| 3856 | } |
| 3857 | } |
| 3858 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3859 | private SearchManager getSearchManager() { |
| 3860 | if (mSearchManager == null) { |
| 3861 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 3862 | } |
| 3863 | return mSearchManager; |
| 3864 | } |
| 3865 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3866 | private void preloadRecentApps() { |
| 3867 | mPreloadedRecentApps = true; |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3868 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3869 | if (statusbar != null) { |
| 3870 | statusbar.preloadRecentApps(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3871 | } |
| 3872 | } |
| 3873 | |
| 3874 | private void cancelPreloadRecentApps() { |
| 3875 | if (mPreloadedRecentApps) { |
| 3876 | mPreloadedRecentApps = false; |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3877 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3878 | if (statusbar != null) { |
| 3879 | statusbar.cancelPreloadRecentApps(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3880 | } |
| 3881 | } |
| 3882 | } |
| 3883 | |
| 3884 | private void toggleRecentApps() { |
| 3885 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3886 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3887 | if (statusbar != null) { |
| 3888 | statusbar.toggleRecentApps(); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3889 | } |
| 3890 | } |
| 3891 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3892 | @Override |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 3893 | public void showRecentApps(boolean fromHome) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3894 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 3895 | mHandler.obtainMessage(MSG_DISPATCH_SHOW_RECENTS, fromHome ? 1 : 0, 0).sendToTarget(); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3896 | } |
| 3897 | |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 3898 | private void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3899 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3900 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3901 | if (statusbar != null) { |
| 3902 | statusbar.showRecentApps(triggeredFromAltTab, fromHome); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3903 | } |
| 3904 | } |
| 3905 | |
Clara Bayarri | 4e850ff | 2016-03-02 11:12:32 -0800 | [diff] [blame] | 3906 | private void toggleKeyboardShortcutsMenu(int deviceId) { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3907 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3908 | if (statusbar != null) { |
| 3909 | statusbar.toggleKeyboardShortcutsMenu(deviceId); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3910 | } |
| 3911 | } |
| 3912 | |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3913 | private void dismissKeyboardShortcutsMenu() { |
| 3914 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3915 | if (statusbar != null) { |
| 3916 | statusbar.dismissKeyboardShortcutsMenu(); |
| 3917 | } |
| 3918 | } |
| 3919 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3920 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3921 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3922 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3923 | if (statusbar != null) { |
| 3924 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3925 | } |
| 3926 | } |
| 3927 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3928 | void launchHomeFromHotKey() { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3929 | launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3930 | } |
| 3931 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3932 | /** |
| 3933 | * A home key -> launch home action was detected. Take the appropriate action |
| 3934 | * given the situation with the keyguard. |
| 3935 | */ |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3936 | void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) { |
| 3937 | if (respectKeyguard) { |
| 3938 | if (isKeyguardShowingAndNotOccluded()) { |
| 3939 | // don't launch home if keyguard showing |
| 3940 | return; |
| 3941 | } |
| 3942 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3943 | if (!mKeyguardOccluded && mKeyguardDelegate.isInputRestricted()) { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3944 | // when in keyguard restricted mode, must first verify unlock |
| 3945 | // before launching home |
| 3946 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
| 3947 | @Override |
| 3948 | public void onKeyguardExitResult(boolean success) { |
| 3949 | if (success) { |
| 3950 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3951 | ActivityManager.getService().stopAppSwitches(); |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3952 | } catch (RemoteException e) { |
| 3953 | } |
| 3954 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3955 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 3956 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3957 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3958 | }); |
| 3959 | return; |
| 3960 | } |
| 3961 | } |
| 3962 | |
| 3963 | // no keyguard stuff to worry about, just launch home! |
| 3964 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3965 | ActivityManager.getService().stopAppSwitches(); |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3966 | } catch (RemoteException e) { |
| 3967 | } |
| 3968 | if (mRecentsVisible) { |
| 3969 | // Hide Recents and notify it to launch Home |
| 3970 | if (awakenFromDreams) { |
| 3971 | awakenDreams(); |
| 3972 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3973 | hideRecentApps(false, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3974 | } else { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3975 | // Otherwise, just launch Home |
| 3976 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3977 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3978 | } |
| 3979 | } |
| 3980 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3981 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 3982 | @Override |
| 3983 | public void run() { |
| 3984 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 3985 | // Clear flags. |
| 3986 | mForceClearedSystemUiFlags &= |
| 3987 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 3988 | } |
| 3989 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3990 | } |
| 3991 | }; |
| 3992 | |
| 3993 | /** |
| 3994 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 3995 | * to determine when the nav bar should be shown and prevent applications from |
| 3996 | * receiving those touches. |
| 3997 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3998 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 3999 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 4000 | super(inputChannel, looper); |
| 4001 | } |
| 4002 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4003 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 4004 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4005 | boolean handled = false; |
| 4006 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4007 | if (event instanceof MotionEvent |
| 4008 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 4009 | final MotionEvent motionEvent = (MotionEvent)event; |
| 4010 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4011 | // When the user taps down, we re-show the nav bar. |
| 4012 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4013 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 4014 | if (mInputConsumer == null) { |
| 4015 | return; |
| 4016 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4017 | // Any user activity always causes us to show the |
| 4018 | // navigation controls, if they had been hidden. |
| 4019 | // We also clear the low profile and only content |
| 4020 | // flags so that tapping on the screen will atomically |
| 4021 | // restore all currently hidden screen decorations. |
| 4022 | int newVal = mResettingSystemUiFlags | |
| 4023 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 4024 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 4025 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4026 | if (mResettingSystemUiFlags != newVal) { |
| 4027 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4028 | changed = true; |
| 4029 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4030 | // We don't allow the system's nav bar to be hidden |
| 4031 | // again for 1 second, to prevent applications from |
| 4032 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4033 | newVal = mForceClearedSystemUiFlags | |
| 4034 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4035 | if (mForceClearedSystemUiFlags != newVal) { |
| 4036 | mForceClearedSystemUiFlags = newVal; |
| 4037 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4038 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4039 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4040 | } |
| 4041 | if (changed) { |
| 4042 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 4043 | } |
| 4044 | } |
| 4045 | } |
| 4046 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 4047 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4048 | } |
| 4049 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 4050 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4051 | |
| 4052 | @Override |
Winson | ab21660 | 2016-08-09 14:05:20 -0700 | [diff] [blame] | 4053 | public void setRecentsVisibilityLw(boolean visible) { |
| 4054 | mRecentsVisible = visible; |
| 4055 | } |
| 4056 | |
| 4057 | @Override |
| 4058 | public void setTvPipVisibilityLw(boolean visible) { |
| 4059 | mTvPictureInPictureVisible = visible; |
| 4060 | } |
| 4061 | |
| 4062 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4063 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 4064 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 4065 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4066 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4067 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 4068 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4069 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4070 | // Clear any bits in the new visibility that are currently being |
| 4071 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4072 | return visibility & ~mResettingSystemUiFlags |
| 4073 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4074 | } |
| 4075 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4076 | @Override |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 4077 | public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds, |
| 4078 | int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets, |
| 4079 | Rect outStableInsets, Rect outOutsets) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4080 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 4081 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 4082 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4083 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4084 | final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl); |
| 4085 | if (useOutsets) { |
| 4086 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 4087 | if (outset > 0) { |
| 4088 | if (displayRotation == Surface.ROTATION_0) { |
| 4089 | outOutsets.bottom += outset; |
| 4090 | } else if (displayRotation == Surface.ROTATION_90) { |
| 4091 | outOutsets.right += outset; |
| 4092 | } else if (displayRotation == Surface.ROTATION_180) { |
| 4093 | outOutsets.top += outset; |
| 4094 | } else if (displayRotation == Surface.ROTATION_270) { |
| 4095 | outOutsets.left += outset; |
| 4096 | } |
| 4097 | } |
| 4098 | } |
| 4099 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4100 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4101 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4102 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4103 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4104 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4105 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4106 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 4107 | } else { |
| 4108 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 4109 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 4110 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4111 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 4112 | if ((fl & FLAG_FULLSCREEN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4113 | outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4114 | availRight - mStableFullscreenRight, |
| 4115 | availBottom - mStableFullscreenBottom); |
| 4116 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4117 | outContentInsets.set(mStableLeft, mStableTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4118 | availRight - mStableRight, availBottom - mStableBottom); |
| 4119 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4120 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4121 | outContentInsets.setEmpty(); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4122 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4123 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4124 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4125 | availRight - mCurRight, availBottom - mCurBottom); |
| 4126 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4127 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4128 | availRight - mCurRight, availBottom - mCurBottom); |
| 4129 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4130 | |
| 4131 | outStableInsets.set(mStableLeft, mStableTop, |
| 4132 | availRight - mStableRight, availBottom - mStableBottom); |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 4133 | if (taskBounds != null) { |
| 4134 | calculateRelevantTaskInsets(taskBounds, outContentInsets, |
| 4135 | displayWidth, displayHeight); |
| 4136 | calculateRelevantTaskInsets(taskBounds, outStableInsets, |
| 4137 | displayWidth, displayHeight); |
| 4138 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 4139 | return mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4140 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4141 | outContentInsets.setEmpty(); |
| 4142 | outStableInsets.setEmpty(); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 4143 | return mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4144 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4145 | |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 4146 | /** |
| 4147 | * For any given task bounds, the insets relevant for these bounds given the insets relevant |
| 4148 | * for the entire display. |
| 4149 | */ |
| 4150 | private void calculateRelevantTaskInsets(Rect taskBounds, Rect inOutInsets, int displayWidth, |
| 4151 | int displayHeight) { |
| 4152 | mTmpRect.set(0, 0, displayWidth, displayHeight); |
| 4153 | mTmpRect.inset(inOutInsets); |
| 4154 | mTmpRect.intersect(taskBounds); |
| 4155 | int leftInset = mTmpRect.left - taskBounds.left; |
| 4156 | int topInset = mTmpRect.top - taskBounds.top; |
| 4157 | int rightInset = taskBounds.right - mTmpRect.right; |
| 4158 | int bottomInset = taskBounds.bottom - mTmpRect.bottom; |
| 4159 | inOutInsets.set(leftInset, topInset, rightInset, bottomInset); |
| 4160 | } |
| 4161 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4162 | private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) { |
| 4163 | return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 4164 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0; |
| 4165 | } |
| 4166 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4167 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4168 | @Override |
| 4169 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 4170 | int displayRotation, int uiMode) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4171 | mDisplayRotation = displayRotation; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4172 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 4173 | if (isDefaultDisplay) { |
| 4174 | switch (displayRotation) { |
| 4175 | case Surface.ROTATION_90: |
| 4176 | overscanLeft = mOverscanTop; |
| 4177 | overscanTop = mOverscanRight; |
| 4178 | overscanRight = mOverscanBottom; |
| 4179 | overscanBottom = mOverscanLeft; |
| 4180 | break; |
| 4181 | case Surface.ROTATION_180: |
| 4182 | overscanLeft = mOverscanRight; |
| 4183 | overscanTop = mOverscanBottom; |
| 4184 | overscanRight = mOverscanLeft; |
| 4185 | overscanBottom = mOverscanTop; |
| 4186 | break; |
| 4187 | case Surface.ROTATION_270: |
| 4188 | overscanLeft = mOverscanBottom; |
| 4189 | overscanTop = mOverscanLeft; |
| 4190 | overscanRight = mOverscanTop; |
| 4191 | overscanBottom = mOverscanRight; |
| 4192 | break; |
| 4193 | default: |
| 4194 | overscanLeft = mOverscanLeft; |
| 4195 | overscanTop = mOverscanTop; |
| 4196 | overscanRight = mOverscanRight; |
| 4197 | overscanBottom = mOverscanBottom; |
| 4198 | break; |
| 4199 | } |
| 4200 | } else { |
| 4201 | overscanLeft = 0; |
| 4202 | overscanTop = 0; |
| 4203 | overscanRight = 0; |
| 4204 | overscanBottom = 0; |
| 4205 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4206 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 4207 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 4208 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 4209 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4210 | mSystemLeft = 0; |
| 4211 | mSystemTop = 0; |
| 4212 | mSystemRight = displayWidth; |
| 4213 | mSystemBottom = displayHeight; |
| 4214 | mUnrestrictedScreenLeft = overscanLeft; |
| 4215 | mUnrestrictedScreenTop = overscanTop; |
| 4216 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 4217 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 4218 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 4219 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4220 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 4221 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4222 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4223 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4224 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4225 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4226 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4227 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4228 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4229 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4230 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 4231 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4232 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4233 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 4234 | final Rect pf = mTmpParentFrame; |
| 4235 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4236 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4237 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4238 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4239 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 4240 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 4241 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 4242 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4243 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4244 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4245 | if (isDefaultDisplay) { |
| 4246 | // For purposes of putting out fake window up to steal focus, we will |
| 4247 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4248 | final int sysui = mLastSystemUiFlags; |
| 4249 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4250 | boolean navTranslucent = (sysui |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4251 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 4252 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 4253 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 4254 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 4255 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4256 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mKeyguardOccluded; |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 4257 | if (!isKeyguardShowing) { |
| 4258 | navTranslucent &= areTranslucentBarsAllowed(); |
| 4259 | } |
Jaewan Kim | 3328433 | 2016-05-12 18:55:46 +0900 | [diff] [blame] | 4260 | boolean statusBarExpandedNotKeyguard = !isKeyguardShowing && mStatusBar != null |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4261 | && mStatusBar.getAttrs().height == MATCH_PARENT |
| 4262 | && mStatusBar.getAttrs().width == MATCH_PARENT; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4263 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4264 | // When the navigation bar isn't visible, we put up a fake |
| 4265 | // input window to catch all touch events. This way we can |
| 4266 | // detect when the user presses anywhere to bring back the nav |
| 4267 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 4268 | if (navVisible || navAllowedHidden) { |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 4269 | if (mInputConsumer != null) { |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 4270 | mHandler.sendMessage( |
| 4271 | mHandler.obtainMessage(MSG_DISPOSE_INPUT_CONSUMER, mInputConsumer)); |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 4272 | mInputConsumer = null; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4273 | } |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 4274 | } else if (mInputConsumer == null) { |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 4275 | mInputConsumer = mWindowManagerFuncs.createInputConsumer(mHandler.getLooper(), |
| 4276 | INPUT_CONSUMER_NAVIGATION, |
| 4277 | (channel, looper) -> new HideNavInputEventReceiver(channel, looper)); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4278 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4279 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4280 | // For purposes of positioning and showing the nav bar, if we have |
| 4281 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 4282 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4283 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4284 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4285 | boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight, |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4286 | displayRotation, uiMode, overscanLeft, overscanRight, overscanBottom, dcf, navVisible, navTranslucent, |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4287 | navAllowedHidden, statusBarExpandedNotKeyguard); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4288 | if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)", |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4289 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4290 | updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4291 | if (updateSysUiVisibility) { |
| 4292 | updateSystemUiVisibilityLw(); |
| 4293 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4294 | } |
| 4295 | } |
| 4296 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4297 | private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui, |
| 4298 | boolean isKeyguardShowing) { |
| 4299 | // decide where the status bar goes ahead of time |
| 4300 | if (mStatusBar != null) { |
| 4301 | // apply any navigation bar insets |
| 4302 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4303 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4304 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 4305 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 4306 | + mUnrestrictedScreenTop; |
| 4307 | vf.left = mStableLeft; |
| 4308 | vf.top = mStableTop; |
| 4309 | vf.right = mStableRight; |
| 4310 | vf.bottom = mStableBottom; |
| 4311 | |
| 4312 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 4313 | |
| 4314 | // Let the status bar determine its size. |
| 4315 | mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */, |
| 4316 | vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */, |
| 4317 | dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */); |
| 4318 | |
| 4319 | // For layout, the status bar is always at the top with our fixed height. |
| 4320 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 4321 | |
| 4322 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
| 4323 | boolean statusBarTranslucent = (sysui |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4324 | & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0; |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4325 | if (!isKeyguardShowing) { |
| 4326 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 4327 | } |
| 4328 | |
| 4329 | // If the status bar is hidden, we don't want to cause |
| 4330 | // windows behind it to scroll. |
| 4331 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
| 4332 | // Status bar may go away, so the screen area it occupies |
| 4333 | // is available to apps but just covering them when the |
| 4334 | // status bar is visible. |
| 4335 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 4336 | |
| 4337 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 4338 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 4339 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 4340 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 4341 | |
| 4342 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
| 4343 | String.format( |
| 4344 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 4345 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 4346 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 4347 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 4348 | } |
| 4349 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
| 4350 | && !statusBarTransient && !statusBarTranslucent |
| 4351 | && !mStatusBarController.wasRecentlyTranslucent()) { |
| 4352 | // If the opaque status bar is currently requested to be visible, |
| 4353 | // and not in the process of animating on or off, then |
| 4354 | // we can tell the app that it is covered by it. |
| 4355 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 4356 | } |
| 4357 | if (mStatusBarController.checkHiddenLw()) { |
| 4358 | return true; |
| 4359 | } |
| 4360 | } |
| 4361 | return false; |
| 4362 | } |
| 4363 | |
| 4364 | private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation, |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4365 | int uiMode, int overscanLeft, int overscanRight, int overscanBottom, Rect dcf, |
| 4366 | boolean navVisible, boolean navTranslucent, boolean navAllowedHidden, |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4367 | boolean statusBarExpandedNotKeyguard) { |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4368 | if (mNavigationBar != null) { |
| 4369 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
| 4370 | // Force the navigation bar to its appropriate place and |
| 4371 | // size. We need to do this directly, instead of relying on |
| 4372 | // it to bubble up from the nav bar, because this needs to |
| 4373 | // change atomically with screen rotations. |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4374 | mNavigationBarPosition = navigationBarPosition(displayWidth, displayHeight, |
| 4375 | displayRotation); |
| 4376 | if (mNavigationBarPosition == NAV_BAR_BOTTOM) { |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4377 | // It's a system nav bar or a portrait screen; nav bar goes on bottom. |
| 4378 | int top = displayHeight - overscanBottom |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 4379 | - getNavigationBarHeight(displayRotation, uiMode); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4380 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
| 4381 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
| 4382 | if (transientNavBarShowing) { |
| 4383 | mNavigationBarController.setBarShowingLw(true); |
| 4384 | } else if (navVisible) { |
| 4385 | mNavigationBarController.setBarShowingLw(true); |
| 4386 | mDockBottom = mTmpNavigationFrame.top; |
| 4387 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 4388 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
| 4389 | } else { |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4390 | // We currently want to hide the navigation UI - unless we expanded the status |
| 4391 | // bar. |
| 4392 | mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4393 | } |
| 4394 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4395 | && !mNavigationBar.isAnimatingLw() |
| 4396 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4397 | // If the opaque nav bar is currently requested to be visible, |
| 4398 | // and not in the process of animating on or off, then |
| 4399 | // we can tell the app that it is covered by it. |
| 4400 | mSystemBottom = mTmpNavigationFrame.top; |
| 4401 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4402 | } else if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4403 | // Landscape screen; nav bar goes to the right. |
| 4404 | int left = displayWidth - overscanRight |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 4405 | - getNavigationBarWidth(displayRotation, uiMode); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4406 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
| 4407 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
| 4408 | if (transientNavBarShowing) { |
| 4409 | mNavigationBarController.setBarShowingLw(true); |
| 4410 | } else if (navVisible) { |
| 4411 | mNavigationBarController.setBarShowingLw(true); |
| 4412 | mDockRight = mTmpNavigationFrame.left; |
| 4413 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 4414 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
| 4415 | } else { |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4416 | // We currently want to hide the navigation UI - unless we expanded the status |
| 4417 | // bar. |
| 4418 | mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4419 | } |
| 4420 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4421 | && !mNavigationBar.isAnimatingLw() |
| 4422 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4423 | // If the nav bar is currently requested to be visible, |
| 4424 | // and not in the process of animating on or off, then |
| 4425 | // we can tell the app that it is covered by it. |
| 4426 | mSystemRight = mTmpNavigationFrame.left; |
| 4427 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4428 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
| 4429 | // Seascape screen; nav bar goes to the left. |
| 4430 | int right = overscanLeft + getNavigationBarWidth(displayRotation, uiMode); |
| 4431 | mTmpNavigationFrame.set(overscanLeft, 0, right, displayHeight); |
| 4432 | mStableLeft = mStableFullscreenLeft = mTmpNavigationFrame.right; |
| 4433 | if (transientNavBarShowing) { |
| 4434 | mNavigationBarController.setBarShowingLw(true); |
| 4435 | } else if (navVisible) { |
| 4436 | mNavigationBarController.setBarShowingLw(true); |
| 4437 | mDockLeft = mTmpNavigationFrame.right; |
| 4438 | // TODO: not so sure about those: |
| 4439 | mRestrictedScreenLeft = mRestrictedOverscanScreenLeft = mDockLeft; |
| 4440 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 4441 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
| 4442 | } else { |
| 4443 | // We currently want to hide the navigation UI - unless we expanded the status |
| 4444 | // bar. |
| 4445 | mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard); |
| 4446 | } |
| 4447 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4448 | && !mNavigationBar.isAnimatingLw() |
| 4449 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4450 | // If the nav bar is currently requested to be visible, |
| 4451 | // and not in the process of animating on or off, then |
| 4452 | // we can tell the app that it is covered by it. |
| 4453 | mSystemLeft = mTmpNavigationFrame.right; |
| 4454 | } |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4455 | } |
| 4456 | // Make sure the content and current rectangles are updated to |
| 4457 | // account for the restrictions from the navigation bar. |
| 4458 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 4459 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 4460 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 4461 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 4462 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 4463 | // And compute the final frame. |
| 4464 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
| 4465 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
| 4466 | mTmpNavigationFrame, mTmpNavigationFrame); |
| 4467 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
| 4468 | if (mNavigationBarController.checkHiddenLw()) { |
| 4469 | return true; |
| 4470 | } |
| 4471 | } |
| 4472 | return false; |
| 4473 | } |
| 4474 | |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4475 | private int navigationBarPosition(int displayWidth, int displayHeight, int displayRotation) { |
| 4476 | if (mNavigationBarCanMove && displayWidth > displayHeight) { |
| 4477 | if (displayRotation == Surface.ROTATION_270) { |
| 4478 | return NAV_BAR_LEFT; |
| 4479 | } else { |
| 4480 | return NAV_BAR_RIGHT; |
| 4481 | } |
| 4482 | } |
| 4483 | return NAV_BAR_BOTTOM; |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 4484 | } |
| 4485 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 4486 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 4487 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4488 | public int getSystemDecorLayerLw() { |
Bryce Lee | 2ed3e5f | 2015-04-01 22:09:19 +0000 | [diff] [blame] | 4489 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 4490 | return mStatusBar.getSurfaceLayer(); |
| 4491 | } |
| 4492 | |
| 4493 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { |
| 4494 | return mNavigationBar.getSurfaceLayer(); |
| 4495 | } |
| 4496 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 4497 | return 0; |
| 4498 | } |
| 4499 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 4500 | @Override |
| 4501 | public void getContentRectLw(Rect r) { |
| 4502 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 4503 | } |
| 4504 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4505 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 4506 | boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4507 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 4508 | // Here's a special case: if this attached window is a panel that is |
| 4509 | // above the dock window, and the window it is attached to is below |
| 4510 | // the dock window, then the frames we computed for the window it is |
| 4511 | // attached to can not be used because the dock is effectively part |
| 4512 | // of the underlying window and the attached window is floating on top |
| 4513 | // of the whole thing. So, we ignore the attached window and explicitly |
| 4514 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4515 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 4516 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 4517 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 4518 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4519 | } else { |
| 4520 | // The effective display frame of the attached window depends on |
| 4521 | // whether it is taking care of insetting its content. If not, |
| 4522 | // we need to use the parent's content frame so that the entire |
| 4523 | // window is positioned within that content. Otherwise we can use |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 4524 | // the overscan frame and let the attached window take care of |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4525 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4526 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 4527 | // Set the content frame of the attached window to the parent's decor frame |
| 4528 | // (same as content frame when IME isn't present) if specifically requested by |
| 4529 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 4530 | // Otherwise, use the overscan frame. |
| 4531 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
| 4532 | ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4533 | } else { |
| 4534 | // If the window is resizing, then we want to base the content |
| 4535 | // frame on our attached content frame to resize... however, |
| 4536 | // things can be tricky if the attached window is NOT in resize |
| 4537 | // mode, in which case its content frame will be larger. |
| 4538 | // Ungh. So to deal with that, make sure the content frame |
| 4539 | // we end up using is not covering the IM dock. |
| 4540 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4541 | if (attached.isVoiceInteraction()) { |
| 4542 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 4543 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 4544 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 4545 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 4546 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4547 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 4548 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 4549 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 4550 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 4551 | } |
| 4552 | } |
| 4553 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4554 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4555 | vf.set(attached.getVisibleFrameLw()); |
| 4556 | } |
| 4557 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 4558 | // window should be positioned relative to its parent or the entire |
| 4559 | // screen. |
| 4560 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 4561 | ? attached.getFrameLw() : df); |
| 4562 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4563 | |
| 4564 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 4565 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 4566 | // If app is requesting a stable layout, don't let the |
| 4567 | // content insets go below the stable values. |
| 4568 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 4569 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 4570 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 4571 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 4572 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 4573 | } else { |
| 4574 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 4575 | if (r.top < mStableTop) r.top = mStableTop; |
| 4576 | if (r.right > mStableRight) r.right = mStableRight; |
| 4577 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 4578 | } |
| 4579 | } |
| 4580 | } |
| 4581 | |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4582 | private boolean canReceiveInput(WindowState win) { |
| 4583 | boolean notFocusable = |
| 4584 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0; |
| 4585 | boolean altFocusableIm = |
| 4586 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0; |
| 4587 | boolean notFocusableForIm = notFocusable ^ altFocusableIm; |
| 4588 | return !notFocusableForIm; |
| 4589 | } |
| 4590 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4591 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4592 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4593 | public void layoutWindowLw(WindowState win, WindowState attached) { |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4594 | // We've already done the navigation bar and status bar. If the status bar can receive |
| 4595 | // input, we need to layout it again to accomodate for the IME window. |
| 4596 | if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4597 | return; |
| 4598 | } |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4599 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4600 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 4601 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4602 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 4603 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4604 | if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state"); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4605 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 4606 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4607 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4608 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 4609 | final int pfl = attrs.privateFlags; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4610 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 4611 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4612 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4613 | final Rect pf = mTmpParentFrame; |
| 4614 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4615 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4616 | final Rect cf = mTmpContentFrame; |
| 4617 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4618 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4619 | final Rect sf = mTmpStableFrame; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4620 | Rect osf = null; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4621 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4622 | |
| 4623 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 4624 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4625 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 4626 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 4627 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4628 | if (isDefaultDisplay) { |
| 4629 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 4630 | } else { |
| 4631 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 4632 | } |
| 4633 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4634 | if (!isDefaultDisplay) { |
| 4635 | if (attached != null) { |
| 4636 | // If this window is attached to another, our display |
| 4637 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4638 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4639 | } else { |
| 4640 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4641 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4642 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4643 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4644 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4645 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4646 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4647 | } |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4648 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4649 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 4650 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 4651 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 4652 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 4653 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 4654 | // ...with content insets above the nav bar |
| 4655 | cf.bottom = vf.bottom = mStableBottom; |
Adrian Roos | dd654ea | 2016-05-27 11:46:10 -0700 | [diff] [blame] | 4656 | if (mStatusBar != null && mFocusedWindow == mStatusBar && canReceiveInput(mStatusBar)) { |
| 4657 | // The status bar forces the navigation bar while it's visible. Make sure the IME |
| 4658 | // avoids the navigation bar in that case. |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4659 | if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
| 4660 | pf.right = df.right = of.right = cf.right = vf.right = mStableRight; |
| 4661 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
| 4662 | pf.left = df.left = of.left = cf.left = vf.left = mStableLeft; |
| 4663 | } |
Adrian Roos | dd654ea | 2016-05-27 11:46:10 -0700 | [diff] [blame] | 4664 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4665 | // IM dock windows always go to the bottom of the screen. |
| 4666 | attrs.gravity = Gravity.BOTTOM; |
| 4667 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4668 | } else if (attrs.type == TYPE_VOICE_INTERACTION) { |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4669 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4670 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4671 | pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4672 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Jorim Jaggi | 4b74f4d | 2016-04-27 18:44:08 -0700 | [diff] [blame] | 4673 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 4674 | cf.left = mDockLeft; |
| 4675 | cf.top = mDockTop; |
| 4676 | cf.right = mDockRight; |
| 4677 | cf.bottom = mDockBottom; |
| 4678 | } else { |
| 4679 | cf.left = mContentLeft; |
| 4680 | cf.top = mContentTop; |
| 4681 | cf.right = mContentRight; |
| 4682 | cf.bottom = mContentBottom; |
| 4683 | } |
| 4684 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4685 | vf.left = mCurLeft; |
| 4686 | vf.top = mCurTop; |
| 4687 | vf.right = mCurRight; |
| 4688 | vf.bottom = mCurBottom; |
| 4689 | } else { |
| 4690 | vf.set(cf); |
| 4691 | } |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 4692 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 4693 | layoutWallpaper(win, pf, df, of, cf); |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4694 | } else if (win == mStatusBar) { |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 4695 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4696 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4697 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 4698 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 4699 | cf.left = vf.left = mStableLeft; |
| 4700 | cf.top = vf.top = mStableTop; |
| 4701 | cf.right = vf.right = mStableRight; |
| 4702 | vf.bottom = mStableBottom; |
Adrian Roos | dc5b453 | 2016-01-06 20:49:41 +0100 | [diff] [blame] | 4703 | |
| 4704 | if (adjust == SOFT_INPUT_ADJUST_RESIZE) { |
| 4705 | cf.bottom = mContentBottom; |
| 4706 | } else { |
| 4707 | cf.bottom = mDockBottom; |
| 4708 | vf.bottom = mContentBottom; |
| 4709 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4710 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4711 | |
| 4712 | // Default policy decor for the default display |
| 4713 | dcf.left = mSystemLeft; |
| 4714 | dcf.top = mSystemTop; |
| 4715 | dcf.right = mSystemRight; |
| 4716 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4717 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 4718 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 4719 | final boolean isAppWindow = |
| 4720 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 4721 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 4722 | final boolean topAtRest = |
| 4723 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 4724 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4725 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 4726 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4727 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 4728 | && (fl & WindowManager.LayoutParams. |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4729 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0 |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 4730 | && (pfl & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4731 | // Ensure policy decor includes status bar |
| 4732 | dcf.top = mStableTop; |
| 4733 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4734 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4735 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 4736 | && (fl & WindowManager.LayoutParams. |
| 4737 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4738 | // Ensure policy decor includes navigation bar |
| 4739 | dcf.bottom = mStableBottom; |
| 4740 | dcf.right = mStableRight; |
| 4741 | } |
| 4742 | } |
| 4743 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4744 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 4745 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4746 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4747 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4748 | // This is the case for a normal activity window: we want it |
| 4749 | // to cover all of the screen space, and it can take care of |
| 4750 | // moving its contents to account for screen decorations that |
| 4751 | // intrude into that space. |
| 4752 | if (attached != null) { |
| 4753 | // If this window is attached to another, our display |
| 4754 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4755 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4756 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4757 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 4758 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4759 | // Status bar panels are the only windows who can go on top of |
| 4760 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 4761 | // permission, so they have the same privileges as the status |
| 4762 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4763 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4764 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4765 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4766 | pf.left = df.left = of.left = hasNavBar |
| 4767 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 4768 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4769 | pf.right = df.right = of.right = hasNavBar |
| 4770 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 4771 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4772 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 4773 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 4774 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4775 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4776 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4777 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 4778 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4779 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4780 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4781 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4782 | // Asking to layout into the overscan region, so give it that pure |
| 4783 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4784 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 4785 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 4786 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4787 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 4788 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4789 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4790 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4791 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4792 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4793 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4794 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4795 | // only do this for application windows to ensure no window that |
| 4796 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4797 | pf.left = df.left = mOverscanScreenLeft; |
| 4798 | pf.top = df.top = mOverscanScreenTop; |
| 4799 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4800 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4801 | // We need to tell the app about where the frame inside the overscan |
| 4802 | // is, so it can inset its content by that amount -- it didn't ask |
| 4803 | // to actually extend itself into the overscan region. |
| 4804 | of.left = mUnrestrictedScreenLeft; |
| 4805 | of.top = mUnrestrictedScreenTop; |
| 4806 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4807 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4808 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4809 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 4810 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 4811 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 4812 | + mRestrictedOverscanScreenWidth; |
| 4813 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 4814 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4815 | // We need to tell the app about where the frame inside the overscan |
| 4816 | // is, so it can inset its content by that amount -- it didn't ask |
| 4817 | // to actually extend itself into the overscan region. |
| 4818 | of.left = mUnrestrictedScreenLeft; |
| 4819 | of.top = mUnrestrictedScreenTop; |
| 4820 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4821 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4822 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4823 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4824 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4825 | if (win.isVoiceInteraction()) { |
| 4826 | cf.left = mVoiceContentLeft; |
| 4827 | cf.top = mVoiceContentTop; |
| 4828 | cf.right = mVoiceContentRight; |
| 4829 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4830 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4831 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 4832 | cf.left = mDockLeft; |
| 4833 | cf.top = mDockTop; |
| 4834 | cf.right = mDockRight; |
| 4835 | cf.bottom = mDockBottom; |
| 4836 | } else { |
| 4837 | cf.left = mContentLeft; |
| 4838 | cf.top = mContentTop; |
| 4839 | cf.right = mContentRight; |
| 4840 | cf.bottom = mContentBottom; |
| 4841 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4842 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4843 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4844 | // Full screen windows are always given a layout that is as if the |
| 4845 | // status bar and other transient decors are gone. This is to avoid |
| 4846 | // bad states when moving from a window that is not hding the |
| 4847 | // status bar to one that is. |
| 4848 | cf.left = mRestrictedScreenLeft; |
| 4849 | cf.top = mRestrictedScreenTop; |
| 4850 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 4851 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4852 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4853 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4854 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4855 | vf.left = mCurLeft; |
| 4856 | vf.top = mCurTop; |
| 4857 | vf.right = mCurRight; |
| 4858 | vf.bottom = mCurBottom; |
| 4859 | } else { |
| 4860 | vf.set(cf); |
| 4861 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4862 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4863 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 4864 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 4865 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4866 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4867 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4868 | // A window that has requested to fill the entire screen just |
| 4869 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4870 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4871 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL |
| 4872 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4873 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 4874 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 4875 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 4876 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4877 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4878 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4879 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4880 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4881 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4882 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 4883 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 4884 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 4885 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 4886 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4887 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4888 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4889 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4890 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 4891 | + mUnrestrictedScreenWidth; |
| 4892 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 4893 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4894 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4895 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 4896 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 4897 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 4898 | || attrs.type == TYPE_BOOT_PROGRESS |
| 4899 | || attrs.type == TYPE_SCREENSHOT) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 4900 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 4901 | // Fullscreen secure system overlays get what they ask for. Screenshot region |
| 4902 | // selection overlay should also expand to full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4903 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4904 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4905 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 4906 | + mOverscanScreenWidth; |
| 4907 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 4908 | + mOverscanScreenHeight; |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 4909 | } else if (attrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 4910 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4911 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4912 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4913 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 4914 | + mOverscanScreenWidth; |
| 4915 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 4916 | + mOverscanScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4917 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4918 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4919 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4920 | // Asking to layout into the overscan region, so give it that pure |
| 4921 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4922 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4923 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4924 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4925 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4926 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4927 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4928 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4929 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 4930 | && (attrs.type == TYPE_STATUS_BAR |
| 4931 | || attrs.type == TYPE_TOAST |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 4932 | || attrs.type == TYPE_DOCK_DIVIDER |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 4933 | || attrs.type == TYPE_VOICE_INTERACTION_STARTING |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 4934 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4935 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4936 | // Asking for layout as if the nav bar is hidden, lets the |
| 4937 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 4938 | // 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] | 4939 | // can be above the nav bar can do this. |
| 4940 | // XXX This assumes that an app asking for this will also |
| 4941 | // ask for layout in only content. We can't currently figure out |
| 4942 | // what the screen would be if only laying out to hide the nav bar. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4943 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 4944 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 4945 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 4946 | + mUnrestrictedScreenWidth; |
| 4947 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 4948 | + mUnrestrictedScreenHeight; |
Jorim Jaggi | 9f6798a | 2016-02-10 22:16:06 -0800 | [diff] [blame] | 4949 | } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) { |
| 4950 | pf.left = df.left = of.left = mRestrictedScreenLeft; |
| 4951 | pf.top = df.top = of.top = mRestrictedScreenTop; |
| 4952 | pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 4953 | pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop |
| 4954 | + mRestrictedScreenHeight; |
| 4955 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 4956 | cf.left = mDockLeft; |
| 4957 | cf.top = mDockTop; |
| 4958 | cf.right = mDockRight; |
| 4959 | cf.bottom = mDockBottom; |
| 4960 | } else { |
| 4961 | cf.left = mContentLeft; |
| 4962 | cf.top = mContentTop; |
| 4963 | cf.right = mContentRight; |
| 4964 | cf.bottom = mContentBottom; |
| 4965 | } |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4966 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4967 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4968 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4969 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4970 | + mRestrictedScreenWidth; |
| 4971 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4972 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4973 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4974 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4975 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4976 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4977 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4978 | vf.left = mCurLeft; |
| 4979 | vf.top = mCurTop; |
| 4980 | vf.right = mCurRight; |
| 4981 | vf.bottom = mCurBottom; |
| 4982 | } else { |
| 4983 | vf.set(cf); |
| 4984 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4985 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4986 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4987 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4988 | // A child window should be placed inside of the same visible |
| 4989 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4990 | setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4991 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4992 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4993 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4994 | // Otherwise, a normal window must be placed inside the content |
| 4995 | // of all screen decorations. |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4996 | if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 4997 | // Status bar panels and the volume dialog are the only windows who can go on |
| 4998 | // top of the status bar. They are protected by the STATUS_BAR_SERVICE |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4999 | // permission, so they have the same privileges as the status |
| 5000 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5001 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 5002 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 5003 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 5004 | + mRestrictedScreenWidth; |
| 5005 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 5006 | + mRestrictedScreenHeight; |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 5007 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) { |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 5008 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5009 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 5010 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 5011 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 5012 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5013 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 5014 | pf.left = mContentLeft; |
| 5015 | pf.top = mContentTop; |
| 5016 | pf.right = mContentRight; |
| 5017 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 5018 | if (win.isVoiceInteraction()) { |
| 5019 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 5020 | df.top = of.top = cf.top = mVoiceContentTop; |
| 5021 | df.right = of.right = cf.right = mVoiceContentRight; |
| 5022 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 5023 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5024 | df.left = of.left = cf.left = mDockLeft; |
| 5025 | df.top = of.top = cf.top = mDockTop; |
| 5026 | df.right = of.right = cf.right = mDockRight; |
| 5027 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 5028 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5029 | df.left = of.left = cf.left = mContentLeft; |
| 5030 | df.top = of.top = cf.top = mContentTop; |
| 5031 | df.right = of.right = cf.right = mContentRight; |
| 5032 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 5033 | } |
| 5034 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 5035 | vf.left = mCurLeft; |
| 5036 | vf.top = mCurTop; |
| 5037 | vf.right = mCurRight; |
| 5038 | vf.bottom = mCurBottom; |
| 5039 | } else { |
| 5040 | vf.set(cf); |
| 5041 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 5042 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5043 | } |
| 5044 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5045 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 5046 | // 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] | 5047 | // Also, we don't allow windows in multi-window mode to extend out of the screen. |
| 5048 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 5049 | && !win.isInMultiWindowMode()) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 5050 | df.left = df.top = -10000; |
| 5051 | df.right = df.bottom = 10000; |
| 5052 | if (attrs.type != TYPE_WALLPAPER) { |
| 5053 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 5054 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 5055 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5056 | } |
| 5057 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5058 | // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we |
| 5059 | // 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] | 5060 | // We only want to apply outsets to certain types of windows. For example, we never want to |
| 5061 | // 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] | 5062 | final boolean useOutsets = shouldUseOutsets(attrs, fl); |
Filip Gruszczynski | b0c673b | 2015-06-05 09:43:06 -0700 | [diff] [blame] | 5063 | if (isDefaultDisplay && useOutsets) { |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5064 | osf = mTmpOutsetFrame; |
| 5065 | osf.set(cf.left, cf.top, cf.right, cf.bottom); |
| 5066 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 5067 | if (outset > 0) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 5068 | int rotation = mDisplayRotation; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5069 | if (rotation == Surface.ROTATION_0) { |
| 5070 | osf.bottom += outset; |
| 5071 | } else if (rotation == Surface.ROTATION_90) { |
| 5072 | osf.right += outset; |
| 5073 | } else if (rotation == Surface.ROTATION_180) { |
| 5074 | osf.top -= outset; |
| 5075 | } else if (rotation == Surface.ROTATION_270) { |
| 5076 | osf.left -= outset; |
| 5077 | } |
| 5078 | if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset |
| 5079 | + " with rotation " + rotation + ", result: " + osf); |
| 5080 | } |
| 5081 | } |
| 5082 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5083 | 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] | 5084 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5085 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 5086 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 5087 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5088 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5089 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5090 | + " dcf=" + dcf.toShortString() |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5091 | + " sf=" + sf.toShortString() |
| 5092 | + " osf=" + (osf == null ? "null" : osf.toShortString())); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5093 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5094 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5095 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5096 | // Dock windows carve out the bottom of the screen, so normal windows |
| 5097 | // can't appear underneath them. |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5098 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleLw() |
| 5099 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5100 | setLastInputMethodWindowLw(null, null); |
| 5101 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5102 | } |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5103 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleLw() |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5104 | && !win.getGivenInsetsPendingLw()) { |
| 5105 | offsetVoiceInputWindowLw(win); |
| 5106 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5107 | } |
| 5108 | |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 5109 | private void layoutWallpaper(WindowState win, Rect pf, Rect df, Rect of, Rect cf) { |
| 5110 | |
| 5111 | // The wallpaper also has Real Ultimate Power, but we want to tell |
| 5112 | // it about the overscan area. |
| 5113 | pf.left = df.left = mOverscanScreenLeft; |
| 5114 | pf.top = df.top = mOverscanScreenTop; |
| 5115 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 5116 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
| 5117 | of.left = cf.left = mUnrestrictedScreenLeft; |
| 5118 | of.top = cf.top = mUnrestrictedScreenTop; |
| 5119 | of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 5120 | of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 5121 | } |
| 5122 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5123 | private void offsetInputMethodWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 5124 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5125 | top += win.getGivenContentInsetsLw().top; |
| 5126 | if (mContentBottom > top) { |
| 5127 | mContentBottom = top; |
| 5128 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5129 | if (mVoiceContentBottom > top) { |
| 5130 | mVoiceContentBottom = top; |
| 5131 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5132 | top = win.getVisibleFrameLw().top; |
| 5133 | top += win.getGivenVisibleInsetsLw().top; |
| 5134 | if (mCurBottom > top) { |
| 5135 | mCurBottom = top; |
| 5136 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5137 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5138 | + mDockBottom + " mContentBottom=" |
| 5139 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 5140 | } |
| 5141 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5142 | private void offsetVoiceInputWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 5143 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 5144 | top += win.getGivenContentInsetsLw().top; |
| 5145 | if (mVoiceContentBottom > top) { |
| 5146 | mVoiceContentBottom = top; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5147 | } |
| 5148 | } |
| 5149 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5150 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 5151 | @Override |
| 5152 | public void finishLayoutLw() { |
| 5153 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5154 | } |
| 5155 | |
| 5156 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5157 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 5158 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5159 | mTopFullscreenOpaqueWindowState = null; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 5160 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5161 | mTopDockedOpaqueWindowState = null; |
| 5162 | mTopDockedOpaqueOrDimmingWindowState = null; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5163 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5164 | mForceStatusBarFromKeyguard = false; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 5165 | mForceStatusBarTransparent = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5166 | mForcingShowNavBar = false; |
| 5167 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5168 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5169 | mAllowLockscreenWhenOn = false; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5170 | mShowingDream = false; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5171 | } |
| 5172 | |
| 5173 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5174 | @Override |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 5175 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs, |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5176 | WindowState attached, WindowState imeTarget) { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 5177 | final boolean visible = !win.isGoneForLayoutLw(); |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5178 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisible=" + visible); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5179 | applyKeyguardPolicyLw(win, imeTarget); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5180 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5181 | if (mTopFullscreenOpaqueWindowState == null && visible && attrs.type == TYPE_INPUT_METHOD) { |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 5182 | mForcingShowNavBar = true; |
| 5183 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5184 | } |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 5185 | if (attrs.type == TYPE_STATUS_BAR) { |
| 5186 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 5187 | mForceStatusBarFromKeyguard = true; |
| 5188 | } |
| 5189 | if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) { |
| 5190 | mForceStatusBarTransparent = true; |
| 5191 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 5192 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 5193 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 5194 | // Don't allow snapshots to influence SystemUI visibility flags. |
| 5195 | // TODO: Revisit this once SystemUI flags for snapshots are handled correctly |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 5196 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 5197 | && attrs.type < FIRST_SYSTEM_WINDOW |
| 5198 | && (attrs.privateFlags & PRIVATE_FLAG_TASK_SNAPSHOT) == 0; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5199 | final int stackId = win.getStackId(); |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5200 | if (mTopFullscreenOpaqueWindowState == null && visible) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5201 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5202 | mForceStatusBar = true; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5203 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5204 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 5205 | // If the lockscreen was showing when the dream started then wait |
| 5206 | // for the dream to draw before hiding the lockscreen. |
| 5207 | if (!mDreamingLockscreen |
| 5208 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 5209 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 5210 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5211 | } |
| 5212 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 5213 | |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 5214 | // For app windows that are not attached, we decide if all windows in the app they |
| 5215 | // represent should be hidden or if we should hide the lockscreen. For attached app |
| 5216 | // windows we defer the decision to the window it is attached to. |
| 5217 | if (appWindow && attached == null) { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5218 | if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 5219 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 5220 | mTopFullscreenOpaqueWindowState = win; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 5221 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 5222 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 5223 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 5224 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 5225 | mAllowLockscreenWhenOn = true; |
| 5226 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5227 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 5228 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5229 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5230 | |
Jorim Jaggi | 90859bc | 2016-06-28 16:25:23 -0700 | [diff] [blame] | 5231 | // Voice interaction overrides both top fullscreen and top docked. |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5232 | if (visible && win.getAttrs().type == TYPE_VOICE_INTERACTION) { |
Jorim Jaggi | 90859bc | 2016-06-28 16:25:23 -0700 | [diff] [blame] | 5233 | if (mTopFullscreenOpaqueWindowState == null) { |
| 5234 | mTopFullscreenOpaqueWindowState = win; |
| 5235 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 5236 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 5237 | } |
| 5238 | } |
| 5239 | if (mTopDockedOpaqueWindowState == null) { |
| 5240 | mTopDockedOpaqueWindowState = win; |
| 5241 | if (mTopDockedOpaqueOrDimmingWindowState == null) { |
| 5242 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 5243 | } |
| 5244 | } |
| 5245 | } |
| 5246 | |
| 5247 | // Keep track of the window if it's dimming but not necessarily fullscreen. |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5248 | if (mTopFullscreenOpaqueOrDimmingWindowState == null && visible |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5249 | && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) { |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 5250 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 5251 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5252 | |
| 5253 | // We need to keep track of the top "fullscreen" opaque window for the docked stack |
| 5254 | // separately, because both the "real fullscreen" opaque window and the one for the docked |
| 5255 | // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR. |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5256 | if (mTopDockedOpaqueWindowState == null && visible && appWindow && attached == null |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5257 | && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) { |
| 5258 | mTopDockedOpaqueWindowState = win; |
| 5259 | if (mTopDockedOpaqueOrDimmingWindowState == null) { |
| 5260 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 5261 | } |
| 5262 | } |
| 5263 | |
| 5264 | // Also keep track of any windows that are dimming but not necessarily fullscreen in the |
| 5265 | // docked stack. |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5266 | if (mTopDockedOpaqueOrDimmingWindowState == null && visible && win.isDimming() |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5267 | && stackId == DOCKED_STACK_ID) { |
| 5268 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 5269 | } |
| 5270 | } |
| 5271 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5272 | private void applyKeyguardPolicyLw(WindowState win, WindowState imeTarget) { |
| 5273 | if (canBeHiddenByKeyguardLw(win)) { |
| 5274 | if (shouldBeHiddenByKeyguard(win, imeTarget)) { |
| 5275 | win.hideLw(false /* doAnimation */); |
| 5276 | } else { |
| 5277 | win.showLw(false /* doAnimation */); |
| 5278 | } |
| 5279 | } |
| 5280 | } |
| 5281 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5282 | private boolean isFullscreen(WindowManager.LayoutParams attrs) { |
| 5283 | return attrs.x == 0 && attrs.y == 0 |
| 5284 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 5285 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5289 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 5290 | public int finishPostLayoutPolicyLw() { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5291 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5292 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 5293 | |
| 5294 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 5295 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 5296 | : null; |
| 5297 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 5298 | // If we are not currently showing a dream then remember the current |
| 5299 | // lockscreen state. We will use this to determine whether the dream |
| 5300 | // started while the lockscreen was showing and remember this state |
| 5301 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5302 | if (!mShowingDream) { |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 5303 | mDreamingLockscreen = isKeyguardShowingAndNotOccluded(); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 5304 | if (mDreamingSleepTokenNeeded) { |
| 5305 | mDreamingSleepTokenNeeded = false; |
| 5306 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget(); |
| 5307 | } |
| 5308 | } else { |
| 5309 | if (!mDreamingSleepTokenNeeded) { |
| 5310 | mDreamingSleepTokenNeeded = true; |
| 5311 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget(); |
| 5312 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5313 | } |
| 5314 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5315 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5316 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5317 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 5318 | + " top=" + mTopFullscreenOpaqueWindowState); |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 5319 | boolean shouldBeTransparent = mForceStatusBarTransparent |
| 5320 | && !mForceStatusBar |
| 5321 | && !mForceStatusBarFromKeyguard; |
| 5322 | if (!shouldBeTransparent) { |
| 5323 | mStatusBarController.setShowTransparent(false /* transparent */); |
| 5324 | } else if (!mStatusBar.isVisibleLw()) { |
| 5325 | mStatusBarController.setShowTransparent(true /* transparent */); |
| 5326 | } |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 5327 | |
| 5328 | WindowManager.LayoutParams statusBarAttrs = mStatusBar.getAttrs(); |
| 5329 | boolean statusBarExpanded = statusBarAttrs.height == MATCH_PARENT |
| 5330 | && statusBarAttrs.width == MATCH_PARENT; |
| 5331 | if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent |
| 5332 | || statusBarExpanded) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5333 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5334 | if (mStatusBarController.setBarShowingLw(true)) { |
| 5335 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5336 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 5337 | // Maintain fullscreen layout until incoming animation is complete. |
| 5338 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 5339 | // Transient status bar on the lockscreen is not allowed |
| 5340 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 5341 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 5342 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 5343 | } |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 5344 | if (statusBarExpanded && mNavigationBar != null) { |
| 5345 | if (mNavigationBarController.setBarShowingLw(true)) { |
| 5346 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5347 | } |
| 5348 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5349 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5350 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5351 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5352 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 5353 | + " shown position: " |
| 5354 | + mTopFullscreenOpaqueWindowState.getShownPositionLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5355 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5356 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5357 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5358 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5359 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5360 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 5361 | // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5362 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 5363 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5364 | if (mStatusBarController.isTransientShowing()) { |
| 5365 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5366 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5367 | } |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 5368 | } else if (topIsFullscreen |
| 5369 | && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID) |
| 5370 | && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5371 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5372 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5373 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5374 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 5375 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 5376 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5377 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5378 | 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] | 5379 | if (mStatusBarController.setBarShowingLw(true)) { |
| 5380 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5381 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5382 | } |
| 5383 | } |
| 5384 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 5385 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 5386 | if (mTopIsFullscreen != topIsFullscreen) { |
| 5387 | if (!topIsFullscreen) { |
| 5388 | // Force another layout when status bar becomes fully shown. |
| 5389 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5390 | } |
| 5391 | mTopIsFullscreen = topIsFullscreen; |
| 5392 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 5393 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5394 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5395 | // If the navigation bar has been hidden or shown, we need to do another |
| 5396 | // layout pass to update that window. |
| 5397 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5398 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5399 | |
Jorim Jaggi | 77e1043 | 2016-10-26 17:43:56 -0700 | [diff] [blame] | 5400 | if (mShowingDream != mLastShowingDream) { |
| 5401 | mLastShowingDream = mShowingDream; |
| 5402 | mWindowManagerFuncs.notifyShowingDreamChanged(); |
| 5403 | } |
| 5404 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5405 | // update since mAllowLockscreenWhenOn might have changed |
| 5406 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5407 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5408 | } |
| 5409 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5410 | /** |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5411 | * Updates the occluded state of the Keyguard. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5412 | * |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5413 | * @return Whether the flags have changed and we have to redo the layout. |
| 5414 | */ |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5415 | private boolean setKeyguardOccludedLw(boolean isOccluded) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5416 | if (DEBUG_KEYGUARD) Slog.d(TAG, "setKeyguardOccluded occluded=" + isOccluded); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5417 | boolean wasOccluded = mKeyguardOccluded; |
| 5418 | boolean showing = mKeyguardDelegate.isShowing(); |
| 5419 | if (wasOccluded && !isOccluded && showing) { |
| 5420 | mKeyguardOccluded = false; |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 5421 | mKeyguardDelegate.setOccluded(false, true /* animate */); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5422 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 5423 | if (!mKeyguardDelegate.hasLockscreenWallpaper()) { |
| 5424 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 5425 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5426 | return true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5427 | } else if (!wasOccluded && isOccluded && showing) { |
| 5428 | mKeyguardOccluded = true; |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 5429 | mKeyguardDelegate.setOccluded(true, false /* animate */); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5430 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 5431 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 5432 | return true; |
Adrian Roos | 909fe2d | 2016-10-12 12:03:24 -0700 | [diff] [blame] | 5433 | } else if (wasOccluded != isOccluded) { |
| 5434 | mKeyguardOccluded = isOccluded; |
| 5435 | mKeyguardDelegate.setOccluded(isOccluded, false /* animate */); |
| 5436 | return false; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5437 | } else { |
| 5438 | return false; |
| 5439 | } |
| 5440 | } |
| 5441 | |
| 5442 | private boolean isStatusBarKeyguard() { |
| 5443 | return mStatusBar != null |
| 5444 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 5445 | } |
| 5446 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5447 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5448 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5449 | if (mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 5450 | // If keyguard or dreams is currently visible, no reason to animate behind it. |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5451 | return false; |
| 5452 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5453 | return true; |
| 5454 | } |
| 5455 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5456 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5457 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5458 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5459 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5460 | // If the navigation bar has been hidden or shown, we need to do another |
| 5461 | // layout pass to update that window. |
| 5462 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 5463 | } |
| 5464 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5465 | } |
| 5466 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 5467 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5468 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5469 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5470 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5471 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 5472 | if (newLidState == mLidState) { |
| 5473 | return; |
| 5474 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5475 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5476 | mLidState = newLidState; |
| 5477 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5478 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5479 | |
| 5480 | if (lidOpen) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5481 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch, |
| 5482 | "android.policy:LID"); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5483 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 5484 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5485 | } |
| 5486 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5487 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5488 | @Override |
| 5489 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 5490 | int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; |
| 5491 | if (mCameraLensCoverState == lensCoverState) { |
| 5492 | return; |
| 5493 | } |
| 5494 | if (mCameraLensCoverState == CAMERA_LENS_COVERED && |
| 5495 | lensCoverState == CAMERA_LENS_UNCOVERED) { |
| 5496 | Intent intent; |
| 5497 | final boolean keyguardActive = mKeyguardDelegate == null ? false : |
| 5498 | mKeyguardDelegate.isShowing(); |
| 5499 | if (keyguardActive) { |
| 5500 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); |
| 5501 | } else { |
| 5502 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 5503 | } |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5504 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens, |
| 5505 | "android.policy:CAMERA_COVER"); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5506 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5507 | } |
| 5508 | mCameraLensCoverState = lensCoverState; |
| 5509 | } |
| 5510 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5511 | void setHdmiPlugged(boolean plugged) { |
| 5512 | if (mHdmiPlugged != plugged) { |
| 5513 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5514 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5515 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5516 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5517 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 5518 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5519 | } |
| 5520 | } |
| 5521 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5522 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 5523 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5524 | // watch for HDMI plug messages if the hdmi switch exists |
| 5525 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 5526 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 5527 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5528 | final String filename = "/sys/class/switch/hdmi/state"; |
| 5529 | FileReader reader = null; |
| 5530 | try { |
| 5531 | reader = new FileReader(filename); |
| 5532 | char[] buf = new char[15]; |
| 5533 | int n = reader.read(buf); |
| 5534 | if (n > 1) { |
| 5535 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 5536 | } |
| 5537 | } catch (IOException ex) { |
| 5538 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 5539 | } catch (NumberFormatException ex) { |
| 5540 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 5541 | } finally { |
| 5542 | if (reader != null) { |
| 5543 | try { |
| 5544 | reader.close(); |
| 5545 | } catch (IOException ex) { |
| 5546 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5547 | } |
| 5548 | } |
| 5549 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 5550 | // This dance forces the code in setHdmiPlugged to run. |
| 5551 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 5552 | mHdmiPlugged = !plugged; |
| 5553 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5554 | } |
| 5555 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 5556 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 5557 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 5558 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5559 | final Runnable mScreenshotTimeout = new Runnable() { |
| 5560 | @Override public void run() { |
| 5561 | synchronized (mScreenshotLock) { |
| 5562 | if (mScreenshotConnection != null) { |
| 5563 | mContext.unbindService(mScreenshotConnection); |
| 5564 | mScreenshotConnection = null; |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5565 | notifyScreenshotError(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 5566 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 5567 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5568 | } |
| 5569 | }; |
| 5570 | |
| 5571 | // Assume this is called from the Handler thread. |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 5572 | private void takeScreenshot(final int screenshotType) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5573 | synchronized (mScreenshotLock) { |
| 5574 | if (mScreenshotConnection != null) { |
| 5575 | return; |
| 5576 | } |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5577 | final ComponentName serviceComponent = new ComponentName(SYSUI_PACKAGE, |
| 5578 | SYSUI_SCREENSHOT_SERVICE); |
| 5579 | final Intent serviceIntent = new Intent(); |
| 5580 | serviceIntent.setComponent(serviceComponent); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5581 | ServiceConnection conn = new ServiceConnection() { |
| 5582 | @Override |
| 5583 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 5584 | synchronized (mScreenshotLock) { |
| 5585 | if (mScreenshotConnection != this) { |
| 5586 | return; |
| 5587 | } |
| 5588 | Messenger messenger = new Messenger(service); |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 5589 | Message msg = Message.obtain(null, screenshotType); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5590 | final ServiceConnection myConn = this; |
| 5591 | Handler h = new Handler(mHandler.getLooper()) { |
| 5592 | @Override |
| 5593 | public void handleMessage(Message msg) { |
| 5594 | synchronized (mScreenshotLock) { |
| 5595 | if (mScreenshotConnection == myConn) { |
| 5596 | mContext.unbindService(mScreenshotConnection); |
| 5597 | mScreenshotConnection = null; |
| 5598 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 5599 | } |
| 5600 | } |
| 5601 | } |
| 5602 | }; |
| 5603 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 5604 | msg.arg1 = msg.arg2 = 0; |
| 5605 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 5606 | msg.arg1 = 1; |
| 5607 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 5608 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5609 | try { |
| 5610 | messenger.send(msg); |
| 5611 | } catch (RemoteException e) { |
| 5612 | } |
| 5613 | } |
| 5614 | } |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5615 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5616 | @Override |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5617 | public void onServiceDisconnected(ComponentName name) { |
Geoffrey Pitsch | b2d6ed3 | 2016-08-24 10:37:19 -0400 | [diff] [blame] | 5618 | synchronized (mScreenshotLock) { |
| 5619 | if (mScreenshotConnection != null) { |
| 5620 | mContext.unbindService(mScreenshotConnection); |
| 5621 | mScreenshotConnection = null; |
| 5622 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 5623 | notifyScreenshotError(); |
| 5624 | } |
| 5625 | } |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5626 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5627 | }; |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5628 | if (mContext.bindServiceAsUser(serviceIntent, conn, |
| 5629 | Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, |
| 5630 | UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5631 | mScreenshotConnection = conn; |
| 5632 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 5633 | } |
| 5634 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 5635 | } |
| 5636 | |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5637 | /** |
| 5638 | * Notifies the screenshot service to show an error. |
| 5639 | */ |
| 5640 | private void notifyScreenshotError() { |
| 5641 | // If the service process is killed, then ask it to clean up after itself |
| 5642 | final ComponentName errorComponent = new ComponentName(SYSUI_PACKAGE, |
| 5643 | SYSUI_SCREENSHOT_ERROR_RECEIVER); |
Dianne Hackborn | a8c1693 | 2016-05-24 12:58:21 -0700 | [diff] [blame] | 5644 | Intent errorIntent = new Intent(Intent.ACTION_USER_PRESENT); |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5645 | errorIntent.setComponent(errorComponent); |
| 5646 | errorIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | |
| 5647 | Intent.FLAG_RECEIVER_FOREGROUND); |
Winson | 538c226 | 2016-05-19 10:06:18 -0700 | [diff] [blame] | 5648 | mContext.sendBroadcastAsUser(errorIntent, UserHandle.CURRENT); |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5649 | } |
| 5650 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5651 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5652 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5653 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 5654 | if (!mSystemBooted) { |
| 5655 | // If we have not yet booted, don't let key events do anything. |
| 5656 | return 0; |
| 5657 | } |
| 5658 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5659 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 5660 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 5661 | final boolean canceled = event.isCanceled(); |
| 5662 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 5663 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 5664 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 5665 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 5666 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 5667 | // the same as if it were open and in front. |
| 5668 | // This will prevent any keys other than the power button from waking the screen |
| 5669 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5670 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5671 | (interactive ? |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5672 | isKeyguardShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5673 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5674 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5675 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5676 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5677 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5678 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5679 | } |
| 5680 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5681 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5682 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 5683 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 5684 | || event.isWakeKey(); |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 5685 | if (interactive || (isInjected && !isWakeKey)) { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 5686 | // When the device is interactive or the key is injected pass the |
| 5687 | // key to the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5688 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5689 | isWakeKey = false; |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 5690 | |
| 5691 | if (interactive) { |
| 5692 | // If the screen is awake, but the button pressed was the one that woke the device |
| 5693 | // then don't pass it to the application |
| 5694 | if (keyCode == mPendingWakeKey && !down) { |
| 5695 | result = 0; |
| 5696 | } |
| 5697 | // Reset the pending key |
| 5698 | mPendingWakeKey = PENDING_KEY_NULL; |
| 5699 | } |
| 5700 | } else if (!interactive && shouldDispatchInputWhenNonInteractive(event)) { |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 5701 | // If we're currently dozing with the screen on and the keyguard showing, pass the key |
| 5702 | // to the application but preserve its wake key status to make sure we still move |
| 5703 | // from dozing to fully interactive if we would normally go from off to fully |
| 5704 | // interactive. |
| 5705 | result = ACTION_PASS_TO_USER; |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 5706 | // Since we're dispatching the input, reset the pending key |
| 5707 | mPendingWakeKey = PENDING_KEY_NULL; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5708 | } else { |
| 5709 | // When the screen is off and the key is not injected, determine whether |
| 5710 | // to wake the device but don't pass the key to the application. |
| 5711 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5712 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 5713 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5714 | } |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 5715 | // Cache the wake key on down event so we can also avoid sending the up event to the app |
| 5716 | if (isWakeKey && down) { |
| 5717 | mPendingWakeKey = keyCode; |
| 5718 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5719 | } |
| 5720 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 5721 | // If the key would be handled globally, just return the result, don't worry about special |
| 5722 | // key processing. |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5723 | if (isValidGlobalKey(keyCode) |
| 5724 | && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 5725 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5726 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 5727 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 5728 | return result; |
| 5729 | } |
| 5730 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5731 | boolean useHapticFeedback = down |
| 5732 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 5733 | && event.getRepeatCount() == 0; |
| 5734 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5735 | // Handle special keys. |
| 5736 | switch (keyCode) { |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 5737 | case KeyEvent.KEYCODE_BACK: { |
| 5738 | if (down) { |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 5739 | interceptBackKeyDown(); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 5740 | } else { |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 5741 | boolean handled = interceptBackKeyUp(event); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 5742 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 5743 | // 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] | 5744 | if (handled) { |
| 5745 | result &= ~ACTION_PASS_TO_USER; |
| 5746 | } |
| 5747 | } |
| 5748 | break; |
| 5749 | } |
| 5750 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5751 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 5752 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5753 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5754 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 5755 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5756 | if (interactive && !mScreenshotChordVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5757 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5758 | mScreenshotChordVolumeDownKeyTriggered = true; |
| 5759 | mScreenshotChordVolumeDownKeyTime = event.getDownTime(); |
| 5760 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5761 | cancelPendingPowerKeyAction(); |
| 5762 | interceptScreenshotChord(); |
| 5763 | } |
| 5764 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5765 | mScreenshotChordVolumeDownKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5766 | cancelPendingScreenshotChordAction(); |
| 5767 | } |
| 5768 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 5769 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5770 | if (interactive && !mScreenshotChordVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5771 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5772 | mScreenshotChordVolumeUpKeyTriggered = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5773 | cancelPendingPowerKeyAction(); |
| 5774 | cancelPendingScreenshotChordAction(); |
| 5775 | } |
| 5776 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5777 | mScreenshotChordVolumeUpKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5778 | cancelPendingScreenshotChordAction(); |
| 5779 | } |
| 5780 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5781 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5782 | TelecomManager telecomManager = getTelecommService(); |
| 5783 | if (telecomManager != null) { |
| 5784 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5785 | // If an incoming call is ringing, either VOLUME key means |
| 5786 | // "silence ringer". We handle these keys here, rather than |
| 5787 | // in the InCallScreen, to make sure we'll respond to them |
| 5788 | // even if the InCallScreen hasn't come to the foreground yet. |
| 5789 | // Look for the DOWN event here, to agree with the "fallback" |
| 5790 | // behavior in the InCallScreen. |
| 5791 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 5792 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5793 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5794 | // Silence the ringer. (It's safe to call this |
| 5795 | // even if the ringer has already been silenced.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5796 | telecomManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5797 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5798 | // And *don't* pass this key thru to the current activity |
| 5799 | // (which is probably the InCallScreen.) |
| 5800 | result &= ~ACTION_PASS_TO_USER; |
| 5801 | break; |
| 5802 | } |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5803 | if (telecomManager.isInCall() |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5804 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 5805 | // If we are in call but we decided not to pass the key to |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 5806 | // the application, just pass it to the session service. |
| 5807 | |
| 5808 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 5809 | .sendVolumeKeyEvent(event, false); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5810 | break; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5811 | } |
| 5812 | } |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 5813 | } |
| 5814 | if (mUseTvRouting) { |
| 5815 | // On TVs, defer special key handlings to |
| 5816 | // {@link interceptKeyBeforeDispatching()}. |
| 5817 | result |= ACTION_PASS_TO_USER; |
| 5818 | } else if ((result & ACTION_PASS_TO_USER) == 0) { |
| 5819 | // If we aren't passing to the user and no one else |
| 5820 | // handled it send it to the session manager to |
| 5821 | // figure out. |
| 5822 | MediaSessionLegacyHelper.getHelper(mContext) |
| 5823 | .sendVolumeKeyEvent(event, true); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5824 | } |
| 5825 | break; |
| 5826 | } |
| 5827 | |
| 5828 | case KeyEvent.KEYCODE_ENDCALL: { |
| 5829 | result &= ~ACTION_PASS_TO_USER; |
| 5830 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5831 | TelecomManager telecomManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5832 | boolean hungUp = false; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5833 | if (telecomManager != null) { |
| 5834 | hungUp = telecomManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5835 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5836 | if (interactive && !hungUp) { |
| 5837 | mEndCallKeyHandled = false; |
| 5838 | mHandler.postDelayed(mEndCallLongPress, |
| 5839 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 5840 | } else { |
| 5841 | mEndCallKeyHandled = true; |
| 5842 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5843 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5844 | if (!mEndCallKeyHandled) { |
| 5845 | mHandler.removeCallbacks(mEndCallLongPress); |
| 5846 | if (!canceled) { |
| 5847 | if ((mEndcallBehavior |
| 5848 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 5849 | if (goHome()) { |
| 5850 | break; |
| 5851 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 5852 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5853 | if ((mEndcallBehavior |
| 5854 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 5855 | mPowerManager.goToSleep(event.getEventTime(), |
| 5856 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 5857 | isWakeKey = false; |
| 5858 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5859 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5860 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5861 | } |
| 5862 | break; |
| 5863 | } |
| 5864 | |
| 5865 | case KeyEvent.KEYCODE_POWER: { |
| 5866 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5867 | isWakeKey = false; // wake-up will be handled separately |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5868 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5869 | interceptPowerKeyDown(event, interactive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5870 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5871 | interceptPowerKeyUp(event, interactive, canceled); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5872 | } |
| 5873 | break; |
| 5874 | } |
| 5875 | |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 5876 | case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN: |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 5877 | // fall through |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 5878 | case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP: |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 5879 | // fall through |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 5880 | case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_LEFT: |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 5881 | // fall through |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 5882 | case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_RIGHT: { |
| 5883 | result &= ~ACTION_PASS_TO_USER; |
| 5884 | interceptSystemNavigationKey(event); |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 5885 | break; |
| 5886 | } |
| 5887 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5888 | case KeyEvent.KEYCODE_SLEEP: { |
| 5889 | result &= ~ACTION_PASS_TO_USER; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 5890 | isWakeKey = false; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5891 | if (!mPowerManager.isInteractive()) { |
| 5892 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 5893 | } |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 5894 | if (down) { |
| 5895 | sleepPress(event.getEventTime()); |
| 5896 | } else { |
| 5897 | sleepRelease(event.getEventTime()); |
| 5898 | } |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5899 | break; |
| 5900 | } |
| 5901 | |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 5902 | case KeyEvent.KEYCODE_SOFT_SLEEP: { |
| 5903 | result &= ~ACTION_PASS_TO_USER; |
| 5904 | isWakeKey = false; |
| 5905 | if (!down) { |
| 5906 | mPowerManagerInternal.setUserInactiveOverrideFromWindowManager(); |
| 5907 | } |
| 5908 | break; |
| 5909 | } |
| 5910 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5911 | case KeyEvent.KEYCODE_WAKEUP: { |
| 5912 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5913 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5914 | break; |
| 5915 | } |
| 5916 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5917 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 5918 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 5919 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5920 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 5921 | case KeyEvent.KEYCODE_MUTE: |
| 5922 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 5923 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 5924 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 5925 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 5926 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 5927 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 5928 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 5929 | if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { |
| 5930 | // If the global session is active pass all media keys to it |
| 5931 | // instead of the active window. |
| 5932 | result &= ~ACTION_PASS_TO_USER; |
| 5933 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5934 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 5935 | // Only do this if we would otherwise not pass it to the user. In that |
| 5936 | // case, the PhoneWindow class will do the same thing, except it will |
| 5937 | // 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] | 5938 | // Note that we need to make a copy of the key event here because the |
| 5939 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5940 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5941 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 5942 | new KeyEvent(event)); |
| 5943 | msg.setAsynchronous(true); |
| 5944 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5945 | } |
| 5946 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5947 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5948 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5949 | case KeyEvent.KEYCODE_CALL: { |
| 5950 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5951 | TelecomManager telecomManager = getTelecommService(); |
| 5952 | if (telecomManager != null) { |
| 5953 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5954 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 5955 | + " CALL key-down while ringing: Answer the call!"); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5956 | telecomManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5957 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5958 | // And *don't* pass this key thru to the current activity |
| 5959 | // (which is presumably the InCallScreen.) |
| 5960 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5961 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5962 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5963 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5964 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5965 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5966 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 5967 | // Only do this if we would otherwise not pass it to the user. In that case, |
| 5968 | // interceptKeyBeforeDispatching would apply a similar but different policy in |
| 5969 | // order to invoke voice assist actions. Note that we need to make a copy of the |
| 5970 | // key event here because the original key event will be recycled when we return. |
| 5971 | if ((result & ACTION_PASS_TO_USER) == 0 && !down) { |
| 5972 | mBroadcastWakeLock.acquire(); |
| 5973 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, |
| 5974 | keyguardActive ? 1 : 0, 0); |
| 5975 | msg.setAsynchronous(true); |
| 5976 | msg.sendToTarget(); |
| 5977 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 5978 | break; |
| 5979 | } |
| 5980 | case KeyEvent.KEYCODE_WINDOW: { |
| 5981 | if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) { |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 5982 | if (mTvPictureInPictureVisible) { |
| 5983 | // Consumes the key only if picture-in-picture is visible |
| 5984 | // to show picture-in-picture control menu. |
| 5985 | // This gives a chance to the foreground activity |
| 5986 | // to customize PIP key behavior. |
| 5987 | if (!down) { |
| 5988 | showTvPictureInPictureMenu(event); |
| 5989 | } |
| 5990 | result &= ~ACTION_PASS_TO_USER; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 5991 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 5992 | } |
| 5993 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5994 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5995 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5996 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5997 | if (useHapticFeedback) { |
| 5998 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 5999 | } |
| 6000 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 6001 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6002 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 6003 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 6004 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6005 | return result; |
| 6006 | } |
| 6007 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 6008 | /** |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6009 | * Handle statusbar expansion events. |
| 6010 | * @param event |
| 6011 | */ |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 6012 | private void interceptSystemNavigationKey(KeyEvent event) { |
Doris Ling | 628cea4 | 2016-06-09 10:35:02 -0700 | [diff] [blame] | 6013 | if (event.getAction() == KeyEvent.ACTION_UP && areSystemNavigationKeysEnabled()) { |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6014 | IStatusBarService sbar = getStatusBarService(); |
| 6015 | if (sbar != null) { |
| 6016 | try { |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 6017 | sbar.handleSystemNavigationKey(event.getKeyCode()); |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6018 | } catch (RemoteException e1) { |
| 6019 | // oops, no statusbar. Ignore event. |
| 6020 | } |
| 6021 | } |
| 6022 | } |
| 6023 | } |
| 6024 | |
| 6025 | /** |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6026 | * Returns true if the key can have global actions attached to it. |
| 6027 | * We reserve all power management keys for the system since they require |
| 6028 | * very careful handling. |
| 6029 | */ |
| 6030 | private static boolean isValidGlobalKey(int keyCode) { |
| 6031 | switch (keyCode) { |
| 6032 | case KeyEvent.KEYCODE_POWER: |
| 6033 | case KeyEvent.KEYCODE_WAKEUP: |
| 6034 | case KeyEvent.KEYCODE_SLEEP: |
| 6035 | return false; |
| 6036 | default: |
| 6037 | return true; |
| 6038 | } |
| 6039 | } |
| 6040 | |
| 6041 | /** |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 6042 | * When the screen is off we ignore some keys that might otherwise typically |
| 6043 | * be considered wake keys. We filter them out here. |
| 6044 | * |
| 6045 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 6046 | * is always considered a wake key. |
| 6047 | */ |
| 6048 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 6049 | switch (keyCode) { |
| 6050 | // ignore volume keys unless docked |
| 6051 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 6052 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 6053 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 6054 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 6055 | |
| 6056 | // ignore media and camera keys |
| 6057 | case KeyEvent.KEYCODE_MUTE: |
| 6058 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 6059 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 6060 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 6061 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 6062 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 6063 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 6064 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 6065 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 6066 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 6067 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 6068 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 6069 | case KeyEvent.KEYCODE_CAMERA: |
| 6070 | return false; |
| 6071 | } |
| 6072 | return true; |
| 6073 | } |
| 6074 | |
| 6075 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 6076 | /** {@inheritDoc} */ |
| 6077 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 6078 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 6079 | if ((policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6080 | if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion, |
| 6081 | "android.policy:MOTION")) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6082 | return 0; |
| 6083 | } |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 6084 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6085 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 6086 | if (shouldDispatchInputWhenNonInteractive(null)) { |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 6087 | return ACTION_PASS_TO_USER; |
| 6088 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6089 | |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 6090 | // If we have not passed the action up and we are in theater mode without dreaming, |
| 6091 | // there will be no dream to intercept the touch and wake into ambient. The device should |
| 6092 | // wake up in this case. |
| 6093 | if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6094 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming, |
| 6095 | "android.policy:MOTION"); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 6096 | } |
| 6097 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 6098 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 6099 | } |
| 6100 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 6101 | private boolean shouldDispatchInputWhenNonInteractive(KeyEvent event) { |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 6102 | final boolean displayOff = (mDisplay == null || mDisplay.getState() == Display.STATE_OFF); |
| 6103 | |
| 6104 | if (displayOff && !mHasFeatureWatch) { |
| 6105 | return false; |
| 6106 | } |
| 6107 | |
| 6108 | // Send events to keyguard while the screen is on and it's showing. |
| 6109 | if (isKeyguardShowingAndNotOccluded() && !displayOff) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6110 | return true; |
| 6111 | } |
| 6112 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 6113 | // Watches handle BACK specially |
| 6114 | if (mHasFeatureWatch |
| 6115 | && event != null |
| 6116 | && (event.getKeyCode() == KeyEvent.KEYCODE_BACK |
| 6117 | || event.getKeyCode() == KeyEvent.KEYCODE_STEM_PRIMARY)) { |
| 6118 | return false; |
| 6119 | } |
| 6120 | |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6121 | // Send events to a dozing dream even if the screen is off since the dream |
| 6122 | // is in control of the state of the screen. |
| 6123 | IDreamManager dreamManager = getDreamManager(); |
| 6124 | |
| 6125 | try { |
| 6126 | if (dreamManager != null && dreamManager.isDreaming()) { |
| 6127 | return true; |
| 6128 | } |
| 6129 | } catch (RemoteException e) { |
| 6130 | Slog.e(TAG, "RemoteException when checking if dreaming", e); |
| 6131 | } |
| 6132 | |
| 6133 | // Otherwise, consume events since the user can't see what is being |
| 6134 | // interacted with. |
| 6135 | return false; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 6136 | } |
| 6137 | |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6138 | private void dispatchDirectAudioEvent(KeyEvent event) { |
| 6139 | if (event.getAction() != KeyEvent.ACTION_DOWN) { |
| 6140 | return; |
| 6141 | } |
| 6142 | int keyCode = event.getKeyCode(); |
John Spurlock | b94f2d6 | 2015-03-17 14:11:57 -0400 | [diff] [blame] | 6143 | int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND |
| 6144 | | AudioManager.FLAG_FROM_KEY; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6145 | String pkgName = mContext.getOpPackageName(); |
| 6146 | switch (keyCode) { |
| 6147 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 6148 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 6149 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 6150 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6151 | } catch (RemoteException e) { |
| 6152 | Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e); |
| 6153 | } |
| 6154 | break; |
| 6155 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 6156 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 6157 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 6158 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6159 | } catch (RemoteException e) { |
| 6160 | Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e); |
| 6161 | } |
| 6162 | break; |
| 6163 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 6164 | try { |
| 6165 | if (event.getRepeatCount() == 0) { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 6166 | getAudioService().adjustSuggestedStreamVolume( |
| 6167 | AudioManager.ADJUST_TOGGLE_MUTE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 6168 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6169 | } |
| 6170 | } catch (RemoteException e) { |
| 6171 | Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e); |
| 6172 | } |
| 6173 | break; |
| 6174 | } |
| 6175 | } |
| 6176 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 6177 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 6178 | if (DEBUG_INPUT) { |
| 6179 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6180 | } |
| 6181 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 6182 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 6183 | if (DEBUG_INPUT) { |
| 6184 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 6185 | } |
| 6186 | |
| 6187 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 6188 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 6189 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 6190 | } |
| 6191 | |
| 6192 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 6193 | |
| 6194 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 6195 | && event.getRepeatCount() == 0) { |
| 6196 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 6197 | |
| 6198 | Message msg = mHandler.obtainMessage( |
| 6199 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 6200 | msg.setAsynchronous(true); |
| 6201 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 6202 | } else { |
| 6203 | mBroadcastWakeLock.release(); |
| 6204 | } |
| 6205 | } |
| 6206 | |
| 6207 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 6208 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 6209 | |
| 6210 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 6211 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 6212 | if (DEBUG_INPUT) { |
| 6213 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 6214 | } |
| 6215 | |
| 6216 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 6217 | mBroadcastWakeLock.release(); |
| 6218 | } |
| 6219 | |
| 6220 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6221 | if (mActivityManagerInternal.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 6222 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6223 | } |
| 6224 | } |
| 6225 | |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 6226 | void launchVoiceAssistWithWakeLock(boolean keyguardActive) { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 6227 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 6228 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 6229 | if (dic != null) { |
| 6230 | try { |
| 6231 | dic.exitIdle("voice-search"); |
| 6232 | } catch (RemoteException e) { |
| 6233 | } |
| 6234 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 6235 | Intent voiceIntent = |
| 6236 | new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 6237 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6238 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 6239 | mBroadcastWakeLock.release(); |
| 6240 | } |
| 6241 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 6242 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 6243 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 6244 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 6245 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 6246 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 6247 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6248 | } else { |
| 6249 | try { |
| 6250 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 6251 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 6252 | mUiMode = uiModeService.getCurrentModeType(); |
| 6253 | } catch (RemoteException e) { |
| 6254 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 6255 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6256 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 6257 | synchronized (mLock) { |
| 6258 | updateOrientationListenerLp(); |
| 6259 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 6260 | } |
| 6261 | }; |
| 6262 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 6263 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 6264 | @Override |
| 6265 | public void onReceive(Context context, Intent intent) { |
| 6266 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6267 | if (mKeyguardDelegate != null) { |
| 6268 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 6269 | } |
| 6270 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6271 | if (mKeyguardDelegate != null) { |
| 6272 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 6273 | } |
| 6274 | } |
| 6275 | } |
| 6276 | }; |
| 6277 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6278 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 6279 | @Override |
| 6280 | public void onReceive(Context context, Intent intent) { |
| 6281 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 6282 | // tickle the settings observer: this first ensures that we're |
| 6283 | // observing the relevant settings for the newly-active user, |
| 6284 | // and then updates our own bookkeeping based on the now- |
| 6285 | // current user. |
| 6286 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 6287 | |
| 6288 | // force a re-application of focused window sysui visibility. |
| 6289 | // the window may never have been shown for this user |
| 6290 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 6291 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 6292 | mLastSystemUiFlags = 0; |
| 6293 | updateSystemUiVisibilityLw(); |
| 6294 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6295 | } |
| 6296 | } |
| 6297 | }; |
| 6298 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6299 | private final Runnable mHiddenNavPanic = new Runnable() { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 6300 | @Override |
| 6301 | public void run() { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6302 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 6303 | if (!isUserSetupComplete()) { |
| 6304 | // Swipe-up for navigation bar is disabled during setup |
| 6305 | return; |
| 6306 | } |
| 6307 | mPendingPanicGestureUptime = SystemClock.uptimeMillis(); |
Adrian Roos | 1f42590 | 2016-07-22 10:37:50 -0700 | [diff] [blame] | 6308 | if (!isNavBarEmpty(mLastSystemUiFlags)) { |
| 6309 | mNavigationBarController.showTransient(); |
| 6310 | } |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6311 | } |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 6312 | } |
| 6313 | }; |
| 6314 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6315 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 6316 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 6317 | if (!isUserSetupComplete()) { |
| 6318 | // Swipe-up for navigation bar is disabled during setup |
| 6319 | return; |
| 6320 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6321 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
Adrian Roos | 1f42590 | 2016-07-22 10:37:50 -0700 | [diff] [blame] | 6322 | boolean nb = mNavigationBarController.checkShowTransientBarLw() |
| 6323 | && !isNavBarEmpty(mLastSystemUiFlags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6324 | if (sb || nb) { |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 6325 | // Don't show status bar when swiping on already visible navigation bar |
| 6326 | if (!nb && swipeTarget == mNavigationBar) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6327 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6328 | return; |
| 6329 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6330 | if (sb) mStatusBarController.showTransient(); |
| 6331 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6332 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6333 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 6334 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6335 | } |
| 6336 | } |
| 6337 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6338 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6339 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6340 | public void startedGoingToSleep(int why) { |
| 6341 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")"); |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6342 | mCameraGestureTriggeredDuringGoingToSleep = false; |
| 6343 | mGoingToSleep = true; |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 6344 | if (mKeyguardDelegate != null) { |
| 6345 | mKeyguardDelegate.onStartedGoingToSleep(why); |
| 6346 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6347 | } |
| 6348 | |
| 6349 | // Called on the PowerManager's Notifier thread. |
| 6350 | @Override |
| 6351 | public void finishedGoingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 6352 | EventLog.writeEvent(70000, 0); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6353 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")"); |
Chris Wren | 9bb290b | 2015-06-29 12:02:13 -0400 | [diff] [blame] | 6354 | MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6355 | |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6356 | mGoingToSleep = false; |
| 6357 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6358 | // We must get this work done here because the power manager will drop |
| 6359 | // 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] | 6360 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6361 | mAwake = false; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6362 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6363 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6364 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6365 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6366 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6367 | mKeyguardDelegate.onFinishedGoingToSleep(why, |
| 6368 | mCameraGestureTriggeredDuringGoingToSleep); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6369 | } |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6370 | mCameraGestureTriggeredDuringGoingToSleep = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6371 | } |
| 6372 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6373 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6374 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6375 | public void startedWakingUp() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 6376 | EventLog.writeEvent(70000, 1); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6377 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up..."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 6378 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6379 | // Since goToSleep performs these functions synchronously, we must |
| 6380 | // do the same here. We cannot post this work to a handler because |
| 6381 | // that might cause it to become reordered with respect to what |
| 6382 | // may happen in a future call to goToSleep. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6383 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6384 | mAwake = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6385 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6386 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6387 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6388 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6389 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6390 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6391 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6392 | mKeyguardDelegate.onStartedWakingUp(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6393 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6394 | } |
| 6395 | |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6396 | // Called on the PowerManager's Notifier thread. |
| 6397 | @Override |
| 6398 | public void finishedWakingUp() { |
| 6399 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up..."); |
| 6400 | } |
| 6401 | |
| 6402 | private void wakeUpFromPowerKey(long eventTime) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6403 | wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER"); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6404 | } |
| 6405 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6406 | private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) { |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 6407 | final boolean theaterModeEnabled = isTheaterModeEnabled(); |
| 6408 | if (!wakeInTheaterMode && theaterModeEnabled) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6409 | return false; |
| 6410 | } |
| 6411 | |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 6412 | if (theaterModeEnabled) { |
| 6413 | Settings.Global.putInt(mContext.getContentResolver(), |
| 6414 | Settings.Global.THEATER_MODE_ON, 0); |
| 6415 | } |
| 6416 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6417 | mPowerManager.wakeUp(wakeTime, reason); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6418 | return true; |
| 6419 | } |
| 6420 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6421 | private void finishKeyguardDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6422 | synchronized (mLock) { |
Jorim Jaggi | f325548 | 2015-07-24 12:32:42 -0700 | [diff] [blame] | 6423 | if (!mScreenOnEarly || mKeyguardDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6424 | 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] | 6425 | } |
| 6426 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6427 | mKeyguardDrawComplete = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6428 | if (mKeyguardDelegate != null) { |
| 6429 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 6430 | } |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6431 | mWindowManagerDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6432 | } |
| 6433 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6434 | // ... eventually calls finishWindowsDrawn which will finalize our screen turn on |
| 6435 | // as well as enabling the orientation change logic/sensor. |
| 6436 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, |
| 6437 | WAITING_FOR_DRAWN_TIMEOUT); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6438 | } |
| 6439 | |
| 6440 | // Called on the DisplayManager's DisplayPowerController thread. |
| 6441 | @Override |
| 6442 | public void screenTurnedOff() { |
| 6443 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); |
| 6444 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6445 | updateScreenOffSleepToken(true); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6446 | synchronized (mLock) { |
| 6447 | mScreenOnEarly = false; |
| 6448 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 6449 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6450 | mWindowManagerDrawComplete = false; |
| 6451 | mScreenOnListener = null; |
| 6452 | updateOrientationListenerLp(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 6453 | |
| 6454 | if (mKeyguardDelegate != null) { |
| 6455 | mKeyguardDelegate.onScreenTurnedOff(); |
| 6456 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6457 | } |
Ruben Brunk | fecb615 | 2016-10-28 20:18:57 -0700 | [diff] [blame] | 6458 | reportScreenStateToVrManager(false); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6459 | } |
| 6460 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6461 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6462 | @Override |
| 6463 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6464 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6465 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6466 | updateScreenOffSleepToken(false); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6467 | synchronized (mLock) { |
| 6468 | mScreenOnEarly = true; |
| 6469 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 6470 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6471 | mWindowManagerDrawComplete = false; |
| 6472 | mScreenOnListener = screenOnListener; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6473 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6474 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | a4b51bc | 2015-08-10 18:20:43 -0700 | [diff] [blame] | 6475 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 6476 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6477 | mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback); |
| 6478 | } else { |
| 6479 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 6480 | "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
| 6481 | finishKeyguardDrawn(); |
| 6482 | } |
| 6483 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6484 | } |
| 6485 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 6486 | // Called on the DisplayManager's DisplayPowerController thread. |
| 6487 | @Override |
| 6488 | public void screenTurnedOn() { |
| 6489 | synchronized (mLock) { |
| 6490 | if (mKeyguardDelegate != null) { |
| 6491 | mKeyguardDelegate.onScreenTurnedOn(); |
| 6492 | } |
| 6493 | } |
Ruben Brunk | fecb615 | 2016-10-28 20:18:57 -0700 | [diff] [blame] | 6494 | reportScreenStateToVrManager(true); |
| 6495 | } |
| 6496 | |
| 6497 | private void reportScreenStateToVrManager(boolean isScreenOn) { |
| 6498 | VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class); |
| 6499 | if (vrService == null) { |
| 6500 | return; |
| 6501 | } |
| 6502 | vrService.onScreenStateChanged(isScreenOn); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 6503 | } |
| 6504 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6505 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6506 | synchronized (mLock) { |
| 6507 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6508 | 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] | 6509 | } |
| 6510 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6511 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6512 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6513 | |
| 6514 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6515 | } |
| 6516 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 6517 | private void finishScreenTurningOn() { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6518 | synchronized (mLock) { |
| 6519 | // We have just finished drawing screen content. Since the orientation listener |
| 6520 | // gets only installed when all windows are drawn, we try to install it again. |
| 6521 | updateOrientationListenerLp(); |
| 6522 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6523 | final ScreenOnListener listener; |
| 6524 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6525 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6526 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 6527 | "finishScreenTurningOn: mAwake=" + mAwake |
| 6528 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 6529 | + ", mScreenOnFully=" + mScreenOnFully |
| 6530 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 6531 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 6532 | |
| 6533 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 6534 | || (mAwake && !mKeyguardDrawComplete)) { |
| 6535 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6536 | } |
| 6537 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6538 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 6539 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 6540 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6541 | mScreenOnFully = true; |
| 6542 | |
| 6543 | // Remember the first time we draw the keyguard so we know when we're done with |
| 6544 | // the main part of booting and can enable the screen and hide boot messages. |
| 6545 | if (!mKeyguardDrawnOnce && mAwake) { |
| 6546 | mKeyguardDrawnOnce = true; |
| 6547 | enableScreen = true; |
| 6548 | if (mBootMessageNeedsHiding) { |
| 6549 | mBootMessageNeedsHiding = false; |
| 6550 | hideBootMessages(); |
| 6551 | } |
| 6552 | } else { |
| 6553 | enableScreen = false; |
| 6554 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6555 | } |
| 6556 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6557 | if (listener != null) { |
| 6558 | listener.onScreenOn(); |
| 6559 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 6560 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6561 | if (enableScreen) { |
| 6562 | try { |
| 6563 | mWindowManager.enableScreenIfNeeded(); |
| 6564 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6565 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6566 | } |
| 6567 | } |
| 6568 | |
| 6569 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6570 | synchronized (mLock) { |
| 6571 | if (!mKeyguardDrawnOnce) { |
| 6572 | mBootMessageNeedsHiding = true; |
| 6573 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 6574 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6575 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6576 | |
| 6577 | if (mBootMsgDialog != null) { |
| 6578 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 6579 | mBootMsgDialog.dismiss(); |
| 6580 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6581 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6582 | } |
| 6583 | |
| 6584 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6585 | public boolean isScreenOn() { |
| 6586 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 6587 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6588 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 6589 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6590 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6591 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6592 | if (mKeyguardDelegate != null) { |
| 6593 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6594 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6595 | } |
| 6596 | |
| 6597 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6598 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6599 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6600 | if (mKeyguardDelegate != null) { |
| 6601 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6602 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6603 | } |
| 6604 | |
Tony Mak | 2c0d6dc | 2016-04-29 16:16:54 +0100 | [diff] [blame] | 6605 | @Override |
| 6606 | public boolean isKeyguardShowingAndNotOccluded() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6607 | if (mKeyguardDelegate == null) return false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6608 | return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6609 | } |
| 6610 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 6611 | @Override |
| 6612 | public boolean isKeyguardTrustedLw() { |
| 6613 | if (mKeyguardDelegate == null) return false; |
| 6614 | return mKeyguardDelegate.isTrusted(); |
| 6615 | } |
| 6616 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6617 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6618 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6619 | public boolean isKeyguardLocked() { |
| 6620 | return keyguardOn(); |
| 6621 | } |
| 6622 | |
| 6623 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6624 | @Override |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 6625 | public boolean isKeyguardSecure(int userId) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6626 | if (mKeyguardDelegate == null) return false; |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 6627 | return mKeyguardDelegate.isSecure(userId); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6628 | } |
| 6629 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6630 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6631 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 6632 | public boolean isKeyguardOccluded() { |
| 6633 | if (mKeyguardDelegate == null) return false; |
| 6634 | return mKeyguardOccluded; |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 6635 | } |
| 6636 | |
| 6637 | /** {@inheritDoc} */ |
| 6638 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6639 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6640 | if (mKeyguardDelegate == null) return false; |
| 6641 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6642 | } |
| 6643 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6644 | @Override |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 6645 | public void dismissKeyguardLw(IKeyguardDismissCallback callback) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 6646 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 6647 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 6648 | |
| 6649 | // ask the keyguard to prompt the user to authenticate if necessary |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 6650 | mKeyguardDelegate.dismiss(callback); |
| 6651 | } else if (callback != null) { |
| 6652 | try { |
| 6653 | callback.onDismissError(); |
| 6654 | } catch (RemoteException e) { |
| 6655 | Slog.w(TAG, "Failed to call callback", e); |
| 6656 | } |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 6657 | } |
| 6658 | } |
| 6659 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 6660 | @Override |
| 6661 | public boolean isKeyguardDrawnLw() { |
| 6662 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6663 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 6664 | } |
| 6665 | } |
| 6666 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6667 | @Override |
Jorim Jaggi | 77e1043 | 2016-10-26 17:43:56 -0700 | [diff] [blame] | 6668 | public boolean isShowingDreamLw() { |
| 6669 | return mShowingDream; |
| 6670 | } |
| 6671 | |
| 6672 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 6673 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6674 | if (mKeyguardDelegate != null) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 6675 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 6676 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6677 | } |
| 6678 | } |
| 6679 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6680 | @Override |
| 6681 | public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
| 6682 | Rect outInsets) { |
| 6683 | outInsets.setEmpty(); |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 6684 | |
| 6685 | // Navigation bar and status bar. |
| 6686 | getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets); |
Matthew Ng | ca4c1a3 | 2016-12-13 16:55:09 -0800 | [diff] [blame] | 6687 | outInsets.top = mStatusBarHeight; |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 6688 | } |
| 6689 | |
| 6690 | @Override |
| 6691 | public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
| 6692 | Rect outInsets) { |
| 6693 | outInsets.setEmpty(); |
| 6694 | |
| 6695 | // Only navigation bar |
Matthew Ng | ca4c1a3 | 2016-12-13 16:55:09 -0800 | [diff] [blame] | 6696 | if (mHasNavigationBar) { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 6697 | int position = navigationBarPosition(displayWidth, displayHeight, displayRotation); |
| 6698 | if (position == NAV_BAR_BOTTOM) { |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6699 | outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode); |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 6700 | } else if (position == NAV_BAR_RIGHT) { |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6701 | outInsets.right = getNavigationBarWidth(displayRotation, mUiMode); |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 6702 | } else if (position == NAV_BAR_LEFT) { |
| 6703 | outInsets.left = getNavigationBarWidth(displayRotation, mUiMode); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6704 | } |
| 6705 | } |
| 6706 | } |
| 6707 | |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 6708 | @Override |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6709 | public boolean isNavBarForcedShownLw(WindowState windowState) { |
Jorim Jaggi | e5638a6 | 2016-03-25 22:57:01 -0700 | [diff] [blame] | 6710 | return mForceShowSystemBars; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6711 | } |
| 6712 | |
| 6713 | @Override |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 6714 | public boolean isDockSideAllowed(int dockSide) { |
| 6715 | |
| 6716 | // We do not allow all dock sides at which the navigation bar touches the docked stack. |
| 6717 | if (!mNavigationBarCanMove) { |
| 6718 | return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT; |
| 6719 | } else { |
| 6720 | return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT; |
| 6721 | } |
| 6722 | } |
| 6723 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6724 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 6725 | PhoneWindow.sendCloseSystemWindows(mContext, null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6726 | } |
| 6727 | |
| 6728 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 6729 | PhoneWindow.sendCloseSystemWindows(mContext, reason); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6730 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 6731 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6732 | @Override |
| 6733 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6734 | if (false) { |
| 6735 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 6736 | + orientation + ", last=" + lastRotation |
| 6737 | + "); user=" + mUserRotation + " " |
| 6738 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 6739 | ? "USER_ROTATION_LOCKED" : "") |
| 6740 | ); |
| 6741 | } |
| 6742 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 6743 | if (mForceDefaultOrientation) { |
| 6744 | return Surface.ROTATION_0; |
| 6745 | } |
| 6746 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6747 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6748 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 6749 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 6750 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6751 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6752 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6753 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 6754 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6755 | // Ignore sensor when lid switch is open and rotation is forced. |
| 6756 | preferredRotation = mLidOpenRotation; |
| 6757 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6758 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6759 | // Ignore sensor when in car dock unless explicitly enabled. |
| 6760 | // This case can override the behavior of NOSENSOR, and can also |
| 6761 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6762 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6763 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 6764 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 6765 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 6766 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6767 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6768 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 6769 | // This case can override the behavior of NOSENSOR, and can also |
| 6770 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6771 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6772 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6773 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 6774 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 6775 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6776 | preferredRotation = mDemoHdmiRotation; |
| 6777 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 6778 | && mUndockedHdmiRotation >= 0) { |
| 6779 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 6780 | // been specified in the configuration (only for legacy devices without |
| 6781 | // full multi-display support). |
| 6782 | // Note that the dock orientation overrides the HDMI orientation. |
| 6783 | preferredRotation = mUndockedHdmiRotation; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 6784 | } else if (mDemoRotationLock) { |
| 6785 | // Ignore sensor when demo rotation lock is enabled. |
| 6786 | // Note that the dock orientation and HDMI rotation lock override this. |
| 6787 | preferredRotation = mDemoRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6788 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 6789 | // Application just wants to remain locked in the last rotation. |
| 6790 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 6791 | } else if (!mSupportAutoRotation) { |
| 6792 | // If we don't support auto-rotation then bail out here and ignore |
| 6793 | // the sensor and any rotation lock settings. |
| 6794 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 6795 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6796 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6797 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 6798 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 6799 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 6800 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6801 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 6802 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 6803 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 6804 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 6805 | // Otherwise, use sensor only if requested by the application or enabled |
| 6806 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 6807 | if (mAllowAllRotations < 0) { |
| 6808 | // Can't read this during init() because the context doesn't |
| 6809 | // have display metrics at that time so we cannot determine |
| 6810 | // tablet vs. phone then. |
| 6811 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 6812 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 6813 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6814 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 6815 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6816 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 6817 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6818 | preferredRotation = sensorRotation; |
| 6819 | } else { |
| 6820 | preferredRotation = lastRotation; |
| 6821 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 6822 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 6823 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 6824 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 6825 | // The idea is that the user rotation expresses a weak preference for the direction |
| 6826 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 6827 | // 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] | 6828 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6829 | } else { |
| 6830 | // No overriding preference. |
| 6831 | // We will do exactly what the application asked us to do. |
| 6832 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6833 | } |
| 6834 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6835 | switch (orientation) { |
| 6836 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6837 | // Return portrait unless overridden. |
| 6838 | if (isAnyPortrait(preferredRotation)) { |
| 6839 | return preferredRotation; |
| 6840 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6841 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6842 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6843 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6844 | // Return landscape unless overridden. |
| 6845 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6846 | return preferredRotation; |
| 6847 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6848 | return mLandscapeRotation; |
| 6849 | |
| 6850 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6851 | // Return reverse portrait unless overridden. |
| 6852 | if (isAnyPortrait(preferredRotation)) { |
| 6853 | return preferredRotation; |
| 6854 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6855 | return mUpsideDownRotation; |
| 6856 | |
| 6857 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6858 | // Return seascape unless overridden. |
| 6859 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6860 | return preferredRotation; |
| 6861 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6862 | return mSeascapeRotation; |
| 6863 | |
| 6864 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6865 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6866 | // Return either landscape rotation. |
| 6867 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6868 | return preferredRotation; |
| 6869 | } |
| 6870 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 6871 | return lastRotation; |
| 6872 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6873 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6874 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6875 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6876 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6877 | // Return either portrait rotation. |
| 6878 | if (isAnyPortrait(preferredRotation)) { |
| 6879 | return preferredRotation; |
| 6880 | } |
| 6881 | if (isAnyPortrait(lastRotation)) { |
| 6882 | return lastRotation; |
| 6883 | } |
| 6884 | return mPortraitRotation; |
| 6885 | |
| 6886 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 6887 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 6888 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6889 | if (preferredRotation >= 0) { |
| 6890 | return preferredRotation; |
| 6891 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6892 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 6893 | } |
| 6894 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 6895 | } |
| 6896 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6897 | @Override |
| 6898 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 6899 | switch (orientation) { |
| 6900 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 6901 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 6902 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 6903 | return isAnyPortrait(rotation); |
| 6904 | |
| 6905 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 6906 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 6907 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 6908 | return isLandscapeOrSeascape(rotation); |
| 6909 | |
| 6910 | default: |
| 6911 | return true; |
| 6912 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 6913 | } |
| 6914 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6915 | @Override |
| 6916 | public void setRotationLw(int rotation) { |
| 6917 | mOrientationListener.setCurrentRotation(rotation); |
| 6918 | } |
| 6919 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6920 | private boolean isLandscapeOrSeascape(int rotation) { |
| 6921 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6922 | } |
| 6923 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6924 | private boolean isAnyPortrait(int rotation) { |
| 6925 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6926 | } |
| 6927 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6928 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6929 | public int getUserRotationMode() { |
| 6930 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 6931 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 6932 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 6933 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6934 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6935 | |
| 6936 | // 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] | 6937 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6938 | public void setUserRotationMode(int mode, int rot) { |
| 6939 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6940 | |
| 6941 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6942 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6943 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6944 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6945 | rot, |
| 6946 | UserHandle.USER_CURRENT); |
| 6947 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6948 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6949 | 0, |
| 6950 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6951 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6952 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6953 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6954 | 1, |
| 6955 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6956 | } |
| 6957 | } |
| 6958 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6959 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6960 | public void setSafeMode(boolean safeMode) { |
| 6961 | mSafeMode = safeMode; |
| 6962 | performHapticFeedbackLw(null, safeMode |
| 6963 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 6964 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6965 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6966 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 6967 | static long[] getLongIntArray(Resources r, int resid) { |
| 6968 | int[] ar = r.getIntArray(resid); |
| 6969 | if (ar == null) { |
| 6970 | return null; |
| 6971 | } |
| 6972 | long[] out = new long[ar.length]; |
| 6973 | for (int i=0; i<ar.length; i++) { |
| 6974 | out[i] = ar[i]; |
| 6975 | } |
| 6976 | return out; |
| 6977 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6978 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6979 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6980 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6981 | public void systemReady() { |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 6982 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext, |
| 6983 | new StateCallback() { |
| 6984 | @Override |
| 6985 | public void onTrustedChanged() { |
| 6986 | mWindowManagerFuncs.notifyKeyguardTrustedChanged(); |
| 6987 | } |
| 6988 | }); |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 6989 | mKeyguardDelegate.onSystemReady(); |
| 6990 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 6991 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6992 | updateUiMode(); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6993 | boolean bindKeyguardNow; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6994 | synchronized (mLock) { |
| 6995 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 6996 | mSystemReady = true; |
| 6997 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6998 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 6999 | public void run() { |
| 7000 | updateSettings(); |
| 7001 | } |
| 7002 | }); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 7003 | |
| 7004 | bindKeyguardNow = mDeferBindKeyguard; |
| 7005 | if (bindKeyguardNow) { |
| 7006 | // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now. |
| 7007 | mDeferBindKeyguard = false; |
| 7008 | } |
| 7009 | } |
| 7010 | |
| 7011 | if (bindKeyguardNow) { |
| 7012 | mKeyguardDelegate.bindService(mContext); |
| 7013 | mKeyguardDelegate.onBootCompleted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7014 | } |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 7015 | mSystemGestures.systemReady(); |
Amith Yamasani | 02a0381 | 2016-04-22 17:32:00 -0700 | [diff] [blame] | 7016 | mImmersiveModeConfirmation.systemReady(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7017 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7018 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7019 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7020 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7021 | public void systemBooted() { |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 7022 | boolean bindKeyguardNow = false; |
| 7023 | synchronized (mLock) { |
| 7024 | // Time to bind Keyguard; take care to only bind it once, either here if ready or |
| 7025 | // in systemReady if not. |
| 7026 | if (mKeyguardDelegate != null) { |
| 7027 | bindKeyguardNow = true; |
| 7028 | } else { |
| 7029 | // Because mKeyguardDelegate is null, we know that the synchronized block in |
| 7030 | // systemReady didn't run yet and setting this will actually have an effect. |
| 7031 | mDeferBindKeyguard = true; |
| 7032 | } |
| 7033 | } |
| 7034 | if (bindKeyguardNow) { |
Jason Monk | 5eeebf5 | 2014-09-26 12:36:51 -0400 | [diff] [blame] | 7035 | mKeyguardDelegate.bindService(mContext); |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 7036 | mKeyguardDelegate.onBootCompleted(); |
| 7037 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7038 | synchronized (mLock) { |
| 7039 | mSystemBooted = true; |
| 7040 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 7041 | startedWakingUp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 7042 | screenTurningOn(null); |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 7043 | screenTurnedOn(); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7044 | } |
| 7045 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7046 | ProgressDialog mBootMsgDialog = null; |
| 7047 | |
| 7048 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7049 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7050 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 7051 | mHandler.post(new Runnable() { |
| 7052 | @Override public void run() { |
| 7053 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 7054 | int theme; |
Michael Kwan | 5a86167 | 2016-06-09 19:44:04 -0700 | [diff] [blame] | 7055 | if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 7056 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 7057 | } else { |
| 7058 | theme = 0; |
| 7059 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 7060 | |
| 7061 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 7062 | // This dialog will consume all events coming in to |
| 7063 | // it, to avoid it trying to do things too early in boot. |
| 7064 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 7065 | return true; |
| 7066 | } |
| 7067 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 7068 | return true; |
| 7069 | } |
| 7070 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 7071 | return true; |
| 7072 | } |
| 7073 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 7074 | return true; |
| 7075 | } |
| 7076 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 7077 | return true; |
| 7078 | } |
| 7079 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 7080 | AccessibilityEvent event) { |
| 7081 | return true; |
| 7082 | } |
| 7083 | }; |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 7084 | if (mContext.getPackageManager().isUpgrade()) { |
| 7085 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 7086 | } else { |
| 7087 | mBootMsgDialog.setTitle(R.string.android_start_title); |
| 7088 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7089 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 7090 | mBootMsgDialog.setIndeterminate(true); |
| 7091 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 7092 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7093 | mBootMsgDialog.getWindow().addFlags( |
| 7094 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 7095 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 7096 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 7097 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 7098 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 7099 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7100 | mBootMsgDialog.setCancelable(false); |
| 7101 | mBootMsgDialog.show(); |
| 7102 | } |
| 7103 | mBootMsgDialog.setMessage(msg); |
| 7104 | } |
| 7105 | }); |
| 7106 | } |
| 7107 | |
| 7108 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7109 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7110 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 7111 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7112 | } |
| 7113 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7114 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7115 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7116 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7117 | // *************************************** |
| 7118 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 7119 | // *************************************** |
| 7120 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 7121 | // WITH ITS LOCKS HELD. |
| 7122 | // |
| 7123 | // This code must be VERY careful about the locks |
| 7124 | // it acquires. |
| 7125 | // In fact, the current code acquires way too many, |
| 7126 | // and probably has lurking deadlocks. |
| 7127 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7128 | synchronized (mScreenLockTimeout) { |
| 7129 | if (mLockScreenTimerActive) { |
| 7130 | // reset the timer |
| 7131 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 7132 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 7133 | } |
| 7134 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 7135 | } |
| 7136 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7137 | class ScreenLockTimeout implements Runnable { |
| 7138 | Bundle options; |
| 7139 | |
| 7140 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7141 | public void run() { |
| 7142 | synchronized (this) { |
| 7143 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 7144 | if (mKeyguardDelegate != null) { |
| 7145 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 7146 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7147 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7148 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7149 | } |
| 7150 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7151 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7152 | public void setLockOptions(Bundle options) { |
| 7153 | this.options = options; |
| 7154 | } |
| 7155 | } |
| 7156 | |
| 7157 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 7158 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7159 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7160 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 7161 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 7162 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7163 | if (options != null) { |
| 7164 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 7165 | // until the runnable actually executes. |
| 7166 | mScreenLockTimeout.setLockOptions(options); |
| 7167 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 7168 | mHandler.post(mScreenLockTimeout); |
| 7169 | } |
| 7170 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7171 | private void updateLockScreenTimeout() { |
| 7172 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7173 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 7174 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure(mCurrentUserId)); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7175 | if (mLockScreenTimerActive != enable) { |
| 7176 | if (enable) { |
| 7177 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
Jim Miller | 2967f48 | 2016-01-07 15:05:32 -0800 | [diff] [blame] | 7178 | mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7179 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 7180 | } else { |
| 7181 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 7182 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 7183 | } |
| 7184 | mLockScreenTimerActive = enable; |
| 7185 | } |
| 7186 | } |
| 7187 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7188 | |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 7189 | private void updateDreamingSleepToken(boolean acquire) { |
| 7190 | if (acquire) { |
| 7191 | if (mDreamingSleepToken == null) { |
| 7192 | mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream"); |
| 7193 | } |
| 7194 | } else { |
| 7195 | if (mDreamingSleepToken != null) { |
| 7196 | mDreamingSleepToken.release(); |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 7197 | mDreamingSleepToken = null; |
| 7198 | } |
| 7199 | } |
| 7200 | } |
| 7201 | |
| 7202 | private void updateScreenOffSleepToken(boolean acquire) { |
| 7203 | if (acquire) { |
| 7204 | if (mScreenOffSleepToken == null) { |
| 7205 | mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff"); |
| 7206 | } |
| 7207 | } else { |
| 7208 | if (mScreenOffSleepToken != null) { |
| 7209 | mScreenOffSleepToken.release(); |
| 7210 | mScreenOffSleepToken = null; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 7211 | } |
| 7212 | } |
| 7213 | } |
| 7214 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7215 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7216 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7217 | public void enableScreenAfterBoot() { |
| 7218 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7219 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7220 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7221 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 7222 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7223 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7224 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7225 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 7226 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7227 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 7228 | } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) { |
| 7229 | mWindowManagerFuncs.lockDeviceNow(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7230 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 7231 | |
| 7232 | synchronized (mLock) { |
| 7233 | updateWakeGestureListenerLp(); |
| 7234 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7235 | } |
| 7236 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 7237 | void updateUiMode() { |
| 7238 | if (mUiModeManager == null) { |
| 7239 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 7240 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 7241 | } |
| 7242 | try { |
| 7243 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 7244 | } catch (RemoteException e) { |
| 7245 | } |
| 7246 | } |
| 7247 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7248 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7249 | try { |
| 7250 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 7251 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 7252 | } catch (RemoteException e) { |
| 7253 | // Ignore |
| 7254 | } |
| 7255 | } |
| 7256 | |
| 7257 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 7258 | try { |
| 7259 | //set orientation on WindowManager |
| 7260 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7261 | } catch (RemoteException e) { |
| 7262 | // Ignore |
| 7263 | } |
| 7264 | } |
| 7265 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7266 | /** |
| 7267 | * Return an Intent to launch the currently active dock app as home. Returns |
| 7268 | * null if the standard home should be launched, which is the case if any of the following is |
| 7269 | * true: |
| 7270 | * <ul> |
| 7271 | * <li>The device is not in either car mode or desk mode |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 7272 | * <li>The device is in car mode but mEnableCarDockHomeCapture is false |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7273 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 7274 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 7275 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 7276 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7277 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7278 | */ |
| 7279 | Intent createHomeDockIntent() { |
| 7280 | Intent intent = null; |
| 7281 | |
| 7282 | // What home does is based on the mode, not the dock state. That |
| 7283 | // is, when in car mode you should be taken to car home regardless |
| 7284 | // of whether we are actually in a car dock. |
| 7285 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 7286 | if (mEnableCarDockHomeCapture) { |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7287 | intent = mCarDockIntent; |
| 7288 | } |
| 7289 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 7290 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 7291 | intent = mDeskDockIntent; |
| 7292 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 7293 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 7294 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 7295 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 7296 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 7297 | // Always launch dock home from home when watch is docked, if it exists. |
| 7298 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7299 | } |
| 7300 | |
| 7301 | if (intent == null) { |
| 7302 | return null; |
| 7303 | } |
| 7304 | |
| 7305 | ActivityInfo ai = null; |
| 7306 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 7307 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 7308 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 7309 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7310 | if (info != null) { |
| 7311 | ai = info.activityInfo; |
| 7312 | } |
| 7313 | if (ai != null |
| 7314 | && ai.metaData != null |
| 7315 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 7316 | intent = new Intent(intent); |
| 7317 | intent.setClassName(ai.packageName, ai.name); |
| 7318 | return intent; |
| 7319 | } |
| 7320 | |
| 7321 | return null; |
| 7322 | } |
| 7323 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 7324 | void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { |
| 7325 | if (awakenFromDreams) { |
| 7326 | awakenDreams(); |
| 7327 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7328 | |
| 7329 | Intent dock = createHomeDockIntent(); |
| 7330 | if (dock != null) { |
| 7331 | try { |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 7332 | if (fromHomeKey) { |
| 7333 | dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 7334 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 7335 | startActivityAsUser(dock, UserHandle.CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7336 | return; |
| 7337 | } catch (ActivityNotFoundException e) { |
| 7338 | } |
| 7339 | } |
| 7340 | |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 7341 | Intent intent; |
| 7342 | |
| 7343 | if (fromHomeKey) { |
| 7344 | intent = new Intent(mHomeIntent); |
| 7345 | intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 7346 | } else { |
| 7347 | intent = mHomeIntent; |
| 7348 | } |
| 7349 | |
Bryce Lee | 9fc0b6f | 2015-03-19 21:37:45 +0000 | [diff] [blame] | 7350 | startActivityAsUser(intent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 7351 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7352 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 7353 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7354 | * goes to the home screen |
| 7355 | * @return whether it did anything |
| 7356 | */ |
| 7357 | boolean goHome() { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 7358 | if (!isUserSetupComplete()) { |
| 7359 | Slog.i(TAG, "Not going home because user setup is in progress."); |
| 7360 | return false; |
| 7361 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7362 | if (false) { |
| 7363 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 7364 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7365 | ActivityManager.getService().stopAppSwitches(); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 7366 | } catch (RemoteException e) { |
| 7367 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 7368 | sendCloseSystemWindows(); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 7369 | startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7370 | } else { |
| 7371 | // This code brings home to the front or, if it is already |
| 7372 | // at the front, puts the device to sleep. |
| 7373 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 7374 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 7375 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 7376 | Log.d(TAG, "UTS-TEST-MODE"); |
| 7377 | } else { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7378 | ActivityManager.getService().stopAppSwitches(); |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 7379 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7380 | Intent dock = createHomeDockIntent(); |
| 7381 | if (dock != null) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7382 | int result = ActivityManager.getService() |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7383 | .startActivityAsUser(null, null, dock, |
| 7384 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 7385 | null, null, 0, |
| 7386 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 7387 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7388 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 7389 | return false; |
| 7390 | } |
| 7391 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 7392 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7393 | int result = ActivityManager.getService() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 7394 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7395 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 7396 | null, null, 0, |
| 7397 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 7398 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 7399 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7400 | return false; |
| 7401 | } |
| 7402 | } catch (RemoteException ex) { |
| 7403 | // bummer, the activity manager, which is in this process, is dead |
| 7404 | } |
| 7405 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7406 | return true; |
| 7407 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7408 | |
| 7409 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 7410 | public void setCurrentOrientationLw(int newOrientation) { |
| 7411 | synchronized (mLock) { |
| 7412 | if (newOrientation != mCurrentAppOrientation) { |
| 7413 | mCurrentAppOrientation = newOrientation; |
| 7414 | updateOrientationListenerLp(); |
| 7415 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7416 | } |
| 7417 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7418 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 7419 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 7420 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 7421 | return; |
| 7422 | } |
| 7423 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 7424 | Context.AUDIO_SERVICE); |
| 7425 | if (audioManager.isSilentMode()) { |
| 7426 | return; |
| 7427 | } |
| 7428 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 7429 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 7430 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 7431 | ringTone.play(); |
| 7432 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7433 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 7434 | private boolean isTheaterModeEnabled() { |
| 7435 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 7436 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 7437 | } |
| 7438 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 7439 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 7440 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 7441 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 7442 | } |
| 7443 | |
Doris Ling | 628cea4 | 2016-06-09 10:35:02 -0700 | [diff] [blame] | 7444 | private boolean areSystemNavigationKeysEnabled() { |
Doris Ling | 34331b7 | 2016-08-09 12:02:28 -0700 | [diff] [blame] | 7445 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 7446 | Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0, UserHandle.USER_CURRENT) == 1; |
Doris Ling | 628cea4 | 2016-06-09 10:35:02 -0700 | [diff] [blame] | 7447 | } |
| 7448 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7449 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 7450 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 7451 | if (!mVibrator.hasVibrator()) { |
| 7452 | return false; |
| 7453 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7454 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 7455 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 7456 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7457 | return false; |
| 7458 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7459 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7460 | switch (effectId) { |
| 7461 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7462 | pattern = mLongPressVibePattern; |
| 7463 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 7464 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7465 | pattern = mVirtualKeyVibePattern; |
| 7466 | break; |
| 7467 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 7468 | pattern = mKeyboardTapVibePattern; |
| 7469 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 7470 | case HapticFeedbackConstants.CLOCK_TICK: |
| 7471 | pattern = mClockTickVibePattern; |
| 7472 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 7473 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 7474 | pattern = mCalendarDateVibePattern; |
| 7475 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 7476 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7477 | pattern = mSafeModeDisabledVibePattern; |
| 7478 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 7479 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7480 | pattern = mSafeModeEnabledVibePattern; |
| 7481 | break; |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 7482 | case HapticFeedbackConstants.CONTEXT_CLICK: |
| 7483 | pattern = mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 7484 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7485 | default: |
| 7486 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7487 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 7488 | int owningUid; |
| 7489 | String owningPackage; |
| 7490 | if (win != null) { |
| 7491 | owningUid = win.getOwningUid(); |
| 7492 | owningPackage = win.getOwningPackage(); |
| 7493 | } else { |
| 7494 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 7495 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 7496 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7497 | if (pattern.length == 1) { |
| 7498 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 7499 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7500 | } else { |
| 7501 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 7502 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7503 | } |
| 7504 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7505 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 7506 | |
| 7507 | @Override |
| 7508 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 7509 | } |
| 7510 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 7511 | @Override |
| 7512 | public void keepScreenOnStoppedLw() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 7513 | if (isKeyguardShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 7514 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7515 | } |
| 7516 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 7517 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7518 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7519 | // If there is no window focused, there will be nobody to handle the events |
| 7520 | // 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] | 7521 | WindowState winCandidate = mFocusedWindow != null ? mFocusedWindow |
Adrian Roos | 53f28ec | 2014-10-29 17:26:12 +0100 | [diff] [blame] | 7522 | : mTopFullscreenOpaqueWindowState; |
Adrian Roos | dab1516 | 2016-09-12 15:08:35 -0700 | [diff] [blame] | 7523 | if (winCandidate == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7524 | return 0; |
| 7525 | } |
Adrian Roos | dab1516 | 2016-09-12 15:08:35 -0700 | [diff] [blame] | 7526 | if (winCandidate.getAttrs().token == mImmersiveModeConfirmation.getWindowToken()) { |
| 7527 | // The immersive mode confirmation should never affect the system bar visibility, |
| 7528 | // otherwise it will unhide the navigation bar and hide itself. |
| 7529 | winCandidate = isStatusBarKeyguard() ? mStatusBar : mTopFullscreenOpaqueWindowState; |
| 7530 | if (winCandidate == null) { |
| 7531 | return 0; |
| 7532 | } |
| 7533 | } |
| 7534 | final WindowState win = winCandidate; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 7535 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mKeyguardOccluded) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 7536 | // We are updating at a point where the keyguard has gotten |
| 7537 | // focus, but we were last in a state where the top window is |
| 7538 | // hiding it. This is probably because the keyguard as been |
| 7539 | // shown while the top window was displayed, so we want to ignore |
| 7540 | // it here because this is just a very transient change and it |
| 7541 | // will quickly lose focus once it correctly gets hidden. |
| 7542 | return 0; |
| 7543 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 7544 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 7545 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 7546 | & ~mResettingSystemUiFlags |
| 7547 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7548 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 7549 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 7550 | } |
Thanh Hai Mai | 6c009f5 | 2015-09-01 16:27:32 -0700 | [diff] [blame] | 7551 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7552 | final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */, |
| 7553 | mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState); |
| 7554 | final int dockedVisibility = updateLightStatusBarLw(0 /* vis */, |
| 7555 | mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState); |
| 7556 | mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds); |
| 7557 | mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7558 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7559 | final int diff = visibility ^ mLastSystemUiFlags; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7560 | final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags; |
| 7561 | final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7562 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7563 | if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu |
| 7564 | && mFocusedApp == win.getAppToken() |
| 7565 | && mLastNonDockedStackBounds.equals(mNonDockedStackBounds) |
| 7566 | && mLastDockedStackBounds.equals(mDockedStackBounds)) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7567 | return 0; |
| 7568 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 7569 | mLastSystemUiFlags = visibility; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7570 | mLastFullscreenStackSysUiFlags = fullscreenVisibility; |
| 7571 | mLastDockedStackSysUiFlags = dockedVisibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 7572 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7573 | mFocusedApp = win.getAppToken(); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7574 | final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds); |
| 7575 | final Rect dockedStackBounds = new Rect(mDockedStackBounds); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7576 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7577 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7578 | public void run() { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7579 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 7580 | if (statusbar != null) { |
| 7581 | statusbar.setSystemUiVisibility(visibility, fullscreenVisibility, |
| 7582 | dockedVisibility, 0xffffffff, fullscreenStackBounds, |
| 7583 | dockedStackBounds, win.toString()); |
| 7584 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7585 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7586 | } |
| 7587 | }); |
| 7588 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7589 | } |
| 7590 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7591 | private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 7592 | WindowState statusColorWin = isStatusBarKeyguard() && !mKeyguardOccluded |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7593 | ? mStatusBar |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7594 | : opaqueOrDimming; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7595 | |
| 7596 | if (statusColorWin != null) { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7597 | if (statusColorWin == opaque) { |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7598 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 7599 | // its light flag. |
| 7600 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 7601 | vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) |
| 7602 | & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 7603 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 7604 | // Otherwise if it's dimming, clear the light flag. |
| 7605 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 7606 | } |
| 7607 | } |
| 7608 | return vis; |
| 7609 | } |
| 7610 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 7611 | private int updateLightNavigationBarLw(int vis, WindowState opaque, |
| 7612 | WindowState opaqueOrDimming) { |
| 7613 | final WindowState imeWin = mWindowManagerFuncs.getInputMethodWindowLw(); |
| 7614 | |
| 7615 | final WindowState navColorWin; |
| 7616 | if (imeWin != null && imeWin.isVisibleLw()) { |
| 7617 | navColorWin = imeWin; |
| 7618 | } else { |
| 7619 | navColorWin = opaqueOrDimming; |
| 7620 | } |
| 7621 | |
| 7622 | if (navColorWin != null) { |
| 7623 | if (navColorWin == opaque) { |
| 7624 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 7625 | // its light flag. |
| 7626 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 7627 | vis |= PolicyControl.getSystemUiVisibility(navColorWin, null) |
| 7628 | & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 7629 | } else if (navColorWin.isDimming() || navColorWin == imeWin) { |
| 7630 | // Otherwise if it's dimming or it's the IME window, clear the light flag. |
| 7631 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 7632 | } |
| 7633 | } |
| 7634 | return vis; |
| 7635 | } |
| 7636 | |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 7637 | private boolean drawsSystemBarBackground(WindowState win) { |
| 7638 | return win == null || (win.getAttrs().flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0; |
| 7639 | } |
| 7640 | |
| 7641 | private boolean forcesDrawStatusBarBackground(WindowState win) { |
| 7642 | return win == null || (win.getAttrs().privateFlags |
| 7643 | & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) != 0; |
| 7644 | } |
| 7645 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7646 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7647 | final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID); |
| 7648 | final boolean freeformStackVisible = |
| 7649 | mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 7650 | final boolean resizing = mWindowManagerInternal.isDockedDividerResizing(); |
| 7651 | |
| 7652 | // We need to force system bars when the docked stack is visible, when the freeform stack |
| 7653 | // is visible but also when we are resizing for the transitions when docked stack |
| 7654 | // visibility changes. |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7655 | mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing; |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7656 | final boolean forceOpaqueStatusBar = mForceShowSystemBars && !mForceStatusBarFromKeyguard; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7657 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7658 | // apply translucent bar vis flags |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 7659 | WindowState fullscreenTransWin = isStatusBarKeyguard() && !mKeyguardOccluded |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 7660 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7661 | : mTopFullscreenOpaqueWindowState; |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 7662 | vis = mStatusBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); |
| 7663 | vis = mNavigationBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); |
| 7664 | final int dockedVis = mStatusBarController.applyTranslucentFlagLw( |
| 7665 | mTopDockedOpaqueWindowState, 0, 0); |
| 7666 | |
| 7667 | final boolean fullscreenDrawsStatusBarBackground = |
| 7668 | (drawsSystemBarBackground(mTopFullscreenOpaqueWindowState) |
| 7669 | && (vis & View.STATUS_BAR_TRANSLUCENT) == 0) |
| 7670 | || forcesDrawStatusBarBackground(mTopFullscreenOpaqueWindowState); |
| 7671 | final boolean dockedDrawsStatusBarBackground = |
| 7672 | (drawsSystemBarBackground(mTopDockedOpaqueWindowState) |
| 7673 | && (dockedVis & View.STATUS_BAR_TRANSLUCENT) == 0) |
| 7674 | || forcesDrawStatusBarBackground(mTopDockedOpaqueWindowState); |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7675 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7676 | // prevent status bar interaction from clearing certain flags |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 7677 | int type = win.getAttrs().type; |
| 7678 | boolean statusBarHasFocus = type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 7679 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7680 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 7681 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 7682 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 73fef8d | 2015-02-16 17:32:28 +0100 | [diff] [blame] | 7683 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 7684 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 7685 | if (mKeyguardOccluded) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 7686 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 7687 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7688 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7689 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7690 | |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 7691 | if (fullscreenDrawsStatusBarBackground && dockedDrawsStatusBarBackground) { |
| 7692 | vis |= View.STATUS_BAR_TRANSPARENT; |
| 7693 | vis &= ~View.STATUS_BAR_TRANSLUCENT; |
| 7694 | } else if ((!areTranslucentBarsAllowed() && fullscreenTransWin != mStatusBar) |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7695 | || forceOpaqueStatusBar) { |
| 7696 | vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7697 | } |
| 7698 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7699 | vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing); |
Yorke Lee | 2e4b732 | 2016-03-02 17:33:06 -0800 | [diff] [blame] | 7700 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7701 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7702 | boolean immersiveSticky = |
| 7703 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7704 | final boolean hideStatusBarWM = |
| 7705 | mTopFullscreenOpaqueWindowState != null |
| 7706 | && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7707 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7708 | final boolean hideStatusBarSysui = |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7709 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7710 | final boolean hideNavBarSysui = |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7711 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7712 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7713 | final boolean transientStatusBarAllowed = mStatusBar != null |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7714 | && (statusBarHasFocus || (!mForceShowSystemBars |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7715 | && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky)))); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7716 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7717 | final boolean transientNavBarAllowed = mNavigationBar != null |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7718 | && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7719 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 7720 | final long now = SystemClock.uptimeMillis(); |
| 7721 | final boolean pendingPanic = mPendingPanicGestureUptime != 0 |
| 7722 | && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION; |
| 7723 | if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) { |
| 7724 | // The user performed the panic gesture recently, we're about to hide the bars, |
| 7725 | // we're no longer on the Keyguard and the screen is ready. We can now request the bars. |
| 7726 | mPendingPanicGestureUptime = 0; |
| 7727 | mStatusBarController.showTransient(); |
Adrian Roos | 1f42590 | 2016-07-22 10:37:50 -0700 | [diff] [blame] | 7728 | if (!isNavBarEmpty(vis)) { |
| 7729 | mNavigationBarController.showTransient(); |
| 7730 | } |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 7731 | } |
| 7732 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7733 | final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7734 | && !transientStatusBarAllowed && hideStatusBarSysui; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7735 | final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7736 | && !transientNavBarAllowed; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7737 | if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7738 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7739 | clearClearableFlagsLw(); |
tiger_huang | c58d756 | 2014-10-23 20:24:19 +0800 | [diff] [blame] | 7740 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7741 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7742 | |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 7743 | final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 7744 | immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 7745 | final boolean navAllowedHidden = immersive || immersiveSticky; |
| 7746 | |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 7747 | if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType()) |
| 7748 | > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) { |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 7749 | // We can't hide the navbar from this window otherwise the input consumer would not get |
| 7750 | // the input events. |
| 7751 | vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); |
| 7752 | } |
| 7753 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7754 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 7755 | |
| 7756 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7757 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 7758 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 7759 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7760 | final String pkg = win.getOwningPackage(); |
Amith Yamasani | 02a0381 | 2016-04-22 17:32:00 -0700 | [diff] [blame] | 7761 | mImmersiveModeConfirmation.immersiveModeChangedLw(pkg, newImmersiveMode, |
Adrian Roos | 7aaa551 | 2016-07-12 15:27:24 -0700 | [diff] [blame] | 7762 | isUserSetupComplete(), isNavBarEmpty(win.getSystemUiVisibility())); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 7763 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7764 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7765 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 7766 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 7767 | vis = updateLightNavigationBarLw(vis, mTopFullscreenOpaqueWindowState, |
| 7768 | mTopFullscreenOpaqueOrDimmingWindowState); |
| 7769 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 7770 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7771 | } |
| 7772 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7773 | /** |
| 7774 | * @return the current visibility flags with the nav-bar opacity related flags toggled based |
| 7775 | * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}. |
| 7776 | */ |
| 7777 | private int configureNavBarOpacity(int visibility, boolean dockedStackVisible, |
| 7778 | boolean freeformStackVisible, boolean isDockedDividerResizing) { |
| 7779 | if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) { |
| 7780 | if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) { |
| 7781 | visibility = setNavBarOpaqueFlag(visibility); |
| 7782 | } |
| 7783 | } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) { |
| 7784 | if (isDockedDividerResizing) { |
| 7785 | visibility = setNavBarOpaqueFlag(visibility); |
| 7786 | } else if (freeformStackVisible) { |
| 7787 | visibility = setNavBarTranslucentFlag(visibility); |
| 7788 | } else { |
| 7789 | visibility = setNavBarOpaqueFlag(visibility); |
| 7790 | } |
| 7791 | } |
| 7792 | |
| 7793 | if (!areTranslucentBarsAllowed()) { |
| 7794 | visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT; |
| 7795 | } |
| 7796 | return visibility; |
| 7797 | } |
| 7798 | |
| 7799 | private int setNavBarOpaqueFlag(int visibility) { |
| 7800 | return visibility &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT); |
| 7801 | } |
| 7802 | |
| 7803 | private int setNavBarTranslucentFlag(int visibility) { |
| 7804 | visibility &= ~View.NAVIGATION_BAR_TRANSPARENT; |
| 7805 | return visibility |= View.NAVIGATION_BAR_TRANSLUCENT; |
| 7806 | } |
| 7807 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7808 | private void clearClearableFlagsLw() { |
| 7809 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 7810 | if (newVal != mResettingSystemUiFlags) { |
| 7811 | mResettingSystemUiFlags = newVal; |
| 7812 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 7813 | } |
| 7814 | } |
| 7815 | |
| 7816 | private boolean isImmersiveMode(int vis) { |
| 7817 | 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] | 7818 | return mNavigationBar != null |
| 7819 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 7820 | && (vis & flags) != 0 |
| 7821 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 7822 | } |
| 7823 | |
Adrian Roos | 7aaa551 | 2016-07-12 15:27:24 -0700 | [diff] [blame] | 7824 | private static boolean isNavBarEmpty(int systemUiFlags) { |
| 7825 | final int disableNavigationBar = (View.STATUS_BAR_DISABLE_HOME |
| 7826 | | View.STATUS_BAR_DISABLE_BACK |
| 7827 | | View.STATUS_BAR_DISABLE_RECENT); |
| 7828 | |
| 7829 | return (systemUiFlags & disableNavigationBar) == disableNavigationBar; |
| 7830 | } |
| 7831 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7832 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 7833 | * @return whether the navigation or status bar can be made translucent |
| 7834 | * |
| 7835 | * This should return true unless touch exploration is not enabled or |
| 7836 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7837 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 7838 | private boolean areTranslucentBarsAllowed() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 7839 | return mTranslucentDecorEnabled; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7840 | } |
| 7841 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 7842 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 7843 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7844 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 7845 | public boolean hasNavigationBar() { |
| 7846 | return mHasNavigationBar; |
| 7847 | } |
| 7848 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 7849 | @Override |
| 7850 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 7851 | mLastInputMethodWindow = ime; |
| 7852 | mLastInputMethodTargetWindow = target; |
| 7853 | } |
| 7854 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7855 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 7856 | public int getInputMethodWindowVisibleHeightLw() { |
| 7857 | return mDockBottom - mCurBottom; |
| 7858 | } |
| 7859 | |
| 7860 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7861 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 7862 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 7863 | if (mKeyguardDelegate != null) { |
| 7864 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7865 | } |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 7866 | StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); |
Adrian Roos | 2a62910 | 2016-04-15 16:28:03 -0700 | [diff] [blame] | 7867 | if (statusBar != null) { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 7868 | statusBar.setCurrentUser(newUserId); |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 7869 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7870 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7871 | } |
| 7872 | |
| 7873 | @Override |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 7874 | public void setSwitchingUser(boolean switching) { |
| 7875 | mKeyguardDelegate.setSwitchingUser(switching); |
| 7876 | } |
| 7877 | |
| 7878 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 7879 | public boolean canMagnifyWindow(int windowType) { |
| 7880 | switch (windowType) { |
| 7881 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 7882 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 7883 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 7884 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 7885 | return false; |
| 7886 | } |
| 7887 | } |
| 7888 | return true; |
| 7889 | } |
| 7890 | |
| 7891 | @Override |
| 7892 | public boolean isTopLevelWindow(int windowType) { |
| 7893 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 7894 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 7895 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 7896 | } |
| 7897 | return true; |
| 7898 | } |
| 7899 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 7900 | @Override |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 7901 | public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) { |
| 7902 | // For the upside down rotation we don't rotate seamlessly as the navigation |
| 7903 | // bar moves position. |
| 7904 | // Note most apps (using orientation:sensor or user as opposed to fullSensor) |
| 7905 | // will not enter the reverse portrait orientation, so actually the |
| 7906 | // orientation won't change at all. |
| 7907 | if (oldRotation == mUpsideDownRotation || newRotation == mUpsideDownRotation) { |
| 7908 | return false; |
| 7909 | } |
Robert Carr | 0b9ac5a | 2016-10-26 14:12:14 -0700 | [diff] [blame] | 7910 | // If the navigation bar can't change sides, then it will |
| 7911 | // jump when we change orientations and we don't rotate |
| 7912 | // seamlessly. |
| 7913 | if (!mNavigationBarCanMove) { |
| 7914 | return false; |
| 7915 | } |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 7916 | int delta = newRotation - oldRotation; |
| 7917 | if (delta < 0) delta += 4; |
| 7918 | // Likewise we don't rotate seamlessly for 180 degree rotations |
Geoffrey Pitsch | b2d6ed3 | 2016-08-24 10:37:19 -0400 | [diff] [blame] | 7919 | // in this case the surfaces never resize, and our logic to |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 7920 | // revert the transformations on size change will fail. We could |
| 7921 | // fix this in the future with the "tagged" frames idea. |
| 7922 | if (delta == Surface.ROTATION_180) { |
| 7923 | return false; |
| 7924 | } |
| 7925 | |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 7926 | final WindowState w = mTopFullscreenOpaqueWindowState; |
Robert Carr | 828ec3dc | 2016-08-22 13:32:34 -0700 | [diff] [blame] | 7927 | if (w != mFocusedWindow) { |
| 7928 | return false; |
| 7929 | } |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 7930 | |
Robert Carr | 606f4d5 | 2016-06-30 14:36:27 -0700 | [diff] [blame] | 7931 | // We only enable seamless rotation if the top window has requested |
| 7932 | // it and is in the fullscreen opaque state. Seamless rotation |
| 7933 | // requires freezing various Surface states and won't work well |
| 7934 | // with animations, so we disable it in the animation case for now. |
Robert Carr | 1ccd425 | 2016-08-15 12:05:21 -0700 | [diff] [blame] | 7935 | if (w != null && !w.isAnimatingLw() && |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 7936 | ((w.getAttrs().rotationAnimation == ROTATION_ANIMATION_JUMPCUT) || |
| 7937 | (w.getAttrs().rotationAnimation == ROTATION_ANIMATION_SEAMLESS))) { |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 7938 | return true; |
| 7939 | } |
| 7940 | return false; |
| 7941 | } |
| 7942 | |
| 7943 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 7944 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7945 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7946 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 7947 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 7948 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7949 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 7950 | pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7951 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 7952 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 7953 | || mForceClearedSystemUiFlags != 0) { |
| 7954 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 7955 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 7956 | pw.print(" mResettingSystemUiFlags=0x"); |
| 7957 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 7958 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 7959 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7960 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 7961 | if (mLastFocusNeedsMenu) { |
| 7962 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 7963 | pw.println(mLastFocusNeedsMenu); |
| 7964 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 7965 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 7966 | pw.println(mWakeGestureEnabledSetting); |
| 7967 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 7968 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7969 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 7970 | pw.print(" mDockMode="); pw.print(mDockMode); |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 7971 | pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7972 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 7973 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 7974 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 7975 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 7976 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 7977 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7978 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 7979 | pw.print(mCarDockEnablesAccelerometer); |
| 7980 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 7981 | pw.println(mDeskDockEnablesAccelerometer); |
| 7982 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 7983 | pw.print(mLidKeyboardAccessibility); |
| 7984 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 7985 | pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 7986 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7987 | pw.print(prefix); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 7988 | pw.print(" mLongPressOnBackBehavior="); pw.println(mLongPressOnBackBehavior); |
| 7989 | pw.print(prefix); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7990 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 7991 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 7992 | pw.print(prefix); |
| 7993 | pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); |
| 7994 | pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7995 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7996 | pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); |
| 7997 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 7998 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 7999 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 8000 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 8001 | pw.print(prefix); pw.print("mOrientationSensorEnabled="); |
| 8002 | pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 8003 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 8004 | pw.print(","); pw.print(mOverscanScreenTop); |
| 8005 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 8006 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 8007 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 8008 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 8009 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 8010 | pw.print(" top="); pw.print(mOverscanTop); |
| 8011 | pw.print(" right="); pw.print(mOverscanRight); |
| 8012 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 8013 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 8014 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 8015 | pw.print(mRestrictedOverscanScreenLeft); |
| 8016 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 8017 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 8018 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8019 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 8020 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 8021 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 8022 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 8023 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 8024 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 8025 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 8026 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 8027 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 8028 | pw.print(","); pw.print(mStableFullscreenTop); |
| 8029 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 8030 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 8031 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 8032 | pw.print(","); pw.print(mStableTop); |
| 8033 | pw.print(")-("); pw.print(mStableRight); |
| 8034 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 8035 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 8036 | pw.print(","); pw.print(mSystemTop); |
| 8037 | pw.print(")-("); pw.print(mSystemRight); |
| 8038 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8039 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 8040 | pw.print(","); pw.print(mCurTop); |
| 8041 | pw.print(")-("); pw.print(mCurRight); |
| 8042 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 8043 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 8044 | pw.print(","); pw.print(mContentTop); |
| 8045 | pw.print(")-("); pw.print(mContentRight); |
| 8046 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 8047 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 8048 | pw.print(","); pw.print(mVoiceContentTop); |
| 8049 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 8050 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8051 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 8052 | pw.print(","); pw.print(mDockTop); |
| 8053 | pw.print(")-("); pw.print(mDockRight); |
| 8054 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 8055 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 8056 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 8057 | pw.print(prefix); pw.print("mShowingDream="); pw.print(mShowingDream); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 8058 | pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); |
| 8059 | pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8060 | if (mLastInputMethodWindow != null) { |
| 8061 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 8062 | pw.println(mLastInputMethodWindow); |
| 8063 | } |
| 8064 | if (mLastInputMethodTargetWindow != null) { |
| 8065 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 8066 | pw.println(mLastInputMethodTargetWindow); |
| 8067 | } |
| 8068 | if (mStatusBar != null) { |
| 8069 | pw.print(prefix); pw.print("mStatusBar="); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 8070 | pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); |
| 8071 | pw.println(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8072 | } |
| 8073 | if (mNavigationBar != null) { |
| 8074 | pw.print(prefix); pw.print("mNavigationBar="); |
| 8075 | pw.println(mNavigationBar); |
| 8076 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8077 | if (mFocusedWindow != null) { |
| 8078 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 8079 | pw.println(mFocusedWindow); |
| 8080 | } |
| 8081 | if (mFocusedApp != null) { |
| 8082 | pw.print(prefix); pw.print("mFocusedApp="); |
| 8083 | pw.println(mFocusedApp); |
| 8084 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8085 | if (mTopFullscreenOpaqueWindowState != null) { |
| 8086 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 8087 | pw.println(mTopFullscreenOpaqueWindowState); |
| 8088 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 8089 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 8090 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 8091 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 8092 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 8093 | if (mForcingShowNavBar) { |
| 8094 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 8095 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 8096 | pw.println(mForcingShowNavBarLayer); |
| 8097 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 8098 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 8099 | pw.print(" mKeyguardOccluded="); pw.println(mKeyguardOccluded); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 8100 | pw.print(" mKeyguardOccludedChanged="); pw.println(mKeyguardOccludedChanged); |
| 8101 | pw.print(" mPendingKeyguardOccluded="); pw.println(mPendingKeyguardOccluded); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 8102 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 8103 | pw.print(" mForceStatusBarFromKeyguard="); |
| 8104 | pw.println(mForceStatusBarFromKeyguard); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 8105 | pw.print(prefix); pw.print("mHomePressed="); pw.println(mHomePressed); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8106 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 8107 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 8108 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 8109 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 8110 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 8111 | pw.print(" mIncallBackBehavior="); pw.print(mIncallBackBehavior); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8112 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 8113 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 8114 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 8115 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 8116 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 8117 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 8118 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 8119 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 8120 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 8121 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8122 | mStatusBarController.dump(pw, prefix); |
| 8123 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 8124 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 8125 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 8126 | if (mWakeGestureListener != null) { |
| 8127 | mWakeGestureListener.dump(pw, prefix); |
| 8128 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 8129 | if (mOrientationListener != null) { |
| 8130 | mOrientationListener.dump(pw, prefix); |
| 8131 | } |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 8132 | if (mBurnInProtectionHelper != null) { |
| 8133 | mBurnInProtectionHelper.dump(prefix, pw); |
| 8134 | } |
Jorim Jaggi | 84dc08a | 2015-09-11 17:45:22 -0700 | [diff] [blame] | 8135 | if (mKeyguardDelegate != null) { |
| 8136 | mKeyguardDelegate.dump(prefix, pw); |
| 8137 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8138 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 8139 | } |