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; |
| 54 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR; |
| 55 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE; |
| 56 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT; |
| 57 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE; |
| 58 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS; |
| 59 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; |
| 60 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 61 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 62 | import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; |
| 63 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL; |
| 64 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 65 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; |
| 66 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; |
| 67 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; |
| 68 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 69 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL; |
| 70 | import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; |
| 71 | import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY; |
| 72 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
| 73 | import static android.view.WindowManager.LayoutParams.TYPE_DRAG; |
| 74 | import static android.view.WindowManager.LayoutParams.TYPE_DREAM; |
| 75 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER; |
| 76 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 77 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 78 | import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; |
| 79 | import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY; |
| 80 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
| 81 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; |
| 82 | import static android.view.WindowManager.LayoutParams.TYPE_PHONE; |
| 83 | import static android.view.WindowManager.LayoutParams.TYPE_POINTER; |
Wale Ogunwale | 5b6714c | 2016-11-01 20:54:46 -0700 | [diff] [blame] | 84 | import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 85 | import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE; |
| 86 | import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION; |
| 87 | import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG; |
| 88 | import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT; |
| 89 | import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR; |
| 90 | import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
| 91 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
| 92 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; |
| 93 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; |
| 94 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; |
| 95 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
| 96 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
| 97 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; |
| 98 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
| 99 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; |
| 100 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING; |
| 101 | import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; |
| 102 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 103 | import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN; |
| 104 | import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 105 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 106 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; |
| 107 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 108 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 109 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
| 110 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 111 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 112 | import android.annotation.Nullable; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 113 | import android.app.ActivityManager; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 114 | import android.app.ActivityManager.StackId; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 115 | import android.app.ActivityManagerInternal; |
| 116 | import android.app.ActivityManagerInternal.SleepToken; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 117 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 118 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 119 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 120 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 121 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 122 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 123 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 124 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 125 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 126 | import android.content.ContentResolver; |
| 127 | import android.content.Context; |
| 128 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 129 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 130 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 131 | import android.content.pm.ActivityInfo; |
Svet Ganov | 03f2afc | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 132 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 133 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 134 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 135 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 136 | import android.content.res.Configuration; |
| 137 | import android.content.res.Resources; |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 138 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 139 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 140 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 141 | import android.graphics.Rect; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 142 | import android.hardware.hdmi.HdmiControlManager; |
| 143 | import android.hardware.hdmi.HdmiPlaybackClient; |
| 144 | import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 145 | import android.hardware.input.InputManagerInternal; |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 146 | import android.hardware.power.V1_0.PowerHint; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 147 | import android.media.AudioAttributes; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 148 | import android.media.AudioManager; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 149 | import android.media.AudioSystem; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 150 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 151 | import android.media.Ringtone; |
| 152 | import android.media.RingtoneManager; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 153 | import android.media.session.MediaSessionLegacyHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 154 | import android.os.Binder; |
Svet Ganov | 03f2afc | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 155 | import android.os.Build; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 156 | import android.os.Bundle; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 157 | import android.os.Debug; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 158 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 159 | import android.os.Handler; |
| 160 | import android.os.IBinder; |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 161 | import android.os.IDeviceIdleController; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 162 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 163 | import android.os.Message; |
| 164 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 165 | import android.os.PowerManager; |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 166 | import android.os.PowerManagerInternal; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 167 | import android.os.Process; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 168 | import android.os.RemoteException; |
| 169 | import android.os.ServiceManager; |
| 170 | import android.os.SystemClock; |
| 171 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 172 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 173 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 174 | import android.os.Vibrator; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 175 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 176 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 177 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 178 | import android.service.dreams.DreamService; |
| 179 | import android.service.dreams.IDreamManager; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 180 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 181 | import android.telecom.TelecomManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 182 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 183 | import android.util.EventLog; |
| 184 | import android.util.Log; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 185 | import android.util.LongSparseArray; |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 186 | import android.util.MutableBoolean; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 187 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 188 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 189 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 190 | import android.view.Gravity; |
| 191 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 192 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 193 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 194 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 195 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 196 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 197 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 198 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 199 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 200 | import android.view.KeyEvent; |
| 201 | import android.view.MotionEvent; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 202 | import android.view.Surface; |
| 203 | import android.view.View; |
| 204 | import android.view.ViewConfiguration; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 205 | import android.view.WindowManager; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 206 | import android.view.WindowManager.LayoutParams; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 207 | import android.view.WindowManagerGlobal; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 208 | import android.view.WindowManagerInternal; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 209 | import android.view.WindowManagerInternal.AppTransitionListener; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 210 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 211 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 212 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 213 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 214 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 215 | import android.view.animation.AnimationUtils; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 216 | |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 217 | import com.android.internal.R; |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 218 | import com.android.internal.logging.MetricsLogger; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 219 | import com.android.internal.policy.IKeyguardDismissCallback; |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 220 | import com.android.internal.policy.IShortcutService; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 221 | import com.android.internal.policy.PhoneWindow; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 222 | import com.android.internal.statusbar.IStatusBarService; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 223 | import com.android.internal.util.ScreenShapeHelper; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 224 | import com.android.internal.widget.PointerLocationView; |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 225 | import com.android.server.GestureLauncherService; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 226 | import com.android.server.LocalServices; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 227 | import com.android.server.policy.keyguard.KeyguardServiceDelegate; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 228 | import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener; |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 229 | import com.android.server.policy.keyguard.KeyguardStateMonitor.StateCallback; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 230 | import com.android.server.statusbar.StatusBarManagerInternal; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 231 | import com.android.server.wm.AppTransition; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 232 | |
| 233 | import java.io.File; |
| 234 | import java.io.FileReader; |
| 235 | import java.io.IOException; |
| 236 | import java.io.PrintWriter; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 237 | import java.util.List; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 238 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 239 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 240 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 241 | * introduces a new method suffix, Lp, for an internal lock of the |
| 242 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 243 | * 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] | 244 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 245 | */ |
| 246 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 247 | static final String TAG = "WindowManager"; |
| 248 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 249 | static final boolean localLOGV = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 250 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 251 | static final boolean DEBUG_KEYGUARD = false; |
| 252 | static final boolean DEBUG_LAYOUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 253 | static final boolean DEBUG_STARTING_WINDOW = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 254 | static final boolean DEBUG_WAKEUP = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 255 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 256 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 257 | // 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] | 258 | // No longer recommended for desk docks; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 259 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 260 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 261 | static final boolean ALTERNATE_CAR_MODE_NAV_SIZE = false; |
| 262 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 263 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 264 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 265 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 266 | 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] | 267 | static final int SHORT_PRESS_POWER_GO_HOME = 4; |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 268 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 269 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 270 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 271 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 272 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 273 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 274 | static final int LONG_PRESS_BACK_NOTHING = 0; |
| 275 | static final int LONG_PRESS_BACK_GO_TO_VOICE_ASSIST = 1; |
| 276 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 277 | static final int MULTI_PRESS_POWER_NOTHING = 0; |
| 278 | static final int MULTI_PRESS_POWER_THEATER_MODE = 1; |
| 279 | static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2; |
| 280 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 281 | // Number of presses needed before we induce panic press behavior on the back button |
| 282 | static final int PANIC_PRESS_BACK_COUNT = 4; |
| 283 | static final int PANIC_PRESS_BACK_NOTHING = 0; |
| 284 | static final int PANIC_PRESS_BACK_HOME = 1; |
| 285 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 286 | // These need to match the documentation/constant in |
| 287 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 288 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 289 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 290 | static final int LONG_PRESS_HOME_ASSIST = 2; |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 291 | static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 292 | |
| 293 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 294 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 295 | |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 296 | static final int SHORT_PRESS_WINDOW_NOTHING = 0; |
| 297 | static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1; |
| 298 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 299 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0; |
| 300 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1; |
| 301 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 302 | static final int PENDING_KEY_NULL = -1; |
| 303 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 304 | // Controls navigation bar opacity depending on which workspace stacks are currently |
| 305 | // visible. |
| 306 | // Nav bar is always opaque when either the freeform stack or docked stack is visible. |
| 307 | static final int NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED = 0; |
| 308 | // Nav bar is always translucent when the freeform stack is visible, otherwise always opaque. |
| 309 | static final int NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE = 1; |
| 310 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 311 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 312 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 313 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 314 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 315 | static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 316 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 317 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 318 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 319 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 320 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 321 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 322 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 323 | /** |
| 324 | * These are the system UI flags that, when changing, can cause the layout |
| 325 | * of the screen to change. |
| 326 | */ |
| 327 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 328 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 329 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 330 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 331 | | View.NAVIGATION_BAR_TRANSLUCENT |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 332 | | View.STATUS_BAR_TRANSPARENT |
| 333 | | View.NAVIGATION_BAR_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 334 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 335 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 336 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 337 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 338 | .build(); |
| 339 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 340 | // The panic gesture may become active only after the keyguard is dismissed and the immersive |
| 341 | // app shows again. If that doesn't happen for 30s we drop the gesture. |
| 342 | private static final long PANIC_GESTURE_EXPIRATION = 30000; |
| 343 | |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 344 | private static final String SYSUI_PACKAGE = "com.android.systemui"; |
| 345 | private static final String SYSUI_SCREENSHOT_SERVICE = |
| 346 | "com.android.systemui.screenshot.TakeScreenshotService"; |
| 347 | private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER = |
| 348 | "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver"; |
| 349 | |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 350 | private static final int NAV_BAR_BOTTOM = 0; |
| 351 | private static final int NAV_BAR_RIGHT = 1; |
| 352 | private static final int NAV_BAR_LEFT = 2; |
| 353 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 354 | /** |
| 355 | * Keyguard stuff |
| 356 | */ |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 357 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 358 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 359 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 360 | * |
| 361 | * These are special keys that are used to launch particular kinds of applications, |
| 362 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 363 | * usage page. We don't support quite that many yet... |
| 364 | */ |
| 365 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 366 | static { |
| 367 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 368 | sApplicationLaunchKeyCategories.append( |
| 369 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 370 | sApplicationLaunchKeyCategories.append( |
| 371 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 372 | sApplicationLaunchKeyCategories.append( |
| 373 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 374 | sApplicationLaunchKeyCategories.append( |
| 375 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 376 | sApplicationLaunchKeyCategories.append( |
| 377 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 378 | sApplicationLaunchKeyCategories.append( |
| 379 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 380 | } |
| 381 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 382 | /** 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] | 383 | static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 384 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 385 | /** Amount of time (in milliseconds) a toast window can be shown. */ |
| 386 | public static final int TOAST_WINDOW_TIMEOUT = 3500; // 3.5 seconds |
| 387 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 388 | /** |
| 389 | * Lock protecting internal state. Must not call out into window |
| 390 | * manager with lock held. (This lock will be acquired in places |
| 391 | * where the window manager is calling in with its own lock held.) |
| 392 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 393 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 394 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 395 | Context mContext; |
| 396 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 397 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 398 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 399 | PowerManager mPowerManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 400 | ActivityManagerInternal mActivityManagerInternal; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 401 | InputManagerInternal mInputManagerInternal; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 402 | DreamManagerInternal mDreamManagerInternal; |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 403 | PowerManagerInternal mPowerManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 404 | IStatusBarService mStatusBarService; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 405 | StatusBarManagerInternal mStatusBarManagerInternal; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 406 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 407 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 408 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 409 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 410 | AccessibilityManager mAccessibilityManager; |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 411 | BurnInProtectionHelper mBurnInProtectionHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 412 | AppOpsManager mAppOpsManager; |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 413 | private boolean mHasFeatureWatch; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 414 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 415 | // Vibrator pattern for haptic feedback of a long press. |
| 416 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 417 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 418 | // Vibrator pattern for haptic feedback of virtual key press. |
| 419 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 420 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 421 | // Vibrator pattern for a short vibration. |
| 422 | long[] mKeyboardTapVibePattern; |
| 423 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 424 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 425 | long[] mClockTickVibePattern; |
| 426 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 427 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 428 | long[] mCalendarDateVibePattern; |
| 429 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 430 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 431 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 432 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 433 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 434 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 435 | |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 436 | // Vibrator pattern for haptic feedback of a context click. |
| 437 | long[] mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 438 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 439 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 440 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 441 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 442 | boolean mSafeMode; |
| 443 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 444 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 445 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 446 | boolean mHasNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 447 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 448 | int mNavigationBarPosition = NAV_BAR_BOTTOM; |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 449 | int[] mNavigationBarHeightForRotationDefault = new int[4]; |
| 450 | int[] mNavigationBarWidthForRotationDefault = new int[4]; |
| 451 | int[] mNavigationBarHeightForRotationInCarMode = new int[4]; |
| 452 | int[] mNavigationBarWidthForRotationInCarMode = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 453 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 454 | private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>(); |
| 455 | |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 456 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 457 | // This is for car dock and this is updated from resource. |
| 458 | private boolean mEnableCarDockHomeCapture = true; |
| 459 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 460 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 461 | KeyguardServiceDelegate mKeyguardDelegate; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 462 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 463 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 464 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 465 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 466 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 467 | } |
| 468 | }; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 469 | final DrawnListener mKeyguardDrawnCallback = new DrawnListener() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 470 | @Override |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 471 | public void onDrawn() { |
| 472 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 473 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 474 | } |
| 475 | }; |
| 476 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 477 | GlobalActions mGlobalActions; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 478 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 479 | WindowState mLastInputMethodWindow = null; |
| 480 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 481 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 482 | // FIXME This state is shared between the input reader and handler thread. |
| 483 | // Technically it's broken and buggy but it has been like this for many years |
| 484 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 485 | // so that only one thread is involved in handling input policy. Unfortunately |
| 486 | // it's on a critical path for power management so we can't just post the work to the |
| 487 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 488 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 489 | volatile boolean mPowerKeyHandled; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 490 | volatile boolean mBackKeyHandled; |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 491 | volatile boolean mBeganFromNonInteractive; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 492 | volatile int mPowerKeyPressCounter; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 493 | volatile int mBackKeyPressCounter; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 494 | volatile boolean mEndCallKeyHandled; |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 495 | volatile boolean mCameraGestureTriggeredDuringGoingToSleep; |
| 496 | volatile boolean mGoingToSleep; |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 497 | volatile boolean mRecentsVisible; |
| 498 | volatile boolean mTvPictureInPictureVisible; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 499 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 500 | // Used to hold the last user key used to wake the device. This helps us prevent up events |
| 501 | // from being passed to the foregrounded app without a corresponding down event |
| 502 | volatile int mPendingWakeKey = PENDING_KEY_NULL; |
| 503 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 504 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 505 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 506 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 507 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 508 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 509 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 510 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 511 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 512 | boolean mSystemBooted; |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 513 | private boolean mDeferBindKeyguard; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 514 | boolean mHdmiPlugged; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 515 | HdmiControl mHdmiControl; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 516 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 517 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 518 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 519 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 520 | int mCarDockRotation; |
| 521 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 522 | int mUndockedHdmiRotation; |
| 523 | int mDemoHdmiRotation; |
| 524 | boolean mDemoHdmiRotationLock; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 525 | int mDemoRotation; |
| 526 | boolean mDemoRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 527 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 528 | boolean mWakeGestureEnabledSetting; |
| 529 | MyWakeGestureListener mWakeGestureListener; |
| 530 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 531 | // Default display does not rotate, apps that require non-default orientation will have to |
| 532 | // have the orientation emulated. |
| 533 | private boolean mForceDefaultOrientation = false; |
| 534 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 535 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 536 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 537 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 538 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 539 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 540 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 541 | boolean mCarDockEnablesAccelerometer; |
| 542 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 543 | int mLidKeyboardAccessibility; |
| 544 | int mLidNavigationAccessibility; |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 545 | boolean mLidControlsScreenLock; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 546 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 547 | int mShortPressOnPowerBehavior; |
| 548 | int mLongPressOnPowerBehavior; |
| 549 | int mDoublePressOnPowerBehavior; |
| 550 | int mTriplePressOnPowerBehavior; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 551 | int mLongPressOnBackBehavior; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 552 | int mPanicPressOnBackBehavior; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 553 | int mShortPressOnSleepBehavior; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 554 | int mShortPressWindowBehavior; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 555 | boolean mAwake; |
| 556 | boolean mScreenOnEarly; |
| 557 | boolean mScreenOnFully; |
| 558 | ScreenOnListener mScreenOnListener; |
| 559 | boolean mKeyguardDrawComplete; |
| 560 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 561 | boolean mOrientationSensorEnabled = false; |
| 562 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 563 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 564 | boolean mTranslucentDecorEnabled = true; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 565 | boolean mUseTvRouting; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 566 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 567 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 568 | |
| 569 | // The last window we were told about in focusChanged. |
| 570 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 571 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 572 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 573 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 574 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 575 | // The current size of the screen; really; extends into the overscan area of |
| 576 | // the screen and doesn't account for any system elements like the status bar. |
| 577 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 578 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 579 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 580 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 581 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 582 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 583 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 584 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 585 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 586 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 587 | // if the status bar can't be hidden; in that case it effectively carves out |
| 588 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 589 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 590 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 591 | // During layout, the current screen borders accounting for any currently |
| 592 | // visible system UI elements. |
| 593 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 594 | // For applications requesting stable content insets, these are them. |
| 595 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 596 | // For applications requesting stable content insets but have also set the |
| 597 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 598 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 599 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 600 | // During layout, the current screen borders with all outer decoration |
| 601 | // (status bar, input method dock) accounted for. |
| 602 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 603 | // During layout, the frame in which content should be displayed |
| 604 | // to the user, accounting for all screen decoration except for any |
| 605 | // space they deem as available for other content. This is usually |
| 606 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 607 | // content insets. |
| 608 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 609 | // During layout, the frame in which voice content should be displayed |
| 610 | // to the user, accounting for all screen decoration except for any |
| 611 | // space they deem as available for other content. |
| 612 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 613 | // 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] | 614 | // windows are placed. |
| 615 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 616 | // During layout, the layer at which the doc window is placed. |
| 617 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 618 | // During layout, this is the layer of the status bar. |
| 619 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 620 | int mLastSystemUiFlags; |
| 621 | // Bits that we are in the process of clearing, so we want to prevent |
| 622 | // them from being set by applications until everything has been updated |
| 623 | // to have them clear. |
| 624 | int mResettingSystemUiFlags = 0; |
| 625 | // Bits that we are currently always keeping cleared. |
| 626 | int mForceClearedSystemUiFlags = 0; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 627 | int mLastFullscreenStackSysUiFlags; |
| 628 | int mLastDockedStackSysUiFlags; |
| 629 | final Rect mNonDockedStackBounds = new Rect(); |
| 630 | final Rect mDockedStackBounds = new Rect(); |
| 631 | final Rect mLastNonDockedStackBounds = new Rect(); |
| 632 | final Rect mLastDockedStackBounds = new Rect(); |
| 633 | |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 634 | // What we last reported to system UI about whether the compatibility |
| 635 | // menu needs to be displayed. |
| 636 | boolean mLastFocusNeedsMenu = false; |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 637 | // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending. |
| 638 | private long mPendingPanicGestureUptime; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 639 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 640 | InputConsumer mInputConsumer = null; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 641 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 642 | static final Rect mTmpParentFrame = new Rect(); |
| 643 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 644 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 645 | static final Rect mTmpContentFrame = new Rect(); |
| 646 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 647 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 648 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 649 | static final Rect mTmpNavigationFrame = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 650 | static final Rect mTmpOutsetFrame = new Rect(); |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 651 | private static final Rect mTmpRect = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 652 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 653 | WindowState mTopFullscreenOpaqueWindowState; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 654 | WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 655 | WindowState mTopDockedOpaqueWindowState; |
| 656 | WindowState mTopDockedOpaqueOrDimmingWindowState; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 657 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 658 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 659 | boolean mForceStatusBarFromKeyguard; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 660 | private boolean mForceStatusBarTransparent; |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 661 | int mNavBarOpacityMode = NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 662 | boolean mForcingShowNavBar; |
| 663 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 664 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 665 | private boolean mPendingKeyguardOccluded; |
| 666 | private boolean mKeyguardOccludedChanged; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 667 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 668 | boolean mShowingDream; |
Jorim Jaggi | 77e1043 | 2016-10-26 17:43:56 -0700 | [diff] [blame] | 669 | private boolean mLastShowingDream; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 670 | boolean mDreamingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 671 | boolean mDreamingSleepTokenNeeded; |
| 672 | SleepToken mDreamingSleepToken; |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 673 | SleepToken mScreenOffSleepToken; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 674 | volatile boolean mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 675 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 676 | boolean mHomeConsumed; |
| 677 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 678 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 679 | Intent mCarDockIntent; |
| 680 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 681 | boolean mSearchKeyShortcutPending; |
| 682 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 683 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 684 | boolean mPendingMetaAction; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 685 | boolean mPendingCapsLockToggle; |
| 686 | int mMetaState; |
| 687 | int mInitialMetaState; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 688 | boolean mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 689 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 690 | // support for activating the lock screen while the screen is on |
| 691 | boolean mAllowLockscreenWhenOn; |
| 692 | int mLockScreenTimeout; |
| 693 | boolean mLockScreenTimerActive; |
| 694 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 695 | // 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] | 696 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 697 | |
| 698 | // Behavior of POWER button while in-call and screen on. |
| 699 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 700 | int mIncallPowerBehavior; |
| 701 | |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 702 | // Behavior of Back button while in-call and screen on |
| 703 | int mIncallBackBehavior; |
| 704 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 705 | Display mDisplay; |
| 706 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 707 | private int mDisplayRotation; |
| 708 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 709 | int mLandscapeRotation = 0; // default landscape rotation |
| 710 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 711 | int mPortraitRotation = 0; // default portrait rotation |
| 712 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 713 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 714 | int mOverscanLeft = 0; |
| 715 | int mOverscanTop = 0; |
| 716 | int mOverscanRight = 0; |
| 717 | int mOverscanBottom = 0; |
| 718 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 719 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 720 | private int mLongPressOnHomeBehavior; |
| 721 | |
| 722 | // What we do when the user double-taps on home |
| 723 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 724 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 725 | // Allowed theater mode wake actions |
| 726 | private boolean mAllowTheaterModeWakeFromKey; |
| 727 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 728 | private boolean mAllowTheaterModeWakeFromMotion; |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 729 | private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 730 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 731 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 732 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 733 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 734 | // Whether to support long press from power button in non-interactive mode |
| 735 | private boolean mSupportLongPressPowerWhenNonInteractive; |
| 736 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 737 | // Whether to go to sleep entering theater mode from power button |
| 738 | private boolean mGoToSleepOnButtonPressTheaterMode; |
| 739 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 740 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 741 | // Time to volume and power must be pressed within this interval of each other. |
| 742 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 743 | // Increase the chord delay when taking a screenshot from the keyguard |
| 744 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 745 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 746 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 747 | private long mScreenshotChordVolumeDownKeyTime; |
| 748 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
| 749 | private boolean mScreenshotChordVolumeUpKeyTriggered; |
| 750 | private boolean mScreenshotChordPowerKeyTriggered; |
| 751 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 752 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 753 | /* The number of steps between min and max brightness */ |
| 754 | private static final int BRIGHTNESS_STEPS = 10; |
| 755 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 756 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 757 | ShortcutManager mShortcutManager; |
| 758 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 759 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 760 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 761 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 762 | private int mCurrentUserId; |
| 763 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 764 | // Maps global key codes to the components that will handle them. |
| 765 | private GlobalKeyManager mGlobalKeyManager; |
| 766 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 767 | // Fallback actions by key code. |
| 768 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 769 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 770 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 771 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 772 | = new LogDecelerateInterpolator(100, 0); |
| 773 | |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 774 | private final MutableBoolean mTmpBoolean = new MutableBoolean(false); |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 775 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 776 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 777 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 778 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 779 | 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] | 780 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 781 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 782 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 783 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 784 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 785 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 786 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 787 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 788 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 789 | private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 790 | private static final int MSG_REQUEST_TRANSIENT_BARS = 16; |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 791 | private static final int MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU = 17; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 792 | private static final int MSG_BACK_LONG_PRESS = 18; |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 793 | private static final int MSG_DISPOSE_INPUT_CONSUMER = 19; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 794 | private static final int MSG_BACK_DELAYED_PRESS = 20; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 795 | |
| 796 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0; |
| 797 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 798 | |
| 799 | private class PolicyHandler extends Handler { |
| 800 | @Override |
| 801 | public void handleMessage(Message msg) { |
| 802 | switch (msg.what) { |
| 803 | case MSG_ENABLE_POINTER_LOCATION: |
| 804 | enablePointerLocation(); |
| 805 | break; |
| 806 | case MSG_DISABLE_POINTER_LOCATION: |
| 807 | disablePointerLocation(); |
| 808 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 809 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 810 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 811 | break; |
| 812 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 813 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 814 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 815 | case MSG_DISPATCH_SHOW_RECENTS: |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 816 | showRecentApps(false, msg.arg1 != 0); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 817 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 818 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 819 | showGlobalActionsInternal(); |
| 820 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 821 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 822 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 823 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 824 | break; |
| 825 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 826 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 827 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 828 | break; |
| 829 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 830 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 831 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 832 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 833 | case MSG_HIDE_BOOT_MESSAGE: |
| 834 | handleHideBootMessage(); |
| 835 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 836 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 837 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 838 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 839 | case MSG_POWER_DELAYED_PRESS: |
| 840 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 841 | finishPowerKeyPress(); |
| 842 | break; |
| 843 | case MSG_POWER_LONG_PRESS: |
| 844 | powerLongPress(); |
| 845 | break; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 846 | case MSG_UPDATE_DREAMING_SLEEP_TOKEN: |
| 847 | updateDreamingSleepToken(msg.arg1 != 0); |
| 848 | break; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 849 | case MSG_REQUEST_TRANSIENT_BARS: |
| 850 | WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ? |
| 851 | mStatusBar : mNavigationBar; |
| 852 | if (targetBar != null) { |
| 853 | requestTransientBars(targetBar); |
| 854 | } |
| 855 | break; |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 856 | case MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU: |
| 857 | showTvPictureInPictureMenuInternal(); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 858 | break; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 859 | case MSG_BACK_LONG_PRESS: |
| 860 | backLongPress(); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 861 | finishBackKeyPress(); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 862 | break; |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 863 | case MSG_DISPOSE_INPUT_CONSUMER: |
| 864 | disposeInputConsumer((InputConsumer) msg.obj); |
| 865 | break; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 866 | case MSG_BACK_DELAYED_PRESS: |
| 867 | backMultiPressAction((Long) msg.obj, msg.arg1); |
| 868 | finishBackKeyPress(); |
| 869 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | } |
| 873 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 874 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 875 | @Override |
| 876 | public void onUEvent(UEventObserver.UEvent event) { |
| 877 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 878 | } |
| 879 | }; |
| 880 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 881 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 882 | SettingsObserver(Handler handler) { |
| 883 | super(handler); |
| 884 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 885 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 886 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 887 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 888 | ContentResolver resolver = mContext.getContentResolver(); |
| 889 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 890 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 891 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 892 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 893 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 894 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 895 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 896 | Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR), false, this, |
| 897 | UserHandle.USER_ALL); |
| 898 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 899 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 900 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 901 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 902 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 903 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 904 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 905 | Settings.System.USER_ROTATION), false, this, |
| 906 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 907 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 908 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 909 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 910 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 911 | Settings.System.POINTER_LOCATION), false, this, |
| 912 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 913 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 914 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 915 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 916 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 917 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 918 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 919 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 920 | Settings.Global.POLICY_CONTROL), false, this, |
| 921 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 922 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 926 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 927 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 928 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 929 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 930 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 931 | class MyWakeGestureListener extends WakeGestureListener { |
| 932 | MyWakeGestureListener(Context context, Handler handler) { |
| 933 | super(context, handler); |
| 934 | } |
| 935 | |
| 936 | @Override |
| 937 | public void onWakeUp() { |
| 938 | synchronized (mLock) { |
| 939 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 940 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 941 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture, |
| 942 | "android.policy:GESTURE"); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 943 | } |
| 944 | } |
| 945 | } |
| 946 | } |
| 947 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 948 | class MyOrientationListener extends WindowOrientationListener { |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 949 | private final Runnable mUpdateRotationRunnable = new Runnable() { |
| 950 | @Override |
| 951 | public void run() { |
Tim Murray | 1f40764 | 2015-10-01 17:07:12 -0700 | [diff] [blame] | 952 | // send interaction hint to improve redraw performance |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 953 | mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 954 | updateRotation(false); |
| 955 | } |
| 956 | }; |
| 957 | |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 958 | MyOrientationListener(Context context, Handler handler) { |
| 959 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 960 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 961 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 962 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 963 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 964 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 965 | mHandler.post(mUpdateRotationRunnable); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 966 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 967 | } |
| 968 | MyOrientationListener mOrientationListener; |
| 969 | |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 970 | private final StatusBarController mStatusBarController = new StatusBarController(); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 971 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 972 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 973 | View.NAVIGATION_BAR_TRANSIENT, |
| 974 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 975 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 976 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 977 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, |
| 978 | View.NAVIGATION_BAR_TRANSPARENT); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 979 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 980 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 981 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 982 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 983 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 984 | IStatusBarService getStatusBarService() { |
| 985 | synchronized (mServiceAquireLock) { |
| 986 | if (mStatusBarService == null) { |
| 987 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 988 | ServiceManager.getService("statusbar")); |
| 989 | } |
| 990 | return mStatusBarService; |
| 991 | } |
| 992 | } |
| 993 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 994 | StatusBarManagerInternal getStatusBarManagerInternal() { |
| 995 | synchronized (mServiceAquireLock) { |
| 996 | if (mStatusBarManagerInternal == null) { |
| 997 | mStatusBarManagerInternal = |
| 998 | LocalServices.getService(StatusBarManagerInternal.class); |
| 999 | } |
| 1000 | return mStatusBarManagerInternal; |
| 1001 | } |
| 1002 | } |
| 1003 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 1004 | /* |
| 1005 | * We always let the sensor be switched on by default except when |
| 1006 | * the user has explicitly disabled sensor based rotation or when the |
| 1007 | * screen is switched off. |
| 1008 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1009 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1010 | if (mSupportAutoRotation) { |
| 1011 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 1012 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 1013 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 1014 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 1015 | // If the application has explicitly requested to follow the |
| 1016 | // orientation, then we need to turn the sensor on. |
| 1017 | return true; |
| 1018 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1019 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1020 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 1021 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 1022 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 1023 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1024 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 1025 | // orientation management, |
| 1026 | return true; |
| 1027 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1028 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1029 | // If the setting for using the sensor by default is enabled, then |
| 1030 | // we will always leave it on. Note that the user could go to |
| 1031 | // a window that forces an orientation that does not use the |
| 1032 | // sensor and in theory we could turn it off... however, when next |
| 1033 | // turning it on we won't have a good value for the current |
| 1034 | // orientation for a little bit, which can cause orientation |
| 1035 | // changes to lag, so we'd like to keep it always on. (It will |
| 1036 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 1037 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1038 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1039 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1040 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1041 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1042 | /* |
| 1043 | * Various use cases for invoking this function |
| 1044 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1045 | * 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] | 1046 | * if not already enabled |
| 1047 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 1048 | * already enabled |
| 1049 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 1050 | * screen turning on and current app has nosensor based orientation, do nothing |
| 1051 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1052 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1053 | if (!mOrientationListener.canDetectOrientation()) { |
| 1054 | // If sensor is turned off or nonexistent for some reason |
| 1055 | return; |
| 1056 | } |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 1057 | // Could have been invoked due to screen turning on or off or |
| 1058 | // change of the currently visible window's orientation. |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1059 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 1060 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 1061 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled |
| 1062 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 1063 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1064 | boolean disable = true; |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 1065 | // Note: We postpone the rotating of the screen until the keyguard as well as the |
| 1066 | // window manager have reported a draw complete. |
| 1067 | if (mScreenOnEarly && mAwake && |
| 1068 | mKeyguardDrawComplete && mWindowManagerDrawComplete) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1069 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1070 | disable = false; |
| 1071 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1072 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1073 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1074 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1075 | mOrientationSensorEnabled = true; |
| 1076 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1077 | } |
| 1078 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1079 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1080 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1081 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1082 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1083 | mOrientationSensorEnabled = false; |
| 1084 | } |
| 1085 | } |
| 1086 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1087 | private void interceptBackKeyDown() { |
Nimrod Gileadi | 580135c | 2016-10-31 20:42:19 +0000 | [diff] [blame] | 1088 | MetricsLogger.count(mContext, "key_back_down", 1); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1089 | // Reset back key state for long press |
| 1090 | mBackKeyHandled = false; |
| 1091 | |
| 1092 | // Cancel multi-press detection timeout. |
| 1093 | if (hasPanicPressOnBackBehavior()) { |
| 1094 | if (mBackKeyPressCounter != 0 |
| 1095 | && mBackKeyPressCounter < PANIC_PRESS_BACK_COUNT) { |
| 1096 | mHandler.removeMessages(MSG_BACK_DELAYED_PRESS); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | if (hasLongPressOnBackBehavior()) { |
| 1101 | Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS); |
| 1102 | msg.setAsynchronous(true); |
| 1103 | mHandler.sendMessageDelayed(msg, |
| 1104 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | // returns true if the key was handled and should not be passed to the user |
| 1109 | private boolean interceptBackKeyUp(KeyEvent event) { |
| 1110 | // Cache handled state |
| 1111 | boolean handled = mBackKeyHandled; |
| 1112 | |
| 1113 | if (hasPanicPressOnBackBehavior()) { |
| 1114 | // Check for back key panic press |
| 1115 | ++mBackKeyPressCounter; |
| 1116 | |
| 1117 | final long eventTime = event.getDownTime(); |
| 1118 | |
| 1119 | if (mBackKeyPressCounter <= PANIC_PRESS_BACK_COUNT) { |
| 1120 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 1121 | Message msg = mHandler.obtainMessage(MSG_BACK_DELAYED_PRESS, |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 1122 | mBackKeyPressCounter, 0, eventTime); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1123 | msg.setAsynchronous(true); |
| 1124 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getMultiPressTimeout()); |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | // Reset back long press state |
| 1129 | cancelPendingBackKeyAction(); |
| 1130 | |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 1131 | if (mHasFeatureWatch) { |
| 1132 | TelecomManager telecomManager = getTelecommService(); |
| 1133 | |
| 1134 | if (telecomManager != null) { |
| 1135 | if (telecomManager.isRinging()) { |
| 1136 | // Pressing back while there's a ringing incoming |
| 1137 | // call should silence the ringer. |
| 1138 | telecomManager.silenceRinger(); |
| 1139 | |
| 1140 | // It should not prevent navigating away |
| 1141 | return false; |
| 1142 | } else if ( |
| 1143 | (mIncallBackBehavior & Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 1144 | && telecomManager.isInCall()) { |
| 1145 | // Otherwise, if "Back button ends call" is enabled, |
| 1146 | // the Back button will hang up any current active call. |
| 1147 | return telecomManager.endCall(); |
| 1148 | } |
| 1149 | } |
| 1150 | } |
| 1151 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1152 | return handled; |
| 1153 | } |
| 1154 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1155 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 1156 | // Hold a wake lock until the power key is released. |
| 1157 | if (!mPowerKeyWakeLock.isHeld()) { |
| 1158 | mPowerKeyWakeLock.acquire(); |
| 1159 | } |
| 1160 | |
| 1161 | // Cancel multi-press detection timeout. |
| 1162 | if (mPowerKeyPressCounter != 0) { |
| 1163 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 1164 | } |
| 1165 | |
| 1166 | // Detect user pressing the power button in panic when an application has |
| 1167 | // taken over the whole screen. |
| 1168 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
Adrian Roos | 7aaa551 | 2016-07-12 15:27:24 -0700 | [diff] [blame] | 1169 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags), |
| 1170 | isNavBarEmpty(mLastSystemUiFlags)); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1171 | if (panic) { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 1172 | mHandler.post(mHiddenNavPanic); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | // Latch power key state to detect screenshot chord. |
| 1176 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 1177 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 1178 | mScreenshotChordPowerKeyTriggered = true; |
| 1179 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 1180 | interceptScreenshotChord(); |
| 1181 | } |
| 1182 | |
| 1183 | // Stop ringing or end call if configured to do so when power is pressed. |
| 1184 | TelecomManager telecomManager = getTelecommService(); |
| 1185 | boolean hungUp = false; |
| 1186 | if (telecomManager != null) { |
| 1187 | if (telecomManager.isRinging()) { |
| 1188 | // Pressing Power while there's a ringing incoming |
| 1189 | // call should silence the ringer. |
| 1190 | telecomManager.silenceRinger(); |
| 1191 | } else if ((mIncallPowerBehavior |
| 1192 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 1193 | && telecomManager.isInCall() && interactive) { |
| 1194 | // Otherwise, if "Power button ends call" is enabled, |
| 1195 | // the Power button will hang up any current active call. |
| 1196 | hungUp = telecomManager.endCall(); |
| 1197 | } |
| 1198 | } |
| 1199 | |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1200 | GestureLauncherService gestureService = LocalServices.getService( |
| 1201 | GestureLauncherService.class); |
| 1202 | boolean gesturedServiceIntercepted = false; |
| 1203 | if (gestureService != null) { |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 1204 | gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive, |
| 1205 | mTmpBoolean); |
| 1206 | if (mTmpBoolean.value && mGoingToSleep) { |
| 1207 | mCameraGestureTriggeredDuringGoingToSleep = true; |
| 1208 | } |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1211 | // If the power key has still not yet been handled, then detect short |
| 1212 | // press, long press, or multi press and decide what to do. |
| 1213 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1214 | || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1215 | if (!mPowerKeyHandled) { |
| 1216 | if (interactive) { |
| 1217 | // When interactive, we're already awake. |
| 1218 | // Wait for a long press or for the button to be released to decide what to do. |
| 1219 | if (hasLongPressOnPowerBehavior()) { |
| 1220 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 1221 | msg.setAsynchronous(true); |
| 1222 | mHandler.sendMessageDelayed(msg, |
| 1223 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 1224 | } |
| 1225 | } else { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1226 | wakeUpFromPowerKey(event.getDownTime()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1227 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1228 | if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { |
| 1229 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 1230 | msg.setAsynchronous(true); |
| 1231 | mHandler.sendMessageDelayed(msg, |
| 1232 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1233 | mBeganFromNonInteractive = true; |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1234 | } else { |
| 1235 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1236 | |
| 1237 | if (maxCount <= 1) { |
| 1238 | mPowerKeyHandled = true; |
| 1239 | } else { |
| 1240 | mBeganFromNonInteractive = true; |
| 1241 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1242 | } |
| 1243 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1244 | } |
| 1245 | } |
| 1246 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1247 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 1248 | final boolean handled = canceled || mPowerKeyHandled; |
| 1249 | mScreenshotChordPowerKeyTriggered = false; |
| 1250 | cancelPendingScreenshotChordAction(); |
| 1251 | cancelPendingPowerKeyAction(); |
| 1252 | |
| 1253 | if (!handled) { |
| 1254 | // Figure out how to handle the key now that it has been released. |
| 1255 | mPowerKeyPressCounter += 1; |
| 1256 | |
| 1257 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1258 | final long eventTime = event.getDownTime(); |
| 1259 | if (mPowerKeyPressCounter < maxCount) { |
| 1260 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 1261 | // Continue holding the wake lock. |
| 1262 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 1263 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 1264 | msg.setAsynchronous(true); |
| 1265 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout()); |
| 1266 | return; |
| 1267 | } |
| 1268 | |
| 1269 | // No other actions. Handle it immediately. |
| 1270 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1271 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1272 | |
| 1273 | // Done. Reset our state. |
| 1274 | finishPowerKeyPress(); |
| 1275 | } |
| 1276 | |
| 1277 | private void finishPowerKeyPress() { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1278 | mBeganFromNonInteractive = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1279 | mPowerKeyPressCounter = 0; |
| 1280 | if (mPowerKeyWakeLock.isHeld()) { |
| 1281 | mPowerKeyWakeLock.release(); |
| 1282 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1285 | private void finishBackKeyPress() { |
| 1286 | mBackKeyPressCounter = 0; |
| 1287 | } |
| 1288 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1289 | private void cancelPendingPowerKeyAction() { |
| 1290 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1291 | mPowerKeyHandled = true; |
| 1292 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1293 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1296 | private void cancelPendingBackKeyAction() { |
| 1297 | if (!mBackKeyHandled) { |
| 1298 | mBackKeyHandled = true; |
| 1299 | mHandler.removeMessages(MSG_BACK_LONG_PRESS); |
| 1300 | } |
| 1301 | } |
| 1302 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1303 | private void backMultiPressAction(long eventTime, int count) { |
| 1304 | if (count >= PANIC_PRESS_BACK_COUNT) { |
| 1305 | switch (mPanicPressOnBackBehavior) { |
| 1306 | case PANIC_PRESS_BACK_NOTHING: |
| 1307 | break; |
| 1308 | case PANIC_PRESS_BACK_HOME: |
| 1309 | launchHomeFromHotKey(); |
| 1310 | break; |
| 1311 | } |
| 1312 | } |
| 1313 | } |
| 1314 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1315 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 1316 | if (mScreenOnEarly && !mScreenOnFully) { |
| 1317 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 1318 | + "already in the process of turning the screen on."); |
| 1319 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 1320 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1321 | |
| 1322 | if (count == 2) { |
| 1323 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 1324 | } else if (count == 3) { |
| 1325 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1326 | } else if (interactive && !mBeganFromNonInteractive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1327 | switch (mShortPressOnPowerBehavior) { |
| 1328 | case SHORT_PRESS_POWER_NOTHING: |
| 1329 | break; |
| 1330 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 1331 | mPowerManager.goToSleep(eventTime, |
| 1332 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1333 | break; |
| 1334 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 1335 | mPowerManager.goToSleep(eventTime, |
| 1336 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1337 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1338 | break; |
| 1339 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 1340 | mPowerManager.goToSleep(eventTime, |
| 1341 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1342 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1343 | launchHomeFromHotKey(); |
| 1344 | break; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1345 | case SHORT_PRESS_POWER_GO_HOME: |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 1346 | launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/); |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1347 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1348 | } |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 1353 | switch (behavior) { |
| 1354 | case MULTI_PRESS_POWER_NOTHING: |
| 1355 | break; |
| 1356 | case MULTI_PRESS_POWER_THEATER_MODE: |
Bryce Lee | 3ae447e | 2015-06-30 12:31:41 -0700 | [diff] [blame] | 1357 | if (!isUserSetupComplete()) { |
| 1358 | Slog.i(TAG, "Ignoring toggling theater mode - device not setup."); |
| 1359 | break; |
| 1360 | } |
| 1361 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1362 | if (isTheaterModeEnabled()) { |
| 1363 | Slog.i(TAG, "Toggling theater mode off."); |
| 1364 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1365 | Settings.Global.THEATER_MODE_ON, 0); |
| 1366 | if (!interactive) { |
| 1367 | wakeUpFromPowerKey(eventTime); |
| 1368 | } |
| 1369 | } else { |
| 1370 | Slog.i(TAG, "Toggling theater mode on."); |
| 1371 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1372 | Settings.Global.THEATER_MODE_ON, 1); |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1373 | |
| 1374 | if (mGoToSleepOnButtonPressTheaterMode && interactive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1375 | mPowerManager.goToSleep(eventTime, |
| 1376 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1377 | } |
| 1378 | } |
| 1379 | break; |
| 1380 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
Jeff Brown | 7b5be5e | 2014-11-12 18:45:31 -0800 | [diff] [blame] | 1381 | Slog.i(TAG, "Starting brightness boost."); |
| 1382 | if (!interactive) { |
| 1383 | wakeUpFromPowerKey(eventTime); |
| 1384 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1385 | mPowerManager.boostScreenBrightness(eventTime); |
| 1386 | break; |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | private int getMaxMultiPressPowerCount() { |
| 1391 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1392 | return 3; |
| 1393 | } |
| 1394 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1395 | return 2; |
| 1396 | } |
| 1397 | return 1; |
| 1398 | } |
| 1399 | |
| 1400 | private void powerLongPress() { |
| 1401 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1402 | switch (behavior) { |
| 1403 | case LONG_PRESS_POWER_NOTHING: |
| 1404 | break; |
| 1405 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1406 | mPowerKeyHandled = true; |
| 1407 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1408 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 1409 | } |
| 1410 | showGlobalActionsInternal(); |
| 1411 | break; |
| 1412 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1413 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1414 | mPowerKeyHandled = true; |
| 1415 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1416 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1417 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1418 | break; |
| 1419 | } |
| 1420 | } |
| 1421 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1422 | private void backLongPress() { |
| 1423 | mBackKeyHandled = true; |
| 1424 | |
| 1425 | switch (mLongPressOnBackBehavior) { |
| 1426 | case LONG_PRESS_BACK_NOTHING: |
| 1427 | break; |
| 1428 | case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST: |
Nancy Zheng | 0d85ee2 | 2016-09-29 09:15:56 -0700 | [diff] [blame] | 1429 | final boolean keyguardActive = mKeyguardDelegate == null |
| 1430 | ? false |
| 1431 | : mKeyguardDelegate.isShowing(); |
| 1432 | if (!keyguardActive) { |
| 1433 | Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST); |
| 1434 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
| 1435 | } |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1436 | break; |
| 1437 | } |
| 1438 | } |
| 1439 | |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 1440 | private void disposeInputConsumer(InputConsumer inputConsumer) { |
| 1441 | if (inputConsumer != null) { |
| 1442 | inputConsumer.dismiss(); |
| 1443 | } |
| 1444 | } |
| 1445 | |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1446 | private void sleepPress(long eventTime) { |
| 1447 | if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) { |
| 1448 | launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | private void sleepRelease(long eventTime) { |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1453 | switch (mShortPressOnSleepBehavior) { |
| 1454 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1455 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1456 | Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)"); |
| 1457 | mPowerManager.goToSleep(eventTime, |
| 1458 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1459 | break; |
| 1460 | } |
| 1461 | } |
| 1462 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1463 | private int getResolvedLongPressOnPowerBehavior() { |
| 1464 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1465 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1466 | } |
| 1467 | return mLongPressOnPowerBehavior; |
| 1468 | } |
| 1469 | |
| 1470 | private boolean hasLongPressOnPowerBehavior() { |
| 1471 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1474 | private boolean hasLongPressOnBackBehavior() { |
| 1475 | return mLongPressOnBackBehavior != LONG_PRESS_BACK_NOTHING; |
| 1476 | } |
| 1477 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1478 | private boolean hasPanicPressOnBackBehavior() { |
| 1479 | return mPanicPressOnBackBehavior != PANIC_PRESS_BACK_NOTHING; |
| 1480 | } |
| 1481 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1482 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1483 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1484 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
| 1485 | && !mScreenshotChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1486 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1487 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1488 | && now <= mScreenshotChordPowerKeyTime |
| 1489 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1490 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1491 | cancelPendingPowerKeyAction(); |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1492 | mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN); |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1493 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1494 | } |
| 1495 | } |
| 1496 | } |
| 1497 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1498 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1499 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1500 | // Double the time it takes to take a screenshot from the keyguard |
| 1501 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1502 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1503 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1504 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1507 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1508 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1511 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1512 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1513 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1514 | mEndCallKeyHandled = true; |
| 1515 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1516 | performAuditoryFeedbackForAccessibilityIfNeed(); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 1517 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1518 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1519 | } |
| 1520 | }; |
| 1521 | |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1522 | private class ScreenshotRunnable implements Runnable { |
| 1523 | private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN; |
| 1524 | |
| 1525 | public void setScreenshotType(int screenshotType) { |
| 1526 | mScreenshotType = screenshotType; |
| 1527 | } |
| 1528 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1529 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1530 | public void run() { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1531 | takeScreenshot(mScreenshotType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1532 | } |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1536 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1537 | @Override |
| 1538 | public void showGlobalActions() { |
| 1539 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1540 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1541 | } |
| 1542 | |
| 1543 | void showGlobalActionsInternal() { |
| 1544 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1545 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1546 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1547 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1548 | final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1549 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1550 | if (keyguardShowing) { |
| 1551 | // since it took two seconds of long press to bring this up, |
| 1552 | // 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] | 1553 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1558 | return Settings.Global.getInt( |
| 1559 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1560 | } |
| 1561 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1562 | boolean isUserSetupComplete() { |
| 1563 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1564 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 1565 | } |
| 1566 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1567 | private void handleShortPressOnHome() { |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1568 | // Turn on the connected TV and switch HDMI input if we're a HDMI playback device. |
| 1569 | getHdmiControl().turnOnTv(); |
| 1570 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1571 | // If there's a dream running then use home to escape the dream |
| 1572 | // but don't actually go home. |
| 1573 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1574 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1575 | return; |
| 1576 | } |
| 1577 | |
| 1578 | // Go home! |
| 1579 | launchHomeFromHotKey(); |
| 1580 | } |
| 1581 | |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1582 | /** |
| 1583 | * Creates an accessor to HDMI control service that performs the operation of |
| 1584 | * turning on TV (optional) and switching input to us. If HDMI control service |
| 1585 | * is not available or we're not a HDMI playback device, the operation is no-op. |
| 1586 | */ |
| 1587 | private HdmiControl getHdmiControl() { |
| 1588 | if (null == mHdmiControl) { |
| 1589 | HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService( |
| 1590 | Context.HDMI_CONTROL_SERVICE); |
| 1591 | HdmiPlaybackClient client = null; |
| 1592 | if (manager != null) { |
| 1593 | client = manager.getPlaybackClient(); |
| 1594 | } |
| 1595 | mHdmiControl = new HdmiControl(client); |
| 1596 | } |
| 1597 | return mHdmiControl; |
| 1598 | } |
| 1599 | |
| 1600 | private static class HdmiControl { |
| 1601 | private final HdmiPlaybackClient mClient; |
| 1602 | |
| 1603 | private HdmiControl(HdmiPlaybackClient client) { |
| 1604 | mClient = client; |
| 1605 | } |
| 1606 | |
| 1607 | public void turnOnTv() { |
| 1608 | if (mClient == null) { |
| 1609 | return; |
| 1610 | } |
| 1611 | mClient.oneTouchPlay(new OneTouchPlayCallback() { |
| 1612 | @Override |
| 1613 | public void onComplete(int result) { |
| 1614 | if (result != HdmiControlManager.RESULT_SUCCESS) { |
| 1615 | Log.w(TAG, "One touch play failed: " + result); |
| 1616 | } |
| 1617 | } |
| 1618 | }); |
| 1619 | } |
| 1620 | } |
| 1621 | |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 1622 | private void handleLongPressOnHome(int deviceId) { |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1623 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) { |
| 1624 | return; |
| 1625 | } |
| 1626 | mHomeConsumed = true; |
| 1627 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1628 | |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1629 | switch (mLongPressOnHomeBehavior) { |
| 1630 | case LONG_PRESS_HOME_RECENT_SYSTEM_UI: |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1631 | toggleRecentApps(); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1632 | break; |
| 1633 | case LONG_PRESS_HOME_ASSIST: |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 1634 | launchAssistAction(null, deviceId); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1635 | break; |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1636 | default: |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 1637 | Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1638 | break; |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1639 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1640 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1641 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1642 | private void handleDoubleTapOnHome() { |
| 1643 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1644 | mHomeConsumed = true; |
| 1645 | toggleRecentApps(); |
| 1646 | } |
| 1647 | } |
| 1648 | |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 1649 | private void showTvPictureInPictureMenu(KeyEvent event) { |
| 1650 | if (DEBUG_INPUT) Log.d(TAG, "showTvPictureInPictureMenu event=" + event); |
| 1651 | mHandler.removeMessages(MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU); |
| 1652 | Message msg = mHandler.obtainMessage(MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1653 | msg.setAsynchronous(true); |
| 1654 | msg.sendToTarget(); |
| 1655 | } |
| 1656 | |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 1657 | private void showTvPictureInPictureMenuInternal() { |
| 1658 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 1659 | if (statusbar != null) { |
| 1660 | statusbar.showTvPictureInPictureMenu(); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1661 | } |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1662 | } |
| 1663 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1664 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1665 | @Override |
| 1666 | public void run() { |
| 1667 | if (mHomeDoubleTapPending) { |
| 1668 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1669 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1670 | } |
| 1671 | } |
| 1672 | }; |
| 1673 | |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1674 | private boolean isRoundWindow() { |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1675 | return mContext.getResources().getConfiguration().isScreenRound(); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1676 | } |
| 1677 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1678 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1679 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1680 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1681 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1682 | mContext = context; |
| 1683 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1684 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1685 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 1686 | mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 1687 | mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1688 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1689 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1690 | mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 1691 | mHasFeatureWatch = mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1692 | |
| 1693 | // Init display burn-in protection |
| 1694 | boolean burnInProtectionEnabled = context.getResources().getBoolean( |
| 1695 | com.android.internal.R.bool.config_enableBurnInProtection); |
| 1696 | // Allow a system property to override this. Used by developer settings. |
| 1697 | boolean burnInProtectionDevMode = |
| 1698 | SystemProperties.getBoolean("persist.debug.force_burn_in", false); |
| 1699 | if (burnInProtectionEnabled || burnInProtectionDevMode) { |
| 1700 | final int minHorizontal; |
| 1701 | final int maxHorizontal; |
| 1702 | final int minVertical; |
| 1703 | final int maxVertical; |
| 1704 | final int maxRadius; |
| 1705 | if (burnInProtectionDevMode) { |
| 1706 | minHorizontal = -8; |
| 1707 | maxHorizontal = 8; |
| 1708 | minVertical = -8; |
| 1709 | maxVertical = -4; |
| 1710 | maxRadius = (isRoundWindow()) ? 6 : -1; |
| 1711 | } else { |
| 1712 | Resources resources = context.getResources(); |
| 1713 | minHorizontal = resources.getInteger( |
| 1714 | com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); |
| 1715 | maxHorizontal = resources.getInteger( |
| 1716 | com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); |
| 1717 | minVertical = resources.getInteger( |
| 1718 | com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); |
| 1719 | maxVertical = resources.getInteger( |
| 1720 | com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); |
| 1721 | maxRadius = resources.getInteger( |
| 1722 | com.android.internal.R.integer.config_burnInProtectionMaxRadius); |
| 1723 | } |
| 1724 | mBurnInProtectionHelper = new BurnInProtectionHelper( |
| 1725 | context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 1726 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1727 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1728 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1729 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1730 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1731 | try { |
| 1732 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 1733 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1734 | mSettingsObserver = new SettingsObserver(mHandler); |
| 1735 | mSettingsObserver.observe(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1736 | mShortcutManager = new ShortcutManager(context); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 1737 | mUiMode = context.getResources().getInteger( |
| 1738 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1739 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1740 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 1741 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1742 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 1743 | mEnableCarDockHomeCapture = context.getResources().getBoolean( |
| 1744 | com.android.internal.R.bool.config_enableCarDockHomeLaunch); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1745 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1746 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 1747 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1748 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1749 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1750 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1751 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1752 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1753 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1754 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1755 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1756 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1757 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1758 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1759 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1760 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1761 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1762 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1763 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1764 | mCarDockRotation = readRotation( |
| 1765 | com.android.internal.R.integer.config_carDockRotation); |
| 1766 | mDeskDockRotation = readRotation( |
| 1767 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1768 | mUndockedHdmiRotation = readRotation( |
| 1769 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1770 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1771 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1772 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1773 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1774 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1775 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1776 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1777 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 1778 | mLidControlsScreenLock = mContext.getResources().getBoolean( |
| 1779 | com.android.internal.R.bool.config_lidControlsScreenLock); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1780 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1781 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1782 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1783 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1784 | |
| 1785 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 1786 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 1787 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 1788 | || mContext.getResources().getBoolean( |
| 1789 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 1790 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 1791 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 1792 | mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( |
| 1793 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1794 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 1795 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 1796 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 1797 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 1798 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 1799 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 1800 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1801 | mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( |
| 1802 | com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); |
| 1803 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1804 | mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( |
| 1805 | com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); |
| 1806 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1807 | mLongPressOnBackBehavior = mContext.getResources().getInteger( |
| 1808 | com.android.internal.R.integer.config_longPressOnBackBehavior); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1809 | mPanicPressOnBackBehavior = mContext.getResources().getInteger( |
| 1810 | com.android.internal.R.integer.config_backPanicBehavior); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1811 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1812 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1813 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 1814 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1815 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 1816 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1817 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 1818 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1819 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1820 | mShortPressOnSleepBehavior = mContext.getResources().getInteger( |
| 1821 | com.android.internal.R.integer.config_shortPressOnSleepBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1822 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 1823 | mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 1824 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1825 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1826 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1827 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1828 | Context.ACCESSIBILITY_SERVICE); |
| 1829 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1830 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1831 | IntentFilter filter = new IntentFilter(); |
| 1832 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1833 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1834 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1835 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1836 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1837 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1838 | if (intent != null) { |
| 1839 | // Retrieve current sticky dock event broadcast. |
| 1840 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1841 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1842 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1843 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1844 | // register for dream-related broadcasts |
| 1845 | filter = new IntentFilter(); |
| 1846 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1847 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1848 | context.registerReceiver(mDreamReceiver, filter); |
| 1849 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1850 | // register for multiuser-relevant broadcasts |
| 1851 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1852 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1853 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1854 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1855 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1856 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1857 | @Override |
| 1858 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1859 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1860 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1861 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1862 | } |
| 1863 | @Override |
| 1864 | public void onSwipeFromBottom() { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 1865 | if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_BOTTOM) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1866 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1867 | } |
| 1868 | } |
| 1869 | @Override |
| 1870 | public void onSwipeFromRight() { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 1871 | if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_RIGHT) { |
| 1872 | requestTransientBars(mNavigationBar); |
| 1873 | } |
| 1874 | } |
| 1875 | @Override |
| 1876 | public void onSwipeFromLeft() { |
| 1877 | if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_LEFT) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1878 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1879 | } |
| 1880 | } |
| 1881 | @Override |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1882 | public void onFling(int duration) { |
| 1883 | if (mPowerManagerInternal != null) { |
| 1884 | mPowerManagerInternal.powerHint( |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 1885 | PowerHint.INTERACTION, duration); |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1886 | } |
| 1887 | } |
| 1888 | @Override |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1889 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1890 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1891 | } |
Adrian Roos | 3595be4 | 2015-03-05 16:31:15 +0100 | [diff] [blame] | 1892 | @Override |
| 1893 | public void onDown() { |
| 1894 | mOrientationListener.onTouchStart(); |
| 1895 | } |
| 1896 | @Override |
| 1897 | public void onUpOrCancel() { |
| 1898 | mOrientationListener.onTouchEnd(); |
| 1899 | } |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 1900 | @Override |
| 1901 | public void onMouseHoverAtTop() { |
| 1902 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1903 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 1904 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS; |
| 1905 | mHandler.sendMessageDelayed(msg, 500); |
| 1906 | } |
| 1907 | @Override |
| 1908 | public void onMouseHoverAtBottom() { |
| 1909 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1910 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 1911 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION; |
| 1912 | mHandler.sendMessageDelayed(msg, 500); |
| 1913 | } |
| 1914 | @Override |
| 1915 | public void onMouseLeaveFromEdge() { |
| 1916 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1917 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1918 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1919 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1920 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1921 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1922 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1923 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1924 | com.android.internal.R.array.config_longPressVibePattern); |
| 1925 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1926 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1927 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1928 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1929 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1930 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1931 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1932 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1933 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1934 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1935 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1936 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 1937 | mContextClickVibePattern = getLongIntArray(mContext.getResources(), |
| 1938 | com.android.internal.R.array.config_contextClickVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1939 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1940 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1941 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 1942 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1943 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1944 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1945 | // Controls rotation and the like. |
| 1946 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1947 | |
| 1948 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1949 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 1950 | startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 1951 | finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1952 | } |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 1953 | |
| 1954 | mWindowManagerInternal.registerAppTransitionListener( |
| 1955 | mStatusBarController.getAppTransitionListener()); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1956 | mWindowManagerInternal.registerAppTransitionListener(new AppTransitionListener() { |
| 1957 | @Override |
| 1958 | public int onAppTransitionStartingLocked(int transit, IBinder openToken, |
| 1959 | IBinder closeToken, |
| 1960 | Animation openAnimation, Animation closeAnimation) { |
| 1961 | return handleStartTransitionForKeyguardLw(transit, openAnimation); |
| 1962 | } |
| 1963 | |
| 1964 | @Override |
| 1965 | public void onAppTransitionCancelledLocked(int transit) { |
| 1966 | handleStartTransitionForKeyguardLw(transit, null /* transit */); |
| 1967 | } |
| 1968 | }); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1971 | /** |
| 1972 | * Read values from config.xml that may be overridden depending on |
| 1973 | * the configuration of the device. |
| 1974 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1975 | */ |
| 1976 | private void readConfigurationDependentBehaviors() { |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1977 | final Resources res = mContext.getResources(); |
| 1978 | |
| 1979 | mLongPressOnHomeBehavior = res.getInteger( |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1980 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1981 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1982 | mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) { |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1983 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1984 | } |
| 1985 | |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1986 | mDoubleTapOnHomeBehavior = res.getInteger( |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1987 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1988 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1989 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1990 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1991 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 1992 | |
| 1993 | mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING; |
| 1994 | if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) { |
| 1995 | mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE; |
| 1996 | } |
Yorke Lee | 2e4b732 | 2016-03-02 17:33:06 -0800 | [diff] [blame] | 1997 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 1998 | mNavBarOpacityMode = res.getInteger( |
| 1999 | com.android.internal.R.integer.config_navBarOpacityMode); |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 2002 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 2003 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 2004 | // This method might be called before the policy has been fully initialized |
| 2005 | // or for other displays we don't care about. |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 2006 | // TODO(multi-display): Define policy for secondary displays. |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 2007 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 2008 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2009 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2010 | mDisplay = display; |
| 2011 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2012 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2013 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2014 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 2015 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2016 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2017 | mLandscapeRotation = Surface.ROTATION_0; |
| 2018 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2019 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2020 | mPortraitRotation = Surface.ROTATION_90; |
| 2021 | mUpsideDownRotation = Surface.ROTATION_270; |
| 2022 | } else { |
| 2023 | mPortraitRotation = Surface.ROTATION_270; |
| 2024 | mUpsideDownRotation = Surface.ROTATION_90; |
| 2025 | } |
| 2026 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 2027 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2028 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2029 | mPortraitRotation = Surface.ROTATION_0; |
| 2030 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2031 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2032 | mLandscapeRotation = Surface.ROTATION_270; |
| 2033 | mSeascapeRotation = Surface.ROTATION_90; |
| 2034 | } else { |
| 2035 | mLandscapeRotation = Surface.ROTATION_90; |
| 2036 | mSeascapeRotation = Surface.ROTATION_270; |
| 2037 | } |
| 2038 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 2039 | |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2040 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 2041 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2042 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2043 | |
Devin Kim | d7b12b4 | 2014-05-05 14:34:58 -0700 | [diff] [blame] | 2044 | // Allow the navigation bar to move on non-square small devices (phones). |
| 2045 | mNavigationBarCanMove = width != height && shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 2046 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2047 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2048 | |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2049 | // Allow a system property to override this. Used by the emulator. |
| 2050 | // See also hasNavigationBar(). |
| 2051 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 2052 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2053 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2054 | } else if ("0".equals(navBarOverride)) { |
| 2055 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 2056 | } |
| 2057 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 2058 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 2059 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 2060 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 2061 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 2062 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 2063 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 2064 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 2065 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2066 | |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 2067 | // For demo purposes, allow the rotation of the remote display to be controlled. |
| 2068 | // By default, remote display locks rotation to landscape. |
| 2069 | if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { |
| 2070 | mDemoRotation = mPortraitRotation; |
| 2071 | } else { |
| 2072 | mDemoRotation = mLandscapeRotation; |
| 2073 | } |
| 2074 | mDemoRotationLock = SystemProperties.getBoolean( |
| 2075 | "persist.demo.rotationlock", false); |
| 2076 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2077 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 2078 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 2079 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 2080 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 2081 | // For debug purposes the next line turns this feature off with: |
| 2082 | // $ adb shell setprop config.override_forced_orient true |
| 2083 | // $ adb shell wm size reset |
| 2084 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 2085 | } |
| 2086 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2087 | /** |
| 2088 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 2089 | * navigation bar and touch exploration is not enabled |
| 2090 | */ |
| 2091 | private boolean canHideNavigationBar() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 2092 | return mHasNavigationBar; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2095 | @Override |
| 2096 | public boolean isDefaultOrientationForced() { |
| 2097 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2098 | } |
| 2099 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2100 | @Override |
| 2101 | 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] | 2102 | // TODO(multi-display): Define policy for secondary displays. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2103 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 2104 | mOverscanLeft = left; |
| 2105 | mOverscanTop = top; |
| 2106 | mOverscanRight = right; |
| 2107 | mOverscanBottom = bottom; |
| 2108 | } |
| 2109 | } |
| 2110 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2111 | public void updateSettings() { |
| 2112 | ContentResolver resolver = mContext.getContentResolver(); |
| 2113 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2114 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2115 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 2116 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2117 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 2118 | UserHandle.USER_CURRENT); |
| 2119 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 2120 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2121 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 2122 | UserHandle.USER_CURRENT); |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 2123 | mIncallBackBehavior = Settings.Secure.getIntForUser(resolver, |
| 2124 | Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR, |
| 2125 | Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_DEFAULT, |
| 2126 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 2127 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 2128 | // Configure wake gesture. |
| 2129 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 2130 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 2131 | UserHandle.USER_CURRENT) != 0; |
| 2132 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 2133 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 2134 | updateWakeGestureListenerLp(); |
| 2135 | } |
| 2136 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 2137 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2138 | int userRotation = Settings.System.getIntForUser(resolver, |
| 2139 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 2140 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 2141 | if (mUserRotation != userRotation) { |
| 2142 | mUserRotation = userRotation; |
| 2143 | updateRotation = true; |
| 2144 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2145 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 2146 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 2147 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 2148 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 2149 | if (mUserRotationMode != userRotationMode) { |
| 2150 | mUserRotationMode = userRotationMode; |
| 2151 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2152 | updateOrientationListenerLp(); |
| 2153 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 2154 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2155 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2156 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 2157 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2158 | if (mPointerLocationMode != pointerLocation) { |
| 2159 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2160 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 2161 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2162 | } |
| 2163 | } |
| 2164 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2165 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 2166 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 2167 | String imId = Settings.Secure.getStringForUser(resolver, |
| 2168 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2169 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 2170 | if (mHasSoftInput != hasSoftInput) { |
| 2171 | mHasSoftInput = hasSoftInput; |
| 2172 | updateRotation = true; |
| 2173 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2174 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 2175 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 2176 | } |
tiger_huang | cc6366d | 2015-06-29 17:17:30 +0800 | [diff] [blame] | 2177 | } |
| 2178 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 2179 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2180 | } |
| 2181 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 2182 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2183 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2184 | } |
| 2185 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 2186 | private void updateWakeGestureListenerLp() { |
| 2187 | if (shouldEnableWakeGestureLp()) { |
| 2188 | mWakeGestureListener.requestWakeUpTrigger(); |
| 2189 | } else { |
| 2190 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 2191 | } |
| 2192 | } |
| 2193 | |
| 2194 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 2195 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 2196 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 2197 | && mWakeGestureListener.isSupported(); |
| 2198 | } |
| 2199 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2200 | private void enablePointerLocation() { |
| 2201 | if (mPointerLocationView == null) { |
| 2202 | mPointerLocationView = new PointerLocationView(mContext); |
| 2203 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2204 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 2205 | WindowManager.LayoutParams.MATCH_PARENT, |
| 2206 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 2207 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 2208 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 2209 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 2210 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 2211 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 2212 | if (ActivityManager.isHighEndGfx()) { |
| 2213 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 2214 | lp.privateFlags |= |
| 2215 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 2216 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2217 | lp.format = PixelFormat.TRANSLUCENT; |
| 2218 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2219 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2220 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2221 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2222 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 2223 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2224 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2225 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2226 | |
| 2227 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2228 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 2229 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 2230 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2231 | wm.removeView(mPointerLocationView); |
| 2232 | mPointerLocationView = null; |
| 2233 | } |
| 2234 | } |
| 2235 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2236 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2237 | try { |
| 2238 | int rotation = mContext.getResources().getInteger(resID); |
| 2239 | switch (rotation) { |
| 2240 | case 0: |
| 2241 | return Surface.ROTATION_0; |
| 2242 | case 90: |
| 2243 | return Surface.ROTATION_90; |
| 2244 | case 180: |
| 2245 | return Surface.ROTATION_180; |
| 2246 | case 270: |
| 2247 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2248 | } |
| 2249 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2250 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2251 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2252 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2256 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2257 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2258 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2259 | |
| 2260 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 2261 | |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 2262 | if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) |
| 2263 | || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) |
| 2264 | || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { |
| 2265 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
| 2266 | } |
| 2267 | |
| 2268 | if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { |
| 2269 | // Window manager will make sure these are okay. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2270 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2271 | } |
| 2272 | String permission = null; |
| 2273 | switch (type) { |
| 2274 | case TYPE_TOAST: |
| 2275 | // XXX right now the app process has complete control over |
| 2276 | // this... should introduce a token to let the system |
| 2277 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2278 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2279 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2280 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2281 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 2282 | case TYPE_WALLPAPER: |
Wale Ogunwale | 5b6714c | 2016-11-01 20:54:46 -0700 | [diff] [blame] | 2283 | case TYPE_PRESENTATION: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2284 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2285 | case TYPE_VOICE_INTERACTION: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2286 | case TYPE_ACCESSIBILITY_OVERLAY: |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 2287 | case TYPE_QS_DIALOG: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 2288 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2289 | break; |
| 2290 | case TYPE_PHONE: |
| 2291 | case TYPE_PRIORITY_PHONE: |
| 2292 | case TYPE_SYSTEM_ALERT: |
| 2293 | case TYPE_SYSTEM_ERROR: |
| 2294 | case TYPE_SYSTEM_OVERLAY: |
| 2295 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2296 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2297 | break; |
| 2298 | default: |
| 2299 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 2300 | } |
| 2301 | if (permission != null) { |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 2302 | if (android.Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permission)) { |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2303 | final int callingUid = Binder.getCallingUid(); |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2304 | // system processes will be automatically allowed privilege to draw |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2305 | if (callingUid == Process.SYSTEM_UID) { |
| 2306 | return WindowManagerGlobal.ADD_OKAY; |
| 2307 | } |
| 2308 | |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2309 | // check if user has enabled this operation. SecurityException will be thrown if |
| 2310 | // this app has not been allowed by the user |
Svet Ganov | 03f2afc | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 2311 | final int mode = mAppOpsManager.checkOpNoThrow(outAppOp[0], callingUid, |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2312 | attrs.packageName); |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2313 | switch (mode) { |
| 2314 | case AppOpsManager.MODE_ALLOWED: |
| 2315 | case AppOpsManager.MODE_IGNORED: |
| 2316 | // although we return ADD_OKAY for MODE_IGNORED, the added window will |
| 2317 | // actually be hidden in WindowManagerService |
| 2318 | return WindowManagerGlobal.ADD_OKAY; |
| 2319 | case AppOpsManager.MODE_ERRORED: |
Svet Ganov | 03f2afc | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 2320 | try { |
| 2321 | ApplicationInfo appInfo = mContext.getPackageManager() |
| 2322 | .getApplicationInfo(attrs.packageName, |
| 2323 | UserHandle.getUserId(callingUid)); |
| 2324 | // Don't crash legacy apps |
| 2325 | if (appInfo.targetSdkVersion < Build.VERSION_CODES.M) { |
| 2326 | return WindowManagerGlobal.ADD_OKAY; |
| 2327 | } |
| 2328 | } catch (PackageManager.NameNotFoundException e) { |
| 2329 | /* ignore */ |
| 2330 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2331 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2332 | default: |
| 2333 | // in the default mode, we will make a decision here based on |
| 2334 | // checkCallingPermission() |
| 2335 | if (mContext.checkCallingPermission(permission) != |
| 2336 | PackageManager.PERMISSION_GRANTED) { |
| 2337 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
| 2338 | } else { |
| 2339 | return WindowManagerGlobal.ADD_OKAY; |
| 2340 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2341 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2342 | } |
| 2343 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2344 | if (mContext.checkCallingOrSelfPermission(permission) |
| 2345 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2346 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2347 | } |
| 2348 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2349 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2350 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2351 | |
| 2352 | @Override |
| 2353 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 2354 | |
| 2355 | // If this switch statement is modified, modify the comment in the declarations of |
| 2356 | // the type in {@link WindowManager.LayoutParams} as well. |
| 2357 | switch (attrs.type) { |
| 2358 | default: |
| 2359 | // These are the windows that by default are shown only to the user that created |
| 2360 | // them. If this needs to be overridden, set |
| 2361 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 2362 | // {@link WindowManager.LayoutParams}. Note that permission |
| 2363 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 2364 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 2365 | return true; |
| 2366 | } |
| 2367 | break; |
| 2368 | |
| 2369 | // These are the windows that by default are shown to all users. However, to |
| 2370 | // protect against spoofing, check permissions below. |
| 2371 | case TYPE_APPLICATION_STARTING: |
| 2372 | case TYPE_BOOT_PROGRESS: |
| 2373 | case TYPE_DISPLAY_OVERLAY: |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2374 | case TYPE_INPUT_CONSUMER: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2375 | case TYPE_KEYGUARD_DIALOG: |
| 2376 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2377 | case TYPE_NAVIGATION_BAR: |
| 2378 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2379 | case TYPE_PHONE: |
| 2380 | case TYPE_POINTER: |
| 2381 | case TYPE_PRIORITY_PHONE: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2382 | case TYPE_SEARCH_BAR: |
| 2383 | case TYPE_STATUS_BAR: |
| 2384 | case TYPE_STATUS_BAR_PANEL: |
| 2385 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 2386 | case TYPE_SYSTEM_DIALOG: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2387 | case TYPE_VOLUME_OVERLAY: |
Wale Ogunwale | 5b6714c | 2016-11-01 20:54:46 -0700 | [diff] [blame] | 2388 | case TYPE_PRESENTATION: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2389 | case TYPE_PRIVATE_PRESENTATION: |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2390 | case TYPE_DOCK_DIVIDER: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2391 | break; |
| 2392 | } |
| 2393 | |
| 2394 | // Check if third party app has set window to system window type. |
| 2395 | return mContext.checkCallingOrSelfPermission( |
| 2396 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 2397 | != PackageManager.PERMISSION_GRANTED; |
| 2398 | } |
| 2399 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2400 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2401 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 2402 | switch (attrs.type) { |
| 2403 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 2404 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2405 | // These types of windows can't receive input events. |
| 2406 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 2407 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 2408 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2409 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2410 | case TYPE_STATUS_BAR: |
| 2411 | |
| 2412 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 2413 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 2414 | // the keyguard as occluded wouldn't set these flags again. |
| 2415 | // See {@link #processKeyguardSetHiddenResultLw}. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2416 | if (mKeyguardOccluded) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2417 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 2418 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2419 | } |
| 2420 | break; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2421 | |
Muyuan Li | 36ca72c | 2016-08-06 20:24:06 -0700 | [diff] [blame] | 2422 | case TYPE_SCREENSHOT: |
| 2423 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 2424 | break; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2425 | |
| 2426 | case TYPE_TOAST: |
| 2427 | // While apps should use the dedicated toast APIs to add such windows |
| 2428 | // it possible legacy apps to add the window directly. Therefore, we |
| 2429 | // make windows added directly by the app behave as a toast as much |
| 2430 | // as possible in terms of timeout and animation. |
| 2431 | if (attrs.hideTimeoutMilliseconds < 0 |
| 2432 | || attrs.hideTimeoutMilliseconds > TOAST_WINDOW_TIMEOUT) { |
| 2433 | attrs.hideTimeoutMilliseconds = TOAST_WINDOW_TIMEOUT; |
| 2434 | } |
| 2435 | attrs.windowAnimations = com.android.internal.R.style.Animation_Toast; |
| 2436 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2437 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 2438 | |
| 2439 | if (attrs.type != TYPE_STATUS_BAR) { |
| 2440 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 2441 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2442 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2443 | |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2444 | if (ActivityManager.isHighEndGfx()) { |
| 2445 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
| 2446 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 2447 | } |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 2448 | final boolean forceWindowDrawsStatusBarBackground = |
| 2449 | (attrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) |
| 2450 | != 0; |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2451 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 2452 | || forceWindowDrawsStatusBarBackground |
| 2453 | && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT) { |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2454 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 2455 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2456 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2457 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2458 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2459 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 2460 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2461 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2462 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 2463 | private void readCameraLensCoverState() { |
| 2464 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 2465 | } |
| 2466 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2467 | private boolean isHidden(int accessibilityMode) { |
| 2468 | switch (accessibilityMode) { |
| 2469 | case 1: |
| 2470 | return mLidState == LID_CLOSED; |
| 2471 | case 2: |
| 2472 | return mLidState == LID_OPEN; |
| 2473 | default: |
| 2474 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2475 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2476 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2477 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2478 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2479 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2480 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 2481 | int navigationPresence) { |
| 2482 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 2483 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2484 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2485 | readLidState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2486 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2487 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 2488 | || (keyboardPresence == PRESENCE_INTERNAL |
| 2489 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2490 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2491 | if (!mHasSoftInput) { |
| 2492 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 2493 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2494 | } |
| 2495 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2496 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 2497 | || (navigationPresence == PRESENCE_INTERNAL |
| 2498 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2499 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2500 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2501 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2502 | |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2503 | @Override |
| 2504 | public void onConfigurationChanged() { |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 2505 | // TODO(multi-display): Define policy for secondary displays. |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2506 | final Resources res = mContext.getResources(); |
| 2507 | |
| 2508 | mStatusBarHeight = |
| 2509 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
| 2510 | |
| 2511 | // Height of the navigation bar when presented horizontally at bottom |
| 2512 | mNavigationBarHeightForRotationDefault[mPortraitRotation] = |
| 2513 | mNavigationBarHeightForRotationDefault[mUpsideDownRotation] = |
| 2514 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
| 2515 | mNavigationBarHeightForRotationDefault[mLandscapeRotation] = |
| 2516 | mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize( |
| 2517 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
| 2518 | |
| 2519 | // Width of the navigation bar when presented vertically along one side |
| 2520 | mNavigationBarWidthForRotationDefault[mPortraitRotation] = |
| 2521 | mNavigationBarWidthForRotationDefault[mUpsideDownRotation] = |
| 2522 | mNavigationBarWidthForRotationDefault[mLandscapeRotation] = |
| 2523 | mNavigationBarWidthForRotationDefault[mSeascapeRotation] = |
| 2524 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
| 2525 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2526 | if (ALTERNATE_CAR_MODE_NAV_SIZE) { |
| 2527 | // Height of the navigation bar when presented horizontally at bottom |
| 2528 | mNavigationBarHeightForRotationInCarMode[mPortraitRotation] = |
| 2529 | mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] = |
| 2530 | res.getDimensionPixelSize( |
| 2531 | com.android.internal.R.dimen.navigation_bar_height_car_mode); |
| 2532 | mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] = |
| 2533 | mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize( |
| 2534 | com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2535 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2536 | // Width of the navigation bar when presented vertically along one side |
| 2537 | mNavigationBarWidthForRotationInCarMode[mPortraitRotation] = |
| 2538 | mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] = |
| 2539 | mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] = |
| 2540 | mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] = |
| 2541 | res.getDimensionPixelSize( |
| 2542 | com.android.internal.R.dimen.navigation_bar_width_car_mode); |
| 2543 | } |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2544 | } |
| 2545 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2546 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2547 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2548 | public int windowTypeToLayerLw(int type) { |
| 2549 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2550 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2551 | } |
| 2552 | switch (type) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2553 | case TYPE_WALLPAPER: |
| 2554 | // wallpaper is at the bottom, though the window manager may move it. |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 2555 | return 1; |
| 2556 | case TYPE_PRESENTATION: |
| 2557 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2558 | return 2; |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2559 | case TYPE_DOCK_DIVIDER: |
| 2560 | return 2; |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 2561 | case TYPE_QS_DIALOG: |
| 2562 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2563 | case TYPE_PHONE: |
| 2564 | return 3; |
| 2565 | case TYPE_SEARCH_BAR: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2566 | case TYPE_VOICE_INTERACTION_STARTING: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2567 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2568 | case TYPE_VOICE_INTERACTION: |
| 2569 | // voice interaction layer is almost immediately above apps. |
| 2570 | return 5; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2571 | case TYPE_INPUT_CONSUMER: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2572 | return 6; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2573 | case TYPE_SYSTEM_DIALOG: |
| 2574 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2575 | case TYPE_TOAST: |
| 2576 | // toasts and the plugged-in battery thing |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2577 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2578 | case TYPE_PRIORITY_PHONE: |
| 2579 | // 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] | 2580 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2581 | case TYPE_DREAM: |
| 2582 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2583 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2584 | case TYPE_SYSTEM_ALERT: |
| 2585 | // like the ANR / app crashed dialogs |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2586 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2587 | case TYPE_INPUT_METHOD: |
| 2588 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2589 | return 12; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2590 | case TYPE_INPUT_METHOD_DIALOG: |
| 2591 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2592 | return 13; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2593 | case TYPE_STATUS_BAR_SUB_PANEL: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2594 | return 15; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2595 | case TYPE_STATUS_BAR: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2596 | return 16; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2597 | case TYPE_STATUS_BAR_PANEL: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2598 | return 17; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2599 | case TYPE_KEYGUARD_DIALOG: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2600 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2601 | case TYPE_VOLUME_OVERLAY: |
| 2602 | // the on-screen volume indicator and controller shown when the user |
| 2603 | // changes the device volume |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2604 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2605 | case TYPE_SYSTEM_OVERLAY: |
| 2606 | // the on-screen volume indicator and controller shown when the user |
| 2607 | // changes the device volume |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2608 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2609 | case TYPE_NAVIGATION_BAR: |
| 2610 | // the navigation bar, if available, shows atop most things |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2611 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2612 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2613 | // 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] | 2614 | return 22; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2615 | case TYPE_SCREENSHOT: |
| 2616 | // screenshot selection layer shouldn't go above system error, but it should cover |
| 2617 | // navigation bars at the very least. |
| 2618 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2619 | case TYPE_SYSTEM_ERROR: |
| 2620 | // system-level error dialogs |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2621 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2622 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2623 | // used to highlight the magnified portion of a display |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2624 | return 25; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2625 | case TYPE_DISPLAY_OVERLAY: |
| 2626 | // used to simulate secondary display devices |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2627 | return 26; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2628 | case TYPE_DRAG: |
| 2629 | // the drag layer: input for drag-and-drop is associated with this window, |
| 2630 | // which sits above all other focusable windows |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2631 | return 27; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2632 | case TYPE_ACCESSIBILITY_OVERLAY: |
| 2633 | // overlay put by accessibility services to intercept user interaction |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2634 | return 28; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2635 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2636 | return 29; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2637 | case TYPE_BOOT_PROGRESS: |
| 2638 | return 30; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2639 | case TYPE_POINTER: |
| 2640 | // the (mouse) pointer layer |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2641 | return 31; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2642 | } |
| 2643 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2644 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2645 | } |
| 2646 | |
| 2647 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2648 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2649 | public int subWindowTypeToLayerLw(int type) { |
| 2650 | switch (type) { |
| 2651 | case TYPE_APPLICATION_PANEL: |
| 2652 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 2653 | return APPLICATION_PANEL_SUBLAYER; |
| 2654 | case TYPE_APPLICATION_MEDIA: |
| 2655 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 2656 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 2657 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2658 | case TYPE_APPLICATION_SUB_PANEL: |
| 2659 | return APPLICATION_SUB_PANEL_SUBLAYER; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 2660 | case TYPE_APPLICATION_ABOVE_SUB_PANEL: |
| 2661 | return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2662 | } |
| 2663 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 2664 | return 0; |
| 2665 | } |
| 2666 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2667 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2668 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2669 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2672 | private int getNavigationBarWidth(int rotation, int uiMode) { |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2673 | 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] | 2674 | return mNavigationBarWidthForRotationInCarMode[rotation]; |
| 2675 | } else { |
| 2676 | return mNavigationBarWidthForRotationDefault[rotation]; |
| 2677 | } |
| 2678 | } |
| 2679 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2680 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2681 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2682 | int displayId) { |
| 2683 | // TODO(multi-display): Support navigation bar on secondary displays. |
| 2684 | if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2685 | // For a basic navigation bar, when we are in landscape mode we place |
| 2686 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2687 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2688 | return fullWidth - getNavigationBarWidth(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2689 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2690 | } |
| 2691 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2692 | } |
| 2693 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2694 | private int getNavigationBarHeight(int rotation, int uiMode) { |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2695 | 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] | 2696 | return mNavigationBarHeightForRotationInCarMode[rotation]; |
| 2697 | } else { |
| 2698 | return mNavigationBarHeightForRotationDefault[rotation]; |
| 2699 | } |
| 2700 | } |
| 2701 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2702 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2703 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2704 | int displayId) { |
| 2705 | // TODO(multi-display): Support navigation bar on secondary displays. |
| 2706 | if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2707 | // For a basic navigation bar, when we are in portrait mode we place |
| 2708 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2709 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2710 | return fullHeight - getNavigationBarHeight(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2711 | } |
| 2712 | } |
| 2713 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2716 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2717 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2718 | int displayId) { |
| 2719 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode, displayId); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2720 | } |
| 2721 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2722 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2723 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2724 | int displayId) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2725 | // There is a separate status bar at the top of the display. We don't count that as part |
| 2726 | // 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] | 2727 | // we do want to exclude it since applications can't generally use that part |
| 2728 | // of the screen. |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2729 | // TODO(multi-display): Support status bars on secondary displays. |
| 2730 | if (displayId == Display.DEFAULT_DISPLAY) { |
| 2731 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation, uiMode, displayId) |
| 2732 | - mStatusBarHeight; |
| 2733 | } |
| 2734 | return fullHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2735 | } |
| 2736 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2737 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2738 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 2739 | return attrs.type == TYPE_STATUS_BAR; |
| 2740 | } |
| 2741 | |
| 2742 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2743 | public boolean canBeHiddenByKeyguardLw(WindowState win) { |
| 2744 | switch (win.getAttrs().type) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2745 | case TYPE_STATUS_BAR: |
| 2746 | case TYPE_NAVIGATION_BAR: |
| 2747 | case TYPE_WALLPAPER: |
| 2748 | case TYPE_DREAM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2749 | return false; |
| 2750 | default: |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 2751 | // Hide only windows below the keyguard host window. |
| 2752 | return windowTypeToLayerLw(win.getBaseType()) |
| 2753 | < windowTypeToLayerLw(TYPE_STATUS_BAR); |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2754 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2755 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2756 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2757 | private boolean shouldBeHiddenByKeyguard(WindowState win, WindowState imeTarget) { |
| 2758 | |
| 2759 | // Keyguard visibility of window from activities are determined over activity visibility. |
| 2760 | if (win.getAppToken() != null) { |
| 2761 | return false; |
| 2762 | } |
| 2763 | |
| 2764 | final LayoutParams attrs = win.getAttrs(); |
| 2765 | final boolean showImeOverKeyguard = imeTarget != null && imeTarget.isVisibleLw() && |
| 2766 | ((imeTarget.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0 |
| 2767 | || !canBeHiddenByKeyguardLw(imeTarget)); |
| 2768 | |
| 2769 | // Show IME over the keyguard if the target allows it |
| 2770 | boolean allowWhenLocked = (win.isInputMethodWindow() || imeTarget == this) |
| 2771 | && showImeOverKeyguard;; |
| 2772 | |
| 2773 | if (isKeyguardLocked() && isKeyguardOccluded()) { |
| 2774 | // Show SHOW_WHEN_LOCKED windows if Keyguard is occluded. |
| 2775 | allowWhenLocked |= (attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0 |
| 2776 | // Show error dialogs over apps that are shown on lockscreen |
| 2777 | || (attrs.privateFlags & PRIVATE_FLAG_SYSTEM_ERROR) != 0; |
| 2778 | } |
| 2779 | |
| 2780 | boolean keyguardLocked = isKeyguardLocked(); |
| 2781 | boolean hideDockDivider = attrs.type == TYPE_DOCK_DIVIDER |
| 2782 | && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID); |
| 2783 | return (keyguardLocked && !allowWhenLocked && win.getDisplayId() == Display.DEFAULT_DISPLAY) |
| 2784 | || hideDockDivider; |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 2785 | } |
| 2786 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2787 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2788 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2789 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 2790 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2791 | int icon, int logo, int windowFlags, Configuration overrideConfig) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2792 | if (!SHOW_STARTING_ANIMATIONS) { |
| 2793 | return null; |
| 2794 | } |
| 2795 | if (packageName == null) { |
| 2796 | return null; |
| 2797 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2798 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2799 | WindowManager wm = null; |
| 2800 | View view = null; |
| 2801 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2802 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2803 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2804 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 2805 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 2806 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2807 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2808 | try { |
| 2809 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2810 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2811 | } catch (PackageManager.NameNotFoundException e) { |
| 2812 | // Ignore |
| 2813 | } |
| 2814 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2815 | |
Andrii Kulian | a8a9bc5 | 2016-10-14 11:00:13 -0700 | [diff] [blame] | 2816 | if (overrideConfig != null && !overrideConfig.equals(EMPTY)) { |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2817 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow: creating context based" |
| 2818 | + " on overrideConfig" + overrideConfig + " for starting window"); |
| 2819 | final Context overrideContext = context.createConfigurationContext(overrideConfig); |
| 2820 | overrideContext.setTheme(theme); |
| 2821 | final TypedArray typedArray = overrideContext.obtainStyledAttributes( |
| 2822 | com.android.internal.R.styleable.Window); |
| 2823 | final int resId = typedArray.getResourceId(R.styleable.Window_windowBackground, 0); |
| 2824 | if (resId != 0 && overrideContext.getDrawable(resId) != null) { |
| 2825 | // We want to use the windowBackground for the override context if it is |
| 2826 | // available, otherwise we use the default one to make sure a themed starting |
| 2827 | // window is displayed for the app. |
| 2828 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow: apply overrideConfig" |
| 2829 | + overrideConfig + " to starting window resId=" + resId); |
| 2830 | context = overrideContext; |
| 2831 | } |
| 2832 | } |
| 2833 | |
| 2834 | final PhoneWindow win = new PhoneWindow(context); |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 2835 | win.setIsStartingWindow(true); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2836 | |
Phil Weaver | 155edc6 | 2016-06-09 10:24:53 -0700 | [diff] [blame] | 2837 | CharSequence label = context.getResources().getText(labelRes, null); |
| 2838 | // Only change the accessibility title if the label is localized |
| 2839 | if (label != null) { |
| 2840 | win.setTitle(label, true); |
| 2841 | } else { |
| 2842 | win.setTitle(nonLocalizedLabel, false); |
| 2843 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2844 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2845 | win.setType( |
| 2846 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2847 | |
| 2848 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2849 | // Assumes it's safe to show starting windows of launched apps while |
| 2850 | // the keyguard is being hidden. This is okay because starting windows never show |
| 2851 | // secret information. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2852 | if (mKeyguardOccluded) { |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2853 | windowFlags |= FLAG_SHOW_WHEN_LOCKED; |
| 2854 | } |
| 2855 | } |
| 2856 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2857 | // Force the window flags: this is a fake window, so it is not really |
| 2858 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 2859 | // flag because we do know that the next window will take input |
| 2860 | // focus, so we want to get the IME window up on top of us right away. |
| 2861 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2862 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2863 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2864 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2865 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2866 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2867 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2868 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2869 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2870 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2871 | win.setDefaultIcon(icon); |
| 2872 | win.setDefaultLogo(logo); |
| 2873 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2874 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2875 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2876 | |
Phil Weaver | 266ed9a | 2016-06-08 00:34:40 +0000 | [diff] [blame] | 2877 | final WindowManager.LayoutParams params = win.getAttributes(); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2878 | params.token = appToken; |
| 2879 | params.packageName = packageName; |
| 2880 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 2881 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2882 | params.privateFlags |= |
| 2883 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2884 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2885 | |
| 2886 | if (!compatInfo.supportsScreen()) { |
| 2887 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 2888 | } |
| 2889 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2890 | params.setTitle("Starting " + packageName); |
| 2891 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2892 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 2893 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2894 | |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2895 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "Adding starting window for " |
| 2896 | + packageName + " / " + appToken + ": " + (view.getParent() != null ? view : null)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2897 | |
| 2898 | wm.addView(view, params); |
| 2899 | |
| 2900 | // Only return the view if it was successfully added to the |
| 2901 | // window manager... which we can tell by it having a parent. |
| 2902 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2903 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2904 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 2905 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 2906 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2907 | } catch (RuntimeException e) { |
| 2908 | // don't crash if something else bad happens, for example a |
| 2909 | // failure loading resources because we are loading from an app |
| 2910 | // on external storage that has been unmounted. |
| 2911 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2912 | } finally { |
| 2913 | if (view != null && view.getParent() == null) { |
| 2914 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 2915 | wm.removeViewImmediate(view); |
| 2916 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | return null; |
| 2920 | } |
| 2921 | |
| 2922 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2923 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2924 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2925 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": " |
| 2926 | + window + " Callers=" + Debug.getCallers(4)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2927 | |
| 2928 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2929 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2930 | wm.removeView(window); |
| 2931 | } |
| 2932 | } |
| 2933 | |
| 2934 | /** |
| 2935 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2936 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2937 | * Currently enforces that three window types are singletons: |
| 2938 | * <ul> |
| 2939 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2940 | * <li>KEYGUARD_TYPE</li> |
| 2941 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2942 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2943 | * @param win The window to be added |
| 2944 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2945 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2946 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 2947 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2948 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2949 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2950 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 2951 | switch (attrs.type) { |
| 2952 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 2953 | mContext.enforceCallingOrSelfPermission( |
| 2954 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2955 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2956 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2957 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2958 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2959 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2960 | } |
| 2961 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2962 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2963 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2964 | case TYPE_NAVIGATION_BAR: |
| 2965 | mContext.enforceCallingOrSelfPermission( |
| 2966 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2967 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2968 | if (mNavigationBar != null) { |
| 2969 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2970 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2971 | } |
| 2972 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2973 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2974 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2975 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2976 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 2977 | case TYPE_NAVIGATION_BAR_PANEL: |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2978 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2979 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2980 | case TYPE_VOICE_INTERACTION_STARTING: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2981 | mContext.enforceCallingOrSelfPermission( |
| 2982 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2983 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2984 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2985 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2986 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2987 | } |
| 2988 | |
| 2989 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2990 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2991 | public void removeWindowLw(WindowState win) { |
| 2992 | if (mStatusBar == win) { |
| 2993 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2994 | mStatusBarController.setWindow(null); |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 2995 | } else if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2996 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2997 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2998 | } |
| 2999 | } |
| 3000 | |
| 3001 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3002 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3003 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3004 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3005 | public int selectAnimationLw(WindowState win, int transit) { |
| 3006 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 3007 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3008 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3009 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3010 | if (transit == TRANSIT_EXIT |
| 3011 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3012 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3013 | } else if (transit == TRANSIT_ENTER |
| 3014 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3015 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3016 | } |
| 3017 | } else if (win == mNavigationBar) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 3018 | if (win.getAttrs().windowAnimations != 0) { |
| 3019 | return 0; |
| 3020 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3021 | // This can be on either the bottom or the right or the left. |
| 3022 | if (mNavigationBarPosition == NAV_BAR_BOTTOM) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3023 | if (transit == TRANSIT_EXIT |
| 3024 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 4883281 | 2016-09-06 12:38:23 -0700 | [diff] [blame] | 3025 | if (isKeyguardShowingAndNotOccluded()) { |
| 3026 | return R.anim.dock_bottom_exit_keyguard; |
| 3027 | } else { |
| 3028 | return R.anim.dock_bottom_exit; |
| 3029 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3030 | } else if (transit == TRANSIT_ENTER |
| 3031 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3032 | return R.anim.dock_bottom_enter; |
| 3033 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3034 | } else if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3035 | if (transit == TRANSIT_EXIT |
| 3036 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3037 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3038 | } else if (transit == TRANSIT_ENTER |
| 3039 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3040 | return R.anim.dock_right_enter; |
| 3041 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3042 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
| 3043 | if (transit == TRANSIT_EXIT |
| 3044 | || transit == TRANSIT_HIDE) { |
| 3045 | return R.anim.dock_left_exit; |
| 3046 | } else if (transit == TRANSIT_ENTER |
| 3047 | || transit == TRANSIT_SHOW) { |
| 3048 | return R.anim.dock_left_enter; |
| 3049 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3050 | } |
Filip Gruszczynski | 57f76f1 | 2015-11-04 16:10:54 -0800 | [diff] [blame] | 3051 | } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) { |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 3052 | return selectDockedDividerAnimationLw(win, transit); |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3053 | } |
| 3054 | |
| 3055 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3056 | if (win.hasAppShownWindows()) { |
| 3057 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 3058 | return com.android.internal.R.anim.app_starting_exit; |
| 3059 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3060 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3061 | && transit == TRANSIT_ENTER) { |
| 3062 | // Special case: we are animating in a dream, while the keyguard |
| 3063 | // is shown. We don't want an animation on the dream, because |
| 3064 | // we need it shown immediately with the keyguard animating away |
| 3065 | // to reveal it. |
| 3066 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | return 0; |
| 3070 | } |
| 3071 | |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 3072 | private int selectDockedDividerAnimationLw(WindowState win, int transit) { |
| 3073 | int insets = mWindowManagerFuncs.getDockedDividerInsetsLw(); |
| 3074 | |
| 3075 | // If the divider is behind the navigation bar, don't animate. |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 3076 | final Rect frame = win.getFrameLw(); |
| 3077 | final boolean behindNavBar = mNavigationBar != null |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3078 | && ((mNavigationBarPosition == NAV_BAR_BOTTOM |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 3079 | && frame.top + insets >= mNavigationBar.getFrameLw().top) |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3080 | || (mNavigationBarPosition == NAV_BAR_RIGHT |
| 3081 | && frame.left + insets >= mNavigationBar.getFrameLw().left) |
| 3082 | || (mNavigationBarPosition == NAV_BAR_LEFT |
| 3083 | && frame.right - insets <= mNavigationBar.getFrameLw().right)); |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 3084 | final boolean landscape = frame.height() > frame.width(); |
| 3085 | final boolean offscreenLandscape = landscape && (frame.right - insets <= 0 |
| 3086 | || frame.left + insets >= win.getDisplayFrameLw().right); |
| 3087 | final boolean offscreenPortrait = !landscape && (frame.top - insets <= 0 |
| 3088 | || frame.bottom + insets >= win.getDisplayFrameLw().bottom); |
| 3089 | final boolean offscreen = offscreenLandscape || offscreenPortrait; |
| 3090 | if (behindNavBar || offscreen) { |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 3091 | return 0; |
| 3092 | } |
| 3093 | if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) { |
| 3094 | return R.anim.fade_in; |
| 3095 | } else if (transit == TRANSIT_EXIT) { |
| 3096 | return R.anim.fade_out; |
| 3097 | } else { |
| 3098 | return 0; |
| 3099 | } |
| 3100 | } |
| 3101 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3102 | @Override |
| 3103 | public void selectRotationAnimationLw(int anim[]) { |
| 3104 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 3105 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 3106 | + (mTopFullscreenOpaqueWindowState == null ? |
| 3107 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 3108 | if (mTopFullscreenOpaqueWindowState != null) { |
| 3109 | int animationHint = mTopFullscreenOpaqueWindowState.getRotationAnimationHint(); |
| 3110 | if (animationHint < 0 && mTopIsFullscreen) { |
| 3111 | animationHint = mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation; |
| 3112 | } |
| 3113 | switch (animationHint) { |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3114 | case ROTATION_ANIMATION_CROSSFADE: |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 3115 | case ROTATION_ANIMATION_SEAMLESS: // Crossfade is fallback for seamless. |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3116 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 3117 | anim[1] = R.anim.rotation_animation_enter; |
| 3118 | break; |
| 3119 | case ROTATION_ANIMATION_JUMPCUT: |
| 3120 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 3121 | anim[1] = R.anim.rotation_animation_enter; |
| 3122 | break; |
| 3123 | case ROTATION_ANIMATION_ROTATE: |
| 3124 | default: |
| 3125 | anim[0] = anim[1] = 0; |
| 3126 | break; |
| 3127 | } |
| 3128 | } else { |
| 3129 | anim[0] = anim[1] = 0; |
| 3130 | } |
| 3131 | } |
| 3132 | |
| 3133 | @Override |
| 3134 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 3135 | boolean forceDefault) { |
| 3136 | switch (exitAnimId) { |
| 3137 | case R.anim.rotation_animation_xfade_exit: |
| 3138 | case R.anim.rotation_animation_jump_exit: |
| 3139 | // These are the only cases that matter. |
| 3140 | if (forceDefault) { |
| 3141 | return false; |
| 3142 | } |
| 3143 | int anim[] = new int[2]; |
| 3144 | selectRotationAnimationLw(anim); |
| 3145 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 3146 | default: |
| 3147 | return true; |
| 3148 | } |
| 3149 | } |
| 3150 | |
| 3151 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3152 | public Animation createHiddenByKeyguardExit(boolean onWallpaper, |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 3153 | boolean goingToNotificationShade) { |
| 3154 | if (goingToNotificationShade) { |
| 3155 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
Craig Mautner | b834080 | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 3156 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 3157 | |
| 3158 | AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? |
| 3159 | R.anim.lock_screen_behind_enter_wallpaper : |
| 3160 | R.anim.lock_screen_behind_enter); |
| 3161 | |
| 3162 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 3163 | final List<Animation> animations = set.getAnimations(); |
| 3164 | for (int i = animations.size() - 1; i >= 0; --i) { |
| 3165 | animations.get(i).setInterpolator(mLogDecelerateInterpolator); |
| 3166 | } |
| 3167 | |
| 3168 | return set; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 3169 | } |
| 3170 | |
| 3171 | |
| 3172 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3173 | public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) { |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 3174 | if (goingToNotificationShade) { |
| 3175 | return null; |
| 3176 | } else { |
| 3177 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 3178 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 3179 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 3180 | |
| 3181 | private static void awakenDreams() { |
| 3182 | IDreamManager dreamManager = getDreamManager(); |
| 3183 | if (dreamManager != null) { |
| 3184 | try { |
| 3185 | dreamManager.awaken(); |
| 3186 | } catch (RemoteException e) { |
| 3187 | // fine, stay asleep then |
| 3188 | } |
| 3189 | } |
| 3190 | } |
| 3191 | |
| 3192 | static IDreamManager getDreamManager() { |
| 3193 | return IDreamManager.Stub.asInterface( |
| 3194 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 3195 | } |
| 3196 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 3197 | TelecomManager getTelecommService() { |
| 3198 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3199 | } |
| 3200 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3201 | static IAudioService getAudioService() { |
| 3202 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 3203 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 3204 | if (audioService == null) { |
| 3205 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 3206 | } |
| 3207 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3208 | } |
| 3209 | |
| 3210 | boolean keyguardOn() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 3211 | return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3212 | } |
| 3213 | |
| 3214 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 3215 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 3216 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 3217 | }; |
| 3218 | |
| 3219 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3220 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3221 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3222 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3223 | final int keyCode = event.getKeyCode(); |
| 3224 | final int repeatCount = event.getRepeatCount(); |
| 3225 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3226 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3227 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 3228 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3229 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3230 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3231 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3232 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 3233 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3234 | } |
| 3235 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3236 | // If we think we might have a volume down & power key chord on the way |
| 3237 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 3238 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 3239 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3240 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3241 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3242 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 3243 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3244 | if (now < timeoutTime) { |
| 3245 | return timeoutTime - now; |
| 3246 | } |
| 3247 | } |
| 3248 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3249 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3250 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3251 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3252 | } |
| 3253 | return -1; |
| 3254 | } |
| 3255 | } |
| 3256 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3257 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 3258 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 3259 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3260 | mPendingMetaAction = false; |
| 3261 | } |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 3262 | // Any key that is not Alt or Meta cancels Caps Lock combo tracking. |
| 3263 | if (mPendingCapsLockToggle && !KeyEvent.isMetaKey(keyCode) && !KeyEvent.isAltKey(keyCode)) { |
| 3264 | mPendingCapsLockToggle = false; |
| 3265 | } |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3266 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3267 | // First we always handle the home key here, so applications |
| 3268 | // can never break it, although if keyguard is on, we do let |
| 3269 | // it handle it, because that gives us the correct 5 second |
| 3270 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3271 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3272 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3273 | // If we have released the home key, and didn't do anything else |
| 3274 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3275 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3276 | cancelPreloadRecentApps(); |
| 3277 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3278 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3279 | if (mHomeConsumed) { |
| 3280 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3281 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3282 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3283 | |
| 3284 | if (canceled) { |
| 3285 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 3286 | return -1; |
| 3287 | } |
| 3288 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3289 | // Delay handling home if a double-tap is possible. |
| 3290 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 3291 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 3292 | mHomeDoubleTapPending = true; |
| 3293 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 3294 | ViewConfiguration.getDoubleTapTimeout()); |
| 3295 | return -1; |
| 3296 | } |
| 3297 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3298 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3299 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3300 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3301 | |
| 3302 | // If a system window has focus, then it doesn't make sense |
| 3303 | // right now to interact with applications. |
| 3304 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 3305 | if (attrs != null) { |
| 3306 | final int type = attrs.type; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 3307 | if (type == TYPE_KEYGUARD_DIALOG |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3308 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3309 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3310 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3311 | } |
| 3312 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 3313 | for (int i=0; i<typeCount; i++) { |
| 3314 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 3315 | // 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] | 3316 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3317 | } |
| 3318 | } |
| 3319 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3320 | |
| 3321 | // Remember that home is pressed and handle special actions. |
| 3322 | if (repeatCount == 0) { |
| 3323 | mHomePressed = true; |
| 3324 | if (mHomeDoubleTapPending) { |
| 3325 | mHomeDoubleTapPending = false; |
| 3326 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 3327 | handleDoubleTapOnHome(); |
| 3328 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 3329 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 3330 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3331 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3332 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 3333 | if (!keyguardOn) { |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 3334 | handleLongPressOnHome(event.getDeviceId()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3335 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3336 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3337 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3338 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3339 | // Hijack modified menu keys for debugging features |
| 3340 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 3341 | |
| 3342 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3343 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3344 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 3345 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 3346 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3347 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3348 | } |
| 3349 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3350 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3351 | if (down) { |
| 3352 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3353 | mSearchKeyShortcutPending = true; |
| 3354 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3355 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3356 | } else { |
| 3357 | mSearchKeyShortcutPending = false; |
| 3358 | if (mConsumeSearchKeyUp) { |
| 3359 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3360 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3361 | } |
| 3362 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3363 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3364 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 3365 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3366 | if (down && repeatCount == 0) { |
| 3367 | preloadRecentApps(); |
| 3368 | } else if (!down) { |
| 3369 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 3370 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3371 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3372 | return -1; |
Jun Mukai | d21b3c8 | 2015-04-23 14:09:34 -0700 | [diff] [blame] | 3373 | } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) { |
| 3374 | if (down) { |
| 3375 | IStatusBarService service = getStatusBarService(); |
| 3376 | if (service != null) { |
| 3377 | try { |
| 3378 | service.expandNotificationsPanel(); |
| 3379 | } catch (RemoteException e) { |
| 3380 | // do nothing. |
| 3381 | } |
| 3382 | } |
| 3383 | } |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 3384 | } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed() |
| 3385 | && event.isCtrlPressed()) { |
| 3386 | if (down && repeatCount == 0) { |
| 3387 | int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION |
| 3388 | : TAKE_SCREENSHOT_FULLSCREEN; |
| 3389 | mScreenshotRunnable.setScreenshotType(type); |
| 3390 | mHandler.post(mScreenshotRunnable); |
| 3391 | return -1; |
| 3392 | } |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3393 | } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) { |
Andrei Stingaceanu | 002f712 | 2016-03-30 12:22:05 +0100 | [diff] [blame] | 3394 | if (down && repeatCount == 0 && !isKeyguardLocked()) { |
| 3395 | toggleKeyboardShortcutsMenu(event.getDeviceId()); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3396 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3397 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 3398 | if (down) { |
| 3399 | if (repeatCount == 0) { |
| 3400 | mAssistKeyLongPressed = false; |
| 3401 | } else if (repeatCount == 1) { |
| 3402 | mAssistKeyLongPressed = true; |
| 3403 | if (!keyguardOn) { |
| 3404 | launchAssistLongPressAction(); |
| 3405 | } |
| 3406 | } |
| 3407 | } else { |
| 3408 | if (mAssistKeyLongPressed) { |
| 3409 | mAssistKeyLongPressed = false; |
| 3410 | } else { |
| 3411 | if (!keyguardOn) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3412 | launchAssistAction(null, event.getDeviceId()); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3413 | } |
| 3414 | } |
| 3415 | } |
| 3416 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3417 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 3418 | if (!down) { |
| 3419 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 3420 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3421 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3422 | } else { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 3423 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 3424 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 3425 | if (dic != null) { |
| 3426 | try { |
| 3427 | dic.exitIdle("voice-search"); |
| 3428 | } catch (RemoteException e) { |
| 3429 | } |
| 3430 | } |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3431 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 3432 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3433 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3434 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3435 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 3436 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 3437 | if (down && repeatCount == 0) { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 3438 | mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN); |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 3439 | mHandler.post(mScreenshotRunnable); |
| 3440 | } |
| 3441 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 3442 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 3443 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 3444 | if (down) { |
| 3445 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 3446 | |
| 3447 | // Disable autobrightness if it's on |
| 3448 | int auto = Settings.System.getIntForUser( |
| 3449 | mContext.getContentResolver(), |
| 3450 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 3451 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 3452 | UserHandle.USER_CURRENT_OR_SELF); |
| 3453 | if (auto != 0) { |
| 3454 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3455 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 3456 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 3457 | UserHandle.USER_CURRENT_OR_SELF); |
| 3458 | } |
| 3459 | |
| 3460 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 3461 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 3462 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 3463 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 3464 | Settings.System.SCREEN_BRIGHTNESS, |
| 3465 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 3466 | UserHandle.USER_CURRENT_OR_SELF); |
| 3467 | brightness += step; |
| 3468 | // Make sure we don't go beyond the limits. |
| 3469 | brightness = Math.min(max, brightness); |
| 3470 | brightness = Math.max(min, brightness); |
| 3471 | |
| 3472 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3473 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 3474 | UserHandle.USER_CURRENT_OR_SELF); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3475 | startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 3476 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 3477 | } |
| 3478 | return -1; |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 3479 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 3480 | || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 3481 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { |
| 3482 | if (mUseTvRouting) { |
| 3483 | // On TVs volume keys never go to the foreground app. |
| 3484 | dispatchDirectAudioEvent(event); |
| 3485 | return -1; |
| 3486 | } |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3487 | } |
| 3488 | |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 3489 | // Toggle Caps Lock on META-ALT. |
| 3490 | boolean actionTriggered = false; |
| 3491 | if (KeyEvent.isModifierKey(keyCode)) { |
| 3492 | if (!mPendingCapsLockToggle) { |
| 3493 | // Start tracking meta state for combo. |
| 3494 | mInitialMetaState = mMetaState; |
| 3495 | mPendingCapsLockToggle = true; |
| 3496 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 3497 | int altOnMask = mMetaState & KeyEvent.META_ALT_MASK; |
| 3498 | int metaOnMask = mMetaState & KeyEvent.META_META_MASK; |
| 3499 | |
| 3500 | // Check for Caps Lock toggle |
| 3501 | if ((metaOnMask != 0) && (altOnMask != 0)) { |
| 3502 | // Check if nothing else is pressed |
| 3503 | if (mInitialMetaState == (mMetaState ^ (altOnMask | metaOnMask))) { |
| 3504 | // Handle Caps Lock Toggle |
| 3505 | mInputManagerInternal.toggleCapsLock(event.getDeviceId()); |
| 3506 | actionTriggered = true; |
| 3507 | } |
| 3508 | } |
| 3509 | |
| 3510 | // Always stop tracking when key goes up. |
| 3511 | mPendingCapsLockToggle = false; |
| 3512 | } |
| 3513 | } |
| 3514 | // Store current meta state to be able to evaluate it later. |
| 3515 | mMetaState = metaState; |
| 3516 | |
| 3517 | if (actionTriggered) { |
| 3518 | return -1; |
| 3519 | } |
| 3520 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3521 | if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3522 | if (down) { |
| 3523 | mPendingMetaAction = true; |
| 3524 | } else if (mPendingMetaAction) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3525 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId()); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3526 | } |
| 3527 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3528 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3529 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3530 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3531 | // Any printing key that is chorded with Search should be consumed |
| 3532 | // even if no shortcut was invoked. This prevents text from being |
| 3533 | // inadvertently inserted when using a keyboard that has built-in macro |
| 3534 | // 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] | 3535 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3536 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 3537 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3538 | mConsumeSearchKeyUp = true; |
| 3539 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3540 | if (down && repeatCount == 0 && !keyguardOn) { |
| 3541 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 3542 | if (shortcutIntent != null) { |
| 3543 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3544 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3545 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3546 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3547 | } catch (ActivityNotFoundException ex) { |
| 3548 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3549 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3550 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3551 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3552 | } else { |
| 3553 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3554 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3555 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3556 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3557 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3558 | } |
| 3559 | } |
| 3560 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3561 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3562 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3563 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 3564 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3565 | if (kcm.isPrintingKey(keyCode)) { |
| 3566 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 3567 | metaState & ~(KeyEvent.META_META_ON |
| 3568 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 3569 | if (shortcutIntent != null) { |
| 3570 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3571 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3572 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3573 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3574 | } catch (ActivityNotFoundException ex) { |
| 3575 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3576 | + "the activity to which it is registered was not found: " |
| 3577 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 3578 | } |
| 3579 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3580 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3581 | } |
| 3582 | } |
| 3583 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3584 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3585 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3586 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 3587 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 3588 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3589 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3590 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3591 | startActivityAsUser(intent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3592 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3593 | } catch (ActivityNotFoundException ex) { |
| 3594 | Slog.w(TAG, "Dropping application launch key because " |
| 3595 | + "the activity to which it is registered was not found: " |
| 3596 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 3597 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3598 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3599 | } |
| 3600 | } |
| 3601 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3602 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3603 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Michael Wright | d847ad5 | 2015-10-24 13:24:15 +0100 | [diff] [blame] | 3604 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3605 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3606 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3607 | mRecentAppsHeldModifiers = shiftlessModifiers; |
Winson | 14db362 | 2016-05-09 13:34:07 -0700 | [diff] [blame] | 3608 | showRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3609 | return -1; |
| 3610 | } |
| 3611 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3612 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 3613 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 3614 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3615 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3616 | } |
| 3617 | |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3618 | // Handle input method switching. |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3619 | if (down && repeatCount == 0 |
| 3620 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3621 | || (keyCode == KeyEvent.KEYCODE_SPACE |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3622 | && (metaState & KeyEvent.META_META_MASK) != 0))) { |
| 3623 | final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0; |
| 3624 | mWindowManagerFuncs.switchInputMethod(forwardDirection); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3625 | return -1; |
| 3626 | } |
| 3627 | if (mLanguageSwitchKeyPressed && !down |
| 3628 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3629 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 3630 | mLanguageSwitchKeyPressed = false; |
| 3631 | return -1; |
| 3632 | } |
| 3633 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3634 | if (isValidGlobalKey(keyCode) |
| 3635 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 3636 | return -1; |
| 3637 | } |
| 3638 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3639 | if (down) { |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 3640 | long shortcutCode = keyCode; |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3641 | if (event.isCtrlPressed()) { |
| 3642 | shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE; |
| 3643 | } |
| 3644 | |
| 3645 | if (event.isAltPressed()) { |
| 3646 | shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE; |
| 3647 | } |
| 3648 | |
| 3649 | if (event.isShiftPressed()) { |
| 3650 | shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE; |
| 3651 | } |
| 3652 | |
| 3653 | if (event.isMetaPressed()) { |
| 3654 | shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE; |
| 3655 | } |
| 3656 | |
| 3657 | IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode); |
| 3658 | if (shortcutService != null) { |
| 3659 | try { |
Muyuan Li | b5dd049 | 2016-04-14 13:22:20 -0700 | [diff] [blame] | 3660 | if (isUserSetupComplete()) { |
| 3661 | shortcutService.notifyShortcutKeyPressed(shortcutCode); |
| 3662 | } |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3663 | } catch (RemoteException e) { |
| 3664 | mShortcutKeyServices.delete(shortcutCode); |
| 3665 | } |
| 3666 | return -1; |
| 3667 | } |
| 3668 | } |
| 3669 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3670 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 3671 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3672 | return -1; |
| 3673 | } |
| 3674 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3675 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3676 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3677 | } |
| 3678 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3679 | /** {@inheritDoc} */ |
| 3680 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3681 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3682 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3683 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3684 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 3685 | + ", flags=" + event.getFlags() |
| 3686 | + ", keyCode=" + event.getKeyCode() |
| 3687 | + ", scanCode=" + event.getScanCode() |
| 3688 | + ", metaState=" + event.getMetaState() |
| 3689 | + ", repeatCount=" + event.getRepeatCount() |
| 3690 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3691 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3692 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3693 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3694 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3695 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3696 | final int keyCode = event.getKeyCode(); |
| 3697 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3698 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 3699 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3700 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3701 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3702 | final FallbackAction fallbackAction; |
| 3703 | if (initialDown) { |
| 3704 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 3705 | } else { |
| 3706 | fallbackAction = mFallbackActions.get(keyCode); |
| 3707 | } |
| 3708 | |
| 3709 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3710 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3711 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 3712 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3713 | } |
| 3714 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3715 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 3716 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3717 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3718 | event.getAction(), fallbackAction.keyCode, |
| 3719 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3720 | event.getDeviceId(), event.getScanCode(), |
| 3721 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3722 | |
| 3723 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 3724 | fallbackEvent.recycle(); |
| 3725 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3726 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3727 | |
| 3728 | if (initialDown) { |
| 3729 | mFallbackActions.put(keyCode, fallbackAction); |
| 3730 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 3731 | mFallbackActions.remove(keyCode); |
| 3732 | fallbackAction.recycle(); |
| 3733 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3734 | } |
| 3735 | } |
| 3736 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3737 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3738 | if (fallbackEvent == null) { |
| 3739 | Slog.d(TAG, "No fallback."); |
| 3740 | } else { |
| 3741 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 3742 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3743 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3744 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3745 | } |
| 3746 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3747 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3748 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3749 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 3750 | long delayMillis = interceptKeyBeforeDispatching( |
| 3751 | win, fallbackEvent, policyFlags); |
| 3752 | if (delayMillis == 0) { |
| 3753 | return true; |
| 3754 | } |
| 3755 | } |
| 3756 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3757 | } |
| 3758 | |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 3759 | @Override |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3760 | public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService) |
| 3761 | throws RemoteException { |
| 3762 | synchronized (mLock) { |
| 3763 | IShortcutService service = mShortcutKeyServices.get(shortcutCode); |
Muyuan Li | 24d24ac | 2016-03-03 21:15:02 -0800 | [diff] [blame] | 3764 | if (service != null && service.asBinder().pingBinder()) { |
| 3765 | throw new RemoteException("Key already exists."); |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3766 | } |
| 3767 | |
| 3768 | mShortcutKeyServices.put(shortcutCode, shortcutService); |
| 3769 | } |
| 3770 | } |
| 3771 | |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 3772 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3773 | public void onKeyguardOccludedChangedLw(boolean occluded) { |
| 3774 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
| 3775 | mPendingKeyguardOccluded = occluded; |
| 3776 | mKeyguardOccludedChanged = true; |
| 3777 | } else { |
| 3778 | setKeyguardOccludedLw(occluded); |
| 3779 | } |
| 3780 | } |
| 3781 | |
| 3782 | private int handleStartTransitionForKeyguardLw(int transit, @Nullable Animation anim) { |
| 3783 | if (mKeyguardOccludedChanged) { |
| 3784 | if (DEBUG_KEYGUARD) Slog.d(TAG, "transition/occluded changed occluded=" |
| 3785 | + mPendingKeyguardOccluded); |
| 3786 | mKeyguardOccludedChanged = false; |
| 3787 | if (setKeyguardOccludedLw(mPendingKeyguardOccluded)) { |
| 3788 | return FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3789 | } |
| 3790 | } |
| 3791 | if (AppTransition.isKeyguardGoingAwayTransit(transit)) { |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 3792 | if (DEBUG_KEYGUARD) Slog.d(TAG, "Starting keyguard exit animation"); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3793 | final long startTime = anim != null |
| 3794 | ? SystemClock.uptimeMillis() + anim.getStartOffset() |
| 3795 | : SystemClock.uptimeMillis(); |
| 3796 | final long duration = anim != null |
| 3797 | ? anim.getDuration() |
| 3798 | : 0; |
| 3799 | startKeyguardExitAnimation(startTime, duration); |
| 3800 | } |
| 3801 | return 0; |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 3802 | } |
| 3803 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3804 | private void launchAssistLongPressAction() { |
| 3805 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 3806 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 3807 | |
| 3808 | // launch the search activity |
| 3809 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 3810 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3811 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3812 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 3813 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3814 | SearchManager searchManager = getSearchManager(); |
| 3815 | if (searchManager != null) { |
| 3816 | searchManager.stopSearch(); |
| 3817 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3818 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3819 | } catch (ActivityNotFoundException e) { |
| 3820 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 3821 | } |
| 3822 | } |
| 3823 | |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3824 | private void launchAssistAction(String hint, int deviceId) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3825 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Maurice Lam | 39d1381 | 2015-07-23 20:49:20 -0700 | [diff] [blame] | 3826 | if (!isUserSetupComplete()) { |
| 3827 | // Disable opening assist window during setup |
| 3828 | return; |
| 3829 | } |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3830 | Bundle args = null; |
| 3831 | if (deviceId > Integer.MIN_VALUE) { |
| 3832 | args = new Bundle(); |
| 3833 | args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3834 | } |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 3835 | if ((mContext.getResources().getConfiguration().uiMode |
| 3836 | & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) { |
| 3837 | // On TV, use legacy handling until assistants are implemented in the proper way. |
| 3838 | ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
| 3839 | .launchLegacyAssist(hint, UserHandle.myUserId(), args); |
| 3840 | } else { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3841 | if (hint != null) { |
| 3842 | if (args == null) { |
| 3843 | args = new Bundle(); |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 3844 | } |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3845 | args.putBoolean(hint, true); |
| 3846 | } |
| 3847 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3848 | if (statusbar != null) { |
| 3849 | statusbar.startAssist(args); |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 3850 | } |
| 3851 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3852 | } |
| 3853 | |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3854 | private void startActivityAsUser(Intent intent, UserHandle handle) { |
| 3855 | if (isUserSetupComplete()) { |
| 3856 | mContext.startActivityAsUser(intent, handle); |
| 3857 | } else { |
| 3858 | Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); |
| 3859 | } |
| 3860 | } |
| 3861 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3862 | private SearchManager getSearchManager() { |
| 3863 | if (mSearchManager == null) { |
| 3864 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 3865 | } |
| 3866 | return mSearchManager; |
| 3867 | } |
| 3868 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3869 | private void preloadRecentApps() { |
| 3870 | mPreloadedRecentApps = true; |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3871 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3872 | if (statusbar != null) { |
| 3873 | statusbar.preloadRecentApps(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3874 | } |
| 3875 | } |
| 3876 | |
| 3877 | private void cancelPreloadRecentApps() { |
| 3878 | if (mPreloadedRecentApps) { |
| 3879 | mPreloadedRecentApps = false; |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3880 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3881 | if (statusbar != null) { |
| 3882 | statusbar.cancelPreloadRecentApps(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3883 | } |
| 3884 | } |
| 3885 | } |
| 3886 | |
| 3887 | private void toggleRecentApps() { |
| 3888 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3889 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3890 | if (statusbar != null) { |
| 3891 | statusbar.toggleRecentApps(); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3892 | } |
| 3893 | } |
| 3894 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3895 | @Override |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 3896 | public void showRecentApps(boolean fromHome) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3897 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 3898 | mHandler.obtainMessage(MSG_DISPATCH_SHOW_RECENTS, fromHome ? 1 : 0, 0).sendToTarget(); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3899 | } |
| 3900 | |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 3901 | private void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3902 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3903 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3904 | if (statusbar != null) { |
| 3905 | statusbar.showRecentApps(triggeredFromAltTab, fromHome); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3906 | } |
| 3907 | } |
| 3908 | |
Clara Bayarri | 4e850ff | 2016-03-02 11:12:32 -0800 | [diff] [blame] | 3909 | private void toggleKeyboardShortcutsMenu(int deviceId) { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3910 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3911 | if (statusbar != null) { |
| 3912 | statusbar.toggleKeyboardShortcutsMenu(deviceId); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3913 | } |
| 3914 | } |
| 3915 | |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3916 | private void dismissKeyboardShortcutsMenu() { |
| 3917 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3918 | if (statusbar != null) { |
| 3919 | statusbar.dismissKeyboardShortcutsMenu(); |
| 3920 | } |
| 3921 | } |
| 3922 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3923 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3924 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3925 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3926 | if (statusbar != null) { |
| 3927 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3928 | } |
| 3929 | } |
| 3930 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3931 | void launchHomeFromHotKey() { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3932 | launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3933 | } |
| 3934 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3935 | /** |
| 3936 | * A home key -> launch home action was detected. Take the appropriate action |
| 3937 | * given the situation with the keyguard. |
| 3938 | */ |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3939 | void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) { |
| 3940 | if (respectKeyguard) { |
| 3941 | if (isKeyguardShowingAndNotOccluded()) { |
| 3942 | // don't launch home if keyguard showing |
| 3943 | return; |
| 3944 | } |
| 3945 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3946 | if (!mKeyguardOccluded && mKeyguardDelegate.isInputRestricted()) { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3947 | // when in keyguard restricted mode, must first verify unlock |
| 3948 | // before launching home |
| 3949 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
| 3950 | @Override |
| 3951 | public void onKeyguardExitResult(boolean success) { |
| 3952 | if (success) { |
| 3953 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3954 | ActivityManager.getService().stopAppSwitches(); |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3955 | } catch (RemoteException e) { |
| 3956 | } |
| 3957 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3958 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 3959 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3960 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3961 | }); |
| 3962 | return; |
| 3963 | } |
| 3964 | } |
| 3965 | |
| 3966 | // no keyguard stuff to worry about, just launch home! |
| 3967 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3968 | ActivityManager.getService().stopAppSwitches(); |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3969 | } catch (RemoteException e) { |
| 3970 | } |
| 3971 | if (mRecentsVisible) { |
| 3972 | // Hide Recents and notify it to launch Home |
| 3973 | if (awakenFromDreams) { |
| 3974 | awakenDreams(); |
| 3975 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3976 | hideRecentApps(false, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3977 | } else { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3978 | // Otherwise, just launch Home |
| 3979 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3980 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3981 | } |
| 3982 | } |
| 3983 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3984 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 3985 | @Override |
| 3986 | public void run() { |
| 3987 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 3988 | // Clear flags. |
| 3989 | mForceClearedSystemUiFlags &= |
| 3990 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 3991 | } |
| 3992 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3993 | } |
| 3994 | }; |
| 3995 | |
| 3996 | /** |
| 3997 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 3998 | * to determine when the nav bar should be shown and prevent applications from |
| 3999 | * receiving those touches. |
| 4000 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 4001 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 4002 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 4003 | super(inputChannel, looper); |
| 4004 | } |
| 4005 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4006 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 4007 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4008 | boolean handled = false; |
| 4009 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4010 | if (event instanceof MotionEvent |
| 4011 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 4012 | final MotionEvent motionEvent = (MotionEvent)event; |
| 4013 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4014 | // When the user taps down, we re-show the nav bar. |
| 4015 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4016 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 4017 | if (mInputConsumer == null) { |
| 4018 | return; |
| 4019 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4020 | // Any user activity always causes us to show the |
| 4021 | // navigation controls, if they had been hidden. |
| 4022 | // We also clear the low profile and only content |
| 4023 | // flags so that tapping on the screen will atomically |
| 4024 | // restore all currently hidden screen decorations. |
| 4025 | int newVal = mResettingSystemUiFlags | |
| 4026 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 4027 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 4028 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4029 | if (mResettingSystemUiFlags != newVal) { |
| 4030 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4031 | changed = true; |
| 4032 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4033 | // We don't allow the system's nav bar to be hidden |
| 4034 | // again for 1 second, to prevent applications from |
| 4035 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4036 | newVal = mForceClearedSystemUiFlags | |
| 4037 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4038 | if (mForceClearedSystemUiFlags != newVal) { |
| 4039 | mForceClearedSystemUiFlags = newVal; |
| 4040 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4041 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4042 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4043 | } |
| 4044 | if (changed) { |
| 4045 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 4046 | } |
| 4047 | } |
| 4048 | } |
| 4049 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 4050 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4051 | } |
| 4052 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 4053 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4054 | |
| 4055 | @Override |
Winson | ab21660 | 2016-08-09 14:05:20 -0700 | [diff] [blame] | 4056 | public void setRecentsVisibilityLw(boolean visible) { |
| 4057 | mRecentsVisible = visible; |
| 4058 | } |
| 4059 | |
| 4060 | @Override |
| 4061 | public void setTvPipVisibilityLw(boolean visible) { |
| 4062 | mTvPictureInPictureVisible = visible; |
| 4063 | } |
| 4064 | |
| 4065 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4066 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 4067 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 4068 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4069 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4070 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 4071 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4072 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4073 | // Clear any bits in the new visibility that are currently being |
| 4074 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4075 | return visibility & ~mResettingSystemUiFlags |
| 4076 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4077 | } |
| 4078 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4079 | @Override |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 4080 | public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds, |
| 4081 | int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets, |
| 4082 | Rect outStableInsets, Rect outOutsets) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4083 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 4084 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 4085 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4086 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4087 | final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl); |
| 4088 | if (useOutsets) { |
| 4089 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 4090 | if (outset > 0) { |
| 4091 | if (displayRotation == Surface.ROTATION_0) { |
| 4092 | outOutsets.bottom += outset; |
| 4093 | } else if (displayRotation == Surface.ROTATION_90) { |
| 4094 | outOutsets.right += outset; |
| 4095 | } else if (displayRotation == Surface.ROTATION_180) { |
| 4096 | outOutsets.top += outset; |
| 4097 | } else if (displayRotation == Surface.ROTATION_270) { |
| 4098 | outOutsets.left += outset; |
| 4099 | } |
| 4100 | } |
| 4101 | } |
| 4102 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4103 | 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] | 4104 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4105 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4106 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4107 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4108 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4109 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 4110 | } else { |
| 4111 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 4112 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 4113 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4114 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 4115 | if ((fl & FLAG_FULLSCREEN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4116 | outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4117 | availRight - mStableFullscreenRight, |
| 4118 | availBottom - mStableFullscreenBottom); |
| 4119 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4120 | outContentInsets.set(mStableLeft, mStableTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4121 | availRight - mStableRight, availBottom - mStableBottom); |
| 4122 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4123 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4124 | outContentInsets.setEmpty(); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4125 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4126 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
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 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4130 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4131 | availRight - mCurRight, availBottom - mCurBottom); |
| 4132 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4133 | |
| 4134 | outStableInsets.set(mStableLeft, mStableTop, |
| 4135 | availRight - mStableRight, availBottom - mStableBottom); |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 4136 | if (taskBounds != null) { |
| 4137 | calculateRelevantTaskInsets(taskBounds, outContentInsets, |
| 4138 | displayWidth, displayHeight); |
| 4139 | calculateRelevantTaskInsets(taskBounds, outStableInsets, |
| 4140 | displayWidth, displayHeight); |
| 4141 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 4142 | return mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4143 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4144 | outContentInsets.setEmpty(); |
| 4145 | outStableInsets.setEmpty(); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 4146 | return mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4147 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4148 | |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 4149 | /** |
| 4150 | * For any given task bounds, the insets relevant for these bounds given the insets relevant |
| 4151 | * for the entire display. |
| 4152 | */ |
| 4153 | private void calculateRelevantTaskInsets(Rect taskBounds, Rect inOutInsets, int displayWidth, |
| 4154 | int displayHeight) { |
| 4155 | mTmpRect.set(0, 0, displayWidth, displayHeight); |
| 4156 | mTmpRect.inset(inOutInsets); |
| 4157 | mTmpRect.intersect(taskBounds); |
| 4158 | int leftInset = mTmpRect.left - taskBounds.left; |
| 4159 | int topInset = mTmpRect.top - taskBounds.top; |
| 4160 | int rightInset = taskBounds.right - mTmpRect.right; |
| 4161 | int bottomInset = taskBounds.bottom - mTmpRect.bottom; |
| 4162 | inOutInsets.set(leftInset, topInset, rightInset, bottomInset); |
| 4163 | } |
| 4164 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4165 | private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) { |
| 4166 | return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 4167 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0; |
| 4168 | } |
| 4169 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4170 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4171 | @Override |
| 4172 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 4173 | int displayRotation, int uiMode) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4174 | mDisplayRotation = displayRotation; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4175 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 4176 | if (isDefaultDisplay) { |
| 4177 | switch (displayRotation) { |
| 4178 | case Surface.ROTATION_90: |
| 4179 | overscanLeft = mOverscanTop; |
| 4180 | overscanTop = mOverscanRight; |
| 4181 | overscanRight = mOverscanBottom; |
| 4182 | overscanBottom = mOverscanLeft; |
| 4183 | break; |
| 4184 | case Surface.ROTATION_180: |
| 4185 | overscanLeft = mOverscanRight; |
| 4186 | overscanTop = mOverscanBottom; |
| 4187 | overscanRight = mOverscanLeft; |
| 4188 | overscanBottom = mOverscanTop; |
| 4189 | break; |
| 4190 | case Surface.ROTATION_270: |
| 4191 | overscanLeft = mOverscanBottom; |
| 4192 | overscanTop = mOverscanLeft; |
| 4193 | overscanRight = mOverscanTop; |
| 4194 | overscanBottom = mOverscanRight; |
| 4195 | break; |
| 4196 | default: |
| 4197 | overscanLeft = mOverscanLeft; |
| 4198 | overscanTop = mOverscanTop; |
| 4199 | overscanRight = mOverscanRight; |
| 4200 | overscanBottom = mOverscanBottom; |
| 4201 | break; |
| 4202 | } |
| 4203 | } else { |
| 4204 | overscanLeft = 0; |
| 4205 | overscanTop = 0; |
| 4206 | overscanRight = 0; |
| 4207 | overscanBottom = 0; |
| 4208 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4209 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 4210 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 4211 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 4212 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4213 | mSystemLeft = 0; |
| 4214 | mSystemTop = 0; |
| 4215 | mSystemRight = displayWidth; |
| 4216 | mSystemBottom = displayHeight; |
| 4217 | mUnrestrictedScreenLeft = overscanLeft; |
| 4218 | mUnrestrictedScreenTop = overscanTop; |
| 4219 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 4220 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 4221 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 4222 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4223 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 4224 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4225 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4226 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4227 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4228 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4229 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4230 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4231 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4232 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4233 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 4234 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4235 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4236 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 4237 | final Rect pf = mTmpParentFrame; |
| 4238 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4239 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4240 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4241 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4242 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 4243 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 4244 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 4245 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4246 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4247 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4248 | if (isDefaultDisplay) { |
| 4249 | // For purposes of putting out fake window up to steal focus, we will |
| 4250 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4251 | final int sysui = mLastSystemUiFlags; |
| 4252 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4253 | boolean navTranslucent = (sysui |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4254 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 4255 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 4256 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 4257 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 4258 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4259 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mKeyguardOccluded; |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 4260 | if (!isKeyguardShowing) { |
| 4261 | navTranslucent &= areTranslucentBarsAllowed(); |
| 4262 | } |
Jaewan Kim | 3328433 | 2016-05-12 18:55:46 +0900 | [diff] [blame] | 4263 | boolean statusBarExpandedNotKeyguard = !isKeyguardShowing && mStatusBar != null |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4264 | && mStatusBar.getAttrs().height == MATCH_PARENT |
| 4265 | && mStatusBar.getAttrs().width == MATCH_PARENT; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4266 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4267 | // When the navigation bar isn't visible, we put up a fake |
| 4268 | // input window to catch all touch events. This way we can |
| 4269 | // detect when the user presses anywhere to bring back the nav |
| 4270 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 4271 | if (navVisible || navAllowedHidden) { |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 4272 | if (mInputConsumer != null) { |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 4273 | mHandler.sendMessage( |
| 4274 | mHandler.obtainMessage(MSG_DISPOSE_INPUT_CONSUMER, mInputConsumer)); |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 4275 | mInputConsumer = null; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4276 | } |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 4277 | } else if (mInputConsumer == null) { |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 4278 | mInputConsumer = mWindowManagerFuncs.createInputConsumer(mHandler.getLooper(), |
| 4279 | INPUT_CONSUMER_NAVIGATION, |
| 4280 | (channel, looper) -> new HideNavInputEventReceiver(channel, looper)); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4281 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4282 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4283 | // For purposes of positioning and showing the nav bar, if we have |
| 4284 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 4285 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4286 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4287 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4288 | boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight, |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4289 | displayRotation, uiMode, overscanLeft, overscanRight, overscanBottom, dcf, navVisible, navTranslucent, |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4290 | navAllowedHidden, statusBarExpandedNotKeyguard); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4291 | 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] | 4292 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4293 | updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4294 | if (updateSysUiVisibility) { |
| 4295 | updateSystemUiVisibilityLw(); |
| 4296 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4297 | } |
| 4298 | } |
| 4299 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4300 | private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui, |
| 4301 | boolean isKeyguardShowing) { |
| 4302 | // decide where the status bar goes ahead of time |
| 4303 | if (mStatusBar != null) { |
| 4304 | // apply any navigation bar insets |
| 4305 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4306 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4307 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 4308 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 4309 | + mUnrestrictedScreenTop; |
| 4310 | vf.left = mStableLeft; |
| 4311 | vf.top = mStableTop; |
| 4312 | vf.right = mStableRight; |
| 4313 | vf.bottom = mStableBottom; |
| 4314 | |
| 4315 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 4316 | |
| 4317 | // Let the status bar determine its size. |
| 4318 | mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */, |
| 4319 | vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */, |
| 4320 | dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */); |
| 4321 | |
| 4322 | // For layout, the status bar is always at the top with our fixed height. |
| 4323 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 4324 | |
| 4325 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
| 4326 | boolean statusBarTranslucent = (sysui |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4327 | & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0; |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4328 | if (!isKeyguardShowing) { |
| 4329 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 4330 | } |
| 4331 | |
| 4332 | // If the status bar is hidden, we don't want to cause |
| 4333 | // windows behind it to scroll. |
| 4334 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
| 4335 | // Status bar may go away, so the screen area it occupies |
| 4336 | // is available to apps but just covering them when the |
| 4337 | // status bar is visible. |
| 4338 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 4339 | |
| 4340 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 4341 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 4342 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 4343 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 4344 | |
| 4345 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
| 4346 | String.format( |
| 4347 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 4348 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 4349 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 4350 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 4351 | } |
| 4352 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
| 4353 | && !statusBarTransient && !statusBarTranslucent |
| 4354 | && !mStatusBarController.wasRecentlyTranslucent()) { |
| 4355 | // If the opaque status bar is currently requested to be visible, |
| 4356 | // and not in the process of animating on or off, then |
| 4357 | // we can tell the app that it is covered by it. |
| 4358 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 4359 | } |
| 4360 | if (mStatusBarController.checkHiddenLw()) { |
| 4361 | return true; |
| 4362 | } |
| 4363 | } |
| 4364 | return false; |
| 4365 | } |
| 4366 | |
| 4367 | private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation, |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4368 | int uiMode, int overscanLeft, int overscanRight, int overscanBottom, Rect dcf, |
| 4369 | boolean navVisible, boolean navTranslucent, boolean navAllowedHidden, |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4370 | boolean statusBarExpandedNotKeyguard) { |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4371 | if (mNavigationBar != null) { |
| 4372 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
| 4373 | // Force the navigation bar to its appropriate place and |
| 4374 | // size. We need to do this directly, instead of relying on |
| 4375 | // it to bubble up from the nav bar, because this needs to |
| 4376 | // change atomically with screen rotations. |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4377 | mNavigationBarPosition = navigationBarPosition(displayWidth, displayHeight, |
| 4378 | displayRotation); |
| 4379 | if (mNavigationBarPosition == NAV_BAR_BOTTOM) { |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4380 | // It's a system nav bar or a portrait screen; nav bar goes on bottom. |
| 4381 | int top = displayHeight - overscanBottom |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 4382 | - getNavigationBarHeight(displayRotation, uiMode); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4383 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
| 4384 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
| 4385 | if (transientNavBarShowing) { |
| 4386 | mNavigationBarController.setBarShowingLw(true); |
| 4387 | } else if (navVisible) { |
| 4388 | mNavigationBarController.setBarShowingLw(true); |
| 4389 | mDockBottom = mTmpNavigationFrame.top; |
| 4390 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 4391 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
| 4392 | } else { |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4393 | // We currently want to hide the navigation UI - unless we expanded the status |
| 4394 | // bar. |
| 4395 | mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4396 | } |
| 4397 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4398 | && !mNavigationBar.isAnimatingLw() |
| 4399 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4400 | // If the opaque nav bar is currently requested to be visible, |
| 4401 | // and not in the process of animating on or off, then |
| 4402 | // we can tell the app that it is covered by it. |
| 4403 | mSystemBottom = mTmpNavigationFrame.top; |
| 4404 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4405 | } else if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4406 | // Landscape screen; nav bar goes to the right. |
| 4407 | int left = displayWidth - overscanRight |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 4408 | - getNavigationBarWidth(displayRotation, uiMode); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4409 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
| 4410 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
| 4411 | if (transientNavBarShowing) { |
| 4412 | mNavigationBarController.setBarShowingLw(true); |
| 4413 | } else if (navVisible) { |
| 4414 | mNavigationBarController.setBarShowingLw(true); |
| 4415 | mDockRight = mTmpNavigationFrame.left; |
| 4416 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 4417 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
| 4418 | } else { |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4419 | // We currently want to hide the navigation UI - unless we expanded the status |
| 4420 | // bar. |
| 4421 | mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4422 | } |
| 4423 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4424 | && !mNavigationBar.isAnimatingLw() |
| 4425 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4426 | // If the nav bar is currently requested to be visible, |
| 4427 | // and not in the process of animating on or off, then |
| 4428 | // we can tell the app that it is covered by it. |
| 4429 | mSystemRight = mTmpNavigationFrame.left; |
| 4430 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4431 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
| 4432 | // Seascape screen; nav bar goes to the left. |
| 4433 | int right = overscanLeft + getNavigationBarWidth(displayRotation, uiMode); |
| 4434 | mTmpNavigationFrame.set(overscanLeft, 0, right, displayHeight); |
| 4435 | mStableLeft = mStableFullscreenLeft = mTmpNavigationFrame.right; |
| 4436 | if (transientNavBarShowing) { |
| 4437 | mNavigationBarController.setBarShowingLw(true); |
| 4438 | } else if (navVisible) { |
| 4439 | mNavigationBarController.setBarShowingLw(true); |
| 4440 | mDockLeft = mTmpNavigationFrame.right; |
| 4441 | // TODO: not so sure about those: |
| 4442 | mRestrictedScreenLeft = mRestrictedOverscanScreenLeft = mDockLeft; |
| 4443 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 4444 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
| 4445 | } else { |
| 4446 | // We currently want to hide the navigation UI - unless we expanded the status |
| 4447 | // bar. |
| 4448 | mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard); |
| 4449 | } |
| 4450 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4451 | && !mNavigationBar.isAnimatingLw() |
| 4452 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4453 | // If the nav bar is currently requested to be visible, |
| 4454 | // and not in the process of animating on or off, then |
| 4455 | // we can tell the app that it is covered by it. |
| 4456 | mSystemLeft = mTmpNavigationFrame.right; |
| 4457 | } |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4458 | } |
| 4459 | // Make sure the content and current rectangles are updated to |
| 4460 | // account for the restrictions from the navigation bar. |
| 4461 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 4462 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 4463 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 4464 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 4465 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 4466 | // And compute the final frame. |
| 4467 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
| 4468 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
| 4469 | mTmpNavigationFrame, mTmpNavigationFrame); |
| 4470 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
| 4471 | if (mNavigationBarController.checkHiddenLw()) { |
| 4472 | return true; |
| 4473 | } |
| 4474 | } |
| 4475 | return false; |
| 4476 | } |
| 4477 | |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4478 | private int navigationBarPosition(int displayWidth, int displayHeight, int displayRotation) { |
| 4479 | if (mNavigationBarCanMove && displayWidth > displayHeight) { |
| 4480 | if (displayRotation == Surface.ROTATION_270) { |
| 4481 | return NAV_BAR_LEFT; |
| 4482 | } else { |
| 4483 | return NAV_BAR_RIGHT; |
| 4484 | } |
| 4485 | } |
| 4486 | return NAV_BAR_BOTTOM; |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 4487 | } |
| 4488 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 4489 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 4490 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4491 | public int getSystemDecorLayerLw() { |
Bryce Lee | 2ed3e5f | 2015-04-01 22:09:19 +0000 | [diff] [blame] | 4492 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 4493 | return mStatusBar.getSurfaceLayer(); |
| 4494 | } |
| 4495 | |
| 4496 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { |
| 4497 | return mNavigationBar.getSurfaceLayer(); |
| 4498 | } |
| 4499 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 4500 | return 0; |
| 4501 | } |
| 4502 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 4503 | @Override |
| 4504 | public void getContentRectLw(Rect r) { |
| 4505 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 4506 | } |
| 4507 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4508 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 4509 | 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] | 4510 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 4511 | // Here's a special case: if this attached window is a panel that is |
| 4512 | // above the dock window, and the window it is attached to is below |
| 4513 | // the dock window, then the frames we computed for the window it is |
| 4514 | // attached to can not be used because the dock is effectively part |
| 4515 | // of the underlying window and the attached window is floating on top |
| 4516 | // of the whole thing. So, we ignore the attached window and explicitly |
| 4517 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4518 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 4519 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 4520 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 4521 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4522 | } else { |
| 4523 | // The effective display frame of the attached window depends on |
| 4524 | // whether it is taking care of insetting its content. If not, |
| 4525 | // we need to use the parent's content frame so that the entire |
| 4526 | // window is positioned within that content. Otherwise we can use |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 4527 | // 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] | 4528 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4529 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 4530 | // Set the content frame of the attached window to the parent's decor frame |
| 4531 | // (same as content frame when IME isn't present) if specifically requested by |
| 4532 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 4533 | // Otherwise, use the overscan frame. |
| 4534 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
| 4535 | ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4536 | } else { |
| 4537 | // If the window is resizing, then we want to base the content |
| 4538 | // frame on our attached content frame to resize... however, |
| 4539 | // things can be tricky if the attached window is NOT in resize |
| 4540 | // mode, in which case its content frame will be larger. |
| 4541 | // Ungh. So to deal with that, make sure the content frame |
| 4542 | // we end up using is not covering the IM dock. |
| 4543 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4544 | if (attached.isVoiceInteraction()) { |
| 4545 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 4546 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 4547 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 4548 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 4549 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4550 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 4551 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 4552 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 4553 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 4554 | } |
| 4555 | } |
| 4556 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4557 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4558 | vf.set(attached.getVisibleFrameLw()); |
| 4559 | } |
| 4560 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 4561 | // window should be positioned relative to its parent or the entire |
| 4562 | // screen. |
| 4563 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 4564 | ? attached.getFrameLw() : df); |
| 4565 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4566 | |
| 4567 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 4568 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 4569 | // If app is requesting a stable layout, don't let the |
| 4570 | // content insets go below the stable values. |
| 4571 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 4572 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 4573 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 4574 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 4575 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 4576 | } else { |
| 4577 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 4578 | if (r.top < mStableTop) r.top = mStableTop; |
| 4579 | if (r.right > mStableRight) r.right = mStableRight; |
| 4580 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 4581 | } |
| 4582 | } |
| 4583 | } |
| 4584 | |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4585 | private boolean canReceiveInput(WindowState win) { |
| 4586 | boolean notFocusable = |
| 4587 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0; |
| 4588 | boolean altFocusableIm = |
| 4589 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0; |
| 4590 | boolean notFocusableForIm = notFocusable ^ altFocusableIm; |
| 4591 | return !notFocusableForIm; |
| 4592 | } |
| 4593 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4594 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4595 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4596 | public void layoutWindowLw(WindowState win, WindowState attached) { |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4597 | // We've already done the navigation bar and status bar. If the status bar can receive |
| 4598 | // input, we need to layout it again to accomodate for the IME window. |
| 4599 | if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4600 | return; |
| 4601 | } |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4602 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4603 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 4604 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4605 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 4606 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4607 | 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] | 4608 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 4609 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4610 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4611 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 4612 | final int pfl = attrs.privateFlags; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4613 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 4614 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4615 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4616 | final Rect pf = mTmpParentFrame; |
| 4617 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4618 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4619 | final Rect cf = mTmpContentFrame; |
| 4620 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4621 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4622 | final Rect sf = mTmpStableFrame; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4623 | Rect osf = null; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4624 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4625 | |
| 4626 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 4627 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4628 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 4629 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 4630 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4631 | if (isDefaultDisplay) { |
| 4632 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 4633 | } else { |
| 4634 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 4635 | } |
| 4636 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4637 | if (!isDefaultDisplay) { |
| 4638 | if (attached != null) { |
| 4639 | // If this window is attached to another, our display |
| 4640 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4641 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4642 | } else { |
| 4643 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4644 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4645 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4646 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4647 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4648 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4649 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4650 | } |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4651 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4652 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 4653 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 4654 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 4655 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 4656 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 4657 | // ...with content insets above the nav bar |
| 4658 | cf.bottom = vf.bottom = mStableBottom; |
Adrian Roos | dd654ea | 2016-05-27 11:46:10 -0700 | [diff] [blame] | 4659 | if (mStatusBar != null && mFocusedWindow == mStatusBar && canReceiveInput(mStatusBar)) { |
| 4660 | // The status bar forces the navigation bar while it's visible. Make sure the IME |
| 4661 | // avoids the navigation bar in that case. |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4662 | if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
| 4663 | pf.right = df.right = of.right = cf.right = vf.right = mStableRight; |
| 4664 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
| 4665 | pf.left = df.left = of.left = cf.left = vf.left = mStableLeft; |
| 4666 | } |
Adrian Roos | dd654ea | 2016-05-27 11:46:10 -0700 | [diff] [blame] | 4667 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4668 | // IM dock windows always go to the bottom of the screen. |
| 4669 | attrs.gravity = Gravity.BOTTOM; |
| 4670 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4671 | } else if (attrs.type == TYPE_VOICE_INTERACTION) { |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4672 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4673 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4674 | pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4675 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Jorim Jaggi | 4b74f4d | 2016-04-27 18:44:08 -0700 | [diff] [blame] | 4676 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 4677 | cf.left = mDockLeft; |
| 4678 | cf.top = mDockTop; |
| 4679 | cf.right = mDockRight; |
| 4680 | cf.bottom = mDockBottom; |
| 4681 | } else { |
| 4682 | cf.left = mContentLeft; |
| 4683 | cf.top = mContentTop; |
| 4684 | cf.right = mContentRight; |
| 4685 | cf.bottom = mContentBottom; |
| 4686 | } |
| 4687 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4688 | vf.left = mCurLeft; |
| 4689 | vf.top = mCurTop; |
| 4690 | vf.right = mCurRight; |
| 4691 | vf.bottom = mCurBottom; |
| 4692 | } else { |
| 4693 | vf.set(cf); |
| 4694 | } |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 4695 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 4696 | layoutWallpaper(win, pf, df, of, cf); |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4697 | } else if (win == mStatusBar) { |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 4698 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4699 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4700 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 4701 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 4702 | cf.left = vf.left = mStableLeft; |
| 4703 | cf.top = vf.top = mStableTop; |
| 4704 | cf.right = vf.right = mStableRight; |
| 4705 | vf.bottom = mStableBottom; |
Adrian Roos | dc5b453 | 2016-01-06 20:49:41 +0100 | [diff] [blame] | 4706 | |
| 4707 | if (adjust == SOFT_INPUT_ADJUST_RESIZE) { |
| 4708 | cf.bottom = mContentBottom; |
| 4709 | } else { |
| 4710 | cf.bottom = mDockBottom; |
| 4711 | vf.bottom = mContentBottom; |
| 4712 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4713 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4714 | |
| 4715 | // Default policy decor for the default display |
| 4716 | dcf.left = mSystemLeft; |
| 4717 | dcf.top = mSystemTop; |
| 4718 | dcf.right = mSystemRight; |
| 4719 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4720 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 4721 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 4722 | final boolean isAppWindow = |
| 4723 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 4724 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 4725 | final boolean topAtRest = |
| 4726 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 4727 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4728 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 4729 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4730 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 4731 | && (fl & WindowManager.LayoutParams. |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4732 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0 |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 4733 | && (pfl & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4734 | // Ensure policy decor includes status bar |
| 4735 | dcf.top = mStableTop; |
| 4736 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4737 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4738 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 4739 | && (fl & WindowManager.LayoutParams. |
| 4740 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4741 | // Ensure policy decor includes navigation bar |
| 4742 | dcf.bottom = mStableBottom; |
| 4743 | dcf.right = mStableRight; |
| 4744 | } |
| 4745 | } |
| 4746 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4747 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 4748 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4749 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4750 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4751 | // This is the case for a normal activity window: we want it |
| 4752 | // to cover all of the screen space, and it can take care of |
| 4753 | // moving its contents to account for screen decorations that |
| 4754 | // intrude into that space. |
| 4755 | if (attached != null) { |
| 4756 | // If this window is attached to another, our display |
| 4757 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4758 | 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] | 4759 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4760 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 4761 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4762 | // Status bar panels are the only windows who can go on top of |
| 4763 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 4764 | // permission, so they have the same privileges as the status |
| 4765 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4766 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4767 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4768 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4769 | pf.left = df.left = of.left = hasNavBar |
| 4770 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 4771 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4772 | pf.right = df.right = of.right = hasNavBar |
| 4773 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 4774 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4775 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 4776 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 4777 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4778 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4779 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4780 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 4781 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4782 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4783 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4784 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4785 | // Asking to layout into the overscan region, so give it that pure |
| 4786 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4787 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 4788 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 4789 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4790 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 4791 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4792 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4793 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4794 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4795 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4796 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4797 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4798 | // only do this for application windows to ensure no window that |
| 4799 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4800 | pf.left = df.left = mOverscanScreenLeft; |
| 4801 | pf.top = df.top = mOverscanScreenTop; |
| 4802 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4803 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4804 | // We need to tell the app about where the frame inside the overscan |
| 4805 | // is, so it can inset its content by that amount -- it didn't ask |
| 4806 | // to actually extend itself into the overscan region. |
| 4807 | of.left = mUnrestrictedScreenLeft; |
| 4808 | of.top = mUnrestrictedScreenTop; |
| 4809 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4810 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4811 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4812 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 4813 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 4814 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 4815 | + mRestrictedOverscanScreenWidth; |
| 4816 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 4817 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4818 | // We need to tell the app about where the frame inside the overscan |
| 4819 | // is, so it can inset its content by that amount -- it didn't ask |
| 4820 | // to actually extend itself into the overscan region. |
| 4821 | of.left = mUnrestrictedScreenLeft; |
| 4822 | of.top = mUnrestrictedScreenTop; |
| 4823 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4824 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4825 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4826 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4827 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4828 | if (win.isVoiceInteraction()) { |
| 4829 | cf.left = mVoiceContentLeft; |
| 4830 | cf.top = mVoiceContentTop; |
| 4831 | cf.right = mVoiceContentRight; |
| 4832 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4833 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4834 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 4835 | cf.left = mDockLeft; |
| 4836 | cf.top = mDockTop; |
| 4837 | cf.right = mDockRight; |
| 4838 | cf.bottom = mDockBottom; |
| 4839 | } else { |
| 4840 | cf.left = mContentLeft; |
| 4841 | cf.top = mContentTop; |
| 4842 | cf.right = mContentRight; |
| 4843 | cf.bottom = mContentBottom; |
| 4844 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4845 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4846 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4847 | // Full screen windows are always given a layout that is as if the |
| 4848 | // status bar and other transient decors are gone. This is to avoid |
| 4849 | // bad states when moving from a window that is not hding the |
| 4850 | // status bar to one that is. |
| 4851 | cf.left = mRestrictedScreenLeft; |
| 4852 | cf.top = mRestrictedScreenTop; |
| 4853 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 4854 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4855 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4856 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4857 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4858 | vf.left = mCurLeft; |
| 4859 | vf.top = mCurTop; |
| 4860 | vf.right = mCurRight; |
| 4861 | vf.bottom = mCurBottom; |
| 4862 | } else { |
| 4863 | vf.set(cf); |
| 4864 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4865 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4866 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 4867 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 4868 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4869 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4870 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4871 | // A window that has requested to fill the entire screen just |
| 4872 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4873 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4874 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL |
| 4875 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4876 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 4877 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 4878 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 4879 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4880 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4881 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4882 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4883 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4884 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4885 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 4886 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 4887 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 4888 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 4889 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4890 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4891 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4892 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4893 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 4894 | + mUnrestrictedScreenWidth; |
| 4895 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 4896 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4897 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4898 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 4899 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 4900 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 4901 | || attrs.type == TYPE_BOOT_PROGRESS |
| 4902 | || attrs.type == TYPE_SCREENSHOT) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 4903 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 4904 | // Fullscreen secure system overlays get what they ask for. Screenshot region |
| 4905 | // selection overlay should also expand to full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4906 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4907 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4908 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 4909 | + mOverscanScreenWidth; |
| 4910 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 4911 | + mOverscanScreenHeight; |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 4912 | } else if (attrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 4913 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4914 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4915 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4916 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 4917 | + mOverscanScreenWidth; |
| 4918 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 4919 | + mOverscanScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4920 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4921 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4922 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4923 | // Asking to layout into the overscan region, so give it that pure |
| 4924 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4925 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4926 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4927 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4928 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4929 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4930 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4931 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4932 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 4933 | && (attrs.type == TYPE_STATUS_BAR |
| 4934 | || attrs.type == TYPE_TOAST |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 4935 | || attrs.type == TYPE_DOCK_DIVIDER |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 4936 | || attrs.type == TYPE_VOICE_INTERACTION_STARTING |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 4937 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4938 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4939 | // Asking for layout as if the nav bar is hidden, lets the |
| 4940 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 4941 | // 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] | 4942 | // can be above the nav bar can do this. |
| 4943 | // XXX This assumes that an app asking for this will also |
| 4944 | // ask for layout in only content. We can't currently figure out |
| 4945 | // 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] | 4946 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 4947 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 4948 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 4949 | + mUnrestrictedScreenWidth; |
| 4950 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 4951 | + mUnrestrictedScreenHeight; |
Jorim Jaggi | 9f6798a | 2016-02-10 22:16:06 -0800 | [diff] [blame] | 4952 | } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) { |
| 4953 | pf.left = df.left = of.left = mRestrictedScreenLeft; |
| 4954 | pf.top = df.top = of.top = mRestrictedScreenTop; |
| 4955 | pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 4956 | pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop |
| 4957 | + mRestrictedScreenHeight; |
| 4958 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 4959 | cf.left = mDockLeft; |
| 4960 | cf.top = mDockTop; |
| 4961 | cf.right = mDockRight; |
| 4962 | cf.bottom = mDockBottom; |
| 4963 | } else { |
| 4964 | cf.left = mContentLeft; |
| 4965 | cf.top = mContentTop; |
| 4966 | cf.right = mContentRight; |
| 4967 | cf.bottom = mContentBottom; |
| 4968 | } |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4969 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4970 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4971 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4972 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4973 | + mRestrictedScreenWidth; |
| 4974 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4975 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4976 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4977 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4978 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4979 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4980 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4981 | vf.left = mCurLeft; |
| 4982 | vf.top = mCurTop; |
| 4983 | vf.right = mCurRight; |
| 4984 | vf.bottom = mCurBottom; |
| 4985 | } else { |
| 4986 | vf.set(cf); |
| 4987 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4988 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4989 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4990 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4991 | // A child window should be placed inside of the same visible |
| 4992 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4993 | 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] | 4994 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4995 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4996 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4997 | // Otherwise, a normal window must be placed inside the content |
| 4998 | // of all screen decorations. |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4999 | if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 5000 | // Status bar panels and the volume dialog are the only windows who can go on |
| 5001 | // 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] | 5002 | // permission, so they have the same privileges as the status |
| 5003 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5004 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 5005 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 5006 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 5007 | + mRestrictedScreenWidth; |
| 5008 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 5009 | + mRestrictedScreenHeight; |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 5010 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) { |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 5011 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5012 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 5013 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 5014 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 5015 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5016 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 5017 | pf.left = mContentLeft; |
| 5018 | pf.top = mContentTop; |
| 5019 | pf.right = mContentRight; |
| 5020 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 5021 | if (win.isVoiceInteraction()) { |
| 5022 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 5023 | df.top = of.top = cf.top = mVoiceContentTop; |
| 5024 | df.right = of.right = cf.right = mVoiceContentRight; |
| 5025 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 5026 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5027 | df.left = of.left = cf.left = mDockLeft; |
| 5028 | df.top = of.top = cf.top = mDockTop; |
| 5029 | df.right = of.right = cf.right = mDockRight; |
| 5030 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 5031 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5032 | df.left = of.left = cf.left = mContentLeft; |
| 5033 | df.top = of.top = cf.top = mContentTop; |
| 5034 | df.right = of.right = cf.right = mContentRight; |
| 5035 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 5036 | } |
| 5037 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 5038 | vf.left = mCurLeft; |
| 5039 | vf.top = mCurTop; |
| 5040 | vf.right = mCurRight; |
| 5041 | vf.bottom = mCurBottom; |
| 5042 | } else { |
| 5043 | vf.set(cf); |
| 5044 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 5045 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5046 | } |
| 5047 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5048 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 5049 | // 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] | 5050 | // Also, we don't allow windows in multi-window mode to extend out of the screen. |
| 5051 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 5052 | && !win.isInMultiWindowMode()) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 5053 | df.left = df.top = -10000; |
| 5054 | df.right = df.bottom = 10000; |
| 5055 | if (attrs.type != TYPE_WALLPAPER) { |
| 5056 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 5057 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 5058 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5059 | } |
| 5060 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5061 | // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we |
| 5062 | // 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] | 5063 | // We only want to apply outsets to certain types of windows. For example, we never want to |
| 5064 | // 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] | 5065 | final boolean useOutsets = shouldUseOutsets(attrs, fl); |
Filip Gruszczynski | b0c673b | 2015-06-05 09:43:06 -0700 | [diff] [blame] | 5066 | if (isDefaultDisplay && useOutsets) { |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5067 | osf = mTmpOutsetFrame; |
| 5068 | osf.set(cf.left, cf.top, cf.right, cf.bottom); |
| 5069 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 5070 | if (outset > 0) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 5071 | int rotation = mDisplayRotation; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5072 | if (rotation == Surface.ROTATION_0) { |
| 5073 | osf.bottom += outset; |
| 5074 | } else if (rotation == Surface.ROTATION_90) { |
| 5075 | osf.right += outset; |
| 5076 | } else if (rotation == Surface.ROTATION_180) { |
| 5077 | osf.top -= outset; |
| 5078 | } else if (rotation == Surface.ROTATION_270) { |
| 5079 | osf.left -= outset; |
| 5080 | } |
| 5081 | if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset |
| 5082 | + " with rotation " + rotation + ", result: " + osf); |
| 5083 | } |
| 5084 | } |
| 5085 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5086 | 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] | 5087 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5088 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 5089 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 5090 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5091 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5092 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5093 | + " dcf=" + dcf.toShortString() |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5094 | + " sf=" + sf.toShortString() |
| 5095 | + " osf=" + (osf == null ? "null" : osf.toShortString())); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5096 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5097 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5098 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5099 | // Dock windows carve out the bottom of the screen, so normal windows |
| 5100 | // can't appear underneath them. |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5101 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleLw() |
| 5102 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5103 | setLastInputMethodWindowLw(null, null); |
| 5104 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5105 | } |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5106 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleLw() |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5107 | && !win.getGivenInsetsPendingLw()) { |
| 5108 | offsetVoiceInputWindowLw(win); |
| 5109 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5110 | } |
| 5111 | |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 5112 | private void layoutWallpaper(WindowState win, Rect pf, Rect df, Rect of, Rect cf) { |
| 5113 | |
| 5114 | // The wallpaper also has Real Ultimate Power, but we want to tell |
| 5115 | // it about the overscan area. |
| 5116 | pf.left = df.left = mOverscanScreenLeft; |
| 5117 | pf.top = df.top = mOverscanScreenTop; |
| 5118 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 5119 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
| 5120 | of.left = cf.left = mUnrestrictedScreenLeft; |
| 5121 | of.top = cf.top = mUnrestrictedScreenTop; |
| 5122 | of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 5123 | of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 5124 | } |
| 5125 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5126 | private void offsetInputMethodWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 5127 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5128 | top += win.getGivenContentInsetsLw().top; |
| 5129 | if (mContentBottom > top) { |
| 5130 | mContentBottom = top; |
| 5131 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5132 | if (mVoiceContentBottom > top) { |
| 5133 | mVoiceContentBottom = top; |
| 5134 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5135 | top = win.getVisibleFrameLw().top; |
| 5136 | top += win.getGivenVisibleInsetsLw().top; |
| 5137 | if (mCurBottom > top) { |
| 5138 | mCurBottom = top; |
| 5139 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5140 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5141 | + mDockBottom + " mContentBottom=" |
| 5142 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 5143 | } |
| 5144 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5145 | private void offsetVoiceInputWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 5146 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 5147 | top += win.getGivenContentInsetsLw().top; |
| 5148 | if (mVoiceContentBottom > top) { |
| 5149 | mVoiceContentBottom = top; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5150 | } |
| 5151 | } |
| 5152 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5153 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 5154 | @Override |
| 5155 | public void finishLayoutLw() { |
| 5156 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5160 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 5161 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5162 | mTopFullscreenOpaqueWindowState = null; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 5163 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5164 | mTopDockedOpaqueWindowState = null; |
| 5165 | mTopDockedOpaqueOrDimmingWindowState = null; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5166 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5167 | mForceStatusBarFromKeyguard = false; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 5168 | mForceStatusBarTransparent = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5169 | mForcingShowNavBar = false; |
| 5170 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5171 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5172 | mAllowLockscreenWhenOn = false; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5173 | mShowingDream = false; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5174 | } |
| 5175 | |
| 5176 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5177 | @Override |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 5178 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs, |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5179 | WindowState attached, WindowState imeTarget) { |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5180 | final boolean visible = win.isVisibleLw(); |
| 5181 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisible=" + visible); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5182 | applyKeyguardPolicyLw(win, imeTarget); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5183 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5184 | if (mTopFullscreenOpaqueWindowState == null && visible && attrs.type == TYPE_INPUT_METHOD) { |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 5185 | mForcingShowNavBar = true; |
| 5186 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5187 | } |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 5188 | if (attrs.type == TYPE_STATUS_BAR) { |
| 5189 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 5190 | mForceStatusBarFromKeyguard = true; |
| 5191 | } |
| 5192 | if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) { |
| 5193 | mForceStatusBarTransparent = true; |
| 5194 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 5195 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 5196 | |
| 5197 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
| 5198 | && attrs.type < FIRST_SYSTEM_WINDOW; |
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 | } |
| 6458 | } |
| 6459 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6460 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6461 | @Override |
| 6462 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6463 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6464 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6465 | updateScreenOffSleepToken(false); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6466 | synchronized (mLock) { |
| 6467 | mScreenOnEarly = true; |
| 6468 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 6469 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6470 | mWindowManagerDrawComplete = false; |
| 6471 | mScreenOnListener = screenOnListener; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6472 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6473 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | a4b51bc | 2015-08-10 18:20:43 -0700 | [diff] [blame] | 6474 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 6475 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6476 | mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback); |
| 6477 | } else { |
| 6478 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 6479 | "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
| 6480 | finishKeyguardDrawn(); |
| 6481 | } |
| 6482 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6483 | } |
| 6484 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 6485 | // Called on the DisplayManager's DisplayPowerController thread. |
| 6486 | @Override |
| 6487 | public void screenTurnedOn() { |
| 6488 | synchronized (mLock) { |
| 6489 | if (mKeyguardDelegate != null) { |
| 6490 | mKeyguardDelegate.onScreenTurnedOn(); |
| 6491 | } |
| 6492 | } |
| 6493 | } |
| 6494 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6495 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6496 | synchronized (mLock) { |
| 6497 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6498 | 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] | 6499 | } |
| 6500 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6501 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6502 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6503 | |
| 6504 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6505 | } |
| 6506 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 6507 | private void finishScreenTurningOn() { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6508 | synchronized (mLock) { |
| 6509 | // We have just finished drawing screen content. Since the orientation listener |
| 6510 | // gets only installed when all windows are drawn, we try to install it again. |
| 6511 | updateOrientationListenerLp(); |
| 6512 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6513 | final ScreenOnListener listener; |
| 6514 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6515 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6516 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 6517 | "finishScreenTurningOn: mAwake=" + mAwake |
| 6518 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 6519 | + ", mScreenOnFully=" + mScreenOnFully |
| 6520 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 6521 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 6522 | |
| 6523 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 6524 | || (mAwake && !mKeyguardDrawComplete)) { |
| 6525 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6526 | } |
| 6527 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6528 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 6529 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 6530 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6531 | mScreenOnFully = true; |
| 6532 | |
| 6533 | // Remember the first time we draw the keyguard so we know when we're done with |
| 6534 | // the main part of booting and can enable the screen and hide boot messages. |
| 6535 | if (!mKeyguardDrawnOnce && mAwake) { |
| 6536 | mKeyguardDrawnOnce = true; |
| 6537 | enableScreen = true; |
| 6538 | if (mBootMessageNeedsHiding) { |
| 6539 | mBootMessageNeedsHiding = false; |
| 6540 | hideBootMessages(); |
| 6541 | } |
| 6542 | } else { |
| 6543 | enableScreen = false; |
| 6544 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6545 | } |
| 6546 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6547 | if (listener != null) { |
| 6548 | listener.onScreenOn(); |
| 6549 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 6550 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6551 | if (enableScreen) { |
| 6552 | try { |
| 6553 | mWindowManager.enableScreenIfNeeded(); |
| 6554 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6555 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6556 | } |
| 6557 | } |
| 6558 | |
| 6559 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6560 | synchronized (mLock) { |
| 6561 | if (!mKeyguardDrawnOnce) { |
| 6562 | mBootMessageNeedsHiding = true; |
| 6563 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 6564 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6565 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6566 | |
| 6567 | if (mBootMsgDialog != null) { |
| 6568 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 6569 | mBootMsgDialog.dismiss(); |
| 6570 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6571 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6572 | } |
| 6573 | |
| 6574 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6575 | public boolean isScreenOn() { |
| 6576 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 6577 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6578 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 6579 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6580 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6581 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6582 | if (mKeyguardDelegate != null) { |
| 6583 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6584 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6585 | } |
| 6586 | |
| 6587 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6588 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6589 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6590 | if (mKeyguardDelegate != null) { |
| 6591 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6592 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6593 | } |
| 6594 | |
Tony Mak | 2c0d6dc | 2016-04-29 16:16:54 +0100 | [diff] [blame] | 6595 | @Override |
| 6596 | public boolean isKeyguardShowingAndNotOccluded() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6597 | if (mKeyguardDelegate == null) return false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6598 | return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6599 | } |
| 6600 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 6601 | @Override |
| 6602 | public boolean isKeyguardTrustedLw() { |
| 6603 | if (mKeyguardDelegate == null) return false; |
| 6604 | return mKeyguardDelegate.isTrusted(); |
| 6605 | } |
| 6606 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6607 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6608 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6609 | public boolean isKeyguardLocked() { |
| 6610 | return keyguardOn(); |
| 6611 | } |
| 6612 | |
| 6613 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6614 | @Override |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 6615 | public boolean isKeyguardSecure(int userId) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6616 | if (mKeyguardDelegate == null) return false; |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 6617 | return mKeyguardDelegate.isSecure(userId); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6618 | } |
| 6619 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6620 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6621 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 6622 | public boolean isKeyguardOccluded() { |
| 6623 | if (mKeyguardDelegate == null) return false; |
| 6624 | return mKeyguardOccluded; |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 6625 | } |
| 6626 | |
| 6627 | /** {@inheritDoc} */ |
| 6628 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6629 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6630 | if (mKeyguardDelegate == null) return false; |
| 6631 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6632 | } |
| 6633 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6634 | @Override |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 6635 | public void dismissKeyguardLw(IKeyguardDismissCallback callback) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 6636 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 6637 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 6638 | |
| 6639 | // ask the keyguard to prompt the user to authenticate if necessary |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 6640 | mKeyguardDelegate.dismiss(callback); |
| 6641 | } else if (callback != null) { |
| 6642 | try { |
| 6643 | callback.onDismissError(); |
| 6644 | } catch (RemoteException e) { |
| 6645 | Slog.w(TAG, "Failed to call callback", e); |
| 6646 | } |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 6647 | } |
| 6648 | } |
| 6649 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 6650 | @Override |
| 6651 | public boolean isKeyguardDrawnLw() { |
| 6652 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6653 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 6654 | } |
| 6655 | } |
| 6656 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6657 | @Override |
Jorim Jaggi | 77e1043 | 2016-10-26 17:43:56 -0700 | [diff] [blame] | 6658 | public boolean isShowingDreamLw() { |
| 6659 | return mShowingDream; |
| 6660 | } |
| 6661 | |
| 6662 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 6663 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6664 | if (mKeyguardDelegate != null) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 6665 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 6666 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6667 | } |
| 6668 | } |
| 6669 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6670 | @Override |
| 6671 | public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
| 6672 | Rect outInsets) { |
| 6673 | outInsets.setEmpty(); |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 6674 | |
| 6675 | // Navigation bar and status bar. |
| 6676 | getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6677 | if (mStatusBar != null) { |
| 6678 | outInsets.top = mStatusBarHeight; |
| 6679 | } |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 6680 | } |
| 6681 | |
| 6682 | @Override |
| 6683 | public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
| 6684 | Rect outInsets) { |
| 6685 | outInsets.setEmpty(); |
| 6686 | |
| 6687 | // Only navigation bar |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6688 | if (mNavigationBar != null) { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 6689 | int position = navigationBarPosition(displayWidth, displayHeight, displayRotation); |
| 6690 | if (position == NAV_BAR_BOTTOM) { |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6691 | outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode); |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 6692 | } else if (position == NAV_BAR_RIGHT) { |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6693 | outInsets.right = getNavigationBarWidth(displayRotation, mUiMode); |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 6694 | } else if (position == NAV_BAR_LEFT) { |
| 6695 | outInsets.left = getNavigationBarWidth(displayRotation, mUiMode); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6696 | } |
| 6697 | } |
| 6698 | } |
| 6699 | |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 6700 | @Override |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6701 | public boolean isNavBarForcedShownLw(WindowState windowState) { |
Jorim Jaggi | e5638a6 | 2016-03-25 22:57:01 -0700 | [diff] [blame] | 6702 | return mForceShowSystemBars; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6703 | } |
| 6704 | |
| 6705 | @Override |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 6706 | public boolean isDockSideAllowed(int dockSide) { |
| 6707 | |
| 6708 | // We do not allow all dock sides at which the navigation bar touches the docked stack. |
| 6709 | if (!mNavigationBarCanMove) { |
| 6710 | return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT; |
| 6711 | } else { |
| 6712 | return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT; |
| 6713 | } |
| 6714 | } |
| 6715 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6716 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 6717 | PhoneWindow.sendCloseSystemWindows(mContext, null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6718 | } |
| 6719 | |
| 6720 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 6721 | PhoneWindow.sendCloseSystemWindows(mContext, reason); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6722 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 6723 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6724 | @Override |
| 6725 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6726 | if (false) { |
| 6727 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 6728 | + orientation + ", last=" + lastRotation |
| 6729 | + "); user=" + mUserRotation + " " |
| 6730 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 6731 | ? "USER_ROTATION_LOCKED" : "") |
| 6732 | ); |
| 6733 | } |
| 6734 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 6735 | if (mForceDefaultOrientation) { |
| 6736 | return Surface.ROTATION_0; |
| 6737 | } |
| 6738 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6739 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6740 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 6741 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 6742 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6743 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6744 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6745 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 6746 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6747 | // Ignore sensor when lid switch is open and rotation is forced. |
| 6748 | preferredRotation = mLidOpenRotation; |
| 6749 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6750 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6751 | // Ignore sensor when in car dock unless explicitly enabled. |
| 6752 | // This case can override the behavior of NOSENSOR, and can also |
| 6753 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6754 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6755 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 6756 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 6757 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 6758 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6759 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6760 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 6761 | // This case can override the behavior of NOSENSOR, and can also |
| 6762 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6763 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6764 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6765 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 6766 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 6767 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6768 | preferredRotation = mDemoHdmiRotation; |
| 6769 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 6770 | && mUndockedHdmiRotation >= 0) { |
| 6771 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 6772 | // been specified in the configuration (only for legacy devices without |
| 6773 | // full multi-display support). |
| 6774 | // Note that the dock orientation overrides the HDMI orientation. |
| 6775 | preferredRotation = mUndockedHdmiRotation; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 6776 | } else if (mDemoRotationLock) { |
| 6777 | // Ignore sensor when demo rotation lock is enabled. |
| 6778 | // Note that the dock orientation and HDMI rotation lock override this. |
| 6779 | preferredRotation = mDemoRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6780 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 6781 | // Application just wants to remain locked in the last rotation. |
| 6782 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 6783 | } else if (!mSupportAutoRotation) { |
| 6784 | // If we don't support auto-rotation then bail out here and ignore |
| 6785 | // the sensor and any rotation lock settings. |
| 6786 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 6787 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6788 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6789 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 6790 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 6791 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 6792 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6793 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 6794 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 6795 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 6796 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 6797 | // Otherwise, use sensor only if requested by the application or enabled |
| 6798 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 6799 | if (mAllowAllRotations < 0) { |
| 6800 | // Can't read this during init() because the context doesn't |
| 6801 | // have display metrics at that time so we cannot determine |
| 6802 | // tablet vs. phone then. |
| 6803 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 6804 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 6805 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6806 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 6807 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6808 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 6809 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6810 | preferredRotation = sensorRotation; |
| 6811 | } else { |
| 6812 | preferredRotation = lastRotation; |
| 6813 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 6814 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 6815 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 6816 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 6817 | // The idea is that the user rotation expresses a weak preference for the direction |
| 6818 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 6819 | // 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] | 6820 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6821 | } else { |
| 6822 | // No overriding preference. |
| 6823 | // We will do exactly what the application asked us to do. |
| 6824 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6825 | } |
| 6826 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6827 | switch (orientation) { |
| 6828 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6829 | // Return portrait unless overridden. |
| 6830 | if (isAnyPortrait(preferredRotation)) { |
| 6831 | return preferredRotation; |
| 6832 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6833 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6834 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6835 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6836 | // Return landscape unless overridden. |
| 6837 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6838 | return preferredRotation; |
| 6839 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6840 | return mLandscapeRotation; |
| 6841 | |
| 6842 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6843 | // Return reverse portrait unless overridden. |
| 6844 | if (isAnyPortrait(preferredRotation)) { |
| 6845 | return preferredRotation; |
| 6846 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6847 | return mUpsideDownRotation; |
| 6848 | |
| 6849 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6850 | // Return seascape unless overridden. |
| 6851 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6852 | return preferredRotation; |
| 6853 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6854 | return mSeascapeRotation; |
| 6855 | |
| 6856 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6857 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6858 | // Return either landscape rotation. |
| 6859 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6860 | return preferredRotation; |
| 6861 | } |
| 6862 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 6863 | return lastRotation; |
| 6864 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6865 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6866 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6867 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6868 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6869 | // Return either portrait rotation. |
| 6870 | if (isAnyPortrait(preferredRotation)) { |
| 6871 | return preferredRotation; |
| 6872 | } |
| 6873 | if (isAnyPortrait(lastRotation)) { |
| 6874 | return lastRotation; |
| 6875 | } |
| 6876 | return mPortraitRotation; |
| 6877 | |
| 6878 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 6879 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 6880 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6881 | if (preferredRotation >= 0) { |
| 6882 | return preferredRotation; |
| 6883 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6884 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 6885 | } |
| 6886 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 6887 | } |
| 6888 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6889 | @Override |
| 6890 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 6891 | switch (orientation) { |
| 6892 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 6893 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 6894 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 6895 | return isAnyPortrait(rotation); |
| 6896 | |
| 6897 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 6898 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 6899 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 6900 | return isLandscapeOrSeascape(rotation); |
| 6901 | |
| 6902 | default: |
| 6903 | return true; |
| 6904 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 6905 | } |
| 6906 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6907 | @Override |
| 6908 | public void setRotationLw(int rotation) { |
| 6909 | mOrientationListener.setCurrentRotation(rotation); |
| 6910 | } |
| 6911 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6912 | private boolean isLandscapeOrSeascape(int rotation) { |
| 6913 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6914 | } |
| 6915 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6916 | private boolean isAnyPortrait(int rotation) { |
| 6917 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6918 | } |
| 6919 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6920 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6921 | public int getUserRotationMode() { |
| 6922 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 6923 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 6924 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 6925 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6926 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6927 | |
| 6928 | // 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] | 6929 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6930 | public void setUserRotationMode(int mode, int rot) { |
| 6931 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6932 | |
| 6933 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6934 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6935 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6936 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6937 | rot, |
| 6938 | UserHandle.USER_CURRENT); |
| 6939 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6940 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6941 | 0, |
| 6942 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6943 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6944 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6945 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6946 | 1, |
| 6947 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6948 | } |
| 6949 | } |
| 6950 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6951 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6952 | public void setSafeMode(boolean safeMode) { |
| 6953 | mSafeMode = safeMode; |
| 6954 | performHapticFeedbackLw(null, safeMode |
| 6955 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 6956 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6957 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6958 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 6959 | static long[] getLongIntArray(Resources r, int resid) { |
| 6960 | int[] ar = r.getIntArray(resid); |
| 6961 | if (ar == null) { |
| 6962 | return null; |
| 6963 | } |
| 6964 | long[] out = new long[ar.length]; |
| 6965 | for (int i=0; i<ar.length; i++) { |
| 6966 | out[i] = ar[i]; |
| 6967 | } |
| 6968 | return out; |
| 6969 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6970 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6971 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6972 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6973 | public void systemReady() { |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 6974 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext, |
| 6975 | new StateCallback() { |
| 6976 | @Override |
| 6977 | public void onTrustedChanged() { |
| 6978 | mWindowManagerFuncs.notifyKeyguardTrustedChanged(); |
| 6979 | } |
| 6980 | }); |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 6981 | mKeyguardDelegate.onSystemReady(); |
| 6982 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 6983 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6984 | updateUiMode(); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6985 | boolean bindKeyguardNow; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6986 | synchronized (mLock) { |
| 6987 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 6988 | mSystemReady = true; |
| 6989 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6990 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 6991 | public void run() { |
| 6992 | updateSettings(); |
| 6993 | } |
| 6994 | }); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6995 | |
| 6996 | bindKeyguardNow = mDeferBindKeyguard; |
| 6997 | if (bindKeyguardNow) { |
| 6998 | // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now. |
| 6999 | mDeferBindKeyguard = false; |
| 7000 | } |
| 7001 | } |
| 7002 | |
| 7003 | if (bindKeyguardNow) { |
| 7004 | mKeyguardDelegate.bindService(mContext); |
| 7005 | mKeyguardDelegate.onBootCompleted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7006 | } |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 7007 | mSystemGestures.systemReady(); |
Amith Yamasani | 02a0381 | 2016-04-22 17:32:00 -0700 | [diff] [blame] | 7008 | mImmersiveModeConfirmation.systemReady(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7009 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7010 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7011 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7012 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7013 | public void systemBooted() { |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 7014 | boolean bindKeyguardNow = false; |
| 7015 | synchronized (mLock) { |
| 7016 | // Time to bind Keyguard; take care to only bind it once, either here if ready or |
| 7017 | // in systemReady if not. |
| 7018 | if (mKeyguardDelegate != null) { |
| 7019 | bindKeyguardNow = true; |
| 7020 | } else { |
| 7021 | // Because mKeyguardDelegate is null, we know that the synchronized block in |
| 7022 | // systemReady didn't run yet and setting this will actually have an effect. |
| 7023 | mDeferBindKeyguard = true; |
| 7024 | } |
| 7025 | } |
| 7026 | if (bindKeyguardNow) { |
Jason Monk | 5eeebf5 | 2014-09-26 12:36:51 -0400 | [diff] [blame] | 7027 | mKeyguardDelegate.bindService(mContext); |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 7028 | mKeyguardDelegate.onBootCompleted(); |
| 7029 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7030 | synchronized (mLock) { |
| 7031 | mSystemBooted = true; |
| 7032 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 7033 | startedWakingUp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 7034 | screenTurningOn(null); |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 7035 | screenTurnedOn(); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7036 | } |
| 7037 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7038 | ProgressDialog mBootMsgDialog = null; |
| 7039 | |
| 7040 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7041 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7042 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 7043 | mHandler.post(new Runnable() { |
| 7044 | @Override public void run() { |
| 7045 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 7046 | int theme; |
Michael Kwan | 5a86167 | 2016-06-09 19:44:04 -0700 | [diff] [blame] | 7047 | if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 7048 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 7049 | } else { |
| 7050 | theme = 0; |
| 7051 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 7052 | |
| 7053 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 7054 | // This dialog will consume all events coming in to |
| 7055 | // it, to avoid it trying to do things too early in boot. |
| 7056 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 7057 | return true; |
| 7058 | } |
| 7059 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 7060 | return true; |
| 7061 | } |
| 7062 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 7063 | return true; |
| 7064 | } |
| 7065 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 7066 | return true; |
| 7067 | } |
| 7068 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 7069 | return true; |
| 7070 | } |
| 7071 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 7072 | AccessibilityEvent event) { |
| 7073 | return true; |
| 7074 | } |
| 7075 | }; |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 7076 | if (mContext.getPackageManager().isUpgrade()) { |
| 7077 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 7078 | } else { |
| 7079 | mBootMsgDialog.setTitle(R.string.android_start_title); |
| 7080 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7081 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 7082 | mBootMsgDialog.setIndeterminate(true); |
| 7083 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 7084 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7085 | mBootMsgDialog.getWindow().addFlags( |
| 7086 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 7087 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 7088 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 7089 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 7090 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 7091 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7092 | mBootMsgDialog.setCancelable(false); |
| 7093 | mBootMsgDialog.show(); |
| 7094 | } |
| 7095 | mBootMsgDialog.setMessage(msg); |
| 7096 | } |
| 7097 | }); |
| 7098 | } |
| 7099 | |
| 7100 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7101 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7102 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 7103 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7104 | } |
| 7105 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7106 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7107 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7108 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7109 | // *************************************** |
| 7110 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 7111 | // *************************************** |
| 7112 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 7113 | // WITH ITS LOCKS HELD. |
| 7114 | // |
| 7115 | // This code must be VERY careful about the locks |
| 7116 | // it acquires. |
| 7117 | // In fact, the current code acquires way too many, |
| 7118 | // and probably has lurking deadlocks. |
| 7119 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7120 | synchronized (mScreenLockTimeout) { |
| 7121 | if (mLockScreenTimerActive) { |
| 7122 | // reset the timer |
| 7123 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 7124 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 7125 | } |
| 7126 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 7127 | } |
| 7128 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7129 | class ScreenLockTimeout implements Runnable { |
| 7130 | Bundle options; |
| 7131 | |
| 7132 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7133 | public void run() { |
| 7134 | synchronized (this) { |
| 7135 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 7136 | if (mKeyguardDelegate != null) { |
| 7137 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 7138 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7139 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7140 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7141 | } |
| 7142 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7143 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7144 | public void setLockOptions(Bundle options) { |
| 7145 | this.options = options; |
| 7146 | } |
| 7147 | } |
| 7148 | |
| 7149 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 7150 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7151 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7152 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 7153 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 7154 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7155 | if (options != null) { |
| 7156 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 7157 | // until the runnable actually executes. |
| 7158 | mScreenLockTimeout.setLockOptions(options); |
| 7159 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 7160 | mHandler.post(mScreenLockTimeout); |
| 7161 | } |
| 7162 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7163 | private void updateLockScreenTimeout() { |
| 7164 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7165 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 7166 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure(mCurrentUserId)); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7167 | if (mLockScreenTimerActive != enable) { |
| 7168 | if (enable) { |
| 7169 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
Jim Miller | 2967f48 | 2016-01-07 15:05:32 -0800 | [diff] [blame] | 7170 | mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7171 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 7172 | } else { |
| 7173 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 7174 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 7175 | } |
| 7176 | mLockScreenTimerActive = enable; |
| 7177 | } |
| 7178 | } |
| 7179 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7180 | |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 7181 | private void updateDreamingSleepToken(boolean acquire) { |
| 7182 | if (acquire) { |
| 7183 | if (mDreamingSleepToken == null) { |
| 7184 | mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream"); |
| 7185 | } |
| 7186 | } else { |
| 7187 | if (mDreamingSleepToken != null) { |
| 7188 | mDreamingSleepToken.release(); |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 7189 | mDreamingSleepToken = null; |
| 7190 | } |
| 7191 | } |
| 7192 | } |
| 7193 | |
| 7194 | private void updateScreenOffSleepToken(boolean acquire) { |
| 7195 | if (acquire) { |
| 7196 | if (mScreenOffSleepToken == null) { |
| 7197 | mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff"); |
| 7198 | } |
| 7199 | } else { |
| 7200 | if (mScreenOffSleepToken != null) { |
| 7201 | mScreenOffSleepToken.release(); |
| 7202 | mScreenOffSleepToken = null; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 7203 | } |
| 7204 | } |
| 7205 | } |
| 7206 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7207 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7208 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7209 | public void enableScreenAfterBoot() { |
| 7210 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7211 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7212 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7213 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 7214 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7215 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7216 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7217 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 7218 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7219 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 7220 | } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) { |
| 7221 | mWindowManagerFuncs.lockDeviceNow(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7222 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 7223 | |
| 7224 | synchronized (mLock) { |
| 7225 | updateWakeGestureListenerLp(); |
| 7226 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7227 | } |
| 7228 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 7229 | void updateUiMode() { |
| 7230 | if (mUiModeManager == null) { |
| 7231 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 7232 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 7233 | } |
| 7234 | try { |
| 7235 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 7236 | } catch (RemoteException e) { |
| 7237 | } |
| 7238 | } |
| 7239 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7240 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7241 | try { |
| 7242 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 7243 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 7244 | } catch (RemoteException e) { |
| 7245 | // Ignore |
| 7246 | } |
| 7247 | } |
| 7248 | |
| 7249 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 7250 | try { |
| 7251 | //set orientation on WindowManager |
| 7252 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7253 | } catch (RemoteException e) { |
| 7254 | // Ignore |
| 7255 | } |
| 7256 | } |
| 7257 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7258 | /** |
| 7259 | * Return an Intent to launch the currently active dock app as home. Returns |
| 7260 | * null if the standard home should be launched, which is the case if any of the following is |
| 7261 | * true: |
| 7262 | * <ul> |
| 7263 | * <li>The device is not in either car mode or desk mode |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 7264 | * <li>The device is in car mode but mEnableCarDockHomeCapture is false |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7265 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 7266 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 7267 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 7268 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7269 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7270 | */ |
| 7271 | Intent createHomeDockIntent() { |
| 7272 | Intent intent = null; |
| 7273 | |
| 7274 | // What home does is based on the mode, not the dock state. That |
| 7275 | // is, when in car mode you should be taken to car home regardless |
| 7276 | // of whether we are actually in a car dock. |
| 7277 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 7278 | if (mEnableCarDockHomeCapture) { |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7279 | intent = mCarDockIntent; |
| 7280 | } |
| 7281 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 7282 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 7283 | intent = mDeskDockIntent; |
| 7284 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 7285 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 7286 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 7287 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 7288 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 7289 | // Always launch dock home from home when watch is docked, if it exists. |
| 7290 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7291 | } |
| 7292 | |
| 7293 | if (intent == null) { |
| 7294 | return null; |
| 7295 | } |
| 7296 | |
| 7297 | ActivityInfo ai = null; |
| 7298 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 7299 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 7300 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 7301 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7302 | if (info != null) { |
| 7303 | ai = info.activityInfo; |
| 7304 | } |
| 7305 | if (ai != null |
| 7306 | && ai.metaData != null |
| 7307 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 7308 | intent = new Intent(intent); |
| 7309 | intent.setClassName(ai.packageName, ai.name); |
| 7310 | return intent; |
| 7311 | } |
| 7312 | |
| 7313 | return null; |
| 7314 | } |
| 7315 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 7316 | void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { |
| 7317 | if (awakenFromDreams) { |
| 7318 | awakenDreams(); |
| 7319 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7320 | |
| 7321 | Intent dock = createHomeDockIntent(); |
| 7322 | if (dock != null) { |
| 7323 | try { |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 7324 | if (fromHomeKey) { |
| 7325 | dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 7326 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 7327 | startActivityAsUser(dock, UserHandle.CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7328 | return; |
| 7329 | } catch (ActivityNotFoundException e) { |
| 7330 | } |
| 7331 | } |
| 7332 | |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 7333 | Intent intent; |
| 7334 | |
| 7335 | if (fromHomeKey) { |
| 7336 | intent = new Intent(mHomeIntent); |
| 7337 | intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 7338 | } else { |
| 7339 | intent = mHomeIntent; |
| 7340 | } |
| 7341 | |
Bryce Lee | 9fc0b6f | 2015-03-19 21:37:45 +0000 | [diff] [blame] | 7342 | startActivityAsUser(intent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 7343 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7344 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 7345 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7346 | * goes to the home screen |
| 7347 | * @return whether it did anything |
| 7348 | */ |
| 7349 | boolean goHome() { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 7350 | if (!isUserSetupComplete()) { |
| 7351 | Slog.i(TAG, "Not going home because user setup is in progress."); |
| 7352 | return false; |
| 7353 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7354 | if (false) { |
| 7355 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 7356 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7357 | ActivityManager.getService().stopAppSwitches(); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 7358 | } catch (RemoteException e) { |
| 7359 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 7360 | sendCloseSystemWindows(); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 7361 | startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7362 | } else { |
| 7363 | // This code brings home to the front or, if it is already |
| 7364 | // at the front, puts the device to sleep. |
| 7365 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 7366 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 7367 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 7368 | Log.d(TAG, "UTS-TEST-MODE"); |
| 7369 | } else { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7370 | ActivityManager.getService().stopAppSwitches(); |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 7371 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7372 | Intent dock = createHomeDockIntent(); |
| 7373 | if (dock != null) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7374 | int result = ActivityManager.getService() |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7375 | .startActivityAsUser(null, null, dock, |
| 7376 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 7377 | null, null, 0, |
| 7378 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 7379 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7380 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 7381 | return false; |
| 7382 | } |
| 7383 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 7384 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7385 | int result = ActivityManager.getService() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 7386 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7387 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 7388 | null, null, 0, |
| 7389 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 7390 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 7391 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7392 | return false; |
| 7393 | } |
| 7394 | } catch (RemoteException ex) { |
| 7395 | // bummer, the activity manager, which is in this process, is dead |
| 7396 | } |
| 7397 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7398 | return true; |
| 7399 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7400 | |
| 7401 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 7402 | public void setCurrentOrientationLw(int newOrientation) { |
| 7403 | synchronized (mLock) { |
| 7404 | if (newOrientation != mCurrentAppOrientation) { |
| 7405 | mCurrentAppOrientation = newOrientation; |
| 7406 | updateOrientationListenerLp(); |
| 7407 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7408 | } |
| 7409 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7410 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 7411 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 7412 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 7413 | return; |
| 7414 | } |
| 7415 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 7416 | Context.AUDIO_SERVICE); |
| 7417 | if (audioManager.isSilentMode()) { |
| 7418 | return; |
| 7419 | } |
| 7420 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 7421 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 7422 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 7423 | ringTone.play(); |
| 7424 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7425 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 7426 | private boolean isTheaterModeEnabled() { |
| 7427 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 7428 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 7429 | } |
| 7430 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 7431 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 7432 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 7433 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 7434 | } |
| 7435 | |
Doris Ling | 628cea4 | 2016-06-09 10:35:02 -0700 | [diff] [blame] | 7436 | private boolean areSystemNavigationKeysEnabled() { |
Doris Ling | 34331b7 | 2016-08-09 12:02:28 -0700 | [diff] [blame] | 7437 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 7438 | Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0, UserHandle.USER_CURRENT) == 1; |
Doris Ling | 628cea4 | 2016-06-09 10:35:02 -0700 | [diff] [blame] | 7439 | } |
| 7440 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7441 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 7442 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 7443 | if (!mVibrator.hasVibrator()) { |
| 7444 | return false; |
| 7445 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7446 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 7447 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 7448 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7449 | return false; |
| 7450 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7451 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7452 | switch (effectId) { |
| 7453 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7454 | pattern = mLongPressVibePattern; |
| 7455 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 7456 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7457 | pattern = mVirtualKeyVibePattern; |
| 7458 | break; |
| 7459 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 7460 | pattern = mKeyboardTapVibePattern; |
| 7461 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 7462 | case HapticFeedbackConstants.CLOCK_TICK: |
| 7463 | pattern = mClockTickVibePattern; |
| 7464 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 7465 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 7466 | pattern = mCalendarDateVibePattern; |
| 7467 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 7468 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7469 | pattern = mSafeModeDisabledVibePattern; |
| 7470 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 7471 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7472 | pattern = mSafeModeEnabledVibePattern; |
| 7473 | break; |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 7474 | case HapticFeedbackConstants.CONTEXT_CLICK: |
| 7475 | pattern = mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 7476 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7477 | default: |
| 7478 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7479 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 7480 | int owningUid; |
| 7481 | String owningPackage; |
| 7482 | if (win != null) { |
| 7483 | owningUid = win.getOwningUid(); |
| 7484 | owningPackage = win.getOwningPackage(); |
| 7485 | } else { |
| 7486 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 7487 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 7488 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7489 | if (pattern.length == 1) { |
| 7490 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 7491 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7492 | } else { |
| 7493 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 7494 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7495 | } |
| 7496 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7497 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 7498 | |
| 7499 | @Override |
| 7500 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 7501 | } |
| 7502 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 7503 | @Override |
| 7504 | public void keepScreenOnStoppedLw() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 7505 | if (isKeyguardShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 7506 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7507 | } |
| 7508 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 7509 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7510 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7511 | // If there is no window focused, there will be nobody to handle the events |
| 7512 | // 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] | 7513 | WindowState winCandidate = mFocusedWindow != null ? mFocusedWindow |
Adrian Roos | 53f28ec | 2014-10-29 17:26:12 +0100 | [diff] [blame] | 7514 | : mTopFullscreenOpaqueWindowState; |
Adrian Roos | dab1516 | 2016-09-12 15:08:35 -0700 | [diff] [blame] | 7515 | if (winCandidate == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7516 | return 0; |
| 7517 | } |
Adrian Roos | dab1516 | 2016-09-12 15:08:35 -0700 | [diff] [blame] | 7518 | if (winCandidate.getAttrs().token == mImmersiveModeConfirmation.getWindowToken()) { |
| 7519 | // The immersive mode confirmation should never affect the system bar visibility, |
| 7520 | // otherwise it will unhide the navigation bar and hide itself. |
| 7521 | winCandidate = isStatusBarKeyguard() ? mStatusBar : mTopFullscreenOpaqueWindowState; |
| 7522 | if (winCandidate == null) { |
| 7523 | return 0; |
| 7524 | } |
| 7525 | } |
| 7526 | final WindowState win = winCandidate; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 7527 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mKeyguardOccluded) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 7528 | // We are updating at a point where the keyguard has gotten |
| 7529 | // focus, but we were last in a state where the top window is |
| 7530 | // hiding it. This is probably because the keyguard as been |
| 7531 | // shown while the top window was displayed, so we want to ignore |
| 7532 | // it here because this is just a very transient change and it |
| 7533 | // will quickly lose focus once it correctly gets hidden. |
| 7534 | return 0; |
| 7535 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 7536 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 7537 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 7538 | & ~mResettingSystemUiFlags |
| 7539 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7540 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 7541 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 7542 | } |
Thanh Hai Mai | 6c009f5 | 2015-09-01 16:27:32 -0700 | [diff] [blame] | 7543 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7544 | final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */, |
| 7545 | mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState); |
| 7546 | final int dockedVisibility = updateLightStatusBarLw(0 /* vis */, |
| 7547 | mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState); |
| 7548 | mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds); |
| 7549 | mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7550 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7551 | final int diff = visibility ^ mLastSystemUiFlags; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7552 | final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags; |
| 7553 | final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7554 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7555 | if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu |
| 7556 | && mFocusedApp == win.getAppToken() |
| 7557 | && mLastNonDockedStackBounds.equals(mNonDockedStackBounds) |
| 7558 | && mLastDockedStackBounds.equals(mDockedStackBounds)) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7559 | return 0; |
| 7560 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 7561 | mLastSystemUiFlags = visibility; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7562 | mLastFullscreenStackSysUiFlags = fullscreenVisibility; |
| 7563 | mLastDockedStackSysUiFlags = dockedVisibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 7564 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7565 | mFocusedApp = win.getAppToken(); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7566 | final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds); |
| 7567 | final Rect dockedStackBounds = new Rect(mDockedStackBounds); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7568 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7569 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7570 | public void run() { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7571 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 7572 | if (statusbar != null) { |
| 7573 | statusbar.setSystemUiVisibility(visibility, fullscreenVisibility, |
| 7574 | dockedVisibility, 0xffffffff, fullscreenStackBounds, |
| 7575 | dockedStackBounds, win.toString()); |
| 7576 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7577 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7578 | } |
| 7579 | }); |
| 7580 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7581 | } |
| 7582 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7583 | private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 7584 | WindowState statusColorWin = isStatusBarKeyguard() && !mKeyguardOccluded |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7585 | ? mStatusBar |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7586 | : opaqueOrDimming; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7587 | |
| 7588 | if (statusColorWin != null) { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7589 | if (statusColorWin == opaque) { |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7590 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 7591 | // its light flag. |
| 7592 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 7593 | vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) |
| 7594 | & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 7595 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 7596 | // Otherwise if it's dimming, clear the light flag. |
| 7597 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 7598 | } |
| 7599 | } |
| 7600 | return vis; |
| 7601 | } |
| 7602 | |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 7603 | private boolean drawsSystemBarBackground(WindowState win) { |
| 7604 | return win == null || (win.getAttrs().flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0; |
| 7605 | } |
| 7606 | |
| 7607 | private boolean forcesDrawStatusBarBackground(WindowState win) { |
| 7608 | return win == null || (win.getAttrs().privateFlags |
| 7609 | & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) != 0; |
| 7610 | } |
| 7611 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7612 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7613 | final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID); |
| 7614 | final boolean freeformStackVisible = |
| 7615 | mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 7616 | final boolean resizing = mWindowManagerInternal.isDockedDividerResizing(); |
| 7617 | |
| 7618 | // We need to force system bars when the docked stack is visible, when the freeform stack |
| 7619 | // is visible but also when we are resizing for the transitions when docked stack |
| 7620 | // visibility changes. |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7621 | mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing; |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7622 | final boolean forceOpaqueStatusBar = mForceShowSystemBars && !mForceStatusBarFromKeyguard; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7623 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7624 | // apply translucent bar vis flags |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 7625 | WindowState fullscreenTransWin = isStatusBarKeyguard() && !mKeyguardOccluded |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 7626 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7627 | : mTopFullscreenOpaqueWindowState; |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 7628 | vis = mStatusBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); |
| 7629 | vis = mNavigationBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); |
| 7630 | final int dockedVis = mStatusBarController.applyTranslucentFlagLw( |
| 7631 | mTopDockedOpaqueWindowState, 0, 0); |
| 7632 | |
| 7633 | final boolean fullscreenDrawsStatusBarBackground = |
| 7634 | (drawsSystemBarBackground(mTopFullscreenOpaqueWindowState) |
| 7635 | && (vis & View.STATUS_BAR_TRANSLUCENT) == 0) |
| 7636 | || forcesDrawStatusBarBackground(mTopFullscreenOpaqueWindowState); |
| 7637 | final boolean dockedDrawsStatusBarBackground = |
| 7638 | (drawsSystemBarBackground(mTopDockedOpaqueWindowState) |
| 7639 | && (dockedVis & View.STATUS_BAR_TRANSLUCENT) == 0) |
| 7640 | || forcesDrawStatusBarBackground(mTopDockedOpaqueWindowState); |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7641 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7642 | // prevent status bar interaction from clearing certain flags |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 7643 | int type = win.getAttrs().type; |
| 7644 | boolean statusBarHasFocus = type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 7645 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7646 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 7647 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 7648 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 73fef8d | 2015-02-16 17:32:28 +0100 | [diff] [blame] | 7649 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 7650 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 7651 | if (mKeyguardOccluded) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 7652 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 7653 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7654 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7655 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7656 | |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 7657 | if (fullscreenDrawsStatusBarBackground && dockedDrawsStatusBarBackground) { |
| 7658 | vis |= View.STATUS_BAR_TRANSPARENT; |
| 7659 | vis &= ~View.STATUS_BAR_TRANSLUCENT; |
| 7660 | } else if ((!areTranslucentBarsAllowed() && fullscreenTransWin != mStatusBar) |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7661 | || forceOpaqueStatusBar) { |
| 7662 | vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7663 | } |
| 7664 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7665 | vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing); |
Yorke Lee | 2e4b732 | 2016-03-02 17:33:06 -0800 | [diff] [blame] | 7666 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7667 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7668 | boolean immersiveSticky = |
| 7669 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7670 | final boolean hideStatusBarWM = |
| 7671 | mTopFullscreenOpaqueWindowState != null |
| 7672 | && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7673 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7674 | final boolean hideStatusBarSysui = |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7675 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7676 | final boolean hideNavBarSysui = |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7677 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7678 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7679 | final boolean transientStatusBarAllowed = mStatusBar != null |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7680 | && (statusBarHasFocus || (!mForceShowSystemBars |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7681 | && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky)))); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7682 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7683 | final boolean transientNavBarAllowed = mNavigationBar != null |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7684 | && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7685 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 7686 | final long now = SystemClock.uptimeMillis(); |
| 7687 | final boolean pendingPanic = mPendingPanicGestureUptime != 0 |
| 7688 | && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION; |
| 7689 | if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) { |
| 7690 | // The user performed the panic gesture recently, we're about to hide the bars, |
| 7691 | // we're no longer on the Keyguard and the screen is ready. We can now request the bars. |
| 7692 | mPendingPanicGestureUptime = 0; |
| 7693 | mStatusBarController.showTransient(); |
Adrian Roos | 1f42590 | 2016-07-22 10:37:50 -0700 | [diff] [blame] | 7694 | if (!isNavBarEmpty(vis)) { |
| 7695 | mNavigationBarController.showTransient(); |
| 7696 | } |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 7697 | } |
| 7698 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7699 | final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7700 | && !transientStatusBarAllowed && hideStatusBarSysui; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7701 | final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7702 | && !transientNavBarAllowed; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7703 | if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7704 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7705 | clearClearableFlagsLw(); |
tiger_huang | c58d756 | 2014-10-23 20:24:19 +0800 | [diff] [blame] | 7706 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7707 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7708 | |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 7709 | final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 7710 | immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 7711 | final boolean navAllowedHidden = immersive || immersiveSticky; |
| 7712 | |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 7713 | if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType()) |
| 7714 | > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) { |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 7715 | // We can't hide the navbar from this window otherwise the input consumer would not get |
| 7716 | // the input events. |
| 7717 | vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); |
| 7718 | } |
| 7719 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7720 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 7721 | |
| 7722 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7723 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 7724 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 7725 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7726 | final String pkg = win.getOwningPackage(); |
Amith Yamasani | 02a0381 | 2016-04-22 17:32:00 -0700 | [diff] [blame] | 7727 | mImmersiveModeConfirmation.immersiveModeChangedLw(pkg, newImmersiveMode, |
Adrian Roos | 7aaa551 | 2016-07-12 15:27:24 -0700 | [diff] [blame] | 7728 | isUserSetupComplete(), isNavBarEmpty(win.getSystemUiVisibility())); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 7729 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7730 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7731 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 7732 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 7733 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7734 | } |
| 7735 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7736 | /** |
| 7737 | * @return the current visibility flags with the nav-bar opacity related flags toggled based |
| 7738 | * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}. |
| 7739 | */ |
| 7740 | private int configureNavBarOpacity(int visibility, boolean dockedStackVisible, |
| 7741 | boolean freeformStackVisible, boolean isDockedDividerResizing) { |
| 7742 | if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) { |
| 7743 | if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) { |
| 7744 | visibility = setNavBarOpaqueFlag(visibility); |
| 7745 | } |
| 7746 | } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) { |
| 7747 | if (isDockedDividerResizing) { |
| 7748 | visibility = setNavBarOpaqueFlag(visibility); |
| 7749 | } else if (freeformStackVisible) { |
| 7750 | visibility = setNavBarTranslucentFlag(visibility); |
| 7751 | } else { |
| 7752 | visibility = setNavBarOpaqueFlag(visibility); |
| 7753 | } |
| 7754 | } |
| 7755 | |
| 7756 | if (!areTranslucentBarsAllowed()) { |
| 7757 | visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT; |
| 7758 | } |
| 7759 | return visibility; |
| 7760 | } |
| 7761 | |
| 7762 | private int setNavBarOpaqueFlag(int visibility) { |
| 7763 | return visibility &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT); |
| 7764 | } |
| 7765 | |
| 7766 | private int setNavBarTranslucentFlag(int visibility) { |
| 7767 | visibility &= ~View.NAVIGATION_BAR_TRANSPARENT; |
| 7768 | return visibility |= View.NAVIGATION_BAR_TRANSLUCENT; |
| 7769 | } |
| 7770 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7771 | private void clearClearableFlagsLw() { |
| 7772 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 7773 | if (newVal != mResettingSystemUiFlags) { |
| 7774 | mResettingSystemUiFlags = newVal; |
| 7775 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 7776 | } |
| 7777 | } |
| 7778 | |
| 7779 | private boolean isImmersiveMode(int vis) { |
| 7780 | 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] | 7781 | return mNavigationBar != null |
| 7782 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 7783 | && (vis & flags) != 0 |
| 7784 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 7785 | } |
| 7786 | |
Adrian Roos | 7aaa551 | 2016-07-12 15:27:24 -0700 | [diff] [blame] | 7787 | private static boolean isNavBarEmpty(int systemUiFlags) { |
| 7788 | final int disableNavigationBar = (View.STATUS_BAR_DISABLE_HOME |
| 7789 | | View.STATUS_BAR_DISABLE_BACK |
| 7790 | | View.STATUS_BAR_DISABLE_RECENT); |
| 7791 | |
| 7792 | return (systemUiFlags & disableNavigationBar) == disableNavigationBar; |
| 7793 | } |
| 7794 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7795 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 7796 | * @return whether the navigation or status bar can be made translucent |
| 7797 | * |
| 7798 | * This should return true unless touch exploration is not enabled or |
| 7799 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7800 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 7801 | private boolean areTranslucentBarsAllowed() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 7802 | return mTranslucentDecorEnabled; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7803 | } |
| 7804 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 7805 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 7806 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7807 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 7808 | public boolean hasNavigationBar() { |
| 7809 | return mHasNavigationBar; |
| 7810 | } |
| 7811 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 7812 | @Override |
| 7813 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 7814 | mLastInputMethodWindow = ime; |
| 7815 | mLastInputMethodTargetWindow = target; |
| 7816 | } |
| 7817 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7818 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 7819 | public int getInputMethodWindowVisibleHeightLw() { |
| 7820 | return mDockBottom - mCurBottom; |
| 7821 | } |
| 7822 | |
| 7823 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7824 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 7825 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 7826 | if (mKeyguardDelegate != null) { |
| 7827 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7828 | } |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 7829 | StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); |
Adrian Roos | 2a62910 | 2016-04-15 16:28:03 -0700 | [diff] [blame] | 7830 | if (statusBar != null) { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 7831 | statusBar.setCurrentUser(newUserId); |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 7832 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7833 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7834 | } |
| 7835 | |
| 7836 | @Override |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 7837 | public void setSwitchingUser(boolean switching) { |
| 7838 | mKeyguardDelegate.setSwitchingUser(switching); |
| 7839 | } |
| 7840 | |
| 7841 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 7842 | public boolean canMagnifyWindow(int windowType) { |
| 7843 | switch (windowType) { |
| 7844 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 7845 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 7846 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 7847 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 7848 | return false; |
| 7849 | } |
| 7850 | } |
| 7851 | return true; |
| 7852 | } |
| 7853 | |
| 7854 | @Override |
| 7855 | public boolean isTopLevelWindow(int windowType) { |
| 7856 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 7857 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 7858 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 7859 | } |
| 7860 | return true; |
| 7861 | } |
| 7862 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 7863 | @Override |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 7864 | public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) { |
| 7865 | // For the upside down rotation we don't rotate seamlessly as the navigation |
| 7866 | // bar moves position. |
| 7867 | // Note most apps (using orientation:sensor or user as opposed to fullSensor) |
| 7868 | // will not enter the reverse portrait orientation, so actually the |
| 7869 | // orientation won't change at all. |
| 7870 | if (oldRotation == mUpsideDownRotation || newRotation == mUpsideDownRotation) { |
| 7871 | return false; |
| 7872 | } |
Robert Carr | 0b9ac5a | 2016-10-26 14:12:14 -0700 | [diff] [blame] | 7873 | // If the navigation bar can't change sides, then it will |
| 7874 | // jump when we change orientations and we don't rotate |
| 7875 | // seamlessly. |
| 7876 | if (!mNavigationBarCanMove) { |
| 7877 | return false; |
| 7878 | } |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 7879 | int delta = newRotation - oldRotation; |
| 7880 | if (delta < 0) delta += 4; |
| 7881 | // Likewise we don't rotate seamlessly for 180 degree rotations |
Geoffrey Pitsch | b2d6ed3 | 2016-08-24 10:37:19 -0400 | [diff] [blame] | 7882 | // in this case the surfaces never resize, and our logic to |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 7883 | // revert the transformations on size change will fail. We could |
| 7884 | // fix this in the future with the "tagged" frames idea. |
| 7885 | if (delta == Surface.ROTATION_180) { |
| 7886 | return false; |
| 7887 | } |
| 7888 | |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 7889 | final WindowState w = mTopFullscreenOpaqueWindowState; |
Robert Carr | 828ec3dc | 2016-08-22 13:32:34 -0700 | [diff] [blame] | 7890 | if (w != mFocusedWindow) { |
| 7891 | return false; |
| 7892 | } |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 7893 | |
Robert Carr | 606f4d5 | 2016-06-30 14:36:27 -0700 | [diff] [blame] | 7894 | // We only enable seamless rotation if the top window has requested |
| 7895 | // it and is in the fullscreen opaque state. Seamless rotation |
| 7896 | // requires freezing various Surface states and won't work well |
| 7897 | // with animations, so we disable it in the animation case for now. |
Robert Carr | 1ccd425 | 2016-08-15 12:05:21 -0700 | [diff] [blame] | 7898 | if (w != null && !w.isAnimatingLw() && |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 7899 | ((w.getAttrs().rotationAnimation == ROTATION_ANIMATION_JUMPCUT) || |
| 7900 | (w.getAttrs().rotationAnimation == ROTATION_ANIMATION_SEAMLESS))) { |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 7901 | return true; |
| 7902 | } |
| 7903 | return false; |
| 7904 | } |
| 7905 | |
| 7906 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 7907 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7908 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7909 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 7910 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 7911 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7912 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 7913 | pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7914 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 7915 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 7916 | || mForceClearedSystemUiFlags != 0) { |
| 7917 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 7918 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 7919 | pw.print(" mResettingSystemUiFlags=0x"); |
| 7920 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 7921 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 7922 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7923 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 7924 | if (mLastFocusNeedsMenu) { |
| 7925 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 7926 | pw.println(mLastFocusNeedsMenu); |
| 7927 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 7928 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 7929 | pw.println(mWakeGestureEnabledSetting); |
| 7930 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 7931 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7932 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 7933 | pw.print(" mDockMode="); pw.print(mDockMode); |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 7934 | pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7935 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 7936 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 7937 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 7938 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 7939 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 7940 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7941 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 7942 | pw.print(mCarDockEnablesAccelerometer); |
| 7943 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 7944 | pw.println(mDeskDockEnablesAccelerometer); |
| 7945 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 7946 | pw.print(mLidKeyboardAccessibility); |
| 7947 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 7948 | pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 7949 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7950 | pw.print(prefix); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 7951 | pw.print(" mLongPressOnBackBehavior="); pw.println(mLongPressOnBackBehavior); |
| 7952 | pw.print(prefix); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7953 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 7954 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 7955 | pw.print(prefix); |
| 7956 | pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); |
| 7957 | pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7958 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7959 | pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); |
| 7960 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 7961 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 7962 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 7963 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 7964 | pw.print(prefix); pw.print("mOrientationSensorEnabled="); |
| 7965 | pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 7966 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 7967 | pw.print(","); pw.print(mOverscanScreenTop); |
| 7968 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 7969 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 7970 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 7971 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 7972 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 7973 | pw.print(" top="); pw.print(mOverscanTop); |
| 7974 | pw.print(" right="); pw.print(mOverscanRight); |
| 7975 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 7976 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 7977 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 7978 | pw.print(mRestrictedOverscanScreenLeft); |
| 7979 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 7980 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 7981 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7982 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 7983 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 7984 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 7985 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 7986 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 7987 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 7988 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 7989 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 7990 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 7991 | pw.print(","); pw.print(mStableFullscreenTop); |
| 7992 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 7993 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7994 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 7995 | pw.print(","); pw.print(mStableTop); |
| 7996 | pw.print(")-("); pw.print(mStableRight); |
| 7997 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 7998 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 7999 | pw.print(","); pw.print(mSystemTop); |
| 8000 | pw.print(")-("); pw.print(mSystemRight); |
| 8001 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8002 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 8003 | pw.print(","); pw.print(mCurTop); |
| 8004 | pw.print(")-("); pw.print(mCurRight); |
| 8005 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 8006 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 8007 | pw.print(","); pw.print(mContentTop); |
| 8008 | pw.print(")-("); pw.print(mContentRight); |
| 8009 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 8010 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 8011 | pw.print(","); pw.print(mVoiceContentTop); |
| 8012 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 8013 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8014 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 8015 | pw.print(","); pw.print(mDockTop); |
| 8016 | pw.print(")-("); pw.print(mDockRight); |
| 8017 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 8018 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 8019 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 8020 | pw.print(prefix); pw.print("mShowingDream="); pw.print(mShowingDream); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 8021 | pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); |
| 8022 | pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8023 | if (mLastInputMethodWindow != null) { |
| 8024 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 8025 | pw.println(mLastInputMethodWindow); |
| 8026 | } |
| 8027 | if (mLastInputMethodTargetWindow != null) { |
| 8028 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 8029 | pw.println(mLastInputMethodTargetWindow); |
| 8030 | } |
| 8031 | if (mStatusBar != null) { |
| 8032 | pw.print(prefix); pw.print("mStatusBar="); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 8033 | pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); |
| 8034 | pw.println(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8035 | } |
| 8036 | if (mNavigationBar != null) { |
| 8037 | pw.print(prefix); pw.print("mNavigationBar="); |
| 8038 | pw.println(mNavigationBar); |
| 8039 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8040 | if (mFocusedWindow != null) { |
| 8041 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 8042 | pw.println(mFocusedWindow); |
| 8043 | } |
| 8044 | if (mFocusedApp != null) { |
| 8045 | pw.print(prefix); pw.print("mFocusedApp="); |
| 8046 | pw.println(mFocusedApp); |
| 8047 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8048 | if (mTopFullscreenOpaqueWindowState != null) { |
| 8049 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 8050 | pw.println(mTopFullscreenOpaqueWindowState); |
| 8051 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 8052 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 8053 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 8054 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 8055 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 8056 | if (mForcingShowNavBar) { |
| 8057 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 8058 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 8059 | pw.println(mForcingShowNavBarLayer); |
| 8060 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 8061 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 8062 | pw.print(" mKeyguardOccluded="); pw.println(mKeyguardOccluded); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 8063 | pw.print(" mKeyguardOccludedChanged="); pw.println(mKeyguardOccludedChanged); |
| 8064 | pw.print(" mPendingKeyguardOccluded="); pw.println(mPendingKeyguardOccluded); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 8065 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 8066 | pw.print(" mForceStatusBarFromKeyguard="); |
| 8067 | pw.println(mForceStatusBarFromKeyguard); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 8068 | pw.print(prefix); pw.print("mHomePressed="); pw.println(mHomePressed); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8069 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 8070 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 8071 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 8072 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 8073 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 8074 | pw.print(" mIncallBackBehavior="); pw.print(mIncallBackBehavior); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8075 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 8076 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 8077 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 8078 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 8079 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 8080 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 8081 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 8082 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 8083 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 8084 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8085 | mStatusBarController.dump(pw, prefix); |
| 8086 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 8087 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 8088 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 8089 | if (mWakeGestureListener != null) { |
| 8090 | mWakeGestureListener.dump(pw, prefix); |
| 8091 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 8092 | if (mOrientationListener != null) { |
| 8093 | mOrientationListener.dump(pw, prefix); |
| 8094 | } |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 8095 | if (mBurnInProtectionHelper != null) { |
| 8096 | mBurnInProtectionHelper.dump(prefix, pw); |
| 8097 | } |
Jorim Jaggi | 84dc08a | 2015-09-11 17:45:22 -0700 | [diff] [blame] | 8098 | if (mKeyguardDelegate != null) { |
| 8099 | mKeyguardDelegate.dump(prefix, pw); |
| 8100 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8101 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 8102 | } |