The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
Jeff Brown | 37df39a9 | 2015-02-25 15:42:31 -0800 | [diff] [blame] | 2 | * Copyright (C) 2006 The Android Open Source Project |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 17 | package com.android.server.policy; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 18 | |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 19 | import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 20 | import static android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 21 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 22 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 23 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 24 | import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
| 25 | import static android.app.AppOpsManager.OP_TOAST_WINDOW; |
Robert Carr | 7ad24ba | 2017-06-20 17:26:06 -0700 | [diff] [blame] | 26 | import static android.content.Context.CONTEXT_RESTRICTED; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 27 | import static android.content.Context.DISPLAY_SERVICE; |
| 28 | import static android.content.Context.WINDOW_SERVICE; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 29 | import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 30 | import static android.content.pm.PackageManager.FEATURE_LEANBACK; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 31 | import static android.content.pm.PackageManager.FEATURE_WATCH; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 32 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 33 | import static android.content.res.Configuration.EMPTY; |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 34 | import static android.content.res.Configuration.UI_MODE_TYPE_CAR; |
| 35 | import static android.content.res.Configuration.UI_MODE_TYPE_MASK; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 36 | import static android.os.Build.VERSION_CODES.M; |
| 37 | import static android.os.Build.VERSION_CODES.O; |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 38 | import static android.view.WindowManager.DOCKED_LEFT; |
| 39 | import static android.view.WindowManager.DOCKED_RIGHT; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 40 | import static android.view.WindowManager.DOCKED_TOP; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 41 | import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 42 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 43 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 44 | import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW; |
| 45 | import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| 46 | import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
| 47 | import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN; |
| 48 | import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN; |
| 49 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR; |
| 50 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR; |
| 51 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN; |
| 52 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
| 53 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
| 54 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 55 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
| 56 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 57 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
| 58 | import static android.view.WindowManager.LayoutParams.LAST_SYSTEM_WINDOW; |
| 59 | import static android.view.WindowManager.LayoutParams.MATCH_PARENT; |
| 60 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND; |
| 61 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT; |
| 62 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 63 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
| 64 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR; |
| 65 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE; |
| 66 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT; |
| 67 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE; |
| 68 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS; |
| 69 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; |
| 70 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 71 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 72 | import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 73 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 74 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 75 | import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; |
| 76 | import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY; |
| 77 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 78 | import static android.view.WindowManager.LayoutParams.TYPE_DREAM; |
| 79 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER; |
| 80 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 81 | import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; |
| 82 | import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY; |
| 83 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
| 84 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; |
| 85 | import static android.view.WindowManager.LayoutParams.TYPE_PHONE; |
| 86 | import static android.view.WindowManager.LayoutParams.TYPE_POINTER; |
Wale Ogunwale | 5b6714c | 2016-11-01 20:54:46 -0700 | [diff] [blame] | 87 | import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 88 | import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE; |
| 89 | import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION; |
| 90 | import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG; |
| 91 | import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT; |
| 92 | import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR; |
| 93 | import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
| 94 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
| 95 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; |
| 96 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; |
| 97 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; |
| 98 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
| 99 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
| 100 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; |
| 101 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
| 102 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; |
| 103 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING; |
| 104 | import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; |
| 105 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 106 | import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 107 | import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN; |
| 108 | import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 109 | import static android.view.WindowManagerGlobal.ADD_OKAY; |
| 110 | import static android.view.WindowManagerGlobal.ADD_PERMISSION_DENIED; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 111 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 112 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; |
| 113 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 114 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 115 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
| 116 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 117 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 118 | import android.annotation.Nullable; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 119 | import android.app.ActivityManager; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 120 | import android.app.ActivityManager.StackId; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 121 | import android.app.ActivityManagerInternal; |
| 122 | import android.app.ActivityManagerInternal.SleepToken; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 123 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 124 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 125 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 126 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 127 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 128 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 129 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 130 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 131 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 132 | import android.content.ContentResolver; |
| 133 | import android.content.Context; |
| 134 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 135 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 136 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 137 | import android.content.pm.ActivityInfo; |
Svet Ganov | 03f2afc | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 138 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 139 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 140 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 141 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 142 | import android.content.res.Configuration; |
| 143 | import android.content.res.Resources; |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 144 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 145 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 146 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 147 | import android.graphics.Rect; |
Jorim Jaggi | 7d0d102 | 2017-02-23 15:35:51 +0100 | [diff] [blame] | 148 | import android.graphics.drawable.Drawable; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 149 | import android.hardware.display.DisplayManager; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 150 | import android.hardware.hdmi.HdmiControlManager; |
| 151 | import android.hardware.hdmi.HdmiPlaybackClient; |
| 152 | import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback; |
Vladislav Kaznacheev | 19dab2d | 2017-02-07 10:12:51 -0800 | [diff] [blame] | 153 | import android.hardware.input.InputManager; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 154 | import android.hardware.input.InputManagerInternal; |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 155 | import android.hardware.power.V1_0.PowerHint; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 156 | import android.media.AudioAttributes; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 157 | import android.media.AudioManager; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 158 | import android.media.AudioSystem; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 159 | import android.media.IAudioService; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 160 | import android.media.session.MediaSessionLegacyHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 161 | import android.os.Binder; |
Svet Ganov | 03f2afc | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 162 | import android.os.Build; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 163 | import android.os.Bundle; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 164 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 165 | import android.os.Handler; |
| 166 | import android.os.IBinder; |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 167 | import android.os.IDeviceIdleController; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 168 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 169 | import android.os.Message; |
| 170 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 171 | import android.os.PowerManager; |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 172 | import android.os.PowerManagerInternal; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 173 | import android.os.Process; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 174 | import android.os.RemoteException; |
| 175 | import android.os.ServiceManager; |
| 176 | import android.os.SystemClock; |
| 177 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 178 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 179 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 180 | import android.os.Vibrator; |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 181 | import android.os.VibrationEffect; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 182 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 183 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 184 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 185 | import android.service.dreams.DreamService; |
| 186 | import android.service.dreams.IDreamManager; |
Santos Cordon | c09d89c | 2017-04-13 16:12:02 -0700 | [diff] [blame] | 187 | import android.service.vr.IPersistentVrStateCallbacks; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 188 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 189 | import android.telecom.TelecomManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 190 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 191 | import android.util.EventLog; |
| 192 | import android.util.Log; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 193 | import android.util.LongSparseArray; |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 194 | import android.util.MutableBoolean; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 195 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 196 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 197 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 198 | import android.view.Gravity; |
| 199 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 200 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 201 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 202 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 203 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 204 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 205 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 206 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 207 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 208 | import android.view.KeyEvent; |
| 209 | import android.view.MotionEvent; |
Vladislav Kaznacheev | 19dab2d | 2017-02-07 10:12:51 -0800 | [diff] [blame] | 210 | import android.view.PointerIcon; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 211 | import android.view.Surface; |
| 212 | import android.view.View; |
| 213 | import android.view.ViewConfiguration; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 214 | import android.view.WindowManager; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 215 | import android.view.WindowManager.LayoutParams; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 216 | import android.view.WindowManagerGlobal; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 217 | import android.view.WindowManagerInternal; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 218 | import android.view.WindowManagerInternal.AppTransitionListener; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 219 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 220 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 221 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 222 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 223 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 224 | import android.view.animation.AnimationUtils; |
Felipe Leme | 5f97880 | 2017-06-08 13:01:13 -0700 | [diff] [blame] | 225 | import android.view.autofill.AutofillManagerInternal; |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 226 | import android.view.inputmethod.InputMethodManagerInternal; |
Yohei Yukawa | abbe1ac | 2017-04-18 09:43:05 -0700 | [diff] [blame] | 227 | |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 228 | import com.android.internal.R; |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 229 | import com.android.internal.logging.MetricsLogger; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 230 | import com.android.internal.policy.IKeyguardDismissCallback; |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 231 | import com.android.internal.policy.IShortcutService; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 232 | import com.android.internal.policy.PhoneWindow; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 233 | import com.android.internal.statusbar.IStatusBarService; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 234 | import com.android.internal.util.ScreenShapeHelper; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 235 | import com.android.internal.widget.PointerLocationView; |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 236 | import com.android.server.GestureLauncherService; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 237 | import com.android.server.LocalServices; |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 238 | import com.android.server.SystemServiceManager; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 239 | import com.android.server.policy.keyguard.KeyguardServiceDelegate; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 240 | import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener; |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 241 | import com.android.server.policy.keyguard.KeyguardStateMonitor.StateCallback; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 242 | import com.android.server.statusbar.StatusBarManagerInternal; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 243 | import com.android.server.wm.AppTransition; |
Ruben Brunk | fecb615 | 2016-10-28 20:18:57 -0700 | [diff] [blame] | 244 | import com.android.server.vr.VrManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 245 | |
| 246 | import java.io.File; |
| 247 | import java.io.FileReader; |
| 248 | import java.io.IOException; |
| 249 | import java.io.PrintWriter; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 250 | import java.util.List; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 251 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 252 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 253 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 254 | * introduces a new method suffix, Lp, for an internal lock of the |
| 255 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 256 | * 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] | 257 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 258 | */ |
| 259 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 260 | static final String TAG = "WindowManager"; |
| 261 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 262 | static final boolean localLOGV = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 263 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 264 | static final boolean DEBUG_KEYGUARD = false; |
| 265 | static final boolean DEBUG_LAYOUT = false; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 266 | static final boolean DEBUG_SPLASH_SCREEN = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 267 | static final boolean DEBUG_WAKEUP = false; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 268 | static final boolean SHOW_SPLASH_SCREENS = true; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 269 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 270 | // 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] | 271 | // No longer recommended for desk docks; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 272 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 273 | |
Zak Cohen | db6ca49 | 2017-01-26 14:09:00 -0800 | [diff] [blame] | 274 | // Whether to allow devices placed in vr headset viewers to have an alternative Home intent. |
| 275 | static final boolean ENABLE_VR_HEADSET_HOME_CAPTURE = true; |
| 276 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 277 | static final boolean ALTERNATE_CAR_MODE_NAV_SIZE = false; |
| 278 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 279 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 280 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 281 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 282 | 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] | 283 | static final int SHORT_PRESS_POWER_GO_HOME = 4; |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 284 | static final int SHORT_PRESS_POWER_CLOSE_IME_OR_GO_HOME = 5; |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 285 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 286 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 287 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 288 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 289 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 290 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 291 | static final int LONG_PRESS_BACK_NOTHING = 0; |
| 292 | static final int LONG_PRESS_BACK_GO_TO_VOICE_ASSIST = 1; |
| 293 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 294 | static final int MULTI_PRESS_POWER_NOTHING = 0; |
| 295 | static final int MULTI_PRESS_POWER_THEATER_MODE = 1; |
| 296 | static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2; |
| 297 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 298 | // Number of presses needed before we induce panic press behavior on the back button |
| 299 | static final int PANIC_PRESS_BACK_COUNT = 4; |
| 300 | static final int PANIC_PRESS_BACK_NOTHING = 0; |
| 301 | static final int PANIC_PRESS_BACK_HOME = 1; |
| 302 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 303 | // These need to match the documentation/constant in |
| 304 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 305 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Sid Soundararajan | ff662fa | 2017-03-15 16:24:24 -0700 | [diff] [blame] | 306 | static final int LONG_PRESS_HOME_ALL_APPS = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 307 | static final int LONG_PRESS_HOME_ASSIST = 2; |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 308 | static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 309 | |
| 310 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 311 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 312 | |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 313 | static final int SHORT_PRESS_WINDOW_NOTHING = 0; |
| 314 | static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1; |
| 315 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 316 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0; |
| 317 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1; |
| 318 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 319 | static final int PENDING_KEY_NULL = -1; |
| 320 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 321 | // Controls navigation bar opacity depending on which workspace stacks are currently |
| 322 | // visible. |
| 323 | // Nav bar is always opaque when either the freeform stack or docked stack is visible. |
| 324 | static final int NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED = 0; |
| 325 | // Nav bar is always translucent when the freeform stack is visible, otherwise always opaque. |
| 326 | static final int NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE = 1; |
| 327 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 328 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 329 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 330 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 331 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 332 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 333 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 334 | /** |
| 335 | * These are the system UI flags that, when changing, can cause the layout |
| 336 | * of the screen to change. |
| 337 | */ |
| 338 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 339 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 340 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 341 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 342 | | View.NAVIGATION_BAR_TRANSLUCENT |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 343 | | View.STATUS_BAR_TRANSPARENT |
| 344 | | View.NAVIGATION_BAR_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 345 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 346 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 347 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 348 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 349 | .build(); |
| 350 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 351 | // The panic gesture may become active only after the keyguard is dismissed and the immersive |
| 352 | // app shows again. If that doesn't happen for 30s we drop the gesture. |
| 353 | private static final long PANIC_GESTURE_EXPIRATION = 30000; |
| 354 | |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 355 | private static final String SYSUI_PACKAGE = "com.android.systemui"; |
| 356 | private static final String SYSUI_SCREENSHOT_SERVICE = |
| 357 | "com.android.systemui.screenshot.TakeScreenshotService"; |
| 358 | private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER = |
| 359 | "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver"; |
| 360 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 361 | /** |
| 362 | * Keyguard stuff |
| 363 | */ |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 364 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 365 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 366 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 367 | * |
| 368 | * These are special keys that are used to launch particular kinds of applications, |
| 369 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 370 | * usage page. We don't support quite that many yet... |
| 371 | */ |
| 372 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 373 | static { |
| 374 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 375 | sApplicationLaunchKeyCategories.append( |
| 376 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 377 | sApplicationLaunchKeyCategories.append( |
| 378 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 379 | sApplicationLaunchKeyCategories.append( |
| 380 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 381 | sApplicationLaunchKeyCategories.append( |
| 382 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 383 | sApplicationLaunchKeyCategories.append( |
| 384 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 385 | sApplicationLaunchKeyCategories.append( |
| 386 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 387 | } |
| 388 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 389 | /** 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] | 390 | static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 391 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 392 | /** Amount of time (in milliseconds) a toast window can be shown. */ |
| 393 | public static final int TOAST_WINDOW_TIMEOUT = 3500; // 3.5 seconds |
| 394 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 395 | /** |
| 396 | * Lock protecting internal state. Must not call out into window |
| 397 | * manager with lock held. (This lock will be acquired in places |
| 398 | * where the window manager is calling in with its own lock held.) |
| 399 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 400 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 401 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 402 | Context mContext; |
| 403 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 404 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 405 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 406 | PowerManager mPowerManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 407 | ActivityManagerInternal mActivityManagerInternal; |
Felipe Leme | 5f97880 | 2017-06-08 13:01:13 -0700 | [diff] [blame] | 408 | AutofillManagerInternal mAutofillManagerInternal; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 409 | InputManagerInternal mInputManagerInternal; |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 410 | InputMethodManagerInternal mInputMethodManagerInternal; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 411 | DreamManagerInternal mDreamManagerInternal; |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 412 | PowerManagerInternal mPowerManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 413 | IStatusBarService mStatusBarService; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 414 | StatusBarManagerInternal mStatusBarManagerInternal; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 415 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 416 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 417 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 418 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 419 | AccessibilityManager mAccessibilityManager; |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 420 | BurnInProtectionHelper mBurnInProtectionHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 421 | AppOpsManager mAppOpsManager; |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 422 | private boolean mHasFeatureWatch; |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 423 | private boolean mHasFeatureLeanback; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 424 | |
Zak Cohen | 732aeb0 | 2017-01-29 14:19:52 -0800 | [diff] [blame] | 425 | // Assigned on main thread, accessed on UI thread |
| 426 | volatile VrManagerInternal mVrManagerInternal; |
| 427 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 428 | // Vibrator pattern for haptic feedback of a long press. |
| 429 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 430 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 431 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 432 | long[] mCalendarDateVibePattern; |
| 433 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 434 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 435 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 436 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 437 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 438 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 439 | |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 440 | /** Controller that supports enabling an AccessibilityService by holding down the volume keys */ |
| 441 | private AccessibilityShortcutController mAccessibilityShortcutController; |
| 442 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 443 | boolean mSafeMode; |
| 444 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 445 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 446 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 447 | boolean mHasNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 448 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 449 | int mNavigationBarPosition = NAV_BAR_BOTTOM; |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 450 | int[] mNavigationBarHeightForRotationDefault = new int[4]; |
| 451 | int[] mNavigationBarWidthForRotationDefault = new int[4]; |
| 452 | int[] mNavigationBarHeightForRotationInCarMode = new int[4]; |
| 453 | int[] mNavigationBarWidthForRotationInCarMode = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 454 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 455 | private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>(); |
| 456 | |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 457 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 458 | // This is for car dock and this is updated from resource. |
| 459 | private boolean mEnableCarDockHomeCapture = true; |
| 460 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 461 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 462 | KeyguardServiceDelegate mKeyguardDelegate; |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 463 | private boolean mKeyguardBound; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 464 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 465 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 466 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 467 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 468 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 469 | } |
| 470 | }; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 471 | final DrawnListener mKeyguardDrawnCallback = new DrawnListener() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 472 | @Override |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 473 | public void onDrawn() { |
| 474 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 475 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 476 | } |
| 477 | }; |
| 478 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 479 | GlobalActions mGlobalActions; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 480 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 481 | WindowState mLastInputMethodWindow = null; |
| 482 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 483 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 484 | // FIXME This state is shared between the input reader and handler thread. |
| 485 | // Technically it's broken and buggy but it has been like this for many years |
| 486 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 487 | // so that only one thread is involved in handling input policy. Unfortunately |
| 488 | // it's on a critical path for power management so we can't just post the work to the |
| 489 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 490 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 491 | volatile boolean mPowerKeyHandled; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 492 | volatile boolean mBackKeyHandled; |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 493 | volatile boolean mBeganFromNonInteractive; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 494 | volatile int mPowerKeyPressCounter; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 495 | volatile int mBackKeyPressCounter; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 496 | volatile boolean mEndCallKeyHandled; |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 497 | volatile boolean mCameraGestureTriggeredDuringGoingToSleep; |
| 498 | volatile boolean mGoingToSleep; |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 499 | volatile boolean mRecentsVisible; |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 500 | volatile boolean mPictureInPictureVisible; |
Santos Cordon | c09d89c | 2017-04-13 16:12:02 -0700 | [diff] [blame] | 501 | // Written by vr manager thread, only read in this class. |
| 502 | volatile private boolean mPersistentVrModeEnabled; |
Yohei Yukawa | abbe1ac | 2017-04-18 09:43:05 -0700 | [diff] [blame] | 503 | volatile private boolean mDismissImeOnBackKeyPressed; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 504 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 505 | // Used to hold the last user key used to wake the device. This helps us prevent up events |
| 506 | // from being passed to the foregrounded app without a corresponding down event |
| 507 | volatile int mPendingWakeKey = PENDING_KEY_NULL; |
| 508 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 509 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 510 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 511 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 512 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 513 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 514 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 515 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 516 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 517 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 518 | boolean mHdmiPlugged; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 519 | HdmiControl mHdmiControl; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 520 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 521 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 522 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 523 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 524 | int mCarDockRotation; |
| 525 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 526 | int mUndockedHdmiRotation; |
| 527 | int mDemoHdmiRotation; |
| 528 | boolean mDemoHdmiRotationLock; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 529 | int mDemoRotation; |
| 530 | boolean mDemoRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 531 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 532 | boolean mWakeGestureEnabledSetting; |
| 533 | MyWakeGestureListener mWakeGestureListener; |
| 534 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 535 | // Default display does not rotate, apps that require non-default orientation will have to |
| 536 | // have the orientation emulated. |
| 537 | private boolean mForceDefaultOrientation = false; |
| 538 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 539 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 540 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 541 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 542 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 543 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 544 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 545 | boolean mCarDockEnablesAccelerometer; |
| 546 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 547 | int mLidKeyboardAccessibility; |
| 548 | int mLidNavigationAccessibility; |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 549 | boolean mLidControlsScreenLock; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 550 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 551 | int mShortPressOnPowerBehavior; |
| 552 | int mLongPressOnPowerBehavior; |
| 553 | int mDoublePressOnPowerBehavior; |
| 554 | int mTriplePressOnPowerBehavior; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 555 | int mLongPressOnBackBehavior; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 556 | int mPanicPressOnBackBehavior; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 557 | int mShortPressOnSleepBehavior; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 558 | int mShortPressWindowBehavior; |
Adrian Roos | e94c15c | 2017-05-09 13:17:54 -0700 | [diff] [blame] | 559 | volatile boolean mAwake; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 560 | boolean mScreenOnEarly; |
| 561 | boolean mScreenOnFully; |
| 562 | ScreenOnListener mScreenOnListener; |
| 563 | boolean mKeyguardDrawComplete; |
| 564 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 565 | boolean mOrientationSensorEnabled = false; |
| 566 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 567 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 568 | boolean mTranslucentDecorEnabled = true; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 569 | boolean mUseTvRouting; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 570 | |
Karthik Ravi Shankar | 86ecf34 | 2017-04-28 15:35:58 -0700 | [diff] [blame] | 571 | private boolean mHandleVolumeKeysInWM; |
| 572 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 573 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 574 | |
| 575 | // The last window we were told about in focusChanged. |
| 576 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 577 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 578 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 579 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 580 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 581 | // The current size of the screen; really; extends into the overscan area of |
| 582 | // the screen and doesn't account for any system elements like the status bar. |
| 583 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 584 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 585 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 586 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 587 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 588 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 589 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 590 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 591 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 592 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 593 | // if the status bar can't be hidden; in that case it effectively carves out |
| 594 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 595 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 596 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 597 | // During layout, the current screen borders accounting for any currently |
| 598 | // visible system UI elements. |
| 599 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 600 | // For applications requesting stable content insets, these are them. |
| 601 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 602 | // For applications requesting stable content insets but have also set the |
| 603 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 604 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 605 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 606 | // During layout, the current screen borders with all outer decoration |
| 607 | // (status bar, input method dock) accounted for. |
| 608 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 609 | // During layout, the frame in which 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. This is usually |
| 612 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 613 | // content insets. |
| 614 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 615 | // During layout, the frame in which voice content should be displayed |
| 616 | // to the user, accounting for all screen decoration except for any |
| 617 | // space they deem as available for other content. |
| 618 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 619 | // 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] | 620 | // windows are placed. |
| 621 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 622 | // During layout, the layer at which the doc window is placed. |
| 623 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 624 | // During layout, this is the layer of the status bar. |
| 625 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 626 | int mLastSystemUiFlags; |
| 627 | // Bits that we are in the process of clearing, so we want to prevent |
| 628 | // them from being set by applications until everything has been updated |
| 629 | // to have them clear. |
| 630 | int mResettingSystemUiFlags = 0; |
| 631 | // Bits that we are currently always keeping cleared. |
| 632 | int mForceClearedSystemUiFlags = 0; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 633 | int mLastFullscreenStackSysUiFlags; |
| 634 | int mLastDockedStackSysUiFlags; |
| 635 | final Rect mNonDockedStackBounds = new Rect(); |
| 636 | final Rect mDockedStackBounds = new Rect(); |
| 637 | final Rect mLastNonDockedStackBounds = new Rect(); |
| 638 | final Rect mLastDockedStackBounds = new Rect(); |
| 639 | |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 640 | // What we last reported to system UI about whether the compatibility |
| 641 | // menu needs to be displayed. |
| 642 | boolean mLastFocusNeedsMenu = false; |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 643 | // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending. |
| 644 | private long mPendingPanicGestureUptime; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 645 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 646 | InputConsumer mInputConsumer = null; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 647 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 648 | static final Rect mTmpParentFrame = new Rect(); |
| 649 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 650 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 651 | static final Rect mTmpContentFrame = new Rect(); |
| 652 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 653 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 654 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 655 | static final Rect mTmpNavigationFrame = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 656 | static final Rect mTmpOutsetFrame = new Rect(); |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 657 | private static final Rect mTmpRect = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 658 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 659 | WindowState mTopFullscreenOpaqueWindowState; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 660 | WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 661 | WindowState mTopDockedOpaqueWindowState; |
| 662 | WindowState mTopDockedOpaqueOrDimmingWindowState; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 663 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 664 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 665 | boolean mForceStatusBarFromKeyguard; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 666 | private boolean mForceStatusBarTransparent; |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 667 | int mNavBarOpacityMode = NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 668 | boolean mForcingShowNavBar; |
| 669 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 670 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 671 | private boolean mPendingKeyguardOccluded; |
| 672 | private boolean mKeyguardOccludedChanged; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 673 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 674 | boolean mShowingDream; |
Jorim Jaggi | 77e1043 | 2016-10-26 17:43:56 -0700 | [diff] [blame] | 675 | private boolean mLastShowingDream; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 676 | boolean mDreamingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 677 | boolean mDreamingSleepTokenNeeded; |
| 678 | SleepToken mDreamingSleepToken; |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 679 | SleepToken mScreenOffSleepToken; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 680 | volatile boolean mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 681 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 682 | boolean mHomeConsumed; |
| 683 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 684 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 685 | Intent mCarDockIntent; |
| 686 | Intent mDeskDockIntent; |
Zak Cohen | db6ca49 | 2017-01-26 14:09:00 -0800 | [diff] [blame] | 687 | Intent mVrHeadsetHomeIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 688 | boolean mSearchKeyShortcutPending; |
| 689 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 690 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 691 | boolean mPendingMetaAction; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 692 | boolean mPendingCapsLockToggle; |
| 693 | int mMetaState; |
| 694 | int mInitialMetaState; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 695 | boolean mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 696 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 697 | // support for activating the lock screen while the screen is on |
| 698 | boolean mAllowLockscreenWhenOn; |
| 699 | int mLockScreenTimeout; |
| 700 | boolean mLockScreenTimerActive; |
| 701 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 702 | // 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] | 703 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 704 | |
| 705 | // Behavior of POWER button while in-call and screen on. |
| 706 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 707 | int mIncallPowerBehavior; |
| 708 | |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 709 | // Behavior of Back button while in-call and screen on |
| 710 | int mIncallBackBehavior; |
| 711 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 712 | Display mDisplay; |
| 713 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 714 | private int mDisplayRotation; |
| 715 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 716 | int mLandscapeRotation = 0; // default landscape rotation |
| 717 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 718 | int mPortraitRotation = 0; // default portrait rotation |
| 719 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 720 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 721 | int mOverscanLeft = 0; |
| 722 | int mOverscanTop = 0; |
| 723 | int mOverscanRight = 0; |
| 724 | int mOverscanBottom = 0; |
| 725 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 726 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 727 | private int mLongPressOnHomeBehavior; |
| 728 | |
| 729 | // What we do when the user double-taps on home |
| 730 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 731 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 732 | // Allowed theater mode wake actions |
| 733 | private boolean mAllowTheaterModeWakeFromKey; |
| 734 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 735 | private boolean mAllowTheaterModeWakeFromMotion; |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 736 | private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 737 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 738 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 739 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 740 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 741 | // Whether to support long press from power button in non-interactive mode |
| 742 | private boolean mSupportLongPressPowerWhenNonInteractive; |
| 743 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 744 | // Whether to go to sleep entering theater mode from power button |
| 745 | private boolean mGoToSleepOnButtonPressTheaterMode; |
| 746 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 747 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 748 | // Time to volume and power must be pressed within this interval of each other. |
| 749 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 750 | // Increase the chord delay when taking a screenshot from the keyguard |
| 751 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 752 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 753 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 754 | private long mScreenshotChordVolumeDownKeyTime; |
| 755 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 756 | private boolean mA11yShortcutChordVolumeUpKeyTriggered; |
| 757 | private long mA11yShortcutChordVolumeUpKeyTime; |
| 758 | private boolean mA11yShortcutChordVolumeUpKeyConsumed; |
| 759 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 760 | private boolean mScreenshotChordPowerKeyTriggered; |
| 761 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 762 | |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 763 | private static final long BUGREPORT_TV_GESTURE_TIMEOUT_MILLIS = 1000; |
| 764 | |
| 765 | private boolean mBugreportTvKey1Pressed; |
| 766 | private boolean mBugreportTvKey2Pressed; |
| 767 | private boolean mBugreportTvScheduled; |
| 768 | |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 769 | private boolean mAccessibilityTvKey1Pressed; |
| 770 | private boolean mAccessibilityTvKey2Pressed; |
| 771 | private boolean mAccessibilityTvScheduled; |
| 772 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 773 | /* The number of steps between min and max brightness */ |
| 774 | private static final int BRIGHTNESS_STEPS = 10; |
| 775 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 776 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 777 | ShortcutManager mShortcutManager; |
| 778 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 779 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 780 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 781 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 782 | private int mCurrentUserId; |
| 783 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 784 | // Maps global key codes to the components that will handle them. |
| 785 | private GlobalKeyManager mGlobalKeyManager; |
| 786 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 787 | // Fallback actions by key code. |
| 788 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 789 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 790 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 791 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 792 | = new LogDecelerateInterpolator(100, 0); |
| 793 | |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 794 | private final MutableBoolean mTmpBoolean = new MutableBoolean(false); |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 795 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 796 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 797 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 798 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 799 | 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] | 800 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 801 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 802 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 803 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 804 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 805 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 806 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 807 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 808 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 809 | private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 810 | private static final int MSG_REQUEST_TRANSIENT_BARS = 16; |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 811 | private static final int MSG_SHOW_PICTURE_IN_PICTURE_MENU = 17; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 812 | private static final int MSG_BACK_LONG_PRESS = 18; |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 813 | private static final int MSG_DISPOSE_INPUT_CONSUMER = 19; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 814 | private static final int MSG_BACK_DELAYED_PRESS = 20; |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 815 | private static final int MSG_ACCESSIBILITY_SHORTCUT = 21; |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 816 | private static final int MSG_BUGREPORT_TV = 22; |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 817 | private static final int MSG_ACCESSIBILITY_TV = 23; |
Felipe Leme | 5f97880 | 2017-06-08 13:01:13 -0700 | [diff] [blame] | 818 | private static final int MSG_DISPATCH_BACK_KEY_TO_AUTOFILL = 24; |
Philip Quinn | 4b5b3c6 | 2017-07-20 21:07:58 -0700 | [diff] [blame] | 819 | private static final int MSG_SYSTEM_KEY_PRESS = 25; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 820 | |
| 821 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0; |
| 822 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 823 | |
| 824 | private class PolicyHandler extends Handler { |
| 825 | @Override |
| 826 | public void handleMessage(Message msg) { |
| 827 | switch (msg.what) { |
| 828 | case MSG_ENABLE_POINTER_LOCATION: |
| 829 | enablePointerLocation(); |
| 830 | break; |
| 831 | case MSG_DISABLE_POINTER_LOCATION: |
| 832 | disablePointerLocation(); |
| 833 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 834 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 835 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 836 | break; |
| 837 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 838 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 839 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 840 | case MSG_DISPATCH_SHOW_RECENTS: |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 841 | showRecentApps(false, msg.arg1 != 0); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 842 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 843 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 844 | showGlobalActionsInternal(); |
| 845 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 846 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 847 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 848 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 849 | break; |
| 850 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 851 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 852 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 853 | break; |
| 854 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 855 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 856 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 857 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 858 | case MSG_HIDE_BOOT_MESSAGE: |
| 859 | handleHideBootMessage(); |
| 860 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 861 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 862 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 863 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 864 | case MSG_POWER_DELAYED_PRESS: |
| 865 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 866 | finishPowerKeyPress(); |
| 867 | break; |
| 868 | case MSG_POWER_LONG_PRESS: |
| 869 | powerLongPress(); |
| 870 | break; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 871 | case MSG_UPDATE_DREAMING_SLEEP_TOKEN: |
| 872 | updateDreamingSleepToken(msg.arg1 != 0); |
| 873 | break; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 874 | case MSG_REQUEST_TRANSIENT_BARS: |
| 875 | WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ? |
| 876 | mStatusBar : mNavigationBar; |
| 877 | if (targetBar != null) { |
| 878 | requestTransientBars(targetBar); |
| 879 | } |
| 880 | break; |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 881 | case MSG_SHOW_PICTURE_IN_PICTURE_MENU: |
| 882 | showPictureInPictureMenuInternal(); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 883 | break; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 884 | case MSG_BACK_LONG_PRESS: |
| 885 | backLongPress(); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 886 | finishBackKeyPress(); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 887 | break; |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 888 | case MSG_DISPOSE_INPUT_CONSUMER: |
| 889 | disposeInputConsumer((InputConsumer) msg.obj); |
| 890 | break; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 891 | case MSG_BACK_DELAYED_PRESS: |
| 892 | backMultiPressAction((Long) msg.obj, msg.arg1); |
| 893 | finishBackKeyPress(); |
| 894 | break; |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 895 | case MSG_ACCESSIBILITY_SHORTCUT: |
| 896 | accessibilityShortcutActivated(); |
| 897 | break; |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 898 | case MSG_BUGREPORT_TV: |
| 899 | takeBugreport(); |
| 900 | break; |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 901 | case MSG_ACCESSIBILITY_TV: |
| 902 | if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(false)) { |
| 903 | accessibilityShortcutActivated(); |
| 904 | } |
| 905 | break; |
Felipe Leme | 5f97880 | 2017-06-08 13:01:13 -0700 | [diff] [blame] | 906 | case MSG_DISPATCH_BACK_KEY_TO_AUTOFILL: |
| 907 | mAutofillManagerInternal.onBackKeyPressed(); |
| 908 | break; |
Philip Quinn | 4b5b3c6 | 2017-07-20 21:07:58 -0700 | [diff] [blame] | 909 | case MSG_SYSTEM_KEY_PRESS: |
| 910 | sendSystemKeyToStatusBar(msg.arg1); |
| 911 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | } |
| 915 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 916 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 917 | @Override |
| 918 | public void onUEvent(UEventObserver.UEvent event) { |
| 919 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 920 | } |
| 921 | }; |
| 922 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 923 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 924 | SettingsObserver(Handler handler) { |
| 925 | super(handler); |
| 926 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 927 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 928 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 929 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 930 | ContentResolver resolver = mContext.getContentResolver(); |
| 931 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 932 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 933 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 934 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 935 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 936 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 937 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 938 | Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR), false, this, |
| 939 | UserHandle.USER_ALL); |
| 940 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 941 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 942 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 943 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 944 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 945 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 946 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 947 | Settings.System.USER_ROTATION), false, this, |
| 948 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 949 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 950 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 951 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 952 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 953 | Settings.System.POINTER_LOCATION), false, this, |
| 954 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 955 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 956 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 957 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 958 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 959 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 960 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 961 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 962 | Settings.Global.POLICY_CONTROL), false, this, |
| 963 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 964 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 968 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 969 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 970 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 971 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 972 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 973 | class MyWakeGestureListener extends WakeGestureListener { |
| 974 | MyWakeGestureListener(Context context, Handler handler) { |
| 975 | super(context, handler); |
| 976 | } |
| 977 | |
| 978 | @Override |
| 979 | public void onWakeUp() { |
| 980 | synchronized (mLock) { |
| 981 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 982 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 983 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture, |
| 984 | "android.policy:GESTURE"); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 985 | } |
| 986 | } |
| 987 | } |
| 988 | } |
| 989 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 990 | class MyOrientationListener extends WindowOrientationListener { |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 991 | private final Runnable mUpdateRotationRunnable = new Runnable() { |
| 992 | @Override |
| 993 | public void run() { |
Tim Murray | 1f40764 | 2015-10-01 17:07:12 -0700 | [diff] [blame] | 994 | // send interaction hint to improve redraw performance |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 995 | mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 996 | updateRotation(false); |
| 997 | } |
| 998 | }; |
| 999 | |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1000 | MyOrientationListener(Context context, Handler handler) { |
| 1001 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1002 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1003 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1004 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1005 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1006 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 1007 | mHandler.post(mUpdateRotationRunnable); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1008 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1009 | } |
| 1010 | MyOrientationListener mOrientationListener; |
| 1011 | |
Santos Cordon | c09d89c | 2017-04-13 16:12:02 -0700 | [diff] [blame] | 1012 | final IPersistentVrStateCallbacks mPersistentVrModeListener = |
| 1013 | new IPersistentVrStateCallbacks.Stub() { |
| 1014 | @Override |
| 1015 | public void onPersistentVrStateChanged(boolean enabled) { |
| 1016 | mPersistentVrModeEnabled = enabled; |
| 1017 | } |
| 1018 | }; |
| 1019 | |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 1020 | private final StatusBarController mStatusBarController = new StatusBarController(); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 1021 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1022 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 1023 | View.NAVIGATION_BAR_TRANSIENT, |
| 1024 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 1025 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 1026 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 1027 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, |
| 1028 | View.NAVIGATION_BAR_TRANSPARENT); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 1029 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1030 | private final BarController.OnBarVisibilityChangedListener mNavBarVisibilityListener = |
| 1031 | new BarController.OnBarVisibilityChangedListener() { |
| 1032 | @Override |
| 1033 | public void onBarVisibilityChanged(boolean visible) { |
Casey Burkhardt | 469a208 | 2017-06-13 20:12:42 -0700 | [diff] [blame] | 1034 | mAccessibilityManager.notifyAccessibilityButtonVisibilityChanged(visible); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1035 | } |
| 1036 | }; |
| 1037 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1038 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1039 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1040 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1041 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1042 | IStatusBarService getStatusBarService() { |
| 1043 | synchronized (mServiceAquireLock) { |
| 1044 | if (mStatusBarService == null) { |
| 1045 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 1046 | ServiceManager.getService("statusbar")); |
| 1047 | } |
| 1048 | return mStatusBarService; |
| 1049 | } |
| 1050 | } |
| 1051 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 1052 | StatusBarManagerInternal getStatusBarManagerInternal() { |
| 1053 | synchronized (mServiceAquireLock) { |
| 1054 | if (mStatusBarManagerInternal == null) { |
| 1055 | mStatusBarManagerInternal = |
| 1056 | LocalServices.getService(StatusBarManagerInternal.class); |
| 1057 | } |
| 1058 | return mStatusBarManagerInternal; |
| 1059 | } |
| 1060 | } |
| 1061 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 1062 | /* |
| 1063 | * We always let the sensor be switched on by default except when |
| 1064 | * the user has explicitly disabled sensor based rotation or when the |
| 1065 | * screen is switched off. |
| 1066 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1067 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1068 | if (mSupportAutoRotation) { |
| 1069 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 1070 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 1071 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 1072 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 1073 | // If the application has explicitly requested to follow the |
| 1074 | // orientation, then we need to turn the sensor on. |
| 1075 | return true; |
| 1076 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1077 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1078 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 1079 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 1080 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 1081 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1082 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 1083 | // orientation management, |
| 1084 | return true; |
| 1085 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1086 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1087 | // If the setting for using the sensor by default is enabled, then |
| 1088 | // we will always leave it on. Note that the user could go to |
| 1089 | // a window that forces an orientation that does not use the |
| 1090 | // sensor and in theory we could turn it off... however, when next |
| 1091 | // turning it on we won't have a good value for the current |
| 1092 | // orientation for a little bit, which can cause orientation |
| 1093 | // changes to lag, so we'd like to keep it always on. (It will |
| 1094 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 1095 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1096 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1097 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1098 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1099 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1100 | /* |
| 1101 | * Various use cases for invoking this function |
| 1102 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1103 | * 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] | 1104 | * if not already enabled |
| 1105 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 1106 | * already enabled |
| 1107 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 1108 | * screen turning on and current app has nosensor based orientation, do nothing |
| 1109 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1110 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1111 | if (!mOrientationListener.canDetectOrientation()) { |
| 1112 | // If sensor is turned off or nonexistent for some reason |
| 1113 | return; |
| 1114 | } |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 1115 | // Could have been invoked due to screen turning on or off or |
| 1116 | // change of the currently visible window's orientation. |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1117 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 1118 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 1119 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled |
| 1120 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 1121 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 1122 | final boolean keyguardGoingAway = mWindowManagerInternal.isKeyguardGoingAway(); |
| 1123 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1124 | boolean disable = true; |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 1125 | // Note: We postpone the rotating of the screen until the keyguard as well as the |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 1126 | // window manager have reported a draw complete or the keyguard is going away in dismiss |
| 1127 | // mode. |
| 1128 | if (mScreenOnEarly && mAwake && ((mKeyguardDrawComplete && mWindowManagerDrawComplete) |
| 1129 | || keyguardGoingAway)) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1130 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1131 | disable = false; |
| 1132 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1133 | if (!mOrientationSensorEnabled) { |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 1134 | // Don't clear the current sensor orientation if the keyguard is going away in |
| 1135 | // dismiss mode. This allows window manager to use the last sensor reading to |
| 1136 | // determine the orientation vs. falling back to the last known orientation if |
| 1137 | // the sensor reading was cleared which can cause it to relaunch the app that |
| 1138 | // will show in the wrong orientation first before correcting leading to app |
| 1139 | // launch delays. |
| 1140 | mOrientationListener.enable(!keyguardGoingAway /* clearCurrentRotation */); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1141 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1142 | mOrientationSensorEnabled = true; |
| 1143 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1144 | } |
| 1145 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1146 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1147 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1148 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1149 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1150 | mOrientationSensorEnabled = false; |
| 1151 | } |
| 1152 | } |
| 1153 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1154 | private void interceptBackKeyDown() { |
Nimrod Gileadi | 580135c | 2016-10-31 20:42:19 +0000 | [diff] [blame] | 1155 | MetricsLogger.count(mContext, "key_back_down", 1); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1156 | // Reset back key state for long press |
| 1157 | mBackKeyHandled = false; |
| 1158 | |
| 1159 | // Cancel multi-press detection timeout. |
| 1160 | if (hasPanicPressOnBackBehavior()) { |
| 1161 | if (mBackKeyPressCounter != 0 |
| 1162 | && mBackKeyPressCounter < PANIC_PRESS_BACK_COUNT) { |
| 1163 | mHandler.removeMessages(MSG_BACK_DELAYED_PRESS); |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | if (hasLongPressOnBackBehavior()) { |
| 1168 | Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS); |
| 1169 | msg.setAsynchronous(true); |
| 1170 | mHandler.sendMessageDelayed(msg, |
| 1171 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | // returns true if the key was handled and should not be passed to the user |
| 1176 | private boolean interceptBackKeyUp(KeyEvent event) { |
| 1177 | // Cache handled state |
| 1178 | boolean handled = mBackKeyHandled; |
| 1179 | |
| 1180 | if (hasPanicPressOnBackBehavior()) { |
| 1181 | // Check for back key panic press |
| 1182 | ++mBackKeyPressCounter; |
| 1183 | |
| 1184 | final long eventTime = event.getDownTime(); |
| 1185 | |
| 1186 | if (mBackKeyPressCounter <= PANIC_PRESS_BACK_COUNT) { |
| 1187 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 1188 | Message msg = mHandler.obtainMessage(MSG_BACK_DELAYED_PRESS, |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 1189 | mBackKeyPressCounter, 0, eventTime); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1190 | msg.setAsynchronous(true); |
| 1191 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getMultiPressTimeout()); |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | // Reset back long press state |
| 1196 | cancelPendingBackKeyAction(); |
| 1197 | |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 1198 | if (mHasFeatureWatch) { |
| 1199 | TelecomManager telecomManager = getTelecommService(); |
| 1200 | |
| 1201 | if (telecomManager != null) { |
| 1202 | if (telecomManager.isRinging()) { |
| 1203 | // Pressing back while there's a ringing incoming |
| 1204 | // call should silence the ringer. |
| 1205 | telecomManager.silenceRinger(); |
| 1206 | |
| 1207 | // It should not prevent navigating away |
| 1208 | return false; |
| 1209 | } else if ( |
| 1210 | (mIncallBackBehavior & Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 1211 | && telecomManager.isInCall()) { |
| 1212 | // Otherwise, if "Back button ends call" is enabled, |
| 1213 | // the Back button will hang up any current active call. |
| 1214 | return telecomManager.endCall(); |
| 1215 | } |
| 1216 | } |
| 1217 | } |
| 1218 | |
Felipe Leme | 5f97880 | 2017-06-08 13:01:13 -0700 | [diff] [blame] | 1219 | if (mAutofillManagerInternal != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) { |
| 1220 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DISPATCH_BACK_KEY_TO_AUTOFILL)); |
| 1221 | } |
| 1222 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1223 | return handled; |
| 1224 | } |
| 1225 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1226 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 1227 | // Hold a wake lock until the power key is released. |
| 1228 | if (!mPowerKeyWakeLock.isHeld()) { |
| 1229 | mPowerKeyWakeLock.acquire(); |
| 1230 | } |
| 1231 | |
| 1232 | // Cancel multi-press detection timeout. |
| 1233 | if (mPowerKeyPressCounter != 0) { |
| 1234 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 1235 | } |
| 1236 | |
| 1237 | // Detect user pressing the power button in panic when an application has |
| 1238 | // taken over the whole screen. |
| 1239 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
Adrian Roos | 7aaa551 | 2016-07-12 15:27:24 -0700 | [diff] [blame] | 1240 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags), |
| 1241 | isNavBarEmpty(mLastSystemUiFlags)); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1242 | if (panic) { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 1243 | mHandler.post(mHiddenNavPanic); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | // Latch power key state to detect screenshot chord. |
| 1247 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 1248 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 1249 | mScreenshotChordPowerKeyTriggered = true; |
| 1250 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 1251 | interceptScreenshotChord(); |
| 1252 | } |
| 1253 | |
| 1254 | // Stop ringing or end call if configured to do so when power is pressed. |
| 1255 | TelecomManager telecomManager = getTelecommService(); |
| 1256 | boolean hungUp = false; |
| 1257 | if (telecomManager != null) { |
| 1258 | if (telecomManager.isRinging()) { |
| 1259 | // Pressing Power while there's a ringing incoming |
| 1260 | // call should silence the ringer. |
| 1261 | telecomManager.silenceRinger(); |
| 1262 | } else if ((mIncallPowerBehavior |
| 1263 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 1264 | && telecomManager.isInCall() && interactive) { |
| 1265 | // Otherwise, if "Power button ends call" is enabled, |
| 1266 | // the Power button will hang up any current active call. |
| 1267 | hungUp = telecomManager.endCall(); |
| 1268 | } |
| 1269 | } |
| 1270 | |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1271 | GestureLauncherService gestureService = LocalServices.getService( |
| 1272 | GestureLauncherService.class); |
| 1273 | boolean gesturedServiceIntercepted = false; |
| 1274 | if (gestureService != null) { |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 1275 | gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive, |
| 1276 | mTmpBoolean); |
| 1277 | if (mTmpBoolean.value && mGoingToSleep) { |
| 1278 | mCameraGestureTriggeredDuringGoingToSleep = true; |
| 1279 | } |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
Philip Quinn | c3a503d | 2017-07-18 23:23:41 -0700 | [diff] [blame] | 1282 | // Inform the StatusBar; but do not allow it to consume the event. |
Philip Quinn | 4b5b3c6 | 2017-07-20 21:07:58 -0700 | [diff] [blame] | 1283 | sendSystemKeyToStatusBarAsync(event.getKeyCode()); |
Philip Quinn | c3a503d | 2017-07-18 23:23:41 -0700 | [diff] [blame] | 1284 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1285 | // If the power key has still not yet been handled, then detect short |
| 1286 | // press, long press, or multi press and decide what to do. |
| 1287 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1288 | || mA11yShortcutChordVolumeUpKeyTriggered || gesturedServiceIntercepted; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1289 | if (!mPowerKeyHandled) { |
| 1290 | if (interactive) { |
| 1291 | // When interactive, we're already awake. |
| 1292 | // Wait for a long press or for the button to be released to decide what to do. |
| 1293 | if (hasLongPressOnPowerBehavior()) { |
| 1294 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 1295 | msg.setAsynchronous(true); |
| 1296 | mHandler.sendMessageDelayed(msg, |
| 1297 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 1298 | } |
| 1299 | } else { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1300 | wakeUpFromPowerKey(event.getDownTime()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1301 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1302 | if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { |
| 1303 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 1304 | msg.setAsynchronous(true); |
| 1305 | mHandler.sendMessageDelayed(msg, |
| 1306 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1307 | mBeganFromNonInteractive = true; |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1308 | } else { |
| 1309 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1310 | |
| 1311 | if (maxCount <= 1) { |
| 1312 | mPowerKeyHandled = true; |
| 1313 | } else { |
| 1314 | mBeganFromNonInteractive = true; |
| 1315 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1316 | } |
| 1317 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1321 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 1322 | final boolean handled = canceled || mPowerKeyHandled; |
| 1323 | mScreenshotChordPowerKeyTriggered = false; |
| 1324 | cancelPendingScreenshotChordAction(); |
| 1325 | cancelPendingPowerKeyAction(); |
| 1326 | |
| 1327 | if (!handled) { |
| 1328 | // Figure out how to handle the key now that it has been released. |
| 1329 | mPowerKeyPressCounter += 1; |
| 1330 | |
| 1331 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1332 | final long eventTime = event.getDownTime(); |
| 1333 | if (mPowerKeyPressCounter < maxCount) { |
| 1334 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 1335 | // Continue holding the wake lock. |
| 1336 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 1337 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 1338 | msg.setAsynchronous(true); |
Alain Vongsouvanh | 0f63a54 | 2017-04-10 17:13:17 -0700 | [diff] [blame] | 1339 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getMultiPressTimeout()); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1340 | return; |
| 1341 | } |
| 1342 | |
| 1343 | // No other actions. Handle it immediately. |
| 1344 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1345 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1346 | |
| 1347 | // Done. Reset our state. |
| 1348 | finishPowerKeyPress(); |
| 1349 | } |
| 1350 | |
| 1351 | private void finishPowerKeyPress() { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1352 | mBeganFromNonInteractive = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1353 | mPowerKeyPressCounter = 0; |
| 1354 | if (mPowerKeyWakeLock.isHeld()) { |
| 1355 | mPowerKeyWakeLock.release(); |
| 1356 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1359 | private void finishBackKeyPress() { |
| 1360 | mBackKeyPressCounter = 0; |
| 1361 | } |
| 1362 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1363 | private void cancelPendingPowerKeyAction() { |
| 1364 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1365 | mPowerKeyHandled = true; |
| 1366 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1367 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1370 | private void cancelPendingBackKeyAction() { |
| 1371 | if (!mBackKeyHandled) { |
| 1372 | mBackKeyHandled = true; |
| 1373 | mHandler.removeMessages(MSG_BACK_LONG_PRESS); |
| 1374 | } |
| 1375 | } |
| 1376 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1377 | private void backMultiPressAction(long eventTime, int count) { |
| 1378 | if (count >= PANIC_PRESS_BACK_COUNT) { |
| 1379 | switch (mPanicPressOnBackBehavior) { |
| 1380 | case PANIC_PRESS_BACK_NOTHING: |
| 1381 | break; |
| 1382 | case PANIC_PRESS_BACK_HOME: |
| 1383 | launchHomeFromHotKey(); |
| 1384 | break; |
| 1385 | } |
| 1386 | } |
| 1387 | } |
| 1388 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1389 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 1390 | if (mScreenOnEarly && !mScreenOnFully) { |
| 1391 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 1392 | + "already in the process of turning the screen on."); |
| 1393 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 1394 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1395 | |
| 1396 | if (count == 2) { |
| 1397 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 1398 | } else if (count == 3) { |
| 1399 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1400 | } else if (interactive && !mBeganFromNonInteractive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1401 | switch (mShortPressOnPowerBehavior) { |
| 1402 | case SHORT_PRESS_POWER_NOTHING: |
| 1403 | break; |
| 1404 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 1405 | mPowerManager.goToSleep(eventTime, |
| 1406 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1407 | break; |
| 1408 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 1409 | mPowerManager.goToSleep(eventTime, |
| 1410 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1411 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1412 | break; |
| 1413 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 1414 | mPowerManager.goToSleep(eventTime, |
| 1415 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1416 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1417 | launchHomeFromHotKey(); |
| 1418 | break; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1419 | case SHORT_PRESS_POWER_GO_HOME: |
Andrew Zeng | b4045d3 | 2017-03-16 17:25:07 -0700 | [diff] [blame] | 1420 | shortPressPowerGoHome(); |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1421 | break; |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 1422 | case SHORT_PRESS_POWER_CLOSE_IME_OR_GO_HOME: { |
Yohei Yukawa | abbe1ac | 2017-04-18 09:43:05 -0700 | [diff] [blame] | 1423 | if (mDismissImeOnBackKeyPressed) { |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 1424 | if (mInputMethodManagerInternal == null) { |
| 1425 | mInputMethodManagerInternal = |
| 1426 | LocalServices.getService(InputMethodManagerInternal.class); |
| 1427 | } |
| 1428 | if (mInputMethodManagerInternal != null) { |
| 1429 | mInputMethodManagerInternal.hideCurrentInputMethod(); |
| 1430 | } |
| 1431 | } else { |
Andrew Zeng | b4045d3 | 2017-03-16 17:25:07 -0700 | [diff] [blame] | 1432 | shortPressPowerGoHome(); |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 1433 | } |
| 1434 | break; |
| 1435 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1436 | } |
| 1437 | } |
| 1438 | } |
| 1439 | |
Andrew Zeng | b4045d3 | 2017-03-16 17:25:07 -0700 | [diff] [blame] | 1440 | private void shortPressPowerGoHome() { |
| 1441 | launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/); |
| 1442 | if (isKeyguardShowingAndNotOccluded()) { |
| 1443 | // Notify keyguard so it can do any special handling for the power button since the |
| 1444 | // device will not power off and only launch home. |
| 1445 | mKeyguardDelegate.onShortPowerPressedGoHome(); |
| 1446 | } |
| 1447 | } |
| 1448 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1449 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 1450 | switch (behavior) { |
| 1451 | case MULTI_PRESS_POWER_NOTHING: |
| 1452 | break; |
| 1453 | case MULTI_PRESS_POWER_THEATER_MODE: |
Bryce Lee | 3ae447e | 2015-06-30 12:31:41 -0700 | [diff] [blame] | 1454 | if (!isUserSetupComplete()) { |
| 1455 | Slog.i(TAG, "Ignoring toggling theater mode - device not setup."); |
| 1456 | break; |
| 1457 | } |
| 1458 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1459 | if (isTheaterModeEnabled()) { |
| 1460 | Slog.i(TAG, "Toggling theater mode off."); |
| 1461 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1462 | Settings.Global.THEATER_MODE_ON, 0); |
| 1463 | if (!interactive) { |
| 1464 | wakeUpFromPowerKey(eventTime); |
| 1465 | } |
| 1466 | } else { |
| 1467 | Slog.i(TAG, "Toggling theater mode on."); |
| 1468 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1469 | Settings.Global.THEATER_MODE_ON, 1); |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1470 | |
| 1471 | if (mGoToSleepOnButtonPressTheaterMode && interactive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1472 | mPowerManager.goToSleep(eventTime, |
| 1473 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1474 | } |
| 1475 | } |
| 1476 | break; |
| 1477 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
Jeff Brown | 7b5be5e | 2014-11-12 18:45:31 -0800 | [diff] [blame] | 1478 | Slog.i(TAG, "Starting brightness boost."); |
| 1479 | if (!interactive) { |
| 1480 | wakeUpFromPowerKey(eventTime); |
| 1481 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1482 | mPowerManager.boostScreenBrightness(eventTime); |
| 1483 | break; |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | private int getMaxMultiPressPowerCount() { |
| 1488 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1489 | return 3; |
| 1490 | } |
| 1491 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1492 | return 2; |
| 1493 | } |
| 1494 | return 1; |
| 1495 | } |
| 1496 | |
| 1497 | private void powerLongPress() { |
| 1498 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1499 | switch (behavior) { |
| 1500 | case LONG_PRESS_POWER_NOTHING: |
| 1501 | break; |
| 1502 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1503 | mPowerKeyHandled = true; |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1504 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1505 | showGlobalActionsInternal(); |
| 1506 | break; |
| 1507 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1508 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1509 | mPowerKeyHandled = true; |
| 1510 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1511 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1512 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1513 | break; |
| 1514 | } |
| 1515 | } |
| 1516 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1517 | private void backLongPress() { |
| 1518 | mBackKeyHandled = true; |
| 1519 | |
| 1520 | switch (mLongPressOnBackBehavior) { |
| 1521 | case LONG_PRESS_BACK_NOTHING: |
| 1522 | break; |
| 1523 | case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST: |
Nancy Zheng | 0d85ee2 | 2016-09-29 09:15:56 -0700 | [diff] [blame] | 1524 | final boolean keyguardActive = mKeyguardDelegate == null |
| 1525 | ? false |
| 1526 | : mKeyguardDelegate.isShowing(); |
| 1527 | if (!keyguardActive) { |
| 1528 | Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST); |
| 1529 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
| 1530 | } |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1531 | break; |
| 1532 | } |
| 1533 | } |
| 1534 | |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1535 | private void accessibilityShortcutActivated() { |
| 1536 | mAccessibilityShortcutController.performAccessibilityShortcut(); |
| 1537 | } |
| 1538 | |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 1539 | private void disposeInputConsumer(InputConsumer inputConsumer) { |
| 1540 | if (inputConsumer != null) { |
| 1541 | inputConsumer.dismiss(); |
| 1542 | } |
| 1543 | } |
| 1544 | |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1545 | private void sleepPress(long eventTime) { |
| 1546 | if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) { |
| 1547 | launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | private void sleepRelease(long eventTime) { |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1552 | switch (mShortPressOnSleepBehavior) { |
| 1553 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1554 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1555 | Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)"); |
| 1556 | mPowerManager.goToSleep(eventTime, |
| 1557 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1558 | break; |
| 1559 | } |
| 1560 | } |
| 1561 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1562 | private int getResolvedLongPressOnPowerBehavior() { |
| 1563 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1564 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1565 | } |
| 1566 | return mLongPressOnPowerBehavior; |
| 1567 | } |
| 1568 | |
| 1569 | private boolean hasLongPressOnPowerBehavior() { |
| 1570 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1573 | private boolean hasLongPressOnBackBehavior() { |
| 1574 | return mLongPressOnBackBehavior != LONG_PRESS_BACK_NOTHING; |
| 1575 | } |
| 1576 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1577 | private boolean hasPanicPressOnBackBehavior() { |
| 1578 | return mPanicPressOnBackBehavior != PANIC_PRESS_BACK_NOTHING; |
| 1579 | } |
| 1580 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1581 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1582 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1583 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1584 | && !mA11yShortcutChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1585 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1586 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1587 | && now <= mScreenshotChordPowerKeyTime |
| 1588 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1589 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1590 | cancelPendingPowerKeyAction(); |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1591 | mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN); |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1592 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1593 | } |
| 1594 | } |
| 1595 | } |
| 1596 | |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1597 | private void interceptAccessibilityShortcutChord() { |
Phil Weaver | ce687c5 | 2017-03-15 08:51:52 -0700 | [diff] [blame] | 1598 | if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(isKeyguardLocked()) |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1599 | && mScreenshotChordVolumeDownKeyTriggered && mA11yShortcutChordVolumeUpKeyTriggered |
| 1600 | && !mScreenshotChordPowerKeyTriggered) { |
| 1601 | final long now = SystemClock.uptimeMillis(); |
| 1602 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1603 | && now <= mA11yShortcutChordVolumeUpKeyTime |
| 1604 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1605 | mScreenshotChordVolumeDownKeyConsumed = true; |
| 1606 | mA11yShortcutChordVolumeUpKeyConsumed = true; |
| 1607 | mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_ACCESSIBILITY_SHORTCUT), |
| 1608 | ViewConfiguration.get(mContext).getAccessibilityShortcutKeyTimeout()); |
| 1609 | } |
| 1610 | } |
| 1611 | } |
| 1612 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1613 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1614 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1615 | // Double the time it takes to take a screenshot from the keyguard |
| 1616 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1617 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1618 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1619 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1620 | } |
| 1621 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1622 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1623 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1626 | private void cancelPendingAccessibilityShortcutAction() { |
| 1627 | mHandler.removeMessages(MSG_ACCESSIBILITY_SHORTCUT); |
| 1628 | } |
| 1629 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1630 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1631 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1632 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1633 | mEndCallKeyHandled = true; |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1634 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1635 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1636 | } |
| 1637 | }; |
| 1638 | |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1639 | private class ScreenshotRunnable implements Runnable { |
| 1640 | private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN; |
| 1641 | |
| 1642 | public void setScreenshotType(int screenshotType) { |
| 1643 | mScreenshotType = screenshotType; |
| 1644 | } |
| 1645 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1646 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1647 | public void run() { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1648 | takeScreenshot(mScreenshotType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1649 | } |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1653 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1654 | @Override |
| 1655 | public void showGlobalActions() { |
| 1656 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1657 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1658 | } |
| 1659 | |
| 1660 | void showGlobalActionsInternal() { |
| 1661 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1662 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1663 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1664 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1665 | final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1666 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1667 | if (keyguardShowing) { |
| 1668 | // since it took two seconds of long press to bring this up, |
| 1669 | // 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] | 1670 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1675 | return Settings.Global.getInt( |
| 1676 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1677 | } |
| 1678 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1679 | boolean isUserSetupComplete() { |
Sujith Ramakrishnan | 0390fff | 2017-06-08 18:18:12 -0700 | [diff] [blame] | 1680 | boolean isSetupComplete = Settings.Secure.getIntForUser(mContext.getContentResolver(), |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1681 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
Sujith Ramakrishnan | 0390fff | 2017-06-08 18:18:12 -0700 | [diff] [blame] | 1682 | if (mHasFeatureLeanback) { |
| 1683 | isSetupComplete &= isTvUserSetupComplete(); |
| 1684 | } |
| 1685 | return isSetupComplete; |
| 1686 | } |
| 1687 | |
| 1688 | private boolean isTvUserSetupComplete() { |
| 1689 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1690 | Settings.Secure.TV_USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1693 | private void handleShortPressOnHome() { |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1694 | // Turn on the connected TV and switch HDMI input if we're a HDMI playback device. |
Andrii Kulian | eb4a794 | 2016-12-21 12:18:05 -0800 | [diff] [blame] | 1695 | final HdmiControl hdmiControl = getHdmiControl(); |
| 1696 | if (hdmiControl != null) { |
| 1697 | hdmiControl.turnOnTv(); |
| 1698 | } |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1699 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1700 | // If there's a dream running then use home to escape the dream |
| 1701 | // but don't actually go home. |
| 1702 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1703 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1704 | return; |
| 1705 | } |
| 1706 | |
| 1707 | // Go home! |
| 1708 | launchHomeFromHotKey(); |
| 1709 | } |
| 1710 | |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1711 | /** |
| 1712 | * Creates an accessor to HDMI control service that performs the operation of |
| 1713 | * turning on TV (optional) and switching input to us. If HDMI control service |
| 1714 | * is not available or we're not a HDMI playback device, the operation is no-op. |
Andrii Kulian | eb4a794 | 2016-12-21 12:18:05 -0800 | [diff] [blame] | 1715 | * @return {@link HdmiControl} instance if available, null otherwise. |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1716 | */ |
| 1717 | private HdmiControl getHdmiControl() { |
| 1718 | if (null == mHdmiControl) { |
Andrii Kulian | eb4a794 | 2016-12-21 12:18:05 -0800 | [diff] [blame] | 1719 | if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) { |
| 1720 | return null; |
| 1721 | } |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1722 | HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService( |
| 1723 | Context.HDMI_CONTROL_SERVICE); |
| 1724 | HdmiPlaybackClient client = null; |
| 1725 | if (manager != null) { |
| 1726 | client = manager.getPlaybackClient(); |
| 1727 | } |
| 1728 | mHdmiControl = new HdmiControl(client); |
| 1729 | } |
| 1730 | return mHdmiControl; |
| 1731 | } |
| 1732 | |
| 1733 | private static class HdmiControl { |
| 1734 | private final HdmiPlaybackClient mClient; |
| 1735 | |
| 1736 | private HdmiControl(HdmiPlaybackClient client) { |
| 1737 | mClient = client; |
| 1738 | } |
| 1739 | |
| 1740 | public void turnOnTv() { |
| 1741 | if (mClient == null) { |
| 1742 | return; |
| 1743 | } |
| 1744 | mClient.oneTouchPlay(new OneTouchPlayCallback() { |
| 1745 | @Override |
| 1746 | public void onComplete(int result) { |
| 1747 | if (result != HdmiControlManager.RESULT_SUCCESS) { |
| 1748 | Log.w(TAG, "One touch play failed: " + result); |
| 1749 | } |
| 1750 | } |
| 1751 | }); |
| 1752 | } |
| 1753 | } |
| 1754 | |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 1755 | private void handleLongPressOnHome(int deviceId) { |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1756 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) { |
| 1757 | return; |
| 1758 | } |
| 1759 | mHomeConsumed = true; |
| 1760 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1761 | switch (mLongPressOnHomeBehavior) { |
Sid Soundararajan | ff662fa | 2017-03-15 16:24:24 -0700 | [diff] [blame] | 1762 | case LONG_PRESS_HOME_ALL_APPS: |
| 1763 | launchAllAppsAction(); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1764 | break; |
| 1765 | case LONG_PRESS_HOME_ASSIST: |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 1766 | launchAssistAction(null, deviceId); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1767 | break; |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1768 | default: |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 1769 | Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1770 | break; |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1771 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1772 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1773 | |
Sid Soundararajan | ff662fa | 2017-03-15 16:24:24 -0700 | [diff] [blame] | 1774 | private void launchAllAppsAction() { |
| 1775 | Intent intent = new Intent(Intent.ACTION_ALL_APPS); |
| 1776 | startActivityAsUser(intent, UserHandle.CURRENT); |
| 1777 | } |
| 1778 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1779 | private void handleDoubleTapOnHome() { |
| 1780 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1781 | mHomeConsumed = true; |
| 1782 | toggleRecentApps(); |
| 1783 | } |
| 1784 | } |
| 1785 | |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 1786 | private void showPictureInPictureMenu(KeyEvent event) { |
| 1787 | if (DEBUG_INPUT) Log.d(TAG, "showPictureInPictureMenu event=" + event); |
| 1788 | mHandler.removeMessages(MSG_SHOW_PICTURE_IN_PICTURE_MENU); |
| 1789 | Message msg = mHandler.obtainMessage(MSG_SHOW_PICTURE_IN_PICTURE_MENU); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1790 | msg.setAsynchronous(true); |
| 1791 | msg.sendToTarget(); |
| 1792 | } |
| 1793 | |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 1794 | private void showPictureInPictureMenuInternal() { |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 1795 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 1796 | if (statusbar != null) { |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 1797 | statusbar.showPictureInPictureMenu(); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1798 | } |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1799 | } |
| 1800 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1801 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1802 | @Override |
| 1803 | public void run() { |
| 1804 | if (mHomeDoubleTapPending) { |
| 1805 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1806 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1807 | } |
| 1808 | } |
| 1809 | }; |
| 1810 | |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1811 | private boolean isRoundWindow() { |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1812 | return mContext.getResources().getConfiguration().isScreenRound(); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1813 | } |
| 1814 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1815 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1816 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1817 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1818 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1819 | mContext = context; |
| 1820 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1821 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1822 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 1823 | mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 1824 | mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1825 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1826 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1827 | mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 1828 | mHasFeatureWatch = mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH); |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 1829 | mHasFeatureLeanback = mContext.getPackageManager().hasSystemFeature(FEATURE_LEANBACK); |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 1830 | mAccessibilityShortcutController = |
Phil Weaver | ce687c5 | 2017-03-15 08:51:52 -0700 | [diff] [blame] | 1831 | new AccessibilityShortcutController(mContext, new Handler(), mCurrentUserId); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1832 | // Init display burn-in protection |
| 1833 | boolean burnInProtectionEnabled = context.getResources().getBoolean( |
| 1834 | com.android.internal.R.bool.config_enableBurnInProtection); |
| 1835 | // Allow a system property to override this. Used by developer settings. |
| 1836 | boolean burnInProtectionDevMode = |
| 1837 | SystemProperties.getBoolean("persist.debug.force_burn_in", false); |
| 1838 | if (burnInProtectionEnabled || burnInProtectionDevMode) { |
| 1839 | final int minHorizontal; |
| 1840 | final int maxHorizontal; |
| 1841 | final int minVertical; |
| 1842 | final int maxVertical; |
| 1843 | final int maxRadius; |
| 1844 | if (burnInProtectionDevMode) { |
| 1845 | minHorizontal = -8; |
| 1846 | maxHorizontal = 8; |
| 1847 | minVertical = -8; |
| 1848 | maxVertical = -4; |
| 1849 | maxRadius = (isRoundWindow()) ? 6 : -1; |
| 1850 | } else { |
| 1851 | Resources resources = context.getResources(); |
| 1852 | minHorizontal = resources.getInteger( |
| 1853 | com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); |
| 1854 | maxHorizontal = resources.getInteger( |
| 1855 | com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); |
| 1856 | minVertical = resources.getInteger( |
| 1857 | com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); |
| 1858 | maxVertical = resources.getInteger( |
| 1859 | com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); |
| 1860 | maxRadius = resources.getInteger( |
| 1861 | com.android.internal.R.integer.config_burnInProtectionMaxRadius); |
| 1862 | } |
| 1863 | mBurnInProtectionHelper = new BurnInProtectionHelper( |
| 1864 | context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 1865 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1866 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1867 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1868 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1869 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1870 | try { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1871 | mOrientationListener.setCurrentRotation(windowManager.getDefaultDisplayRotation()); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1872 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1873 | mSettingsObserver = new SettingsObserver(mHandler); |
| 1874 | mSettingsObserver.observe(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1875 | mShortcutManager = new ShortcutManager(context); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 1876 | mUiMode = context.getResources().getInteger( |
| 1877 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1878 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1879 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 1880 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1881 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 1882 | mEnableCarDockHomeCapture = context.getResources().getBoolean( |
| 1883 | com.android.internal.R.bool.config_enableCarDockHomeLaunch); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1884 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1885 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 1886 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1887 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1888 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1889 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1890 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1891 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Zak Cohen | db6ca49 | 2017-01-26 14:09:00 -0800 | [diff] [blame] | 1892 | mVrHeadsetHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1893 | mVrHeadsetHomeIntent.addCategory(Intent.CATEGORY_VR_HOME); |
| 1894 | mVrHeadsetHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1895 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1896 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1897 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1898 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1899 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1900 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1901 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1902 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1903 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1904 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1905 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1906 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1907 | mCarDockRotation = readRotation( |
| 1908 | com.android.internal.R.integer.config_carDockRotation); |
| 1909 | mDeskDockRotation = readRotation( |
| 1910 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1911 | mUndockedHdmiRotation = readRotation( |
| 1912 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1913 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1914 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1915 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1916 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1917 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1918 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1919 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1920 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 1921 | mLidControlsScreenLock = mContext.getResources().getBoolean( |
| 1922 | com.android.internal.R.bool.config_lidControlsScreenLock); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1923 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1924 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1925 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1926 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1927 | |
| 1928 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 1929 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 1930 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 1931 | || mContext.getResources().getBoolean( |
| 1932 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 1933 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 1934 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 1935 | mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( |
| 1936 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1937 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 1938 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 1939 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 1940 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 1941 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 1942 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 1943 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1944 | mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( |
| 1945 | com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); |
| 1946 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1947 | mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( |
| 1948 | com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); |
| 1949 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1950 | mLongPressOnBackBehavior = mContext.getResources().getInteger( |
| 1951 | com.android.internal.R.integer.config_longPressOnBackBehavior); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 1952 | mPanicPressOnBackBehavior = mContext.getResources().getInteger( |
| 1953 | com.android.internal.R.integer.config_backPanicBehavior); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1954 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1955 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1956 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 1957 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1958 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 1959 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1960 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 1961 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1962 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1963 | mShortPressOnSleepBehavior = mContext.getResources().getInteger( |
| 1964 | com.android.internal.R.integer.config_shortPressOnSleepBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1965 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 1966 | mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 1967 | |
Karthik Ravi Shankar | 86ecf34 | 2017-04-28 15:35:58 -0700 | [diff] [blame] | 1968 | mHandleVolumeKeysInWM = mContext.getResources().getBoolean( |
| 1969 | com.android.internal.R.bool.config_handleVolumeKeysInWindowManager); |
| 1970 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1971 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1972 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1973 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1974 | Context.ACCESSIBILITY_SERVICE); |
| 1975 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1976 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1977 | IntentFilter filter = new IntentFilter(); |
| 1978 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1979 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1980 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1981 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1982 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1983 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1984 | if (intent != null) { |
| 1985 | // Retrieve current sticky dock event broadcast. |
| 1986 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1987 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1988 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1989 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1990 | // register for dream-related broadcasts |
| 1991 | filter = new IntentFilter(); |
| 1992 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1993 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1994 | context.registerReceiver(mDreamReceiver, filter); |
| 1995 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1996 | // register for multiuser-relevant broadcasts |
| 1997 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1998 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1999 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 2000 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 2001 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 2002 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 2003 | @Override |
| 2004 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2005 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2006 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2007 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2008 | } |
| 2009 | @Override |
| 2010 | public void onSwipeFromBottom() { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 2011 | if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_BOTTOM) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2012 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2013 | } |
| 2014 | } |
| 2015 | @Override |
| 2016 | public void onSwipeFromRight() { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 2017 | if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_RIGHT) { |
| 2018 | requestTransientBars(mNavigationBar); |
| 2019 | } |
| 2020 | } |
| 2021 | @Override |
| 2022 | public void onSwipeFromLeft() { |
| 2023 | if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_LEFT) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2024 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2025 | } |
| 2026 | } |
| 2027 | @Override |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 2028 | public void onFling(int duration) { |
| 2029 | if (mPowerManagerInternal != null) { |
| 2030 | mPowerManagerInternal.powerHint( |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 2031 | PowerHint.INTERACTION, duration); |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 2032 | } |
| 2033 | } |
| 2034 | @Override |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2035 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 2036 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2037 | } |
Adrian Roos | 3595be4 | 2015-03-05 16:31:15 +0100 | [diff] [blame] | 2038 | @Override |
| 2039 | public void onDown() { |
| 2040 | mOrientationListener.onTouchStart(); |
| 2041 | } |
| 2042 | @Override |
| 2043 | public void onUpOrCancel() { |
| 2044 | mOrientationListener.onTouchEnd(); |
| 2045 | } |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 2046 | @Override |
| 2047 | public void onMouseHoverAtTop() { |
| 2048 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 2049 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 2050 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS; |
| 2051 | mHandler.sendMessageDelayed(msg, 500); |
| 2052 | } |
| 2053 | @Override |
| 2054 | public void onMouseHoverAtBottom() { |
| 2055 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 2056 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 2057 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION; |
| 2058 | mHandler.sendMessageDelayed(msg, 500); |
| 2059 | } |
| 2060 | @Override |
| 2061 | public void onMouseLeaveFromEdge() { |
| 2062 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 2063 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2064 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2065 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 2066 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 2067 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 2068 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2069 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 2070 | com.android.internal.R.array.config_longPressVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 2071 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 2072 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2073 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 2074 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 2075 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2076 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 2077 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 2078 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2079 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 2080 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 2081 | // Controls rotation and the like. |
| 2082 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 2083 | |
| 2084 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 2085 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 2086 | startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 2087 | finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 2088 | } |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 2089 | |
| 2090 | mWindowManagerInternal.registerAppTransitionListener( |
| 2091 | mStatusBarController.getAppTransitionListener()); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2092 | mWindowManagerInternal.registerAppTransitionListener(new AppTransitionListener() { |
| 2093 | @Override |
| 2094 | public int onAppTransitionStartingLocked(int transit, IBinder openToken, |
| 2095 | IBinder closeToken, |
| 2096 | Animation openAnimation, Animation closeAnimation) { |
| 2097 | return handleStartTransitionForKeyguardLw(transit, openAnimation); |
| 2098 | } |
| 2099 | |
| 2100 | @Override |
| 2101 | public void onAppTransitionCancelledLocked(int transit) { |
| 2102 | handleStartTransitionForKeyguardLw(transit, null /* transit */); |
| 2103 | } |
| 2104 | }); |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 2105 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext, |
| 2106 | new StateCallback() { |
| 2107 | @Override |
| 2108 | public void onTrustedChanged() { |
| 2109 | mWindowManagerFuncs.notifyKeyguardTrustedChanged(); |
| 2110 | } |
| 2111 | }); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2114 | /** |
| 2115 | * Read values from config.xml that may be overridden depending on |
| 2116 | * the configuration of the device. |
| 2117 | * eg. Disable long press on home goes to recents on sw600dp. |
| 2118 | */ |
| 2119 | private void readConfigurationDependentBehaviors() { |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 2120 | final Resources res = mContext.getResources(); |
| 2121 | |
| 2122 | mLongPressOnHomeBehavior = res.getInteger( |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2123 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 2124 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 2125 | mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) { |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2126 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 2127 | } |
| 2128 | |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 2129 | mDoubleTapOnHomeBehavior = res.getInteger( |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2130 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 2131 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 2132 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2133 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 2134 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 2135 | |
| 2136 | mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING; |
| 2137 | if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) { |
| 2138 | mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE; |
| 2139 | } |
Yorke Lee | 2e4b732 | 2016-03-02 17:33:06 -0800 | [diff] [blame] | 2140 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 2141 | mNavBarOpacityMode = res.getInteger( |
| 2142 | com.android.internal.R.integer.config_navBarOpacityMode); |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 2145 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 2146 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 2147 | // This method might be called before the policy has been fully initialized |
| 2148 | // or for other displays we don't care about. |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 2149 | // TODO(multi-display): Define policy for secondary displays. |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 2150 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 2151 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2152 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2153 | mDisplay = display; |
| 2154 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2155 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2156 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2157 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 2158 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2159 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2160 | mLandscapeRotation = Surface.ROTATION_0; |
| 2161 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2162 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2163 | mPortraitRotation = Surface.ROTATION_90; |
| 2164 | mUpsideDownRotation = Surface.ROTATION_270; |
| 2165 | } else { |
| 2166 | mPortraitRotation = Surface.ROTATION_270; |
| 2167 | mUpsideDownRotation = Surface.ROTATION_90; |
| 2168 | } |
| 2169 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 2170 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2171 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2172 | mPortraitRotation = Surface.ROTATION_0; |
| 2173 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2174 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2175 | mLandscapeRotation = Surface.ROTATION_270; |
| 2176 | mSeascapeRotation = Surface.ROTATION_90; |
| 2177 | } else { |
| 2178 | mLandscapeRotation = Surface.ROTATION_90; |
| 2179 | mSeascapeRotation = Surface.ROTATION_270; |
| 2180 | } |
| 2181 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 2182 | |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2183 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 2184 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2185 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2186 | |
Devin Kim | d7b12b4 | 2014-05-05 14:34:58 -0700 | [diff] [blame] | 2187 | // Allow the navigation bar to move on non-square small devices (phones). |
| 2188 | mNavigationBarCanMove = width != height && shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 2189 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2190 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2191 | |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2192 | // Allow a system property to override this. Used by the emulator. |
| 2193 | // See also hasNavigationBar(). |
| 2194 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 2195 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2196 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2197 | } else if ("0".equals(navBarOverride)) { |
| 2198 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 2199 | } |
| 2200 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 2201 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 2202 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 2203 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 2204 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 2205 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 2206 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 2207 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 2208 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2209 | |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 2210 | // For demo purposes, allow the rotation of the remote display to be controlled. |
| 2211 | // By default, remote display locks rotation to landscape. |
| 2212 | if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { |
| 2213 | mDemoRotation = mPortraitRotation; |
| 2214 | } else { |
| 2215 | mDemoRotation = mLandscapeRotation; |
| 2216 | } |
| 2217 | mDemoRotationLock = SystemProperties.getBoolean( |
| 2218 | "persist.demo.rotationlock", false); |
| 2219 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2220 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 2221 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 2222 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 2223 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 2224 | // For debug purposes the next line turns this feature off with: |
| 2225 | // $ adb shell setprop config.override_forced_orient true |
| 2226 | // $ adb shell wm size reset |
| 2227 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 2228 | } |
| 2229 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2230 | /** |
| 2231 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 2232 | * navigation bar and touch exploration is not enabled |
| 2233 | */ |
| 2234 | private boolean canHideNavigationBar() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 2235 | return mHasNavigationBar; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2236 | } |
| 2237 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2238 | @Override |
| 2239 | public boolean isDefaultOrientationForced() { |
| 2240 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2243 | @Override |
| 2244 | 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] | 2245 | // TODO(multi-display): Define policy for secondary displays. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2246 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 2247 | mOverscanLeft = left; |
| 2248 | mOverscanTop = top; |
| 2249 | mOverscanRight = right; |
| 2250 | mOverscanBottom = bottom; |
| 2251 | } |
| 2252 | } |
| 2253 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2254 | public void updateSettings() { |
| 2255 | ContentResolver resolver = mContext.getContentResolver(); |
| 2256 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2257 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2258 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 2259 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2260 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 2261 | UserHandle.USER_CURRENT); |
| 2262 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 2263 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2264 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 2265 | UserHandle.USER_CURRENT); |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 2266 | mIncallBackBehavior = Settings.Secure.getIntForUser(resolver, |
| 2267 | Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR, |
| 2268 | Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_DEFAULT, |
| 2269 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 2270 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 2271 | // Configure wake gesture. |
| 2272 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 2273 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 2274 | UserHandle.USER_CURRENT) != 0; |
| 2275 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 2276 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 2277 | updateWakeGestureListenerLp(); |
| 2278 | } |
| 2279 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 2280 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2281 | int userRotation = Settings.System.getIntForUser(resolver, |
| 2282 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 2283 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 2284 | if (mUserRotation != userRotation) { |
| 2285 | mUserRotation = userRotation; |
| 2286 | updateRotation = true; |
| 2287 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2288 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 2289 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 2290 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 2291 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 2292 | if (mUserRotationMode != userRotationMode) { |
| 2293 | mUserRotationMode = userRotationMode; |
| 2294 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2295 | updateOrientationListenerLp(); |
| 2296 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 2297 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2298 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2299 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 2300 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2301 | if (mPointerLocationMode != pointerLocation) { |
| 2302 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2303 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 2304 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2305 | } |
| 2306 | } |
| 2307 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 2308 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 2309 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 2310 | String imId = Settings.Secure.getStringForUser(resolver, |
| 2311 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2312 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 2313 | if (mHasSoftInput != hasSoftInput) { |
| 2314 | mHasSoftInput = hasSoftInput; |
| 2315 | updateRotation = true; |
| 2316 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2317 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 2318 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 2319 | } |
tiger_huang | cc6366d | 2015-06-29 17:17:30 +0800 | [diff] [blame] | 2320 | } |
| 2321 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 2322 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2323 | } |
| 2324 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 2325 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2326 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2327 | } |
| 2328 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 2329 | private void updateWakeGestureListenerLp() { |
| 2330 | if (shouldEnableWakeGestureLp()) { |
| 2331 | mWakeGestureListener.requestWakeUpTrigger(); |
| 2332 | } else { |
| 2333 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 2338 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 2339 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 2340 | && mWakeGestureListener.isSupported(); |
| 2341 | } |
| 2342 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2343 | private void enablePointerLocation() { |
| 2344 | if (mPointerLocationView == null) { |
| 2345 | mPointerLocationView = new PointerLocationView(mContext); |
| 2346 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2347 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 2348 | WindowManager.LayoutParams.MATCH_PARENT, |
| 2349 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 2350 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 2351 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 2352 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 2353 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 2354 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 2355 | if (ActivityManager.isHighEndGfx()) { |
| 2356 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 2357 | lp.privateFlags |= |
| 2358 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 2359 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2360 | lp.format = PixelFormat.TRANSLUCENT; |
| 2361 | lp.setTitle("PointerLocation"); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2362 | WindowManager wm = (WindowManager) mContext.getSystemService(WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2363 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2364 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 2365 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2366 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2367 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2368 | |
| 2369 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2370 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 2371 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2372 | WindowManager wm = (WindowManager) mContext.getSystemService(WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2373 | wm.removeView(mPointerLocationView); |
| 2374 | mPointerLocationView = null; |
| 2375 | } |
| 2376 | } |
| 2377 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2378 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2379 | try { |
| 2380 | int rotation = mContext.getResources().getInteger(resID); |
| 2381 | switch (rotation) { |
| 2382 | case 0: |
| 2383 | return Surface.ROTATION_0; |
| 2384 | case 90: |
| 2385 | return Surface.ROTATION_90; |
| 2386 | case 180: |
| 2387 | return Surface.ROTATION_180; |
| 2388 | case 270: |
| 2389 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2390 | } |
| 2391 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2392 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2393 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2394 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2398 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2399 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2400 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2401 | |
| 2402 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 2403 | |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 2404 | if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) |
| 2405 | || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) |
| 2406 | || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { |
| 2407 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
| 2408 | } |
| 2409 | |
| 2410 | if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { |
| 2411 | // Window manager will make sure these are okay. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2412 | return ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2413 | } |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2414 | |
| 2415 | if (!isSystemAlertWindowType(type)) { |
| 2416 | switch (type) { |
| 2417 | case TYPE_TOAST: |
| 2418 | // Only apps that target older than O SDK can add window without a token, after |
| 2419 | // that we require a token so apps cannot add toasts directly as the token is |
| 2420 | // added by the notification system. |
| 2421 | // Window manager does the checking for this. |
| 2422 | outAppOp[0] = OP_TOAST_WINDOW; |
| 2423 | return ADD_OKAY; |
| 2424 | case TYPE_DREAM: |
| 2425 | case TYPE_INPUT_METHOD: |
| 2426 | case TYPE_WALLPAPER: |
| 2427 | case TYPE_PRESENTATION: |
| 2428 | case TYPE_PRIVATE_PRESENTATION: |
| 2429 | case TYPE_VOICE_INTERACTION: |
| 2430 | case TYPE_ACCESSIBILITY_OVERLAY: |
| 2431 | case TYPE_QS_DIALOG: |
| 2432 | // The window manager will check these. |
| 2433 | return ADD_OKAY; |
| 2434 | } |
| 2435 | return mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW) |
| 2436 | == PERMISSION_GRANTED ? ADD_OKAY : ADD_PERMISSION_DENIED; |
| 2437 | } |
| 2438 | |
| 2439 | // Things get a little more interesting for alert windows... |
| 2440 | outAppOp[0] = OP_SYSTEM_ALERT_WINDOW; |
| 2441 | |
| 2442 | final int callingUid = Binder.getCallingUid(); |
| 2443 | // system processes will be automatically granted privilege to draw |
| 2444 | if (UserHandle.getAppId(callingUid) == Process.SYSTEM_UID) { |
| 2445 | return ADD_OKAY; |
| 2446 | } |
| 2447 | |
| 2448 | ApplicationInfo appInfo; |
| 2449 | try { |
Tony Mak | 22295fd | 2017-03-20 16:17:54 +0000 | [diff] [blame] | 2450 | appInfo = mContext.getPackageManager().getApplicationInfoAsUser( |
| 2451 | attrs.packageName, |
| 2452 | 0 /* flags */, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2453 | UserHandle.getUserId(callingUid)); |
| 2454 | } catch (PackageManager.NameNotFoundException e) { |
| 2455 | appInfo = null; |
| 2456 | } |
| 2457 | |
| 2458 | if (appInfo == null || (type != TYPE_APPLICATION_OVERLAY && appInfo.targetSdkVersion >= O)) { |
| 2459 | /** |
| 2460 | * Apps targeting >= {@link Build.VERSION_CODES#O} are required to hold |
| 2461 | * {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} (system signature apps) |
| 2462 | * permission to add alert windows that aren't |
| 2463 | * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY}. |
| 2464 | */ |
Wale Ogunwale | 5aa8683 | 2017-02-28 10:40:27 -0800 | [diff] [blame] | 2465 | return (mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW) |
| 2466 | == PERMISSION_GRANTED) ? ADD_OKAY : ADD_PERMISSION_DENIED; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | // check if user has enabled this operation. SecurityException will be thrown if this app |
| 2470 | // has not been allowed by the user |
| 2471 | final int mode = mAppOpsManager.checkOpNoThrow(outAppOp[0], callingUid, attrs.packageName); |
| 2472 | switch (mode) { |
| 2473 | case AppOpsManager.MODE_ALLOWED: |
| 2474 | case AppOpsManager.MODE_IGNORED: |
| 2475 | // although we return ADD_OKAY for MODE_IGNORED, the added window will |
| 2476 | // actually be hidden in WindowManagerService |
| 2477 | return ADD_OKAY; |
| 2478 | case AppOpsManager.MODE_ERRORED: |
| 2479 | // Don't crash legacy apps |
| 2480 | if (appInfo.targetSdkVersion < M) { |
| 2481 | return ADD_OKAY; |
| 2482 | } |
| 2483 | return ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2484 | default: |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2485 | // in the default mode, we will make a decision here based on |
| 2486 | // checkCallingPermission() |
Wale Ogunwale | 5aa8683 | 2017-02-28 10:40:27 -0800 | [diff] [blame] | 2487 | return (mContext.checkCallingOrSelfPermission(SYSTEM_ALERT_WINDOW) |
| 2488 | == PERMISSION_GRANTED) ? ADD_OKAY : ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2489 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2490 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2491 | |
| 2492 | @Override |
| 2493 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 2494 | |
| 2495 | // If this switch statement is modified, modify the comment in the declarations of |
| 2496 | // the type in {@link WindowManager.LayoutParams} as well. |
| 2497 | switch (attrs.type) { |
| 2498 | default: |
| 2499 | // These are the windows that by default are shown only to the user that created |
| 2500 | // them. If this needs to be overridden, set |
| 2501 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 2502 | // {@link WindowManager.LayoutParams}. Note that permission |
| 2503 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 2504 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 2505 | return true; |
| 2506 | } |
| 2507 | break; |
| 2508 | |
| 2509 | // These are the windows that by default are shown to all users. However, to |
| 2510 | // protect against spoofing, check permissions below. |
| 2511 | case TYPE_APPLICATION_STARTING: |
| 2512 | case TYPE_BOOT_PROGRESS: |
| 2513 | case TYPE_DISPLAY_OVERLAY: |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2514 | case TYPE_INPUT_CONSUMER: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2515 | case TYPE_KEYGUARD_DIALOG: |
| 2516 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2517 | case TYPE_NAVIGATION_BAR: |
| 2518 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2519 | case TYPE_PHONE: |
| 2520 | case TYPE_POINTER: |
| 2521 | case TYPE_PRIORITY_PHONE: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2522 | case TYPE_SEARCH_BAR: |
| 2523 | case TYPE_STATUS_BAR: |
| 2524 | case TYPE_STATUS_BAR_PANEL: |
| 2525 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 2526 | case TYPE_SYSTEM_DIALOG: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2527 | case TYPE_VOLUME_OVERLAY: |
Wale Ogunwale | 5b6714c | 2016-11-01 20:54:46 -0700 | [diff] [blame] | 2528 | case TYPE_PRESENTATION: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2529 | case TYPE_PRIVATE_PRESENTATION: |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2530 | case TYPE_DOCK_DIVIDER: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2531 | break; |
| 2532 | } |
| 2533 | |
| 2534 | // Check if third party app has set window to system window type. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2535 | return mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW) != PERMISSION_GRANTED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2536 | } |
| 2537 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2538 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2539 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 2540 | switch (attrs.type) { |
| 2541 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 2542 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2543 | // These types of windows can't receive input events. |
| 2544 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 2545 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 2546 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2547 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2548 | case TYPE_STATUS_BAR: |
| 2549 | |
| 2550 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 2551 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 2552 | // the keyguard as occluded wouldn't set these flags again. |
| 2553 | // See {@link #processKeyguardSetHiddenResultLw}. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2554 | if (mKeyguardOccluded) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2555 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 2556 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2557 | } |
| 2558 | break; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2559 | |
Muyuan Li | 36ca72c | 2016-08-06 20:24:06 -0700 | [diff] [blame] | 2560 | case TYPE_SCREENSHOT: |
| 2561 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 2562 | break; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2563 | |
| 2564 | case TYPE_TOAST: |
| 2565 | // While apps should use the dedicated toast APIs to add such windows |
| 2566 | // it possible legacy apps to add the window directly. Therefore, we |
| 2567 | // make windows added directly by the app behave as a toast as much |
| 2568 | // as possible in terms of timeout and animation. |
| 2569 | if (attrs.hideTimeoutMilliseconds < 0 |
| 2570 | || attrs.hideTimeoutMilliseconds > TOAST_WINDOW_TIMEOUT) { |
| 2571 | attrs.hideTimeoutMilliseconds = TOAST_WINDOW_TIMEOUT; |
| 2572 | } |
| 2573 | attrs.windowAnimations = com.android.internal.R.style.Animation_Toast; |
| 2574 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2575 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 2576 | |
| 2577 | if (attrs.type != TYPE_STATUS_BAR) { |
| 2578 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 2579 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2580 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2581 | |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2582 | if (ActivityManager.isHighEndGfx()) { |
| 2583 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
| 2584 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 2585 | } |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 2586 | final boolean forceWindowDrawsStatusBarBackground = |
| 2587 | (attrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) |
| 2588 | != 0; |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2589 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 2590 | || forceWindowDrawsStatusBarBackground |
| 2591 | && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT) { |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2592 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 2593 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2594 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2595 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2596 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2597 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 2598 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2599 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2600 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 2601 | private void readCameraLensCoverState() { |
| 2602 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 2603 | } |
| 2604 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2605 | private boolean isHidden(int accessibilityMode) { |
| 2606 | switch (accessibilityMode) { |
| 2607 | case 1: |
| 2608 | return mLidState == LID_CLOSED; |
| 2609 | case 2: |
| 2610 | return mLidState == LID_OPEN; |
| 2611 | default: |
| 2612 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2613 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2614 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2615 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2616 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2617 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2618 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 2619 | int navigationPresence) { |
| 2620 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 2621 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2622 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2623 | readLidState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2624 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2625 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 2626 | || (keyboardPresence == PRESENCE_INTERNAL |
| 2627 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2628 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2629 | if (!mHasSoftInput) { |
| 2630 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 2631 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2632 | } |
| 2633 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2634 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 2635 | || (navigationPresence == PRESENCE_INTERNAL |
| 2636 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2637 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2638 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2639 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2640 | |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2641 | @Override |
| 2642 | public void onConfigurationChanged() { |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 2643 | // TODO(multi-display): Define policy for secondary displays. |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2644 | final Resources res = mContext.getResources(); |
| 2645 | |
| 2646 | mStatusBarHeight = |
| 2647 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
| 2648 | |
| 2649 | // Height of the navigation bar when presented horizontally at bottom |
| 2650 | mNavigationBarHeightForRotationDefault[mPortraitRotation] = |
| 2651 | mNavigationBarHeightForRotationDefault[mUpsideDownRotation] = |
| 2652 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
| 2653 | mNavigationBarHeightForRotationDefault[mLandscapeRotation] = |
| 2654 | mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize( |
| 2655 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
| 2656 | |
| 2657 | // Width of the navigation bar when presented vertically along one side |
| 2658 | mNavigationBarWidthForRotationDefault[mPortraitRotation] = |
| 2659 | mNavigationBarWidthForRotationDefault[mUpsideDownRotation] = |
| 2660 | mNavigationBarWidthForRotationDefault[mLandscapeRotation] = |
| 2661 | mNavigationBarWidthForRotationDefault[mSeascapeRotation] = |
| 2662 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
| 2663 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2664 | if (ALTERNATE_CAR_MODE_NAV_SIZE) { |
| 2665 | // Height of the navigation bar when presented horizontally at bottom |
| 2666 | mNavigationBarHeightForRotationInCarMode[mPortraitRotation] = |
| 2667 | mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] = |
| 2668 | res.getDimensionPixelSize( |
| 2669 | com.android.internal.R.dimen.navigation_bar_height_car_mode); |
| 2670 | mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] = |
| 2671 | mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize( |
| 2672 | com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2673 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2674 | // Width of the navigation bar when presented vertically along one side |
| 2675 | mNavigationBarWidthForRotationInCarMode[mPortraitRotation] = |
| 2676 | mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] = |
| 2677 | mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] = |
| 2678 | mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] = |
| 2679 | res.getDimensionPixelSize( |
| 2680 | com.android.internal.R.dimen.navigation_bar_width_car_mode); |
| 2681 | } |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2684 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2685 | public int getMaxWallpaperLayer() { |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2686 | return getWindowLayerFromTypeLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2687 | } |
| 2688 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2689 | private int getNavigationBarWidth(int rotation, int uiMode) { |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2690 | 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] | 2691 | return mNavigationBarWidthForRotationInCarMode[rotation]; |
| 2692 | } else { |
| 2693 | return mNavigationBarWidthForRotationDefault[rotation]; |
| 2694 | } |
| 2695 | } |
| 2696 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2697 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2698 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2699 | int displayId) { |
| 2700 | // TODO(multi-display): Support navigation bar on secondary displays. |
| 2701 | if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2702 | // For a basic navigation bar, when we are in landscape mode we place |
| 2703 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2704 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2705 | return fullWidth - getNavigationBarWidth(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2706 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2707 | } |
| 2708 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2709 | } |
| 2710 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2711 | private int getNavigationBarHeight(int rotation, int uiMode) { |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 2712 | 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] | 2713 | return mNavigationBarHeightForRotationInCarMode[rotation]; |
| 2714 | } else { |
| 2715 | return mNavigationBarHeightForRotationDefault[rotation]; |
| 2716 | } |
| 2717 | } |
| 2718 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2719 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2720 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2721 | int displayId) { |
| 2722 | // TODO(multi-display): Support navigation bar on secondary displays. |
| 2723 | if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2724 | // For a basic navigation bar, when we are in portrait mode we place |
| 2725 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2726 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2727 | return fullHeight - getNavigationBarHeight(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2728 | } |
| 2729 | } |
| 2730 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2731 | } |
| 2732 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2733 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2734 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2735 | int displayId) { |
| 2736 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode, displayId); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2739 | @Override |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2740 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, |
| 2741 | int displayId) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2742 | // There is a separate status bar at the top of the display. We don't count that as part |
| 2743 | // 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] | 2744 | // we do want to exclude it since applications can't generally use that part |
| 2745 | // of the screen. |
Andrii Kulian | db8e106 | 2016-11-15 18:30:27 -0800 | [diff] [blame] | 2746 | // TODO(multi-display): Support status bars on secondary displays. |
| 2747 | if (displayId == Display.DEFAULT_DISPLAY) { |
| 2748 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation, uiMode, displayId) |
| 2749 | - mStatusBarHeight; |
| 2750 | } |
| 2751 | return fullHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2752 | } |
| 2753 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2754 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2755 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 2756 | return attrs.type == TYPE_STATUS_BAR; |
| 2757 | } |
| 2758 | |
| 2759 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2760 | public boolean canBeHiddenByKeyguardLw(WindowState win) { |
| 2761 | switch (win.getAttrs().type) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2762 | case TYPE_STATUS_BAR: |
| 2763 | case TYPE_NAVIGATION_BAR: |
| 2764 | case TYPE_WALLPAPER: |
| 2765 | case TYPE_DREAM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2766 | return false; |
| 2767 | default: |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 2768 | // Hide only windows below the keyguard host window. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2769 | return getWindowLayerLw(win) < getWindowLayerFromTypeLw(TYPE_STATUS_BAR); |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2770 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2771 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2772 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2773 | private boolean shouldBeHiddenByKeyguard(WindowState win, WindowState imeTarget) { |
| 2774 | |
| 2775 | // Keyguard visibility of window from activities are determined over activity visibility. |
| 2776 | if (win.getAppToken() != null) { |
| 2777 | return false; |
| 2778 | } |
| 2779 | |
| 2780 | final LayoutParams attrs = win.getAttrs(); |
| 2781 | final boolean showImeOverKeyguard = imeTarget != null && imeTarget.isVisibleLw() && |
| 2782 | ((imeTarget.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0 |
| 2783 | || !canBeHiddenByKeyguardLw(imeTarget)); |
| 2784 | |
| 2785 | // Show IME over the keyguard if the target allows it |
| 2786 | boolean allowWhenLocked = (win.isInputMethodWindow() || imeTarget == this) |
| 2787 | && showImeOverKeyguard;; |
| 2788 | |
| 2789 | if (isKeyguardLocked() && isKeyguardOccluded()) { |
| 2790 | // Show SHOW_WHEN_LOCKED windows if Keyguard is occluded. |
| 2791 | allowWhenLocked |= (attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0 |
| 2792 | // Show error dialogs over apps that are shown on lockscreen |
| 2793 | || (attrs.privateFlags & PRIVATE_FLAG_SYSTEM_ERROR) != 0; |
| 2794 | } |
| 2795 | |
| 2796 | boolean keyguardLocked = isKeyguardLocked(); |
| 2797 | boolean hideDockDivider = attrs.type == TYPE_DOCK_DIVIDER |
| 2798 | && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID); |
| 2799 | return (keyguardLocked && !allowWhenLocked && win.getDisplayId() == Display.DEFAULT_DISPLAY) |
| 2800 | || hideDockDivider; |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 2801 | } |
| 2802 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2803 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2804 | @Override |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 2805 | public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme, |
| 2806 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon, |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2807 | int logo, int windowFlags, Configuration overrideConfig, int displayId) { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 2808 | if (!SHOW_SPLASH_SCREENS) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2809 | return null; |
| 2810 | } |
| 2811 | if (packageName == null) { |
| 2812 | return null; |
| 2813 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2814 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2815 | WindowManager wm = null; |
| 2816 | View view = null; |
| 2817 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2818 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2819 | Context context = mContext; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 2820 | if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen " + packageName |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2821 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 2822 | + Integer.toHexString(theme)); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2823 | |
| 2824 | // Obtain proper context to launch on the right display. |
| 2825 | final Context displayContext = getDisplayContext(context, displayId); |
| 2826 | if (displayContext == null) { |
| 2827 | // Can't show splash screen on requested display, so skip showing at all. |
| 2828 | return null; |
| 2829 | } |
| 2830 | context = displayContext; |
| 2831 | |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2832 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2833 | try { |
Robert Carr | 7ad24ba | 2017-06-20 17:26:06 -0700 | [diff] [blame] | 2834 | context = context.createPackageContext(packageName, CONTEXT_RESTRICTED); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2835 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2836 | } catch (PackageManager.NameNotFoundException e) { |
| 2837 | // Ignore |
| 2838 | } |
| 2839 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2840 | |
Andrii Kulian | a8a9bc5 | 2016-10-14 11:00:13 -0700 | [diff] [blame] | 2841 | if (overrideConfig != null && !overrideConfig.equals(EMPTY)) { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 2842 | if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen: creating context based" |
| 2843 | + " on overrideConfig" + overrideConfig + " for splash screen"); |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2844 | final Context overrideContext = context.createConfigurationContext(overrideConfig); |
| 2845 | overrideContext.setTheme(theme); |
| 2846 | final TypedArray typedArray = overrideContext.obtainStyledAttributes( |
| 2847 | com.android.internal.R.styleable.Window); |
| 2848 | final int resId = typedArray.getResourceId(R.styleable.Window_windowBackground, 0); |
| 2849 | if (resId != 0 && overrideContext.getDrawable(resId) != null) { |
| 2850 | // We want to use the windowBackground for the override context if it is |
| 2851 | // available, otherwise we use the default one to make sure a themed starting |
| 2852 | // window is displayed for the app. |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 2853 | if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen: apply overrideConfig" |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2854 | + overrideConfig + " to starting window resId=" + resId); |
| 2855 | context = overrideContext; |
| 2856 | } |
Jorim Jaggi | 7d0d102 | 2017-02-23 15:35:51 +0100 | [diff] [blame] | 2857 | typedArray.recycle(); |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | final PhoneWindow win = new PhoneWindow(context); |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 2861 | win.setIsStartingWindow(true); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2862 | |
Phil Weaver | 155edc6 | 2016-06-09 10:24:53 -0700 | [diff] [blame] | 2863 | CharSequence label = context.getResources().getText(labelRes, null); |
| 2864 | // Only change the accessibility title if the label is localized |
| 2865 | if (label != null) { |
| 2866 | win.setTitle(label, true); |
| 2867 | } else { |
| 2868 | win.setTitle(nonLocalizedLabel, false); |
| 2869 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2870 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2871 | win.setType( |
| 2872 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2873 | |
| 2874 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2875 | // Assumes it's safe to show starting windows of launched apps while |
| 2876 | // the keyguard is being hidden. This is okay because starting windows never show |
| 2877 | // secret information. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2878 | if (mKeyguardOccluded) { |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2879 | windowFlags |= FLAG_SHOW_WHEN_LOCKED; |
| 2880 | } |
| 2881 | } |
| 2882 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2883 | // Force the window flags: this is a fake window, so it is not really |
| 2884 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 2885 | // flag because we do know that the next window will take input |
| 2886 | // focus, so we want to get the IME window up on top of us right away. |
| 2887 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2888 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2889 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2890 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2891 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2892 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2893 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2894 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2895 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2896 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2897 | win.setDefaultIcon(icon); |
| 2898 | win.setDefaultLogo(logo); |
| 2899 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2900 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2901 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2902 | |
Phil Weaver | 266ed9a | 2016-06-08 00:34:40 +0000 | [diff] [blame] | 2903 | final WindowManager.LayoutParams params = win.getAttributes(); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2904 | params.token = appToken; |
| 2905 | params.packageName = packageName; |
| 2906 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 2907 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2908 | params.privateFlags |= |
| 2909 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2910 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2911 | |
| 2912 | if (!compatInfo.supportsScreen()) { |
| 2913 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 2914 | } |
| 2915 | |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 2916 | params.setTitle("Splash Screen " + packageName); |
Jorim Jaggi | 7d0d102 | 2017-02-23 15:35:51 +0100 | [diff] [blame] | 2917 | addSplashscreenContent(win, context); |
| 2918 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 2919 | wm = (WindowManager) context.getSystemService(WINDOW_SERVICE); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2920 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2921 | |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 2922 | if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "Adding splash screen window for " |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2923 | + packageName + " / " + appToken + ": " + (view.getParent() != null ? view : null)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2924 | |
| 2925 | wm.addView(view, params); |
| 2926 | |
| 2927 | // Only return the view if it was successfully added to the |
| 2928 | // window manager... which we can tell by it having a parent. |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2929 | return view.getParent() != null ? new SplashScreenSurface(view, appToken) : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2930 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2931 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 2932 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 2933 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2934 | } catch (RuntimeException e) { |
| 2935 | // don't crash if something else bad happens, for example a |
| 2936 | // failure loading resources because we are loading from an app |
| 2937 | // on external storage that has been unmounted. |
| 2938 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2939 | } finally { |
| 2940 | if (view != null && view.getParent() == null) { |
| 2941 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 2942 | wm.removeViewImmediate(view); |
| 2943 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | return null; |
| 2947 | } |
| 2948 | |
Jorim Jaggi | 7d0d102 | 2017-02-23 15:35:51 +0100 | [diff] [blame] | 2949 | private void addSplashscreenContent(PhoneWindow win, Context ctx) { |
| 2950 | final TypedArray a = ctx.obtainStyledAttributes(R.styleable.Window); |
| 2951 | final int resId = a.getResourceId(R.styleable.Window_windowSplashscreenContent, 0); |
| 2952 | a.recycle(); |
| 2953 | if (resId == 0) { |
| 2954 | return; |
| 2955 | } |
| 2956 | final Drawable drawable = ctx.getDrawable(resId); |
| 2957 | if (drawable == null) { |
| 2958 | return; |
| 2959 | } |
| 2960 | |
| 2961 | // We wrap this into a view so the system insets get applied to the drawable. |
| 2962 | final View v = new View(ctx); |
| 2963 | v.setBackground(drawable); |
| 2964 | win.setContentView(v); |
| 2965 | } |
| 2966 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2967 | /** Obtain proper context for showing splash screen on the provided display. */ |
| 2968 | private Context getDisplayContext(Context context, int displayId) { |
| 2969 | if (displayId == Display.DEFAULT_DISPLAY) { |
| 2970 | // The default context fits. |
| 2971 | return context; |
| 2972 | } |
| 2973 | |
| 2974 | final DisplayManager dm = (DisplayManager) context.getSystemService(DISPLAY_SERVICE); |
| 2975 | final Display targetDisplay = dm.getDisplay(displayId); |
| 2976 | if (targetDisplay == null) { |
| 2977 | // Failed to obtain the non-default display where splash screen should be shown, |
| 2978 | // lets not show at all. |
| 2979 | return null; |
| 2980 | } |
| 2981 | |
| 2982 | return context.createDisplayContext(targetDisplay); |
| 2983 | } |
| 2984 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2985 | /** |
| 2986 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2987 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2988 | * Currently enforces that three window types are singletons: |
| 2989 | * <ul> |
| 2990 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2991 | * <li>KEYGUARD_TYPE</li> |
| 2992 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2993 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2994 | * @param win The window to be added |
| 2995 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2996 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2997 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 2998 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2999 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 3000 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3001 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 3002 | switch (attrs.type) { |
| 3003 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 3004 | mContext.enforceCallingOrSelfPermission( |
| 3005 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 3006 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3007 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3008 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3009 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3010 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3011 | } |
| 3012 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3013 | mStatusBarController.setWindow(win); |
Jorim Jaggi | 9ba2e10 | 2017-04-04 12:51:03 +0200 | [diff] [blame] | 3014 | setKeyguardOccludedLw(mKeyguardOccluded, true /* force */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3015 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3016 | case TYPE_NAVIGATION_BAR: |
| 3017 | mContext.enforceCallingOrSelfPermission( |
| 3018 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 3019 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3020 | if (mNavigationBar != null) { |
| 3021 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3022 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3023 | } |
| 3024 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3025 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3026 | mNavigationBarController.setWindow(win); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 3027 | mNavigationBarController.setOnBarVisibilityChangedListener( |
Casey Burkhardt | 469a208 | 2017-06-13 20:12:42 -0700 | [diff] [blame] | 3028 | mNavBarVisibilityListener, true); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3029 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3030 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3031 | case TYPE_NAVIGATION_BAR_PANEL: |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3032 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3033 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3034 | case TYPE_VOICE_INTERACTION_STARTING: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3035 | mContext.enforceCallingOrSelfPermission( |
| 3036 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 3037 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3038 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3039 | } |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 3040 | return ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 3044 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3045 | public void removeWindowLw(WindowState win) { |
| 3046 | if (mStatusBar == win) { |
| 3047 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3048 | mStatusBarController.setWindow(null); |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 3049 | } else if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3050 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3051 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3052 | } |
| 3053 | } |
| 3054 | |
| 3055 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3056 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3057 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3058 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3059 | public int selectAnimationLw(WindowState win, int transit) { |
| 3060 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 3061 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3062 | if (win == mStatusBar) { |
Jorim Jaggi | 67b29d5 | 2017-06-09 18:00:00 -0700 | [diff] [blame] | 3063 | final boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 3064 | final boolean expanded = win.getAttrs().height == MATCH_PARENT |
| 3065 | && win.getAttrs().width == MATCH_PARENT; |
| 3066 | if (isKeyguard || expanded) { |
| 3067 | return -1; |
| 3068 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3069 | if (transit == TRANSIT_EXIT |
| 3070 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 67b29d5 | 2017-06-09 18:00:00 -0700 | [diff] [blame] | 3071 | return R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3072 | } else if (transit == TRANSIT_ENTER |
| 3073 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 67b29d5 | 2017-06-09 18:00:00 -0700 | [diff] [blame] | 3074 | return R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3075 | } |
| 3076 | } else if (win == mNavigationBar) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 3077 | if (win.getAttrs().windowAnimations != 0) { |
| 3078 | return 0; |
| 3079 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3080 | // This can be on either the bottom or the right or the left. |
| 3081 | if (mNavigationBarPosition == NAV_BAR_BOTTOM) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3082 | if (transit == TRANSIT_EXIT |
| 3083 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 4883281 | 2016-09-06 12:38:23 -0700 | [diff] [blame] | 3084 | if (isKeyguardShowingAndNotOccluded()) { |
| 3085 | return R.anim.dock_bottom_exit_keyguard; |
| 3086 | } else { |
| 3087 | return R.anim.dock_bottom_exit; |
| 3088 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3089 | } else if (transit == TRANSIT_ENTER |
| 3090 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3091 | return R.anim.dock_bottom_enter; |
| 3092 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3093 | } else if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3094 | if (transit == TRANSIT_EXIT |
| 3095 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3096 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3097 | } else if (transit == TRANSIT_ENTER |
| 3098 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3099 | return R.anim.dock_right_enter; |
| 3100 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3101 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
| 3102 | if (transit == TRANSIT_EXIT |
| 3103 | || transit == TRANSIT_HIDE) { |
| 3104 | return R.anim.dock_left_exit; |
| 3105 | } else if (transit == TRANSIT_ENTER |
| 3106 | || transit == TRANSIT_SHOW) { |
| 3107 | return R.anim.dock_left_enter; |
| 3108 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3109 | } |
Filip Gruszczynski | 57f76f1 | 2015-11-04 16:10:54 -0800 | [diff] [blame] | 3110 | } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) { |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 3111 | return selectDockedDividerAnimationLw(win, transit); |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3115 | if (win.hasAppShownWindows()) { |
| 3116 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 3117 | return com.android.internal.R.anim.app_starting_exit; |
| 3118 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3119 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3120 | && transit == TRANSIT_ENTER) { |
| 3121 | // Special case: we are animating in a dream, while the keyguard |
| 3122 | // is shown. We don't want an animation on the dream, because |
| 3123 | // we need it shown immediately with the keyguard animating away |
| 3124 | // to reveal it. |
| 3125 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | return 0; |
| 3129 | } |
| 3130 | |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 3131 | private int selectDockedDividerAnimationLw(WindowState win, int transit) { |
| 3132 | int insets = mWindowManagerFuncs.getDockedDividerInsetsLw(); |
| 3133 | |
| 3134 | // If the divider is behind the navigation bar, don't animate. |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 3135 | final Rect frame = win.getFrameLw(); |
| 3136 | final boolean behindNavBar = mNavigationBar != null |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3137 | && ((mNavigationBarPosition == NAV_BAR_BOTTOM |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 3138 | && frame.top + insets >= mNavigationBar.getFrameLw().top) |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 3139 | || (mNavigationBarPosition == NAV_BAR_RIGHT |
| 3140 | && frame.left + insets >= mNavigationBar.getFrameLw().left) |
| 3141 | || (mNavigationBarPosition == NAV_BAR_LEFT |
| 3142 | && frame.right - insets <= mNavigationBar.getFrameLw().right)); |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 3143 | final boolean landscape = frame.height() > frame.width(); |
| 3144 | final boolean offscreenLandscape = landscape && (frame.right - insets <= 0 |
| 3145 | || frame.left + insets >= win.getDisplayFrameLw().right); |
| 3146 | final boolean offscreenPortrait = !landscape && (frame.top - insets <= 0 |
| 3147 | || frame.bottom + insets >= win.getDisplayFrameLw().bottom); |
| 3148 | final boolean offscreen = offscreenLandscape || offscreenPortrait; |
| 3149 | if (behindNavBar || offscreen) { |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 3150 | return 0; |
| 3151 | } |
| 3152 | if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) { |
| 3153 | return R.anim.fade_in; |
| 3154 | } else if (transit == TRANSIT_EXIT) { |
| 3155 | return R.anim.fade_out; |
| 3156 | } else { |
| 3157 | return 0; |
| 3158 | } |
| 3159 | } |
| 3160 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3161 | @Override |
| 3162 | public void selectRotationAnimationLw(int anim[]) { |
Adrian Roos | 7c89480 | 2017-07-19 12:25:34 +0200 | [diff] [blame] | 3163 | // If the screen is off or non-interactive, force a jumpcut. |
Adrian Roos | 3162b8f | 2017-07-25 15:37:32 +0200 | [diff] [blame] | 3164 | final boolean forceJumpcut = !mScreenOnFully || !okToAnimate(); |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3165 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 3166 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 3167 | + (mTopFullscreenOpaqueWindowState == null ? |
Adrian Roos | 7c89480 | 2017-07-19 12:25:34 +0200 | [diff] [blame] | 3168 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) |
| 3169 | + " forceJumpcut=" + forceJumpcut); |
| 3170 | if (forceJumpcut) { |
| 3171 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 3172 | anim[1] = R.anim.rotation_animation_enter; |
| 3173 | return; |
| 3174 | } |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 3175 | if (mTopFullscreenOpaqueWindowState != null) { |
| 3176 | int animationHint = mTopFullscreenOpaqueWindowState.getRotationAnimationHint(); |
| 3177 | if (animationHint < 0 && mTopIsFullscreen) { |
| 3178 | animationHint = mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation; |
| 3179 | } |
| 3180 | switch (animationHint) { |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3181 | case ROTATION_ANIMATION_CROSSFADE: |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 3182 | case ROTATION_ANIMATION_SEAMLESS: // Crossfade is fallback for seamless. |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3183 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 3184 | anim[1] = R.anim.rotation_animation_enter; |
| 3185 | break; |
| 3186 | case ROTATION_ANIMATION_JUMPCUT: |
| 3187 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 3188 | anim[1] = R.anim.rotation_animation_enter; |
| 3189 | break; |
| 3190 | case ROTATION_ANIMATION_ROTATE: |
| 3191 | default: |
| 3192 | anim[0] = anim[1] = 0; |
| 3193 | break; |
| 3194 | } |
| 3195 | } else { |
| 3196 | anim[0] = anim[1] = 0; |
| 3197 | } |
| 3198 | } |
| 3199 | |
| 3200 | @Override |
| 3201 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 3202 | boolean forceDefault) { |
| 3203 | switch (exitAnimId) { |
| 3204 | case R.anim.rotation_animation_xfade_exit: |
| 3205 | case R.anim.rotation_animation_jump_exit: |
| 3206 | // These are the only cases that matter. |
| 3207 | if (forceDefault) { |
| 3208 | return false; |
| 3209 | } |
| 3210 | int anim[] = new int[2]; |
| 3211 | selectRotationAnimationLw(anim); |
| 3212 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 3213 | default: |
| 3214 | return true; |
| 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3219 | public Animation createHiddenByKeyguardExit(boolean onWallpaper, |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 3220 | boolean goingToNotificationShade) { |
| 3221 | if (goingToNotificationShade) { |
| 3222 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
Craig Mautner | b834080 | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 3223 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 3224 | |
| 3225 | AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? |
| 3226 | R.anim.lock_screen_behind_enter_wallpaper : |
| 3227 | R.anim.lock_screen_behind_enter); |
| 3228 | |
| 3229 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 3230 | final List<Animation> animations = set.getAnimations(); |
| 3231 | for (int i = animations.size() - 1; i >= 0; --i) { |
| 3232 | animations.get(i).setInterpolator(mLogDecelerateInterpolator); |
| 3233 | } |
| 3234 | |
| 3235 | return set; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 3236 | } |
| 3237 | |
| 3238 | |
| 3239 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3240 | public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) { |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 3241 | if (goingToNotificationShade) { |
| 3242 | return null; |
| 3243 | } else { |
| 3244 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 3245 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 3246 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 3247 | |
| 3248 | private static void awakenDreams() { |
| 3249 | IDreamManager dreamManager = getDreamManager(); |
| 3250 | if (dreamManager != null) { |
| 3251 | try { |
| 3252 | dreamManager.awaken(); |
| 3253 | } catch (RemoteException e) { |
| 3254 | // fine, stay asleep then |
| 3255 | } |
| 3256 | } |
| 3257 | } |
| 3258 | |
| 3259 | static IDreamManager getDreamManager() { |
| 3260 | return IDreamManager.Stub.asInterface( |
| 3261 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 3262 | } |
| 3263 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 3264 | TelecomManager getTelecommService() { |
| 3265 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3266 | } |
| 3267 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3268 | static IAudioService getAudioService() { |
| 3269 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 3270 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 3271 | if (audioService == null) { |
| 3272 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 3273 | } |
| 3274 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | boolean keyguardOn() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 3278 | return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 3282 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 3283 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 3284 | }; |
| 3285 | |
| 3286 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3287 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3288 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3289 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3290 | final int keyCode = event.getKeyCode(); |
| 3291 | final int repeatCount = event.getRepeatCount(); |
| 3292 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3293 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3294 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 3295 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3296 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3297 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3298 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3299 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 3300 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3301 | } |
| 3302 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3303 | // If we think we might have a volume down & power key chord on the way |
| 3304 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 3305 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 3306 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3307 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3308 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3309 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 3310 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3311 | if (now < timeoutTime) { |
| 3312 | return timeoutTime - now; |
| 3313 | } |
| 3314 | } |
| 3315 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3316 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3317 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3318 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3319 | } |
| 3320 | return -1; |
| 3321 | } |
| 3322 | } |
| 3323 | |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 3324 | // If an accessibility shortcut might be partially complete, hold off dispatching until we |
| 3325 | // know if it is complete or not |
Phil Weaver | ce687c5 | 2017-03-15 08:51:52 -0700 | [diff] [blame] | 3326 | if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(false) |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 3327 | && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3328 | if (mScreenshotChordVolumeDownKeyTriggered ^ mA11yShortcutChordVolumeUpKeyTriggered) { |
| 3329 | final long now = SystemClock.uptimeMillis(); |
| 3330 | final long timeoutTime = (mScreenshotChordVolumeDownKeyTriggered |
| 3331 | ? mScreenshotChordVolumeDownKeyTime : mA11yShortcutChordVolumeUpKeyTime) |
| 3332 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
| 3333 | if (now < timeoutTime) { |
| 3334 | return timeoutTime - now; |
| 3335 | } |
| 3336 | } |
| 3337 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && mScreenshotChordVolumeDownKeyConsumed) { |
| 3338 | if (!down) { |
| 3339 | mScreenshotChordVolumeDownKeyConsumed = false; |
| 3340 | } |
| 3341 | return -1; |
| 3342 | } |
| 3343 | if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && mA11yShortcutChordVolumeUpKeyConsumed) { |
| 3344 | if (!down) { |
| 3345 | mA11yShortcutChordVolumeUpKeyConsumed = false; |
| 3346 | } |
| 3347 | return -1; |
| 3348 | } |
| 3349 | } |
| 3350 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3351 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 3352 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 3353 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3354 | mPendingMetaAction = false; |
| 3355 | } |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 3356 | // Any key that is not Alt or Meta cancels Caps Lock combo tracking. |
| 3357 | if (mPendingCapsLockToggle && !KeyEvent.isMetaKey(keyCode) && !KeyEvent.isAltKey(keyCode)) { |
| 3358 | mPendingCapsLockToggle = false; |
| 3359 | } |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3360 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3361 | // First we always handle the home key here, so applications |
| 3362 | // can never break it, although if keyguard is on, we do let |
| 3363 | // it handle it, because that gives us the correct 5 second |
| 3364 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3365 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3366 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3367 | // If we have released the home key, and didn't do anything else |
| 3368 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3369 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3370 | cancelPreloadRecentApps(); |
| 3371 | |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 3372 | if (mHasFeatureLeanback) { |
| 3373 | // Clear flags |
| 3374 | mAccessibilityTvKey2Pressed = down; |
| 3375 | } |
| 3376 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3377 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3378 | if (mHomeConsumed) { |
| 3379 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3380 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3381 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3382 | |
| 3383 | if (canceled) { |
| 3384 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 3385 | return -1; |
| 3386 | } |
| 3387 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3388 | // Delay handling home if a double-tap is possible. |
| 3389 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 3390 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 3391 | mHomeDoubleTapPending = true; |
| 3392 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 3393 | ViewConfiguration.getDoubleTapTimeout()); |
| 3394 | return -1; |
| 3395 | } |
| 3396 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3397 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3398 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3399 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3400 | |
| 3401 | // If a system window has focus, then it doesn't make sense |
| 3402 | // right now to interact with applications. |
| 3403 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 3404 | if (attrs != null) { |
| 3405 | final int type = attrs.type; |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 3406 | if (type == TYPE_KEYGUARD_DIALOG |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3407 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3408 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3409 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3410 | } |
| 3411 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 3412 | for (int i=0; i<typeCount; i++) { |
| 3413 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 3414 | // 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] | 3415 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3416 | } |
| 3417 | } |
| 3418 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3419 | |
| 3420 | // Remember that home is pressed and handle special actions. |
| 3421 | if (repeatCount == 0) { |
| 3422 | mHomePressed = true; |
| 3423 | if (mHomeDoubleTapPending) { |
| 3424 | mHomeDoubleTapPending = false; |
| 3425 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 3426 | handleDoubleTapOnHome(); |
Sid Soundararajan | ff662fa | 2017-03-15 16:24:24 -0700 | [diff] [blame] | 3427 | } else if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3428 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3429 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3430 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 3431 | if (mHasFeatureLeanback) { |
| 3432 | mAccessibilityTvKey2Pressed = down; |
| 3433 | if (interceptAccessibilityGestureTv()) { |
| 3434 | return -1; |
| 3435 | } |
| 3436 | } |
| 3437 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3438 | if (!keyguardOn) { |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 3439 | handleLongPressOnHome(event.getDeviceId()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3440 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3441 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3442 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3443 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3444 | // Hijack modified menu keys for debugging features |
| 3445 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 3446 | |
| 3447 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3448 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3449 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 3450 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 3451 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3452 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3453 | } |
| 3454 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3455 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3456 | if (down) { |
| 3457 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3458 | mSearchKeyShortcutPending = true; |
| 3459 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3460 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3461 | } else { |
| 3462 | mSearchKeyShortcutPending = false; |
| 3463 | if (mConsumeSearchKeyUp) { |
| 3464 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3465 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3466 | } |
| 3467 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3468 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3469 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 3470 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3471 | if (down && repeatCount == 0) { |
| 3472 | preloadRecentApps(); |
| 3473 | } else if (!down) { |
| 3474 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 3475 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3476 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3477 | return -1; |
Jun Mukai | d21b3c8 | 2015-04-23 14:09:34 -0700 | [diff] [blame] | 3478 | } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) { |
| 3479 | if (down) { |
| 3480 | IStatusBarService service = getStatusBarService(); |
| 3481 | if (service != null) { |
| 3482 | try { |
| 3483 | service.expandNotificationsPanel(); |
| 3484 | } catch (RemoteException e) { |
| 3485 | // do nothing. |
| 3486 | } |
| 3487 | } |
| 3488 | } |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 3489 | } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed() |
| 3490 | && event.isCtrlPressed()) { |
| 3491 | if (down && repeatCount == 0) { |
| 3492 | int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION |
| 3493 | : TAKE_SCREENSHOT_FULLSCREEN; |
| 3494 | mScreenshotRunnable.setScreenshotType(type); |
| 3495 | mHandler.post(mScreenshotRunnable); |
| 3496 | return -1; |
| 3497 | } |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3498 | } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) { |
Andrei Stingaceanu | 002f712 | 2016-03-30 12:22:05 +0100 | [diff] [blame] | 3499 | if (down && repeatCount == 0 && !isKeyguardLocked()) { |
| 3500 | toggleKeyboardShortcutsMenu(event.getDeviceId()); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3501 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3502 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 3503 | if (down) { |
| 3504 | if (repeatCount == 0) { |
| 3505 | mAssistKeyLongPressed = false; |
| 3506 | } else if (repeatCount == 1) { |
| 3507 | mAssistKeyLongPressed = true; |
| 3508 | if (!keyguardOn) { |
| 3509 | launchAssistLongPressAction(); |
| 3510 | } |
| 3511 | } |
| 3512 | } else { |
| 3513 | if (mAssistKeyLongPressed) { |
| 3514 | mAssistKeyLongPressed = false; |
| 3515 | } else { |
| 3516 | if (!keyguardOn) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3517 | launchAssistAction(null, event.getDeviceId()); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3518 | } |
| 3519 | } |
| 3520 | } |
| 3521 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3522 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 3523 | if (!down) { |
| 3524 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 3525 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3526 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3527 | } else { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 3528 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 3529 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 3530 | if (dic != null) { |
| 3531 | try { |
| 3532 | dic.exitIdle("voice-search"); |
| 3533 | } catch (RemoteException e) { |
| 3534 | } |
| 3535 | } |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3536 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 3537 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3538 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3539 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3540 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 3541 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 3542 | if (down && repeatCount == 0) { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 3543 | mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN); |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 3544 | mHandler.post(mScreenshotRunnable); |
| 3545 | } |
| 3546 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 3547 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 3548 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 3549 | if (down) { |
| 3550 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 3551 | |
| 3552 | // Disable autobrightness if it's on |
| 3553 | int auto = Settings.System.getIntForUser( |
| 3554 | mContext.getContentResolver(), |
| 3555 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 3556 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 3557 | UserHandle.USER_CURRENT_OR_SELF); |
| 3558 | if (auto != 0) { |
| 3559 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3560 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 3561 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 3562 | UserHandle.USER_CURRENT_OR_SELF); |
| 3563 | } |
| 3564 | |
| 3565 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 3566 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 3567 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 3568 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 3569 | Settings.System.SCREEN_BRIGHTNESS, |
| 3570 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 3571 | UserHandle.USER_CURRENT_OR_SELF); |
| 3572 | brightness += step; |
| 3573 | // Make sure we don't go beyond the limits. |
| 3574 | brightness = Math.min(max, brightness); |
| 3575 | brightness = Math.max(min, brightness); |
| 3576 | |
| 3577 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3578 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 3579 | UserHandle.USER_CURRENT_OR_SELF); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3580 | startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 3581 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 3582 | } |
| 3583 | return -1; |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 3584 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 3585 | || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 3586 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { |
Karthik Ravi Shankar | 86ecf34 | 2017-04-28 15:35:58 -0700 | [diff] [blame] | 3587 | if (mUseTvRouting || mHandleVolumeKeysInWM) { |
| 3588 | // On TVs or when the configuration is enabled, volume keys never |
| 3589 | // go to the foreground app. |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 3590 | dispatchDirectAudioEvent(event); |
| 3591 | return -1; |
| 3592 | } |
Karthik Ravi Shankar | 86ecf34 | 2017-04-28 15:35:58 -0700 | [diff] [blame] | 3593 | |
| 3594 | // If the device is in Vr mode, drop the volume keys and don't |
| 3595 | // forward it to the application/dispatch the audio event. |
| 3596 | if (mPersistentVrModeEnabled) { |
| 3597 | return -1; |
| 3598 | } |
Evan Rosky | 516f9e6 | 2017-01-23 16:43:52 -0800 | [diff] [blame] | 3599 | } else if (keyCode == KeyEvent.KEYCODE_TAB && event.isMetaPressed()) { |
| 3600 | // Pass through keyboard navigation keys. |
| 3601 | return 0; |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 3602 | } else if (mHasFeatureLeanback && interceptBugreportGestureTv(keyCode, down)) { |
| 3603 | return -1; |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 3604 | } else if (mHasFeatureLeanback && keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { |
| 3605 | mAccessibilityTvKey1Pressed = down; |
| 3606 | if (interceptAccessibilityGestureTv()) { |
| 3607 | return -1; |
| 3608 | } |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3609 | } |
| 3610 | |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 3611 | // Toggle Caps Lock on META-ALT. |
| 3612 | boolean actionTriggered = false; |
| 3613 | if (KeyEvent.isModifierKey(keyCode)) { |
| 3614 | if (!mPendingCapsLockToggle) { |
| 3615 | // Start tracking meta state for combo. |
| 3616 | mInitialMetaState = mMetaState; |
| 3617 | mPendingCapsLockToggle = true; |
| 3618 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 3619 | int altOnMask = mMetaState & KeyEvent.META_ALT_MASK; |
| 3620 | int metaOnMask = mMetaState & KeyEvent.META_META_MASK; |
| 3621 | |
| 3622 | // Check for Caps Lock toggle |
| 3623 | if ((metaOnMask != 0) && (altOnMask != 0)) { |
| 3624 | // Check if nothing else is pressed |
| 3625 | if (mInitialMetaState == (mMetaState ^ (altOnMask | metaOnMask))) { |
| 3626 | // Handle Caps Lock Toggle |
| 3627 | mInputManagerInternal.toggleCapsLock(event.getDeviceId()); |
| 3628 | actionTriggered = true; |
| 3629 | } |
| 3630 | } |
| 3631 | |
| 3632 | // Always stop tracking when key goes up. |
| 3633 | mPendingCapsLockToggle = false; |
| 3634 | } |
| 3635 | } |
| 3636 | // Store current meta state to be able to evaluate it later. |
| 3637 | mMetaState = metaState; |
| 3638 | |
| 3639 | if (actionTriggered) { |
| 3640 | return -1; |
| 3641 | } |
| 3642 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3643 | if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3644 | if (down) { |
| 3645 | mPendingMetaAction = true; |
| 3646 | } else if (mPendingMetaAction) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3647 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId()); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3648 | } |
| 3649 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3650 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3651 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3652 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3653 | // Any printing key that is chorded with Search should be consumed |
| 3654 | // even if no shortcut was invoked. This prevents text from being |
| 3655 | // inadvertently inserted when using a keyboard that has built-in macro |
| 3656 | // 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] | 3657 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3658 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 3659 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3660 | mConsumeSearchKeyUp = true; |
| 3661 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3662 | if (down && repeatCount == 0 && !keyguardOn) { |
| 3663 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 3664 | if (shortcutIntent != null) { |
| 3665 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3666 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3667 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3668 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3669 | } catch (ActivityNotFoundException ex) { |
| 3670 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3671 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3672 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3673 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3674 | } else { |
| 3675 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3676 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3677 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3678 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3679 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3680 | } |
| 3681 | } |
| 3682 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3683 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3684 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3685 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 3686 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3687 | if (kcm.isPrintingKey(keyCode)) { |
| 3688 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 3689 | metaState & ~(KeyEvent.META_META_ON |
| 3690 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 3691 | if (shortcutIntent != null) { |
| 3692 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3693 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3694 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3695 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3696 | } catch (ActivityNotFoundException ex) { |
| 3697 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3698 | + "the activity to which it is registered was not found: " |
| 3699 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 3700 | } |
| 3701 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3702 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3703 | } |
| 3704 | } |
| 3705 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3706 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3707 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3708 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 3709 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 3710 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3711 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3712 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3713 | startActivityAsUser(intent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3714 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3715 | } catch (ActivityNotFoundException ex) { |
| 3716 | Slog.w(TAG, "Dropping application launch key because " |
| 3717 | + "the activity to which it is registered was not found: " |
| 3718 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 3719 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3720 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3721 | } |
| 3722 | } |
| 3723 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3724 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3725 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Michael Wright | d847ad5 | 2015-10-24 13:24:15 +0100 | [diff] [blame] | 3726 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3727 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3728 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3729 | mRecentAppsHeldModifiers = shiftlessModifiers; |
Winson | 14db362 | 2016-05-09 13:34:07 -0700 | [diff] [blame] | 3730 | showRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3731 | return -1; |
| 3732 | } |
| 3733 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3734 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 3735 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 3736 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3737 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3738 | } |
| 3739 | |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3740 | // Handle input method switching. |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3741 | if (down && repeatCount == 0 |
| 3742 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3743 | || (keyCode == KeyEvent.KEYCODE_SPACE |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3744 | && (metaState & KeyEvent.META_META_MASK) != 0))) { |
| 3745 | final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0; |
| 3746 | mWindowManagerFuncs.switchInputMethod(forwardDirection); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3747 | return -1; |
| 3748 | } |
| 3749 | if (mLanguageSwitchKeyPressed && !down |
| 3750 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3751 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 3752 | mLanguageSwitchKeyPressed = false; |
| 3753 | return -1; |
| 3754 | } |
| 3755 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3756 | if (isValidGlobalKey(keyCode) |
| 3757 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 3758 | return -1; |
| 3759 | } |
| 3760 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3761 | if (down) { |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 3762 | long shortcutCode = keyCode; |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3763 | if (event.isCtrlPressed()) { |
| 3764 | shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE; |
| 3765 | } |
| 3766 | |
| 3767 | if (event.isAltPressed()) { |
| 3768 | shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE; |
| 3769 | } |
| 3770 | |
| 3771 | if (event.isShiftPressed()) { |
| 3772 | shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE; |
| 3773 | } |
| 3774 | |
| 3775 | if (event.isMetaPressed()) { |
| 3776 | shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE; |
| 3777 | } |
| 3778 | |
| 3779 | IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode); |
| 3780 | if (shortcutService != null) { |
| 3781 | try { |
Muyuan Li | b5dd049 | 2016-04-14 13:22:20 -0700 | [diff] [blame] | 3782 | if (isUserSetupComplete()) { |
| 3783 | shortcutService.notifyShortcutKeyPressed(shortcutCode); |
| 3784 | } |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3785 | } catch (RemoteException e) { |
| 3786 | mShortcutKeyServices.delete(shortcutCode); |
| 3787 | } |
| 3788 | return -1; |
| 3789 | } |
| 3790 | } |
| 3791 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3792 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 3793 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3794 | return -1; |
| 3795 | } |
| 3796 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3797 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3798 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3799 | } |
| 3800 | |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 3801 | /** |
| 3802 | * TV only: recognizes a remote control gesture for capturing a bug report. |
| 3803 | */ |
| 3804 | private boolean interceptBugreportGestureTv(int keyCode, boolean down) { |
| 3805 | // The bugreport capture chord is a long press on DPAD CENTER and BACK simultaneously. |
| 3806 | if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { |
| 3807 | mBugreportTvKey1Pressed = down; |
| 3808 | } else if (keyCode == KeyEvent.KEYCODE_BACK) { |
| 3809 | mBugreportTvKey2Pressed = down; |
| 3810 | } |
| 3811 | |
| 3812 | if (mBugreportTvKey1Pressed && mBugreportTvKey2Pressed) { |
| 3813 | if (!mBugreportTvScheduled) { |
| 3814 | mBugreportTvScheduled = true; |
| 3815 | Message msg = Message.obtain(mHandler, MSG_BUGREPORT_TV); |
| 3816 | msg.setAsynchronous(true); |
| 3817 | mHandler.sendMessageDelayed(msg, BUGREPORT_TV_GESTURE_TIMEOUT_MILLIS); |
| 3818 | } |
| 3819 | } else if (mBugreportTvScheduled) { |
| 3820 | mHandler.removeMessages(MSG_BUGREPORT_TV); |
| 3821 | mBugreportTvScheduled = false; |
| 3822 | } |
| 3823 | |
| 3824 | return mBugreportTvScheduled; |
| 3825 | } |
| 3826 | |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 3827 | /** |
| 3828 | * TV only: recognizes a remote control gesture as Accessibility shortcut. |
| 3829 | * Shortcut: Long press (HOME + DPAD_CENTER) |
| 3830 | */ |
| 3831 | private boolean interceptAccessibilityGestureTv() { |
| 3832 | if (mAccessibilityTvKey1Pressed && mAccessibilityTvKey2Pressed) { |
| 3833 | if (!mAccessibilityTvScheduled) { |
| 3834 | mAccessibilityTvScheduled = true; |
| 3835 | Message msg = Message.obtain(mHandler, MSG_ACCESSIBILITY_TV); |
| 3836 | msg.setAsynchronous(true); |
| 3837 | mHandler.sendMessage(msg); |
| 3838 | } |
| 3839 | } else if (mAccessibilityTvScheduled) { |
| 3840 | mHandler.removeMessages(MSG_ACCESSIBILITY_TV); |
| 3841 | mAccessibilityTvScheduled = false; |
| 3842 | } |
| 3843 | return mAccessibilityTvScheduled; |
| 3844 | } |
| 3845 | |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 3846 | private void takeBugreport() { |
| 3847 | if ("1".equals(SystemProperties.get("ro.debuggable")) |
| 3848 | || Settings.Global.getInt(mContext.getContentResolver(), |
| 3849 | Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1) { |
| 3850 | try { |
| 3851 | ActivityManager.getService() |
| 3852 | .requestBugReport(ActivityManager.BUGREPORT_OPTION_INTERACTIVE); |
| 3853 | } catch (RemoteException e) { |
| 3854 | Slog.e(TAG, "Error taking bugreport", e); |
| 3855 | } |
| 3856 | } |
| 3857 | } |
| 3858 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3859 | /** {@inheritDoc} */ |
| 3860 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3861 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3862 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3863 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3864 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 3865 | + ", flags=" + event.getFlags() |
| 3866 | + ", keyCode=" + event.getKeyCode() |
| 3867 | + ", scanCode=" + event.getScanCode() |
| 3868 | + ", metaState=" + event.getMetaState() |
| 3869 | + ", repeatCount=" + event.getRepeatCount() |
| 3870 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3871 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3872 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3873 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3874 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3875 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3876 | final int keyCode = event.getKeyCode(); |
| 3877 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3878 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 3879 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3880 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3881 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3882 | final FallbackAction fallbackAction; |
| 3883 | if (initialDown) { |
| 3884 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 3885 | } else { |
| 3886 | fallbackAction = mFallbackActions.get(keyCode); |
| 3887 | } |
| 3888 | |
| 3889 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3890 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3891 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 3892 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3893 | } |
| 3894 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3895 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 3896 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3897 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3898 | event.getAction(), fallbackAction.keyCode, |
| 3899 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3900 | event.getDeviceId(), event.getScanCode(), |
| 3901 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3902 | |
| 3903 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 3904 | fallbackEvent.recycle(); |
| 3905 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3906 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3907 | |
| 3908 | if (initialDown) { |
| 3909 | mFallbackActions.put(keyCode, fallbackAction); |
| 3910 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 3911 | mFallbackActions.remove(keyCode); |
| 3912 | fallbackAction.recycle(); |
| 3913 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3914 | } |
| 3915 | } |
| 3916 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3917 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3918 | if (fallbackEvent == null) { |
| 3919 | Slog.d(TAG, "No fallback."); |
| 3920 | } else { |
| 3921 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 3922 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3923 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3924 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3925 | } |
| 3926 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3927 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3928 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3929 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 3930 | long delayMillis = interceptKeyBeforeDispatching( |
| 3931 | win, fallbackEvent, policyFlags); |
| 3932 | if (delayMillis == 0) { |
| 3933 | return true; |
| 3934 | } |
| 3935 | } |
| 3936 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3937 | } |
| 3938 | |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 3939 | @Override |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3940 | public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService) |
| 3941 | throws RemoteException { |
| 3942 | synchronized (mLock) { |
| 3943 | IShortcutService service = mShortcutKeyServices.get(shortcutCode); |
Muyuan Li | 24d24ac | 2016-03-03 21:15:02 -0800 | [diff] [blame] | 3944 | if (service != null && service.asBinder().pingBinder()) { |
| 3945 | throw new RemoteException("Key already exists."); |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | mShortcutKeyServices.put(shortcutCode, shortcutService); |
| 3949 | } |
| 3950 | } |
| 3951 | |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 3952 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3953 | public void onKeyguardOccludedChangedLw(boolean occluded) { |
| 3954 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
| 3955 | mPendingKeyguardOccluded = occluded; |
| 3956 | mKeyguardOccludedChanged = true; |
| 3957 | } else { |
Jorim Jaggi | 9ba2e10 | 2017-04-04 12:51:03 +0200 | [diff] [blame] | 3958 | setKeyguardOccludedLw(occluded, false /* force */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3959 | } |
| 3960 | } |
| 3961 | |
| 3962 | private int handleStartTransitionForKeyguardLw(int transit, @Nullable Animation anim) { |
| 3963 | if (mKeyguardOccludedChanged) { |
| 3964 | if (DEBUG_KEYGUARD) Slog.d(TAG, "transition/occluded changed occluded=" |
| 3965 | + mPendingKeyguardOccluded); |
| 3966 | mKeyguardOccludedChanged = false; |
Jorim Jaggi | 9ba2e10 | 2017-04-04 12:51:03 +0200 | [diff] [blame] | 3967 | if (setKeyguardOccludedLw(mPendingKeyguardOccluded, false /* force */)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3968 | return FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3969 | } |
| 3970 | } |
| 3971 | if (AppTransition.isKeyguardGoingAwayTransit(transit)) { |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 3972 | if (DEBUG_KEYGUARD) Slog.d(TAG, "Starting keyguard exit animation"); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3973 | final long startTime = anim != null |
| 3974 | ? SystemClock.uptimeMillis() + anim.getStartOffset() |
| 3975 | : SystemClock.uptimeMillis(); |
| 3976 | final long duration = anim != null |
| 3977 | ? anim.getDuration() |
| 3978 | : 0; |
| 3979 | startKeyguardExitAnimation(startTime, duration); |
| 3980 | } |
| 3981 | return 0; |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 3982 | } |
| 3983 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3984 | private void launchAssistLongPressAction() { |
| 3985 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 3986 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 3987 | |
| 3988 | // launch the search activity |
| 3989 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 3990 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3991 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3992 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 3993 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3994 | SearchManager searchManager = getSearchManager(); |
| 3995 | if (searchManager != null) { |
| 3996 | searchManager.stopSearch(); |
| 3997 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3998 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3999 | } catch (ActivityNotFoundException e) { |
| 4000 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 4001 | } |
| 4002 | } |
| 4003 | |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 4004 | private void launchAssistAction(String hint, int deviceId) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 4005 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Maurice Lam | 39d1381 | 2015-07-23 20:49:20 -0700 | [diff] [blame] | 4006 | if (!isUserSetupComplete()) { |
| 4007 | // Disable opening assist window during setup |
| 4008 | return; |
| 4009 | } |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 4010 | Bundle args = null; |
| 4011 | if (deviceId > Integer.MIN_VALUE) { |
| 4012 | args = new Bundle(); |
| 4013 | args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 4014 | } |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 4015 | if ((mContext.getResources().getConfiguration().uiMode |
| 4016 | & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) { |
| 4017 | // On TV, use legacy handling until assistants are implemented in the proper way. |
| 4018 | ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
| 4019 | .launchLegacyAssist(hint, UserHandle.myUserId(), args); |
| 4020 | } else { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4021 | if (hint != null) { |
| 4022 | if (args == null) { |
| 4023 | args = new Bundle(); |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 4024 | } |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4025 | args.putBoolean(hint, true); |
| 4026 | } |
| 4027 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4028 | if (statusbar != null) { |
| 4029 | statusbar.startAssist(args); |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 4030 | } |
| 4031 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 4032 | } |
| 4033 | |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 4034 | private void startActivityAsUser(Intent intent, UserHandle handle) { |
| 4035 | if (isUserSetupComplete()) { |
| 4036 | mContext.startActivityAsUser(intent, handle); |
| 4037 | } else { |
| 4038 | Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); |
| 4039 | } |
| 4040 | } |
| 4041 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 4042 | private SearchManager getSearchManager() { |
| 4043 | if (mSearchManager == null) { |
| 4044 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 4045 | } |
| 4046 | return mSearchManager; |
| 4047 | } |
| 4048 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 4049 | private void preloadRecentApps() { |
| 4050 | mPreloadedRecentApps = true; |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4051 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4052 | if (statusbar != null) { |
| 4053 | statusbar.preloadRecentApps(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 4054 | } |
| 4055 | } |
| 4056 | |
| 4057 | private void cancelPreloadRecentApps() { |
| 4058 | if (mPreloadedRecentApps) { |
| 4059 | mPreloadedRecentApps = false; |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4060 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4061 | if (statusbar != null) { |
| 4062 | statusbar.cancelPreloadRecentApps(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 4063 | } |
| 4064 | } |
| 4065 | } |
| 4066 | |
| 4067 | private void toggleRecentApps() { |
| 4068 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4069 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4070 | if (statusbar != null) { |
| 4071 | statusbar.toggleRecentApps(); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 4072 | } |
| 4073 | } |
| 4074 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4075 | @Override |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 4076 | public void showRecentApps(boolean fromHome) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4077 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 4078 | mHandler.obtainMessage(MSG_DISPATCH_SHOW_RECENTS, fromHome ? 1 : 0, 0).sendToTarget(); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4079 | } |
| 4080 | |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 4081 | private void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 4082 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4083 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4084 | if (statusbar != null) { |
| 4085 | statusbar.showRecentApps(triggeredFromAltTab, fromHome); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 4086 | } |
| 4087 | } |
| 4088 | |
Clara Bayarri | 4e850ff | 2016-03-02 11:12:32 -0800 | [diff] [blame] | 4089 | private void toggleKeyboardShortcutsMenu(int deviceId) { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4090 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4091 | if (statusbar != null) { |
| 4092 | statusbar.toggleKeyboardShortcutsMenu(deviceId); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 4093 | } |
| 4094 | } |
| 4095 | |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 4096 | private void dismissKeyboardShortcutsMenu() { |
| 4097 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4098 | if (statusbar != null) { |
| 4099 | statusbar.dismissKeyboardShortcutsMenu(); |
| 4100 | } |
| 4101 | } |
| 4102 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 4103 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 4104 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 4105 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 4106 | if (statusbar != null) { |
| 4107 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 4108 | } |
| 4109 | } |
| 4110 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 4111 | void launchHomeFromHotKey() { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4112 | launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 4113 | } |
| 4114 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4115 | /** |
| 4116 | * A home key -> launch home action was detected. Take the appropriate action |
| 4117 | * given the situation with the keyguard. |
| 4118 | */ |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4119 | void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) { |
| 4120 | if (respectKeyguard) { |
| 4121 | if (isKeyguardShowingAndNotOccluded()) { |
| 4122 | // don't launch home if keyguard showing |
| 4123 | return; |
| 4124 | } |
| 4125 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4126 | if (!mKeyguardOccluded && mKeyguardDelegate.isInputRestricted()) { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4127 | // when in keyguard restricted mode, must first verify unlock |
| 4128 | // before launching home |
| 4129 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
| 4130 | @Override |
| 4131 | public void onKeyguardExitResult(boolean success) { |
| 4132 | if (success) { |
| 4133 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4134 | ActivityManager.getService().stopAppSwitches(); |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4135 | } catch (RemoteException e) { |
| 4136 | } |
| 4137 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 4138 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 4139 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4140 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4141 | }); |
| 4142 | return; |
| 4143 | } |
| 4144 | } |
| 4145 | |
| 4146 | // no keyguard stuff to worry about, just launch home! |
| 4147 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4148 | ActivityManager.getService().stopAppSwitches(); |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4149 | } catch (RemoteException e) { |
| 4150 | } |
| 4151 | if (mRecentsVisible) { |
| 4152 | // Hide Recents and notify it to launch Home |
| 4153 | if (awakenFromDreams) { |
| 4154 | awakenDreams(); |
| 4155 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4156 | hideRecentApps(false, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4157 | } else { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 4158 | // Otherwise, just launch Home |
| 4159 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 4160 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4161 | } |
| 4162 | } |
| 4163 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4164 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 4165 | @Override |
| 4166 | public void run() { |
| 4167 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 4168 | // Clear flags. |
| 4169 | mForceClearedSystemUiFlags &= |
| 4170 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 4171 | } |
| 4172 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4173 | } |
| 4174 | }; |
| 4175 | |
| 4176 | /** |
| 4177 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 4178 | * to determine when the nav bar should be shown and prevent applications from |
| 4179 | * receiving those touches. |
| 4180 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 4181 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 4182 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 4183 | super(inputChannel, looper); |
| 4184 | } |
| 4185 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4186 | @Override |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 4187 | public void onInputEvent(InputEvent event, int displayId) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4188 | boolean handled = false; |
| 4189 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4190 | if (event instanceof MotionEvent |
| 4191 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 4192 | final MotionEvent motionEvent = (MotionEvent)event; |
| 4193 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4194 | // When the user taps down, we re-show the nav bar. |
| 4195 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4196 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 4197 | if (mInputConsumer == null) { |
| 4198 | return; |
| 4199 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4200 | // Any user activity always causes us to show the |
| 4201 | // navigation controls, if they had been hidden. |
| 4202 | // We also clear the low profile and only content |
| 4203 | // flags so that tapping on the screen will atomically |
| 4204 | // restore all currently hidden screen decorations. |
| 4205 | int newVal = mResettingSystemUiFlags | |
| 4206 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 4207 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 4208 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4209 | if (mResettingSystemUiFlags != newVal) { |
| 4210 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4211 | changed = true; |
| 4212 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4213 | // We don't allow the system's nav bar to be hidden |
| 4214 | // again for 1 second, to prevent applications from |
| 4215 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4216 | newVal = mForceClearedSystemUiFlags | |
| 4217 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4218 | if (mForceClearedSystemUiFlags != newVal) { |
| 4219 | mForceClearedSystemUiFlags = newVal; |
| 4220 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4221 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4222 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4223 | } |
| 4224 | if (changed) { |
| 4225 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 4226 | } |
| 4227 | } |
| 4228 | } |
| 4229 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 4230 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4231 | } |
| 4232 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 4233 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4234 | |
| 4235 | @Override |
Winson | ab21660 | 2016-08-09 14:05:20 -0700 | [diff] [blame] | 4236 | public void setRecentsVisibilityLw(boolean visible) { |
| 4237 | mRecentsVisible = visible; |
| 4238 | } |
| 4239 | |
| 4240 | @Override |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 4241 | public void setPipVisibilityLw(boolean visible) { |
| 4242 | mPictureInPictureVisible = visible; |
Winson | ab21660 | 2016-08-09 14:05:20 -0700 | [diff] [blame] | 4243 | } |
| 4244 | |
| 4245 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4246 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 4247 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 4248 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4249 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4250 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 4251 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4252 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4253 | // Clear any bits in the new visibility that are currently being |
| 4254 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4255 | return visibility & ~mResettingSystemUiFlags |
| 4256 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4257 | } |
| 4258 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4259 | @Override |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 4260 | public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds, |
| 4261 | int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets, |
| 4262 | Rect outStableInsets, Rect outOutsets) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4263 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 4264 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 4265 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4266 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4267 | final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl); |
| 4268 | if (useOutsets) { |
| 4269 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 4270 | if (outset > 0) { |
| 4271 | if (displayRotation == Surface.ROTATION_0) { |
| 4272 | outOutsets.bottom += outset; |
| 4273 | } else if (displayRotation == Surface.ROTATION_90) { |
| 4274 | outOutsets.right += outset; |
| 4275 | } else if (displayRotation == Surface.ROTATION_180) { |
| 4276 | outOutsets.top += outset; |
| 4277 | } else if (displayRotation == Surface.ROTATION_270) { |
| 4278 | outOutsets.left += outset; |
| 4279 | } |
| 4280 | } |
| 4281 | } |
| 4282 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4283 | 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] | 4284 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4285 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4286 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4287 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4288 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4289 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 4290 | } else { |
| 4291 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 4292 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 4293 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4294 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 4295 | if ((fl & FLAG_FULLSCREEN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4296 | outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4297 | availRight - mStableFullscreenRight, |
| 4298 | availBottom - mStableFullscreenBottom); |
| 4299 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4300 | outContentInsets.set(mStableLeft, mStableTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4301 | availRight - mStableRight, availBottom - mStableBottom); |
| 4302 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4303 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4304 | outContentInsets.setEmpty(); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4305 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4306 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4307 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4308 | availRight - mCurRight, availBottom - mCurBottom); |
| 4309 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4310 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4311 | availRight - mCurRight, availBottom - mCurBottom); |
| 4312 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4313 | |
| 4314 | outStableInsets.set(mStableLeft, mStableTop, |
| 4315 | availRight - mStableRight, availBottom - mStableBottom); |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 4316 | if (taskBounds != null) { |
| 4317 | calculateRelevantTaskInsets(taskBounds, outContentInsets, |
| 4318 | displayWidth, displayHeight); |
| 4319 | calculateRelevantTaskInsets(taskBounds, outStableInsets, |
| 4320 | displayWidth, displayHeight); |
| 4321 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 4322 | return mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4323 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 4324 | outContentInsets.setEmpty(); |
| 4325 | outStableInsets.setEmpty(); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 4326 | return mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4327 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4328 | |
Jorim Jaggi | 23bf546 | 2016-05-13 15:24:39 -0700 | [diff] [blame] | 4329 | /** |
| 4330 | * For any given task bounds, the insets relevant for these bounds given the insets relevant |
| 4331 | * for the entire display. |
| 4332 | */ |
| 4333 | private void calculateRelevantTaskInsets(Rect taskBounds, Rect inOutInsets, int displayWidth, |
| 4334 | int displayHeight) { |
| 4335 | mTmpRect.set(0, 0, displayWidth, displayHeight); |
| 4336 | mTmpRect.inset(inOutInsets); |
| 4337 | mTmpRect.intersect(taskBounds); |
| 4338 | int leftInset = mTmpRect.left - taskBounds.left; |
| 4339 | int topInset = mTmpRect.top - taskBounds.top; |
| 4340 | int rightInset = taskBounds.right - mTmpRect.right; |
| 4341 | int bottomInset = taskBounds.bottom - mTmpRect.bottom; |
| 4342 | inOutInsets.set(leftInset, topInset, rightInset, bottomInset); |
| 4343 | } |
| 4344 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4345 | private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) { |
| 4346 | return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 4347 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0; |
| 4348 | } |
| 4349 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4350 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4351 | @Override |
| 4352 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 4353 | int displayRotation, int uiMode) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4354 | mDisplayRotation = displayRotation; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4355 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 4356 | if (isDefaultDisplay) { |
| 4357 | switch (displayRotation) { |
| 4358 | case Surface.ROTATION_90: |
| 4359 | overscanLeft = mOverscanTop; |
| 4360 | overscanTop = mOverscanRight; |
| 4361 | overscanRight = mOverscanBottom; |
| 4362 | overscanBottom = mOverscanLeft; |
| 4363 | break; |
| 4364 | case Surface.ROTATION_180: |
| 4365 | overscanLeft = mOverscanRight; |
| 4366 | overscanTop = mOverscanBottom; |
| 4367 | overscanRight = mOverscanLeft; |
| 4368 | overscanBottom = mOverscanTop; |
| 4369 | break; |
| 4370 | case Surface.ROTATION_270: |
| 4371 | overscanLeft = mOverscanBottom; |
| 4372 | overscanTop = mOverscanLeft; |
| 4373 | overscanRight = mOverscanTop; |
| 4374 | overscanBottom = mOverscanRight; |
| 4375 | break; |
| 4376 | default: |
| 4377 | overscanLeft = mOverscanLeft; |
| 4378 | overscanTop = mOverscanTop; |
| 4379 | overscanRight = mOverscanRight; |
| 4380 | overscanBottom = mOverscanBottom; |
| 4381 | break; |
| 4382 | } |
| 4383 | } else { |
| 4384 | overscanLeft = 0; |
| 4385 | overscanTop = 0; |
| 4386 | overscanRight = 0; |
| 4387 | overscanBottom = 0; |
| 4388 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4389 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 4390 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 4391 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 4392 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4393 | mSystemLeft = 0; |
| 4394 | mSystemTop = 0; |
| 4395 | mSystemRight = displayWidth; |
| 4396 | mSystemBottom = displayHeight; |
| 4397 | mUnrestrictedScreenLeft = overscanLeft; |
| 4398 | mUnrestrictedScreenTop = overscanTop; |
| 4399 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 4400 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 4401 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 4402 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4403 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 4404 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4405 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4406 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4407 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4408 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4409 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4410 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4411 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4412 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4413 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 4414 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4415 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4416 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 4417 | final Rect pf = mTmpParentFrame; |
| 4418 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4419 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4420 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4421 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4422 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 4423 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 4424 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 4425 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4426 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4427 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4428 | if (isDefaultDisplay) { |
| 4429 | // For purposes of putting out fake window up to steal focus, we will |
| 4430 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4431 | final int sysui = mLastSystemUiFlags; |
| 4432 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4433 | boolean navTranslucent = (sysui |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4434 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 4435 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 4436 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 4437 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 4438 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4439 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mKeyguardOccluded; |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 4440 | if (!isKeyguardShowing) { |
| 4441 | navTranslucent &= areTranslucentBarsAllowed(); |
| 4442 | } |
Jaewan Kim | 3328433 | 2016-05-12 18:55:46 +0900 | [diff] [blame] | 4443 | boolean statusBarExpandedNotKeyguard = !isKeyguardShowing && mStatusBar != null |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4444 | && mStatusBar.getAttrs().height == MATCH_PARENT |
| 4445 | && mStatusBar.getAttrs().width == MATCH_PARENT; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4446 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4447 | // When the navigation bar isn't visible, we put up a fake |
| 4448 | // input window to catch all touch events. This way we can |
| 4449 | // detect when the user presses anywhere to bring back the nav |
| 4450 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 4451 | if (navVisible || navAllowedHidden) { |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 4452 | if (mInputConsumer != null) { |
Chong Zhang | 9f7fb09 | 2016-05-20 17:03:08 -0700 | [diff] [blame] | 4453 | mHandler.sendMessage( |
| 4454 | mHandler.obtainMessage(MSG_DISPOSE_INPUT_CONSUMER, mInputConsumer)); |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 4455 | mInputConsumer = null; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4456 | } |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 4457 | } else if (mInputConsumer == null) { |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 4458 | mInputConsumer = mWindowManagerFuncs.createInputConsumer(mHandler.getLooper(), |
| 4459 | INPUT_CONSUMER_NAVIGATION, |
| 4460 | (channel, looper) -> new HideNavInputEventReceiver(channel, looper)); |
Vladislav Kaznacheev | 19dab2d | 2017-02-07 10:12:51 -0800 | [diff] [blame] | 4461 | // As long as mInputConsumer is active, hover events are not dispatched to the app |
| 4462 | // and the pointer icon is likely to become stale. Hide it to avoid confusion. |
| 4463 | InputManager.getInstance().setPointerIconType(PointerIcon.TYPE_NULL); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4464 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4465 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4466 | // For purposes of positioning and showing the nav bar, if we have |
| 4467 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 4468 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4469 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4470 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4471 | boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight, |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4472 | displayRotation, uiMode, overscanLeft, overscanRight, overscanBottom, dcf, navVisible, navTranslucent, |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4473 | navAllowedHidden, statusBarExpandedNotKeyguard); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4474 | 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] | 4475 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4476 | updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4477 | if (updateSysUiVisibility) { |
| 4478 | updateSystemUiVisibilityLw(); |
| 4479 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4480 | } |
| 4481 | } |
| 4482 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4483 | private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui, |
| 4484 | boolean isKeyguardShowing) { |
| 4485 | // decide where the status bar goes ahead of time |
| 4486 | if (mStatusBar != null) { |
| 4487 | // apply any navigation bar insets |
| 4488 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4489 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4490 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 4491 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 4492 | + mUnrestrictedScreenTop; |
| 4493 | vf.left = mStableLeft; |
| 4494 | vf.top = mStableTop; |
| 4495 | vf.right = mStableRight; |
| 4496 | vf.bottom = mStableBottom; |
| 4497 | |
| 4498 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 4499 | |
| 4500 | // Let the status bar determine its size. |
| 4501 | mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */, |
| 4502 | vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */, |
| 4503 | dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */); |
| 4504 | |
| 4505 | // For layout, the status bar is always at the top with our fixed height. |
| 4506 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 4507 | |
| 4508 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
| 4509 | boolean statusBarTranslucent = (sysui |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4510 | & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0; |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4511 | if (!isKeyguardShowing) { |
| 4512 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 4513 | } |
| 4514 | |
| 4515 | // If the status bar is hidden, we don't want to cause |
| 4516 | // windows behind it to scroll. |
| 4517 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
| 4518 | // Status bar may go away, so the screen area it occupies |
| 4519 | // is available to apps but just covering them when the |
| 4520 | // status bar is visible. |
| 4521 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 4522 | |
| 4523 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 4524 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 4525 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 4526 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 4527 | |
| 4528 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
| 4529 | String.format( |
| 4530 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 4531 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 4532 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 4533 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 4534 | } |
| 4535 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
| 4536 | && !statusBarTransient && !statusBarTranslucent |
| 4537 | && !mStatusBarController.wasRecentlyTranslucent()) { |
| 4538 | // If the opaque status bar is currently requested to be visible, |
| 4539 | // and not in the process of animating on or off, then |
| 4540 | // we can tell the app that it is covered by it. |
| 4541 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 4542 | } |
| 4543 | if (mStatusBarController.checkHiddenLw()) { |
| 4544 | return true; |
| 4545 | } |
| 4546 | } |
| 4547 | return false; |
| 4548 | } |
| 4549 | |
| 4550 | private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation, |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4551 | int uiMode, int overscanLeft, int overscanRight, int overscanBottom, Rect dcf, |
| 4552 | boolean navVisible, boolean navTranslucent, boolean navAllowedHidden, |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4553 | boolean statusBarExpandedNotKeyguard) { |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4554 | if (mNavigationBar != null) { |
| 4555 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
| 4556 | // Force the navigation bar to its appropriate place and |
| 4557 | // size. We need to do this directly, instead of relying on |
| 4558 | // it to bubble up from the nav bar, because this needs to |
| 4559 | // change atomically with screen rotations. |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4560 | mNavigationBarPosition = navigationBarPosition(displayWidth, displayHeight, |
| 4561 | displayRotation); |
| 4562 | if (mNavigationBarPosition == NAV_BAR_BOTTOM) { |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4563 | // It's a system nav bar or a portrait screen; nav bar goes on bottom. |
| 4564 | int top = displayHeight - overscanBottom |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 4565 | - getNavigationBarHeight(displayRotation, uiMode); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4566 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
| 4567 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
| 4568 | if (transientNavBarShowing) { |
| 4569 | mNavigationBarController.setBarShowingLw(true); |
| 4570 | } else if (navVisible) { |
| 4571 | mNavigationBarController.setBarShowingLw(true); |
| 4572 | mDockBottom = mTmpNavigationFrame.top; |
| 4573 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 4574 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
| 4575 | } else { |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4576 | // We currently want to hide the navigation UI - unless we expanded the status |
| 4577 | // bar. |
| 4578 | mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4579 | } |
| 4580 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4581 | && !mNavigationBar.isAnimatingLw() |
| 4582 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4583 | // If the opaque nav bar is currently requested to be visible, |
| 4584 | // and not in the process of animating on or off, then |
| 4585 | // we can tell the app that it is covered by it. |
| 4586 | mSystemBottom = mTmpNavigationFrame.top; |
| 4587 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4588 | } else if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4589 | // Landscape screen; nav bar goes to the right. |
| 4590 | int left = displayWidth - overscanRight |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 4591 | - getNavigationBarWidth(displayRotation, uiMode); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4592 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
| 4593 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
| 4594 | if (transientNavBarShowing) { |
| 4595 | mNavigationBarController.setBarShowingLw(true); |
| 4596 | } else if (navVisible) { |
| 4597 | mNavigationBarController.setBarShowingLw(true); |
| 4598 | mDockRight = mTmpNavigationFrame.left; |
| 4599 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 4600 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
| 4601 | } else { |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 4602 | // We currently want to hide the navigation UI - unless we expanded the status |
| 4603 | // bar. |
| 4604 | mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4605 | } |
| 4606 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4607 | && !mNavigationBar.isAnimatingLw() |
| 4608 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4609 | // If the nav bar is currently requested to be visible, |
| 4610 | // and not in the process of animating on or off, then |
| 4611 | // we can tell the app that it is covered by it. |
| 4612 | mSystemRight = mTmpNavigationFrame.left; |
| 4613 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4614 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
| 4615 | // Seascape screen; nav bar goes to the left. |
| 4616 | int right = overscanLeft + getNavigationBarWidth(displayRotation, uiMode); |
| 4617 | mTmpNavigationFrame.set(overscanLeft, 0, right, displayHeight); |
| 4618 | mStableLeft = mStableFullscreenLeft = mTmpNavigationFrame.right; |
| 4619 | if (transientNavBarShowing) { |
| 4620 | mNavigationBarController.setBarShowingLw(true); |
| 4621 | } else if (navVisible) { |
| 4622 | mNavigationBarController.setBarShowingLw(true); |
| 4623 | mDockLeft = mTmpNavigationFrame.right; |
| 4624 | // TODO: not so sure about those: |
| 4625 | mRestrictedScreenLeft = mRestrictedOverscanScreenLeft = mDockLeft; |
| 4626 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 4627 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
| 4628 | } else { |
| 4629 | // We currently want to hide the navigation UI - unless we expanded the status |
| 4630 | // bar. |
| 4631 | mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard); |
| 4632 | } |
| 4633 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4634 | && !mNavigationBar.isAnimatingLw() |
| 4635 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4636 | // If the nav bar is currently requested to be visible, |
| 4637 | // and not in the process of animating on or off, then |
| 4638 | // we can tell the app that it is covered by it. |
| 4639 | mSystemLeft = mTmpNavigationFrame.right; |
| 4640 | } |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4641 | } |
| 4642 | // Make sure the content and current rectangles are updated to |
| 4643 | // account for the restrictions from the navigation bar. |
| 4644 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 4645 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 4646 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 4647 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 4648 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 4649 | // And compute the final frame. |
| 4650 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
| 4651 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
| 4652 | mTmpNavigationFrame, mTmpNavigationFrame); |
| 4653 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
| 4654 | if (mNavigationBarController.checkHiddenLw()) { |
| 4655 | return true; |
| 4656 | } |
| 4657 | } |
| 4658 | return false; |
| 4659 | } |
| 4660 | |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4661 | private int navigationBarPosition(int displayWidth, int displayHeight, int displayRotation) { |
| 4662 | if (mNavigationBarCanMove && displayWidth > displayHeight) { |
| 4663 | if (displayRotation == Surface.ROTATION_270) { |
| 4664 | return NAV_BAR_LEFT; |
| 4665 | } else { |
| 4666 | return NAV_BAR_RIGHT; |
| 4667 | } |
| 4668 | } |
| 4669 | return NAV_BAR_BOTTOM; |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 4670 | } |
| 4671 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 4672 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 4673 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4674 | public int getSystemDecorLayerLw() { |
Bryce Lee | 2ed3e5f | 2015-04-01 22:09:19 +0000 | [diff] [blame] | 4675 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 4676 | return mStatusBar.getSurfaceLayer(); |
| 4677 | } |
| 4678 | |
| 4679 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { |
| 4680 | return mNavigationBar.getSurfaceLayer(); |
| 4681 | } |
| 4682 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 4683 | return 0; |
| 4684 | } |
| 4685 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 4686 | @Override |
| 4687 | public void getContentRectLw(Rect r) { |
| 4688 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 4689 | } |
| 4690 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4691 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 4692 | 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] | 4693 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 4694 | // Here's a special case: if this attached window is a panel that is |
| 4695 | // above the dock window, and the window it is attached to is below |
| 4696 | // the dock window, then the frames we computed for the window it is |
| 4697 | // attached to can not be used because the dock is effectively part |
| 4698 | // of the underlying window and the attached window is floating on top |
| 4699 | // of the whole thing. So, we ignore the attached window and explicitly |
| 4700 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4701 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 4702 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 4703 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 4704 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4705 | } else { |
| 4706 | // The effective display frame of the attached window depends on |
| 4707 | // whether it is taking care of insetting its content. If not, |
| 4708 | // we need to use the parent's content frame so that the entire |
| 4709 | // window is positioned within that content. Otherwise we can use |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 4710 | // 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] | 4711 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4712 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 4713 | // Set the content frame of the attached window to the parent's decor frame |
| 4714 | // (same as content frame when IME isn't present) if specifically requested by |
| 4715 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 4716 | // Otherwise, use the overscan frame. |
| 4717 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
| 4718 | ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4719 | } else { |
| 4720 | // If the window is resizing, then we want to base the content |
| 4721 | // frame on our attached content frame to resize... however, |
| 4722 | // things can be tricky if the attached window is NOT in resize |
| 4723 | // mode, in which case its content frame will be larger. |
| 4724 | // Ungh. So to deal with that, make sure the content frame |
| 4725 | // we end up using is not covering the IM dock. |
| 4726 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4727 | if (attached.isVoiceInteraction()) { |
| 4728 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 4729 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 4730 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 4731 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 4732 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4733 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 4734 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 4735 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 4736 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 4737 | } |
| 4738 | } |
| 4739 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4740 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4741 | vf.set(attached.getVisibleFrameLw()); |
| 4742 | } |
| 4743 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 4744 | // window should be positioned relative to its parent or the entire |
| 4745 | // screen. |
| 4746 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 4747 | ? attached.getFrameLw() : df); |
| 4748 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4749 | |
| 4750 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 4751 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 4752 | // If app is requesting a stable layout, don't let the |
| 4753 | // content insets go below the stable values. |
| 4754 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 4755 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 4756 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 4757 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 4758 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 4759 | } else { |
| 4760 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 4761 | if (r.top < mStableTop) r.top = mStableTop; |
| 4762 | if (r.right > mStableRight) r.right = mStableRight; |
| 4763 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 4764 | } |
| 4765 | } |
| 4766 | } |
| 4767 | |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4768 | private boolean canReceiveInput(WindowState win) { |
| 4769 | boolean notFocusable = |
| 4770 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0; |
| 4771 | boolean altFocusableIm = |
| 4772 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0; |
| 4773 | boolean notFocusableForIm = notFocusable ^ altFocusableIm; |
| 4774 | return !notFocusableForIm; |
| 4775 | } |
| 4776 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4777 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4778 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4779 | public void layoutWindowLw(WindowState win, WindowState attached) { |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4780 | // We've already done the navigation bar and status bar. If the status bar can receive |
| 4781 | // input, we need to layout it again to accomodate for the IME window. |
| 4782 | if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4783 | return; |
| 4784 | } |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4785 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4786 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 4787 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4788 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 4789 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4790 | 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] | 4791 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 4792 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4793 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4794 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 4795 | final int pfl = attrs.privateFlags; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4796 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 4797 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4798 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4799 | final Rect pf = mTmpParentFrame; |
| 4800 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4801 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4802 | final Rect cf = mTmpContentFrame; |
| 4803 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4804 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4805 | final Rect sf = mTmpStableFrame; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4806 | Rect osf = null; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4807 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4808 | |
| 4809 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 4810 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4811 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 4812 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 4813 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4814 | if (isDefaultDisplay) { |
| 4815 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 4816 | } else { |
| 4817 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 4818 | } |
| 4819 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4820 | if (!isDefaultDisplay) { |
| 4821 | if (attached != null) { |
| 4822 | // If this window is attached to another, our display |
| 4823 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4824 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4825 | } else { |
| 4826 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4827 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4828 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4829 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4830 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4831 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4832 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4833 | } |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4834 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4835 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 4836 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 4837 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 4838 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 4839 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 4840 | // ...with content insets above the nav bar |
| 4841 | cf.bottom = vf.bottom = mStableBottom; |
Adrian Roos | dd654ea | 2016-05-27 11:46:10 -0700 | [diff] [blame] | 4842 | if (mStatusBar != null && mFocusedWindow == mStatusBar && canReceiveInput(mStatusBar)) { |
| 4843 | // The status bar forces the navigation bar while it's visible. Make sure the IME |
| 4844 | // avoids the navigation bar in that case. |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 4845 | if (mNavigationBarPosition == NAV_BAR_RIGHT) { |
| 4846 | pf.right = df.right = of.right = cf.right = vf.right = mStableRight; |
| 4847 | } else if (mNavigationBarPosition == NAV_BAR_LEFT) { |
| 4848 | pf.left = df.left = of.left = cf.left = vf.left = mStableLeft; |
| 4849 | } |
Adrian Roos | dd654ea | 2016-05-27 11:46:10 -0700 | [diff] [blame] | 4850 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4851 | // IM dock windows always go to the bottom of the screen. |
| 4852 | attrs.gravity = Gravity.BOTTOM; |
| 4853 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4854 | } else if (attrs.type == TYPE_VOICE_INTERACTION) { |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4855 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4856 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4857 | pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4858 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Jorim Jaggi | 4b74f4d | 2016-04-27 18:44:08 -0700 | [diff] [blame] | 4859 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 4860 | cf.left = mDockLeft; |
| 4861 | cf.top = mDockTop; |
| 4862 | cf.right = mDockRight; |
| 4863 | cf.bottom = mDockBottom; |
| 4864 | } else { |
| 4865 | cf.left = mContentLeft; |
| 4866 | cf.top = mContentTop; |
| 4867 | cf.right = mContentRight; |
| 4868 | cf.bottom = mContentBottom; |
| 4869 | } |
| 4870 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4871 | vf.left = mCurLeft; |
| 4872 | vf.top = mCurTop; |
| 4873 | vf.right = mCurRight; |
| 4874 | vf.bottom = mCurBottom; |
| 4875 | } else { |
| 4876 | vf.set(cf); |
| 4877 | } |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 4878 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 4879 | layoutWallpaper(win, pf, df, of, cf); |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4880 | } else if (win == mStatusBar) { |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 4881 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4882 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4883 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 4884 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 4885 | cf.left = vf.left = mStableLeft; |
| 4886 | cf.top = vf.top = mStableTop; |
| 4887 | cf.right = vf.right = mStableRight; |
| 4888 | vf.bottom = mStableBottom; |
Adrian Roos | dc5b453 | 2016-01-06 20:49:41 +0100 | [diff] [blame] | 4889 | |
| 4890 | if (adjust == SOFT_INPUT_ADJUST_RESIZE) { |
| 4891 | cf.bottom = mContentBottom; |
| 4892 | } else { |
| 4893 | cf.bottom = mDockBottom; |
| 4894 | vf.bottom = mContentBottom; |
| 4895 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4896 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4897 | |
| 4898 | // Default policy decor for the default display |
| 4899 | dcf.left = mSystemLeft; |
| 4900 | dcf.top = mSystemTop; |
| 4901 | dcf.right = mSystemRight; |
| 4902 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4903 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 4904 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 4905 | final boolean isAppWindow = |
| 4906 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 4907 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 4908 | final boolean topAtRest = |
| 4909 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 4910 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4911 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 4912 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4913 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 4914 | && (fl & WindowManager.LayoutParams. |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4915 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0 |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 4916 | && (pfl & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4917 | // Ensure policy decor includes status bar |
| 4918 | dcf.top = mStableTop; |
| 4919 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4920 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4921 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 4922 | && (fl & WindowManager.LayoutParams. |
| 4923 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4924 | // Ensure policy decor includes navigation bar |
| 4925 | dcf.bottom = mStableBottom; |
| 4926 | dcf.right = mStableRight; |
| 4927 | } |
| 4928 | } |
| 4929 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4930 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 4931 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4932 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4933 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4934 | // This is the case for a normal activity window: we want it |
| 4935 | // to cover all of the screen space, and it can take care of |
| 4936 | // moving its contents to account for screen decorations that |
| 4937 | // intrude into that space. |
| 4938 | if (attached != null) { |
| 4939 | // If this window is attached to another, our display |
| 4940 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4941 | 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] | 4942 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4943 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 4944 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4945 | // Status bar panels are the only windows who can go on top of |
| 4946 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 4947 | // permission, so they have the same privileges as the status |
| 4948 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4949 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4950 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4951 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4952 | pf.left = df.left = of.left = hasNavBar |
| 4953 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 4954 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4955 | pf.right = df.right = of.right = hasNavBar |
| 4956 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 4957 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4958 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 4959 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 4960 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4961 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4962 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4963 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 4964 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4965 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4966 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4967 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4968 | // Asking to layout into the overscan region, so give it that pure |
| 4969 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4970 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 4971 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 4972 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4973 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 4974 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4975 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4976 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4977 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4978 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4979 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4980 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4981 | // only do this for application windows to ensure no window that |
| 4982 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4983 | pf.left = df.left = mOverscanScreenLeft; |
| 4984 | pf.top = df.top = mOverscanScreenTop; |
| 4985 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4986 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4987 | // We need to tell the app about where the frame inside the overscan |
| 4988 | // is, so it can inset its content by that amount -- it didn't ask |
| 4989 | // to actually extend itself into the overscan region. |
| 4990 | of.left = mUnrestrictedScreenLeft; |
| 4991 | of.top = mUnrestrictedScreenTop; |
| 4992 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4993 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4994 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4995 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 4996 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 4997 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 4998 | + mRestrictedOverscanScreenWidth; |
| 4999 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 5000 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5001 | // We need to tell the app about where the frame inside the overscan |
| 5002 | // is, so it can inset its content by that amount -- it didn't ask |
| 5003 | // to actually extend itself into the overscan region. |
| 5004 | of.left = mUnrestrictedScreenLeft; |
| 5005 | of.top = mUnrestrictedScreenTop; |
| 5006 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 5007 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 5008 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5009 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5010 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5011 | if (win.isVoiceInteraction()) { |
| 5012 | cf.left = mVoiceContentLeft; |
| 5013 | cf.top = mVoiceContentTop; |
| 5014 | cf.right = mVoiceContentRight; |
| 5015 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5016 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5017 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 5018 | cf.left = mDockLeft; |
| 5019 | cf.top = mDockTop; |
| 5020 | cf.right = mDockRight; |
| 5021 | cf.bottom = mDockBottom; |
| 5022 | } else { |
| 5023 | cf.left = mContentLeft; |
| 5024 | cf.top = mContentTop; |
| 5025 | cf.right = mContentRight; |
| 5026 | cf.bottom = mContentBottom; |
| 5027 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5028 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5029 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5030 | // Full screen windows are always given a layout that is as if the |
| 5031 | // status bar and other transient decors are gone. This is to avoid |
| 5032 | // bad states when moving from a window that is not hding the |
| 5033 | // status bar to one that is. |
| 5034 | cf.left = mRestrictedScreenLeft; |
| 5035 | cf.top = mRestrictedScreenTop; |
| 5036 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 5037 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5038 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 5039 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 5040 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 5041 | vf.left = mCurLeft; |
| 5042 | vf.top = mCurTop; |
| 5043 | vf.right = mCurRight; |
| 5044 | vf.bottom = mCurBottom; |
| 5045 | } else { |
| 5046 | vf.set(cf); |
| 5047 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5048 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5049 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 5050 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 5051 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5052 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 5053 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5054 | // A window that has requested to fill the entire screen just |
| 5055 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 5056 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 5057 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5058 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 5059 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 5060 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 5061 | pf.right = df.right = of.right = cf.right = hasNavBar |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 5062 | ? mRestrictedScreenLeft + mRestrictedScreenWidth |
| 5063 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5064 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 5065 | ? mRestrictedScreenTop + mRestrictedScreenHeight |
| 5066 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 5067 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
| 5068 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 5069 | pf.left, pf.top, pf.right, pf.bottom)); |
| 5070 | } else if (attrs.type == TYPE_VOLUME_OVERLAY) { |
| 5071 | // Volume overlay covers everything, including the status and navbar |
| 5072 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 5073 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 5074 | pf.right = df.right = of.right = cf.right = |
| 5075 | mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 5076 | pf.bottom = df.bottom = of.bottom = cf.bottom = |
| 5077 | mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5078 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 5079 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 5080 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 5081 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 5082 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 5083 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5084 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 5085 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 5086 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 5087 | + mUnrestrictedScreenWidth; |
| 5088 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 5089 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5090 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 5091 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 5092 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 5093 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 5094 | || attrs.type == TYPE_BOOT_PROGRESS |
| 5095 | || attrs.type == TYPE_SCREENSHOT) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 5096 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 5097 | // Fullscreen secure system overlays get what they ask for. Screenshot region |
| 5098 | // selection overlay should also expand to full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5099 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 5100 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 5101 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 5102 | + mOverscanScreenWidth; |
| 5103 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 5104 | + mOverscanScreenHeight; |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 5105 | } else if (attrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 5106 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5107 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 5108 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 5109 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 5110 | + mOverscanScreenWidth; |
| 5111 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 5112 | + mOverscanScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5113 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 5114 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 5115 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 5116 | // Asking to layout into the overscan region, so give it that pure |
| 5117 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5118 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 5119 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 5120 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 5121 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5122 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 5123 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5124 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5125 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 5126 | && (attrs.type == TYPE_STATUS_BAR |
| 5127 | || attrs.type == TYPE_TOAST |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 5128 | || attrs.type == TYPE_DOCK_DIVIDER |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 5129 | || attrs.type == TYPE_VOICE_INTERACTION_STARTING |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5130 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 5131 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5132 | // Asking for layout as if the nav bar is hidden, lets the |
| 5133 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5134 | // 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] | 5135 | // can be above the nav bar can do this. |
| 5136 | // XXX This assumes that an app asking for this will also |
| 5137 | // ask for layout in only content. We can't currently figure out |
| 5138 | // 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] | 5139 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 5140 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 5141 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 5142 | + mUnrestrictedScreenWidth; |
| 5143 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 5144 | + mUnrestrictedScreenHeight; |
Jorim Jaggi | 9f6798a | 2016-02-10 22:16:06 -0800 | [diff] [blame] | 5145 | } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) { |
| 5146 | pf.left = df.left = of.left = mRestrictedScreenLeft; |
| 5147 | pf.top = df.top = of.top = mRestrictedScreenTop; |
| 5148 | pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 5149 | pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop |
| 5150 | + mRestrictedScreenHeight; |
| 5151 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 5152 | cf.left = mDockLeft; |
| 5153 | cf.top = mDockTop; |
| 5154 | cf.right = mDockRight; |
| 5155 | cf.bottom = mDockBottom; |
| 5156 | } else { |
| 5157 | cf.left = mContentLeft; |
| 5158 | cf.top = mContentTop; |
| 5159 | cf.right = mContentRight; |
| 5160 | cf.bottom = mContentBottom; |
| 5161 | } |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 5162 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5163 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 5164 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 5165 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 5166 | + mRestrictedScreenWidth; |
| 5167 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 5168 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 5169 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5170 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 5171 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5172 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 5173 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 5174 | vf.left = mCurLeft; |
| 5175 | vf.top = mCurTop; |
| 5176 | vf.right = mCurRight; |
| 5177 | vf.bottom = mCurBottom; |
| 5178 | } else { |
| 5179 | vf.set(cf); |
| 5180 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5181 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5182 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 5183 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5184 | // A child window should be placed inside of the same visible |
| 5185 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5186 | 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] | 5187 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5188 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 5189 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5190 | // Otherwise, a normal window must be placed inside the content |
| 5191 | // of all screen decorations. |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 5192 | if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 5193 | // Status bar panels and the volume dialog are the only windows who can go on |
| 5194 | // 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] | 5195 | // permission, so they have the same privileges as the status |
| 5196 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5197 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 5198 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 5199 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 5200 | + mRestrictedScreenWidth; |
| 5201 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 5202 | + mRestrictedScreenHeight; |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 5203 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) { |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 5204 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5205 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 5206 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 5207 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 5208 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5209 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 5210 | pf.left = mContentLeft; |
| 5211 | pf.top = mContentTop; |
| 5212 | pf.right = mContentRight; |
| 5213 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 5214 | if (win.isVoiceInteraction()) { |
| 5215 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 5216 | df.top = of.top = cf.top = mVoiceContentTop; |
| 5217 | df.right = of.right = cf.right = mVoiceContentRight; |
| 5218 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 5219 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5220 | df.left = of.left = cf.left = mDockLeft; |
| 5221 | df.top = of.top = cf.top = mDockTop; |
| 5222 | df.right = of.right = cf.right = mDockRight; |
| 5223 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 5224 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5225 | df.left = of.left = cf.left = mContentLeft; |
| 5226 | df.top = of.top = cf.top = mContentTop; |
| 5227 | df.right = of.right = cf.right = mContentRight; |
| 5228 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 5229 | } |
| 5230 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 5231 | vf.left = mCurLeft; |
| 5232 | vf.top = mCurTop; |
| 5233 | vf.right = mCurRight; |
| 5234 | vf.bottom = mCurBottom; |
| 5235 | } else { |
| 5236 | vf.set(cf); |
| 5237 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 5238 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5239 | } |
| 5240 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5241 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 5242 | // 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] | 5243 | // Also, we don't allow windows in multi-window mode to extend out of the screen. |
| 5244 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 5245 | && !win.isInMultiWindowMode()) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 5246 | df.left = df.top = -10000; |
| 5247 | df.right = df.bottom = 10000; |
| 5248 | if (attrs.type != TYPE_WALLPAPER) { |
| 5249 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 5250 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 5251 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5252 | } |
| 5253 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5254 | // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we |
| 5255 | // 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] | 5256 | // We only want to apply outsets to certain types of windows. For example, we never want to |
| 5257 | // 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] | 5258 | final boolean useOutsets = shouldUseOutsets(attrs, fl); |
Filip Gruszczynski | b0c673b | 2015-06-05 09:43:06 -0700 | [diff] [blame] | 5259 | if (isDefaultDisplay && useOutsets) { |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5260 | osf = mTmpOutsetFrame; |
| 5261 | osf.set(cf.left, cf.top, cf.right, cf.bottom); |
| 5262 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 5263 | if (outset > 0) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 5264 | int rotation = mDisplayRotation; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5265 | if (rotation == Surface.ROTATION_0) { |
| 5266 | osf.bottom += outset; |
| 5267 | } else if (rotation == Surface.ROTATION_90) { |
| 5268 | osf.right += outset; |
| 5269 | } else if (rotation == Surface.ROTATION_180) { |
| 5270 | osf.top -= outset; |
| 5271 | } else if (rotation == Surface.ROTATION_270) { |
| 5272 | osf.left -= outset; |
| 5273 | } |
| 5274 | if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset |
| 5275 | + " with rotation " + rotation + ", result: " + osf); |
| 5276 | } |
| 5277 | } |
| 5278 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5279 | 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] | 5280 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5281 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 5282 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 5283 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5284 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 5285 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5286 | + " dcf=" + dcf.toShortString() |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5287 | + " sf=" + sf.toShortString() |
| 5288 | + " osf=" + (osf == null ? "null" : osf.toShortString())); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5289 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5290 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 5291 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5292 | // Dock windows carve out the bottom of the screen, so normal windows |
| 5293 | // can't appear underneath them. |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5294 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleLw() |
| 5295 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5296 | setLastInputMethodWindowLw(null, null); |
| 5297 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5298 | } |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 5299 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleLw() |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5300 | && !win.getGivenInsetsPendingLw()) { |
| 5301 | offsetVoiceInputWindowLw(win); |
| 5302 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5303 | } |
| 5304 | |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 5305 | private void layoutWallpaper(WindowState win, Rect pf, Rect df, Rect of, Rect cf) { |
| 5306 | |
| 5307 | // The wallpaper also has Real Ultimate Power, but we want to tell |
| 5308 | // it about the overscan area. |
| 5309 | pf.left = df.left = mOverscanScreenLeft; |
| 5310 | pf.top = df.top = mOverscanScreenTop; |
| 5311 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 5312 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
| 5313 | of.left = cf.left = mUnrestrictedScreenLeft; |
| 5314 | of.top = cf.top = mUnrestrictedScreenTop; |
| 5315 | of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 5316 | of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 5317 | } |
| 5318 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5319 | private void offsetInputMethodWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 5320 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5321 | top += win.getGivenContentInsetsLw().top; |
| 5322 | if (mContentBottom > top) { |
| 5323 | mContentBottom = top; |
| 5324 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5325 | if (mVoiceContentBottom > top) { |
| 5326 | mVoiceContentBottom = top; |
| 5327 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5328 | top = win.getVisibleFrameLw().top; |
| 5329 | top += win.getGivenVisibleInsetsLw().top; |
| 5330 | if (mCurBottom > top) { |
| 5331 | mCurBottom = top; |
| 5332 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5333 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5334 | + mDockBottom + " mContentBottom=" |
| 5335 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 5336 | } |
| 5337 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5338 | private void offsetVoiceInputWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 5339 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 5340 | top += win.getGivenContentInsetsLw().top; |
| 5341 | if (mVoiceContentBottom > top) { |
| 5342 | mVoiceContentBottom = top; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5343 | } |
| 5344 | } |
| 5345 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5346 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 5347 | @Override |
| 5348 | public void finishLayoutLw() { |
| 5349 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5353 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 5354 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5355 | mTopFullscreenOpaqueWindowState = null; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 5356 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5357 | mTopDockedOpaqueWindowState = null; |
| 5358 | mTopDockedOpaqueOrDimmingWindowState = null; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5359 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5360 | mForceStatusBarFromKeyguard = false; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 5361 | mForceStatusBarTransparent = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5362 | mForcingShowNavBar = false; |
| 5363 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5364 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5365 | mAllowLockscreenWhenOn = false; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5366 | mShowingDream = false; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5367 | } |
| 5368 | |
| 5369 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5370 | @Override |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 5371 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs, |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5372 | WindowState attached, WindowState imeTarget) { |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5373 | final boolean affectsSystemUi = win.canAffectSystemUiFlags(); |
| 5374 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": affectsSystemUi=" + affectsSystemUi); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5375 | applyKeyguardPolicyLw(win, imeTarget); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5376 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5377 | if (mTopFullscreenOpaqueWindowState == null && affectsSystemUi |
| 5378 | && attrs.type == TYPE_INPUT_METHOD) { |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 5379 | mForcingShowNavBar = true; |
| 5380 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5381 | } |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 5382 | if (attrs.type == TYPE_STATUS_BAR) { |
| 5383 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 5384 | mForceStatusBarFromKeyguard = true; |
| 5385 | } |
| 5386 | if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) { |
| 5387 | mForceStatusBarTransparent = true; |
| 5388 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 5389 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 5390 | |
| 5391 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 5392 | && attrs.type < FIRST_SYSTEM_WINDOW; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5393 | final int stackId = win.getStackId(); |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5394 | if (mTopFullscreenOpaqueWindowState == null && affectsSystemUi) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5395 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5396 | mForceStatusBar = true; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5397 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5398 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 5399 | // If the lockscreen was showing when the dream started then wait |
| 5400 | // for the dream to draw before hiding the lockscreen. |
| 5401 | if (!mDreamingLockscreen |
| 5402 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 5403 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 5404 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5405 | } |
| 5406 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 5407 | |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 5408 | // For app windows that are not attached, we decide if all windows in the app they |
| 5409 | // represent should be hidden or if we should hide the lockscreen. For attached app |
| 5410 | // windows we defer the decision to the window it is attached to. |
| 5411 | if (appWindow && attached == null) { |
Jorim Jaggi | e6c6ecb | 2017-07-20 18:09:20 +0200 | [diff] [blame] | 5412 | if (attrs.isFullscreen() && StackId.normallyFullscreenWindows(stackId)) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 5413 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 5414 | mTopFullscreenOpaqueWindowState = win; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 5415 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 5416 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 5417 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 5418 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 5419 | mAllowLockscreenWhenOn = true; |
| 5420 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5421 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 5422 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5423 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5424 | |
Jorim Jaggi | 90859bc | 2016-06-28 16:25:23 -0700 | [diff] [blame] | 5425 | // Voice interaction overrides both top fullscreen and top docked. |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5426 | if (affectsSystemUi && win.getAttrs().type == TYPE_VOICE_INTERACTION) { |
Jorim Jaggi | 90859bc | 2016-06-28 16:25:23 -0700 | [diff] [blame] | 5427 | if (mTopFullscreenOpaqueWindowState == null) { |
| 5428 | mTopFullscreenOpaqueWindowState = win; |
| 5429 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 5430 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 5431 | } |
| 5432 | } |
| 5433 | if (mTopDockedOpaqueWindowState == null) { |
| 5434 | mTopDockedOpaqueWindowState = win; |
| 5435 | if (mTopDockedOpaqueOrDimmingWindowState == null) { |
| 5436 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 5437 | } |
| 5438 | } |
| 5439 | } |
| 5440 | |
| 5441 | // Keep track of the window if it's dimming but not necessarily fullscreen. |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5442 | if (mTopFullscreenOpaqueOrDimmingWindowState == null && affectsSystemUi |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5443 | && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) { |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 5444 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 5445 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5446 | |
| 5447 | // We need to keep track of the top "fullscreen" opaque window for the docked stack |
| 5448 | // separately, because both the "real fullscreen" opaque window and the one for the docked |
| 5449 | // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR. |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5450 | if (mTopDockedOpaqueWindowState == null && affectsSystemUi && appWindow && attached == null |
Jorim Jaggi | e6c6ecb | 2017-07-20 18:09:20 +0200 | [diff] [blame] | 5451 | && attrs.isFullscreen() && stackId == DOCKED_STACK_ID) { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5452 | mTopDockedOpaqueWindowState = win; |
| 5453 | if (mTopDockedOpaqueOrDimmingWindowState == null) { |
| 5454 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 5455 | } |
| 5456 | } |
| 5457 | |
| 5458 | // Also keep track of any windows that are dimming but not necessarily fullscreen in the |
| 5459 | // docked stack. |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 5460 | if (mTopDockedOpaqueOrDimmingWindowState == null && affectsSystemUi && win.isDimming() |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 5461 | && stackId == DOCKED_STACK_ID) { |
| 5462 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 5463 | } |
| 5464 | } |
| 5465 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5466 | private void applyKeyguardPolicyLw(WindowState win, WindowState imeTarget) { |
| 5467 | if (canBeHiddenByKeyguardLw(win)) { |
| 5468 | if (shouldBeHiddenByKeyguard(win, imeTarget)) { |
| 5469 | win.hideLw(false /* doAnimation */); |
| 5470 | } else { |
| 5471 | win.showLw(false /* doAnimation */); |
| 5472 | } |
| 5473 | } |
| 5474 | } |
| 5475 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 5476 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5477 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 5478 | public int finishPostLayoutPolicyLw() { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5479 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5480 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 5481 | |
| 5482 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 5483 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 5484 | : null; |
| 5485 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 5486 | // If we are not currently showing a dream then remember the current |
| 5487 | // lockscreen state. We will use this to determine whether the dream |
| 5488 | // started while the lockscreen was showing and remember this state |
| 5489 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5490 | if (!mShowingDream) { |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 5491 | mDreamingLockscreen = isKeyguardShowingAndNotOccluded(); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 5492 | if (mDreamingSleepTokenNeeded) { |
| 5493 | mDreamingSleepTokenNeeded = false; |
| 5494 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget(); |
| 5495 | } |
| 5496 | } else { |
| 5497 | if (!mDreamingSleepTokenNeeded) { |
| 5498 | mDreamingSleepTokenNeeded = true; |
| 5499 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget(); |
| 5500 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5501 | } |
| 5502 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5503 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5504 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5505 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 5506 | + " top=" + mTopFullscreenOpaqueWindowState); |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 5507 | boolean shouldBeTransparent = mForceStatusBarTransparent |
| 5508 | && !mForceStatusBar |
| 5509 | && !mForceStatusBarFromKeyguard; |
| 5510 | if (!shouldBeTransparent) { |
| 5511 | mStatusBarController.setShowTransparent(false /* transparent */); |
| 5512 | } else if (!mStatusBar.isVisibleLw()) { |
| 5513 | mStatusBarController.setShowTransparent(true /* transparent */); |
| 5514 | } |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 5515 | |
| 5516 | WindowManager.LayoutParams statusBarAttrs = mStatusBar.getAttrs(); |
| 5517 | boolean statusBarExpanded = statusBarAttrs.height == MATCH_PARENT |
| 5518 | && statusBarAttrs.width == MATCH_PARENT; |
| 5519 | if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent |
| 5520 | || statusBarExpanded) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5521 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5522 | if (mStatusBarController.setBarShowingLw(true)) { |
| 5523 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5524 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 5525 | // Maintain fullscreen layout until incoming animation is complete. |
| 5526 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 5527 | // Transient status bar on the lockscreen is not allowed |
Jorim Jaggi | 2dc47c1 | 2017-05-05 17:39:58 +0200 | [diff] [blame] | 5528 | if ((mForceStatusBarFromKeyguard || statusBarExpanded) |
| 5529 | && mStatusBarController.isTransientShowing()) { |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 5530 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 5531 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 5532 | } |
Adrian Roos | db1bc6b | 2016-04-14 17:49:43 -0700 | [diff] [blame] | 5533 | if (statusBarExpanded && mNavigationBar != null) { |
| 5534 | if (mNavigationBarController.setBarShowingLw(true)) { |
| 5535 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5536 | } |
| 5537 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5538 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5539 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5540 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5541 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 5542 | + " shown position: " |
| 5543 | + mTopFullscreenOpaqueWindowState.getShownPositionLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5544 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5545 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5546 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5547 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5548 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5549 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 5550 | // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5551 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 5552 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5553 | if (mStatusBarController.isTransientShowing()) { |
| 5554 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5555 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5556 | } |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 5557 | } else if (topIsFullscreen |
| 5558 | && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID) |
| 5559 | && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5560 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5561 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5562 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5563 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 5564 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 5565 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5566 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5567 | 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] | 5568 | if (mStatusBarController.setBarShowingLw(true)) { |
| 5569 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5570 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5571 | } |
| 5572 | } |
| 5573 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 5574 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 5575 | if (mTopIsFullscreen != topIsFullscreen) { |
| 5576 | if (!topIsFullscreen) { |
| 5577 | // Force another layout when status bar becomes fully shown. |
| 5578 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5579 | } |
| 5580 | mTopIsFullscreen = topIsFullscreen; |
| 5581 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 5582 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5583 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5584 | // If the navigation bar has been hidden or shown, we need to do another |
| 5585 | // layout pass to update that window. |
| 5586 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5587 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5588 | |
Jorim Jaggi | 77e1043 | 2016-10-26 17:43:56 -0700 | [diff] [blame] | 5589 | if (mShowingDream != mLastShowingDream) { |
| 5590 | mLastShowingDream = mShowingDream; |
| 5591 | mWindowManagerFuncs.notifyShowingDreamChanged(); |
| 5592 | } |
| 5593 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5594 | // update since mAllowLockscreenWhenOn might have changed |
| 5595 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5596 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5597 | } |
| 5598 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5599 | /** |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5600 | * Updates the occluded state of the Keyguard. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5601 | * |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5602 | * @return Whether the flags have changed and we have to redo the layout. |
| 5603 | */ |
Jorim Jaggi | 9ba2e10 | 2017-04-04 12:51:03 +0200 | [diff] [blame] | 5604 | private boolean setKeyguardOccludedLw(boolean isOccluded, boolean force) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5605 | if (DEBUG_KEYGUARD) Slog.d(TAG, "setKeyguardOccluded occluded=" + isOccluded); |
Jorim Jaggi | ec7708a | 2017-04-10 18:47:36 -0700 | [diff] [blame] | 5606 | final boolean wasOccluded = mKeyguardOccluded; |
| 5607 | final boolean showing = mKeyguardDelegate.isShowing(); |
| 5608 | final boolean changed = wasOccluded != isOccluded || force; |
| 5609 | if (!isOccluded && changed && showing) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5610 | mKeyguardOccluded = false; |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 5611 | mKeyguardDelegate.setOccluded(false, true /* animate */); |
Jorim Jaggi | 9ba2e10 | 2017-04-04 12:51:03 +0200 | [diff] [blame] | 5612 | if (mStatusBar != null) { |
| 5613 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 5614 | if (!mKeyguardDelegate.hasLockscreenWallpaper()) { |
| 5615 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 5616 | } |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 5617 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5618 | return true; |
Jorim Jaggi | ec7708a | 2017-04-10 18:47:36 -0700 | [diff] [blame] | 5619 | } else if (isOccluded && changed && showing) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5620 | mKeyguardOccluded = true; |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 5621 | mKeyguardDelegate.setOccluded(true, false /* animate */); |
Jorim Jaggi | 9ba2e10 | 2017-04-04 12:51:03 +0200 | [diff] [blame] | 5622 | if (mStatusBar != null) { |
| 5623 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 5624 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 5625 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5626 | return true; |
Jorim Jaggi | ec7708a | 2017-04-10 18:47:36 -0700 | [diff] [blame] | 5627 | } else if (changed) { |
Adrian Roos | 909fe2d | 2016-10-12 12:03:24 -0700 | [diff] [blame] | 5628 | mKeyguardOccluded = isOccluded; |
| 5629 | mKeyguardDelegate.setOccluded(isOccluded, false /* animate */); |
| 5630 | return false; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5631 | } else { |
| 5632 | return false; |
| 5633 | } |
| 5634 | } |
| 5635 | |
| 5636 | private boolean isStatusBarKeyguard() { |
| 5637 | return mStatusBar != null |
| 5638 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 5639 | } |
| 5640 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5641 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5642 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5643 | if (mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 5644 | // 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] | 5645 | return false; |
| 5646 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5647 | return true; |
| 5648 | } |
| 5649 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5650 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5651 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5652 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5653 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5654 | // If the navigation bar has been hidden or shown, we need to do another |
| 5655 | // layout pass to update that window. |
| 5656 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 5657 | } |
| 5658 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5659 | } |
| 5660 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 5661 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5662 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5663 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5664 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5665 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 5666 | if (newLidState == mLidState) { |
| 5667 | return; |
| 5668 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5669 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5670 | mLidState = newLidState; |
| 5671 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5672 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5673 | |
| 5674 | if (lidOpen) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5675 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch, |
| 5676 | "android.policy:LID"); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5677 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 5678 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5679 | } |
| 5680 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5681 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5682 | @Override |
| 5683 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 5684 | int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; |
| 5685 | if (mCameraLensCoverState == lensCoverState) { |
| 5686 | return; |
| 5687 | } |
| 5688 | if (mCameraLensCoverState == CAMERA_LENS_COVERED && |
| 5689 | lensCoverState == CAMERA_LENS_UNCOVERED) { |
| 5690 | Intent intent; |
| 5691 | final boolean keyguardActive = mKeyguardDelegate == null ? false : |
| 5692 | mKeyguardDelegate.isShowing(); |
| 5693 | if (keyguardActive) { |
| 5694 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); |
| 5695 | } else { |
| 5696 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 5697 | } |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5698 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens, |
| 5699 | "android.policy:CAMERA_COVER"); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5700 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5701 | } |
| 5702 | mCameraLensCoverState = lensCoverState; |
| 5703 | } |
| 5704 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5705 | void setHdmiPlugged(boolean plugged) { |
| 5706 | if (mHdmiPlugged != plugged) { |
| 5707 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5708 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5709 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5710 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5711 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 5712 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5713 | } |
| 5714 | } |
| 5715 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5716 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 5717 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5718 | // watch for HDMI plug messages if the hdmi switch exists |
| 5719 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 5720 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 5721 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5722 | final String filename = "/sys/class/switch/hdmi/state"; |
| 5723 | FileReader reader = null; |
| 5724 | try { |
| 5725 | reader = new FileReader(filename); |
| 5726 | char[] buf = new char[15]; |
| 5727 | int n = reader.read(buf); |
| 5728 | if (n > 1) { |
| 5729 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 5730 | } |
| 5731 | } catch (IOException ex) { |
| 5732 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 5733 | } catch (NumberFormatException ex) { |
| 5734 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 5735 | } finally { |
| 5736 | if (reader != null) { |
| 5737 | try { |
| 5738 | reader.close(); |
| 5739 | } catch (IOException ex) { |
| 5740 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5741 | } |
| 5742 | } |
| 5743 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 5744 | // This dance forces the code in setHdmiPlugged to run. |
| 5745 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 5746 | mHdmiPlugged = !plugged; |
| 5747 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5748 | } |
| 5749 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 5750 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 5751 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 5752 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5753 | final Runnable mScreenshotTimeout = new Runnable() { |
| 5754 | @Override public void run() { |
| 5755 | synchronized (mScreenshotLock) { |
| 5756 | if (mScreenshotConnection != null) { |
| 5757 | mContext.unbindService(mScreenshotConnection); |
| 5758 | mScreenshotConnection = null; |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5759 | notifyScreenshotError(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 5760 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 5761 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5762 | } |
| 5763 | }; |
| 5764 | |
| 5765 | // Assume this is called from the Handler thread. |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 5766 | private void takeScreenshot(final int screenshotType) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5767 | synchronized (mScreenshotLock) { |
| 5768 | if (mScreenshotConnection != null) { |
| 5769 | return; |
| 5770 | } |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5771 | final ComponentName serviceComponent = new ComponentName(SYSUI_PACKAGE, |
| 5772 | SYSUI_SCREENSHOT_SERVICE); |
| 5773 | final Intent serviceIntent = new Intent(); |
| 5774 | serviceIntent.setComponent(serviceComponent); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5775 | ServiceConnection conn = new ServiceConnection() { |
| 5776 | @Override |
| 5777 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 5778 | synchronized (mScreenshotLock) { |
| 5779 | if (mScreenshotConnection != this) { |
| 5780 | return; |
| 5781 | } |
| 5782 | Messenger messenger = new Messenger(service); |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 5783 | Message msg = Message.obtain(null, screenshotType); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5784 | final ServiceConnection myConn = this; |
| 5785 | Handler h = new Handler(mHandler.getLooper()) { |
| 5786 | @Override |
| 5787 | public void handleMessage(Message msg) { |
| 5788 | synchronized (mScreenshotLock) { |
| 5789 | if (mScreenshotConnection == myConn) { |
| 5790 | mContext.unbindService(mScreenshotConnection); |
| 5791 | mScreenshotConnection = null; |
| 5792 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 5793 | } |
| 5794 | } |
| 5795 | } |
| 5796 | }; |
| 5797 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 5798 | msg.arg1 = msg.arg2 = 0; |
| 5799 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 5800 | msg.arg1 = 1; |
| 5801 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 5802 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5803 | try { |
| 5804 | messenger.send(msg); |
| 5805 | } catch (RemoteException e) { |
| 5806 | } |
| 5807 | } |
| 5808 | } |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5809 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5810 | @Override |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5811 | public void onServiceDisconnected(ComponentName name) { |
Geoffrey Pitsch | b2d6ed3 | 2016-08-24 10:37:19 -0400 | [diff] [blame] | 5812 | synchronized (mScreenshotLock) { |
| 5813 | if (mScreenshotConnection != null) { |
| 5814 | mContext.unbindService(mScreenshotConnection); |
| 5815 | mScreenshotConnection = null; |
| 5816 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 5817 | notifyScreenshotError(); |
| 5818 | } |
| 5819 | } |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5820 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5821 | }; |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5822 | if (mContext.bindServiceAsUser(serviceIntent, conn, |
| 5823 | Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, |
| 5824 | UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5825 | mScreenshotConnection = conn; |
| 5826 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 5827 | } |
| 5828 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 5829 | } |
| 5830 | |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5831 | /** |
| 5832 | * Notifies the screenshot service to show an error. |
| 5833 | */ |
| 5834 | private void notifyScreenshotError() { |
| 5835 | // If the service process is killed, then ask it to clean up after itself |
| 5836 | final ComponentName errorComponent = new ComponentName(SYSUI_PACKAGE, |
| 5837 | SYSUI_SCREENSHOT_ERROR_RECEIVER); |
Dianne Hackborn | a8c1693 | 2016-05-24 12:58:21 -0700 | [diff] [blame] | 5838 | Intent errorIntent = new Intent(Intent.ACTION_USER_PRESENT); |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5839 | errorIntent.setComponent(errorComponent); |
| 5840 | errorIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | |
| 5841 | Intent.FLAG_RECEIVER_FOREGROUND); |
Winson | 538c226 | 2016-05-19 10:06:18 -0700 | [diff] [blame] | 5842 | mContext.sendBroadcastAsUser(errorIntent, UserHandle.CURRENT); |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5843 | } |
| 5844 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5845 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5846 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5847 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 5848 | if (!mSystemBooted) { |
| 5849 | // If we have not yet booted, don't let key events do anything. |
| 5850 | return 0; |
| 5851 | } |
| 5852 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5853 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 5854 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 5855 | final boolean canceled = event.isCanceled(); |
| 5856 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 5857 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 5858 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 5859 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 5860 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 5861 | // the same as if it were open and in front. |
| 5862 | // This will prevent any keys other than the power button from waking the screen |
| 5863 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5864 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5865 | (interactive ? |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5866 | isKeyguardShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5867 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5868 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5869 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5870 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5871 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5872 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5873 | } |
| 5874 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5875 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5876 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 5877 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 5878 | || event.isWakeKey(); |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 5879 | if (interactive || (isInjected && !isWakeKey)) { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 5880 | // When the device is interactive or the key is injected pass the |
| 5881 | // key to the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5882 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5883 | isWakeKey = false; |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 5884 | |
| 5885 | if (interactive) { |
| 5886 | // If the screen is awake, but the button pressed was the one that woke the device |
| 5887 | // then don't pass it to the application |
| 5888 | if (keyCode == mPendingWakeKey && !down) { |
| 5889 | result = 0; |
| 5890 | } |
| 5891 | // Reset the pending key |
| 5892 | mPendingWakeKey = PENDING_KEY_NULL; |
| 5893 | } |
| 5894 | } else if (!interactive && shouldDispatchInputWhenNonInteractive(event)) { |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 5895 | // If we're currently dozing with the screen on and the keyguard showing, pass the key |
| 5896 | // to the application but preserve its wake key status to make sure we still move |
| 5897 | // from dozing to fully interactive if we would normally go from off to fully |
| 5898 | // interactive. |
| 5899 | result = ACTION_PASS_TO_USER; |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 5900 | // Since we're dispatching the input, reset the pending key |
| 5901 | mPendingWakeKey = PENDING_KEY_NULL; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5902 | } else { |
| 5903 | // When the screen is off and the key is not injected, determine whether |
| 5904 | // to wake the device but don't pass the key to the application. |
| 5905 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5906 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 5907 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5908 | } |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 5909 | // Cache the wake key on down event so we can also avoid sending the up event to the app |
| 5910 | if (isWakeKey && down) { |
| 5911 | mPendingWakeKey = keyCode; |
| 5912 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5913 | } |
| 5914 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 5915 | // If the key would be handled globally, just return the result, don't worry about special |
| 5916 | // key processing. |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5917 | if (isValidGlobalKey(keyCode) |
| 5918 | && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 5919 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5920 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 5921 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 5922 | return result; |
| 5923 | } |
| 5924 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5925 | boolean useHapticFeedback = down |
| 5926 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 5927 | && event.getRepeatCount() == 0; |
| 5928 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5929 | // Handle special keys. |
| 5930 | switch (keyCode) { |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 5931 | case KeyEvent.KEYCODE_BACK: { |
| 5932 | if (down) { |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 5933 | interceptBackKeyDown(); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 5934 | } else { |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 5935 | boolean handled = interceptBackKeyUp(event); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 5936 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 5937 | // 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] | 5938 | if (handled) { |
| 5939 | result &= ~ACTION_PASS_TO_USER; |
| 5940 | } |
| 5941 | } |
| 5942 | break; |
| 5943 | } |
| 5944 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5945 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 5946 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5947 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5948 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 5949 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5950 | if (interactive && !mScreenshotChordVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5951 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5952 | mScreenshotChordVolumeDownKeyTriggered = true; |
| 5953 | mScreenshotChordVolumeDownKeyTime = event.getDownTime(); |
| 5954 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5955 | cancelPendingPowerKeyAction(); |
| 5956 | interceptScreenshotChord(); |
Phil Weaver | ce687c5 | 2017-03-15 08:51:52 -0700 | [diff] [blame] | 5957 | interceptAccessibilityShortcutChord(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5958 | } |
| 5959 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5960 | mScreenshotChordVolumeDownKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5961 | cancelPendingScreenshotChordAction(); |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 5962 | cancelPendingAccessibilityShortcutAction(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5963 | } |
| 5964 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 5965 | if (down) { |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 5966 | if (interactive && !mA11yShortcutChordVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5967 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 5968 | mA11yShortcutChordVolumeUpKeyTriggered = true; |
| 5969 | mA11yShortcutChordVolumeUpKeyTime = event.getDownTime(); |
| 5970 | mA11yShortcutChordVolumeUpKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5971 | cancelPendingPowerKeyAction(); |
| 5972 | cancelPendingScreenshotChordAction(); |
Phil Weaver | ce687c5 | 2017-03-15 08:51:52 -0700 | [diff] [blame] | 5973 | interceptAccessibilityShortcutChord(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5974 | } |
| 5975 | } else { |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 5976 | mA11yShortcutChordVolumeUpKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5977 | cancelPendingScreenshotChordAction(); |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 5978 | cancelPendingAccessibilityShortcutAction(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5979 | } |
| 5980 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5981 | if (down) { |
Philip Quinn | 4b5b3c6 | 2017-07-20 21:07:58 -0700 | [diff] [blame] | 5982 | sendSystemKeyToStatusBarAsync(event.getKeyCode()); |
| 5983 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5984 | TelecomManager telecomManager = getTelecommService(); |
| 5985 | if (telecomManager != null) { |
| 5986 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5987 | // If an incoming call is ringing, either VOLUME key means |
| 5988 | // "silence ringer". We handle these keys here, rather than |
| 5989 | // in the InCallScreen, to make sure we'll respond to them |
| 5990 | // even if the InCallScreen hasn't come to the foreground yet. |
| 5991 | // Look for the DOWN event here, to agree with the "fallback" |
| 5992 | // behavior in the InCallScreen. |
| 5993 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 5994 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5995 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5996 | // Silence the ringer. (It's safe to call this |
| 5997 | // even if the ringer has already been silenced.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5998 | telecomManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5999 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 6000 | // And *don't* pass this key thru to the current activity |
| 6001 | // (which is probably the InCallScreen.) |
| 6002 | result &= ~ACTION_PASS_TO_USER; |
| 6003 | break; |
| 6004 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6005 | } |
Eric Laurent | a9a5258 | 2017-05-10 15:16:01 -0700 | [diff] [blame] | 6006 | int audioMode = AudioManager.MODE_NORMAL; |
| 6007 | try { |
| 6008 | audioMode = getAudioService().getMode(); |
| 6009 | } catch (Exception e) { |
| 6010 | Log.e(TAG, "Error getting AudioService in interceptKeyBeforeQueueing.", e); |
| 6011 | } |
| 6012 | boolean isInCall = (telecomManager != null && telecomManager.isInCall()) || |
| 6013 | audioMode == AudioManager.MODE_IN_COMMUNICATION; |
| 6014 | if (isInCall && (result & ACTION_PASS_TO_USER) == 0) { |
| 6015 | // If we are in call but we decided not to pass the key to |
| 6016 | // the application, just pass it to the session service. |
| 6017 | MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent( |
| 6018 | event, AudioManager.USE_DEFAULT_STREAM_TYPE, false); |
| 6019 | break; |
| 6020 | } |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 6021 | } |
Karthik Ravi Shankar | 86ecf34 | 2017-04-28 15:35:58 -0700 | [diff] [blame] | 6022 | if (mUseTvRouting || mHandleVolumeKeysInWM) { |
| 6023 | // Defer special key handlings to |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 6024 | // {@link interceptKeyBeforeDispatching()}. |
| 6025 | result |= ACTION_PASS_TO_USER; |
| 6026 | } else if ((result & ACTION_PASS_TO_USER) == 0) { |
| 6027 | // If we aren't passing to the user and no one else |
| 6028 | // handled it send it to the session manager to |
| 6029 | // figure out. |
Jaewan Kim | 5026936 | 2016-12-23 11:22:02 +0900 | [diff] [blame] | 6030 | MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent( |
David Lin | f52b607 | 2017-04-21 18:52:18 -0700 | [diff] [blame] | 6031 | event, AudioManager.USE_DEFAULT_STREAM_TYPE, true); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6032 | } |
| 6033 | break; |
| 6034 | } |
| 6035 | |
| 6036 | case KeyEvent.KEYCODE_ENDCALL: { |
| 6037 | result &= ~ACTION_PASS_TO_USER; |
| 6038 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 6039 | TelecomManager telecomManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6040 | boolean hungUp = false; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 6041 | if (telecomManager != null) { |
| 6042 | hungUp = telecomManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6043 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6044 | if (interactive && !hungUp) { |
| 6045 | mEndCallKeyHandled = false; |
| 6046 | mHandler.postDelayed(mEndCallLongPress, |
| 6047 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 6048 | } else { |
| 6049 | mEndCallKeyHandled = true; |
| 6050 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6051 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6052 | if (!mEndCallKeyHandled) { |
| 6053 | mHandler.removeCallbacks(mEndCallLongPress); |
| 6054 | if (!canceled) { |
| 6055 | if ((mEndcallBehavior |
| 6056 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 6057 | if (goHome()) { |
| 6058 | break; |
| 6059 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 6060 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6061 | if ((mEndcallBehavior |
| 6062 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 6063 | mPowerManager.goToSleep(event.getEventTime(), |
| 6064 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 6065 | isWakeKey = false; |
| 6066 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6067 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6068 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6069 | } |
| 6070 | break; |
| 6071 | } |
| 6072 | |
| 6073 | case KeyEvent.KEYCODE_POWER: { |
Phil Weaver | 106fe73 | 2016-11-22 18:18:39 -0800 | [diff] [blame] | 6074 | // Any activity on the power button stops the accessibility shortcut |
| 6075 | cancelPendingAccessibilityShortcutAction(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6076 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6077 | isWakeKey = false; // wake-up will be handled separately |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6078 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6079 | interceptPowerKeyDown(event, interactive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6080 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6081 | interceptPowerKeyUp(event, interactive, canceled); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6082 | } |
| 6083 | break; |
| 6084 | } |
| 6085 | |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 6086 | case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN: |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6087 | // fall through |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 6088 | case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP: |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6089 | // fall through |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 6090 | case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_LEFT: |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6091 | // fall through |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 6092 | case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_RIGHT: { |
| 6093 | result &= ~ACTION_PASS_TO_USER; |
| 6094 | interceptSystemNavigationKey(event); |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6095 | break; |
| 6096 | } |
| 6097 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 6098 | case KeyEvent.KEYCODE_SLEEP: { |
| 6099 | result &= ~ACTION_PASS_TO_USER; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6100 | isWakeKey = false; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 6101 | if (!mPowerManager.isInteractive()) { |
| 6102 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 6103 | } |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 6104 | if (down) { |
| 6105 | sleepPress(event.getEventTime()); |
| 6106 | } else { |
| 6107 | sleepRelease(event.getEventTime()); |
| 6108 | } |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 6109 | break; |
| 6110 | } |
| 6111 | |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 6112 | case KeyEvent.KEYCODE_SOFT_SLEEP: { |
| 6113 | result &= ~ACTION_PASS_TO_USER; |
| 6114 | isWakeKey = false; |
| 6115 | if (!down) { |
| 6116 | mPowerManagerInternal.setUserInactiveOverrideFromWindowManager(); |
| 6117 | } |
| 6118 | break; |
| 6119 | } |
| 6120 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 6121 | case KeyEvent.KEYCODE_WAKEUP: { |
| 6122 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6123 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 6124 | break; |
| 6125 | } |
| 6126 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6127 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 6128 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 6129 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6130 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 6131 | case KeyEvent.KEYCODE_MUTE: |
| 6132 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 6133 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 6134 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 6135 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 6136 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 6137 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 6138 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 6139 | if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { |
| 6140 | // If the global session is active pass all media keys to it |
| 6141 | // instead of the active window. |
| 6142 | result &= ~ACTION_PASS_TO_USER; |
| 6143 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6144 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 6145 | // Only do this if we would otherwise not pass it to the user. In that |
| 6146 | // case, the PhoneWindow class will do the same thing, except it will |
| 6147 | // 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] | 6148 | // Note that we need to make a copy of the key event here because the |
| 6149 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6150 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 6151 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 6152 | new KeyEvent(event)); |
| 6153 | msg.setAsynchronous(true); |
| 6154 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6155 | } |
| 6156 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6157 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6158 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6159 | case KeyEvent.KEYCODE_CALL: { |
| 6160 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 6161 | TelecomManager telecomManager = getTelecommService(); |
| 6162 | if (telecomManager != null) { |
| 6163 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 6164 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 6165 | + " CALL key-down while ringing: Answer the call!"); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 6166 | telecomManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6167 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 6168 | // And *don't* pass this key thru to the current activity |
| 6169 | // (which is presumably the InCallScreen.) |
| 6170 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6171 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6172 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6173 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 6174 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6175 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 6176 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 6177 | // Only do this if we would otherwise not pass it to the user. In that case, |
| 6178 | // interceptKeyBeforeDispatching would apply a similar but different policy in |
| 6179 | // order to invoke voice assist actions. Note that we need to make a copy of the |
| 6180 | // key event here because the original key event will be recycled when we return. |
| 6181 | if ((result & ACTION_PASS_TO_USER) == 0 && !down) { |
| 6182 | mBroadcastWakeLock.acquire(); |
| 6183 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, |
| 6184 | keyguardActive ? 1 : 0, 0); |
| 6185 | msg.setAsynchronous(true); |
| 6186 | msg.sendToTarget(); |
| 6187 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 6188 | break; |
| 6189 | } |
| 6190 | case KeyEvent.KEYCODE_WINDOW: { |
| 6191 | if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) { |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 6192 | if (mPictureInPictureVisible) { |
| 6193 | // Consumes the key only if picture-in-picture is visible to show |
| 6194 | // picture-in-picture control menu. This gives a chance to the foreground |
| 6195 | // activity to customize PIP key behavior. |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 6196 | if (!down) { |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 6197 | showPictureInPictureMenu(event); |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 6198 | } |
| 6199 | result &= ~ACTION_PASS_TO_USER; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 6200 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 6201 | } |
| 6202 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 6203 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6204 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 6205 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 6206 | if (useHapticFeedback) { |
| 6207 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 6208 | } |
| 6209 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 6210 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6211 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 6212 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 6213 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6214 | return result; |
| 6215 | } |
| 6216 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 6217 | /** |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6218 | * Handle statusbar expansion events. |
| 6219 | * @param event |
| 6220 | */ |
Jim Miller | 07e0384 | 2016-06-22 15:18:13 -0700 | [diff] [blame] | 6221 | private void interceptSystemNavigationKey(KeyEvent event) { |
Phil Weaver | 27fcd9c | 2017-01-20 15:57:24 -0800 | [diff] [blame] | 6222 | if (event.getAction() == KeyEvent.ACTION_UP) { |
| 6223 | if (!mAccessibilityManager.isEnabled() |
| 6224 | || !mAccessibilityManager.sendFingerprintGesture(event.getKeyCode())) { |
| 6225 | if (areSystemNavigationKeysEnabled()) { |
Philip Quinn | 4b5b3c6 | 2017-07-20 21:07:58 -0700 | [diff] [blame] | 6226 | sendSystemKeyToStatusBarAsync(event.getKeyCode()); |
Jim Miller | f4c0a13 | 2016-05-17 18:11:52 -0700 | [diff] [blame] | 6227 | } |
| 6228 | } |
| 6229 | } |
| 6230 | } |
| 6231 | |
| 6232 | /** |
Philip Quinn | 4b5b3c6 | 2017-07-20 21:07:58 -0700 | [diff] [blame] | 6233 | * Notify the StatusBar that a system key was pressed. |
| 6234 | */ |
| 6235 | private void sendSystemKeyToStatusBar(int keyCode) { |
| 6236 | IStatusBarService statusBar = getStatusBarService(); |
| 6237 | if (statusBar != null) { |
| 6238 | try { |
| 6239 | statusBar.handleSystemKey(keyCode); |
| 6240 | } catch (RemoteException e) { |
| 6241 | // Oh well. |
| 6242 | } |
| 6243 | } |
| 6244 | } |
| 6245 | |
| 6246 | /** |
| 6247 | * Notify the StatusBar that a system key was pressed without blocking the current thread. |
| 6248 | */ |
| 6249 | private void sendSystemKeyToStatusBarAsync(int keyCode) { |
| 6250 | Message message = mHandler.obtainMessage(MSG_SYSTEM_KEY_PRESS, keyCode, 0); |
| 6251 | message.setAsynchronous(true); |
| 6252 | mHandler.sendMessage(message); |
| 6253 | } |
| 6254 | |
| 6255 | /** |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6256 | * Returns true if the key can have global actions attached to it. |
| 6257 | * We reserve all power management keys for the system since they require |
| 6258 | * very careful handling. |
| 6259 | */ |
| 6260 | private static boolean isValidGlobalKey(int keyCode) { |
| 6261 | switch (keyCode) { |
| 6262 | case KeyEvent.KEYCODE_POWER: |
| 6263 | case KeyEvent.KEYCODE_WAKEUP: |
| 6264 | case KeyEvent.KEYCODE_SLEEP: |
| 6265 | return false; |
| 6266 | default: |
| 6267 | return true; |
| 6268 | } |
| 6269 | } |
| 6270 | |
| 6271 | /** |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 6272 | * When the screen is off we ignore some keys that might otherwise typically |
| 6273 | * be considered wake keys. We filter them out here. |
| 6274 | * |
| 6275 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 6276 | * is always considered a wake key. |
| 6277 | */ |
| 6278 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 6279 | switch (keyCode) { |
| 6280 | // ignore volume keys unless docked |
| 6281 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 6282 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 6283 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 6284 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 6285 | |
| 6286 | // ignore media and camera keys |
| 6287 | case KeyEvent.KEYCODE_MUTE: |
| 6288 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 6289 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 6290 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 6291 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 6292 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 6293 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 6294 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 6295 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 6296 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 6297 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 6298 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 6299 | case KeyEvent.KEYCODE_CAMERA: |
| 6300 | return false; |
| 6301 | } |
| 6302 | return true; |
| 6303 | } |
| 6304 | |
| 6305 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 6306 | /** {@inheritDoc} */ |
| 6307 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 6308 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 6309 | if ((policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6310 | if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion, |
| 6311 | "android.policy:MOTION")) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6312 | return 0; |
| 6313 | } |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 6314 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6315 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 6316 | if (shouldDispatchInputWhenNonInteractive(null)) { |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 6317 | return ACTION_PASS_TO_USER; |
| 6318 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6319 | |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 6320 | // If we have not passed the action up and we are in theater mode without dreaming, |
| 6321 | // there will be no dream to intercept the touch and wake into ambient. The device should |
| 6322 | // wake up in this case. |
| 6323 | if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6324 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming, |
| 6325 | "android.policy:MOTION"); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 6326 | } |
| 6327 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 6328 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 6329 | } |
| 6330 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 6331 | private boolean shouldDispatchInputWhenNonInteractive(KeyEvent event) { |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 6332 | final boolean displayOff = (mDisplay == null || mDisplay.getState() == Display.STATE_OFF); |
| 6333 | |
| 6334 | if (displayOff && !mHasFeatureWatch) { |
| 6335 | return false; |
| 6336 | } |
| 6337 | |
| 6338 | // Send events to keyguard while the screen is on and it's showing. |
| 6339 | if (isKeyguardShowingAndNotOccluded() && !displayOff) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6340 | return true; |
| 6341 | } |
| 6342 | |
Anthony Hugh | 4b13ab8 | 2016-05-17 13:03:00 -0700 | [diff] [blame] | 6343 | // Watches handle BACK specially |
| 6344 | if (mHasFeatureWatch |
| 6345 | && event != null |
| 6346 | && (event.getKeyCode() == KeyEvent.KEYCODE_BACK |
| 6347 | || event.getKeyCode() == KeyEvent.KEYCODE_STEM_PRIMARY)) { |
| 6348 | return false; |
| 6349 | } |
| 6350 | |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 6351 | // Send events to a dozing dream even if the screen is off since the dream |
| 6352 | // is in control of the state of the screen. |
| 6353 | IDreamManager dreamManager = getDreamManager(); |
| 6354 | |
| 6355 | try { |
| 6356 | if (dreamManager != null && dreamManager.isDreaming()) { |
| 6357 | return true; |
| 6358 | } |
| 6359 | } catch (RemoteException e) { |
| 6360 | Slog.e(TAG, "RemoteException when checking if dreaming", e); |
| 6361 | } |
| 6362 | |
| 6363 | // Otherwise, consume events since the user can't see what is being |
| 6364 | // interacted with. |
| 6365 | return false; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 6366 | } |
| 6367 | |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6368 | private void dispatchDirectAudioEvent(KeyEvent event) { |
| 6369 | if (event.getAction() != KeyEvent.ACTION_DOWN) { |
| 6370 | return; |
| 6371 | } |
| 6372 | int keyCode = event.getKeyCode(); |
John Spurlock | b94f2d6 | 2015-03-17 14:11:57 -0400 | [diff] [blame] | 6373 | int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND |
| 6374 | | AudioManager.FLAG_FROM_KEY; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6375 | String pkgName = mContext.getOpPackageName(); |
| 6376 | switch (keyCode) { |
| 6377 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 6378 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 6379 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 6380 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
Eric Laurent | a9a5258 | 2017-05-10 15:16:01 -0700 | [diff] [blame] | 6381 | } catch (Exception e) { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6382 | Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e); |
| 6383 | } |
| 6384 | break; |
| 6385 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 6386 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 6387 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 6388 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
Eric Laurent | a9a5258 | 2017-05-10 15:16:01 -0700 | [diff] [blame] | 6389 | } catch (Exception e) { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6390 | Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e); |
| 6391 | } |
| 6392 | break; |
| 6393 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 6394 | try { |
| 6395 | if (event.getRepeatCount() == 0) { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 6396 | getAudioService().adjustSuggestedStreamVolume( |
| 6397 | AudioManager.ADJUST_TOGGLE_MUTE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 6398 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6399 | } |
Eric Laurent | a9a5258 | 2017-05-10 15:16:01 -0700 | [diff] [blame] | 6400 | } catch (Exception e) { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 6401 | Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e); |
| 6402 | } |
| 6403 | break; |
| 6404 | } |
| 6405 | } |
| 6406 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 6407 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 6408 | if (DEBUG_INPUT) { |
| 6409 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6410 | } |
| 6411 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 6412 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 6413 | if (DEBUG_INPUT) { |
| 6414 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 6415 | } |
| 6416 | |
| 6417 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 6418 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 6419 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 6420 | } |
| 6421 | |
| 6422 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 6423 | |
| 6424 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 6425 | && event.getRepeatCount() == 0) { |
| 6426 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 6427 | |
| 6428 | Message msg = mHandler.obtainMessage( |
| 6429 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 6430 | msg.setAsynchronous(true); |
| 6431 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 6432 | } else { |
| 6433 | mBroadcastWakeLock.release(); |
| 6434 | } |
| 6435 | } |
| 6436 | |
| 6437 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 6438 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 6439 | |
| 6440 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 6441 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 6442 | if (DEBUG_INPUT) { |
| 6443 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 6444 | } |
| 6445 | |
| 6446 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 6447 | mBroadcastWakeLock.release(); |
| 6448 | } |
| 6449 | |
| 6450 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6451 | if (mActivityManagerInternal.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 6452 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6453 | } |
| 6454 | } |
| 6455 | |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 6456 | void launchVoiceAssistWithWakeLock(boolean keyguardActive) { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 6457 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 6458 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 6459 | if (dic != null) { |
| 6460 | try { |
| 6461 | dic.exitIdle("voice-search"); |
| 6462 | } catch (RemoteException e) { |
| 6463 | } |
| 6464 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 6465 | Intent voiceIntent = |
| 6466 | new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 6467 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6468 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 6469 | mBroadcastWakeLock.release(); |
| 6470 | } |
| 6471 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 6472 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 6473 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 6474 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 6475 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 6476 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 6477 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6478 | } else { |
| 6479 | try { |
| 6480 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 6481 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 6482 | mUiMode = uiModeService.getCurrentModeType(); |
| 6483 | } catch (RemoteException e) { |
| 6484 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 6485 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6486 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 6487 | synchronized (mLock) { |
| 6488 | updateOrientationListenerLp(); |
| 6489 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 6490 | } |
| 6491 | }; |
| 6492 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 6493 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 6494 | @Override |
| 6495 | public void onReceive(Context context, Intent intent) { |
| 6496 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6497 | if (mKeyguardDelegate != null) { |
| 6498 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 6499 | } |
| 6500 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6501 | if (mKeyguardDelegate != null) { |
| 6502 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 6503 | } |
| 6504 | } |
| 6505 | } |
| 6506 | }; |
| 6507 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6508 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 6509 | @Override |
| 6510 | public void onReceive(Context context, Intent intent) { |
| 6511 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 6512 | // tickle the settings observer: this first ensures that we're |
| 6513 | // observing the relevant settings for the newly-active user, |
| 6514 | // and then updates our own bookkeeping based on the now- |
| 6515 | // current user. |
| 6516 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 6517 | |
| 6518 | // force a re-application of focused window sysui visibility. |
| 6519 | // the window may never have been shown for this user |
| 6520 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 6521 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 6522 | mLastSystemUiFlags = 0; |
| 6523 | updateSystemUiVisibilityLw(); |
| 6524 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6525 | } |
| 6526 | } |
| 6527 | }; |
| 6528 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6529 | private final Runnable mHiddenNavPanic = new Runnable() { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 6530 | @Override |
| 6531 | public void run() { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6532 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 6533 | if (!isUserSetupComplete()) { |
| 6534 | // Swipe-up for navigation bar is disabled during setup |
| 6535 | return; |
| 6536 | } |
| 6537 | mPendingPanicGestureUptime = SystemClock.uptimeMillis(); |
Adrian Roos | 1f42590 | 2016-07-22 10:37:50 -0700 | [diff] [blame] | 6538 | if (!isNavBarEmpty(mLastSystemUiFlags)) { |
| 6539 | mNavigationBarController.showTransient(); |
| 6540 | } |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6541 | } |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 6542 | } |
| 6543 | }; |
| 6544 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6545 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 6546 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 6547 | if (!isUserSetupComplete()) { |
| 6548 | // Swipe-up for navigation bar is disabled during setup |
| 6549 | return; |
| 6550 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6551 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
Adrian Roos | 1f42590 | 2016-07-22 10:37:50 -0700 | [diff] [blame] | 6552 | boolean nb = mNavigationBarController.checkShowTransientBarLw() |
| 6553 | && !isNavBarEmpty(mLastSystemUiFlags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6554 | if (sb || nb) { |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 6555 | // Don't show status bar when swiping on already visible navigation bar |
| 6556 | if (!nb && swipeTarget == mNavigationBar) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6557 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6558 | return; |
| 6559 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6560 | if (sb) mStatusBarController.showTransient(); |
| 6561 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6562 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6563 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 6564 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6565 | } |
| 6566 | } |
| 6567 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6568 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6569 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6570 | public void startedGoingToSleep(int why) { |
| 6571 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")"); |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6572 | mCameraGestureTriggeredDuringGoingToSleep = false; |
| 6573 | mGoingToSleep = true; |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 6574 | if (mKeyguardDelegate != null) { |
| 6575 | mKeyguardDelegate.onStartedGoingToSleep(why); |
| 6576 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6577 | } |
| 6578 | |
| 6579 | // Called on the PowerManager's Notifier thread. |
| 6580 | @Override |
| 6581 | public void finishedGoingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 6582 | EventLog.writeEvent(70000, 0); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6583 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")"); |
Chris Wren | 9bb290b | 2015-06-29 12:02:13 -0400 | [diff] [blame] | 6584 | MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6585 | |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6586 | mGoingToSleep = false; |
| 6587 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6588 | // We must get this work done here because the power manager will drop |
| 6589 | // 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] | 6590 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6591 | mAwake = false; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6592 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6593 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6594 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6595 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6596 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6597 | mKeyguardDelegate.onFinishedGoingToSleep(why, |
| 6598 | mCameraGestureTriggeredDuringGoingToSleep); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6599 | } |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6600 | mCameraGestureTriggeredDuringGoingToSleep = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6601 | } |
| 6602 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6603 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6604 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6605 | public void startedWakingUp() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 6606 | EventLog.writeEvent(70000, 1); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6607 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up..."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 6608 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6609 | // Since goToSleep performs these functions synchronously, we must |
| 6610 | // do the same here. We cannot post this work to a handler because |
| 6611 | // that might cause it to become reordered with respect to what |
| 6612 | // may happen in a future call to goToSleep. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6613 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6614 | mAwake = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6615 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6616 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6617 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6618 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6619 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6620 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6621 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6622 | mKeyguardDelegate.onStartedWakingUp(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6623 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6624 | } |
| 6625 | |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6626 | // Called on the PowerManager's Notifier thread. |
| 6627 | @Override |
| 6628 | public void finishedWakingUp() { |
| 6629 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up..."); |
Adrian Roos | 369907f | 2017-07-14 14:53:39 +0200 | [diff] [blame] | 6630 | |
| 6631 | if (mKeyguardDelegate != null) { |
| 6632 | mKeyguardDelegate.onFinishedWakingUp(); |
| 6633 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6634 | } |
| 6635 | |
| 6636 | private void wakeUpFromPowerKey(long eventTime) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6637 | wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER"); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6638 | } |
| 6639 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6640 | private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) { |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 6641 | final boolean theaterModeEnabled = isTheaterModeEnabled(); |
| 6642 | if (!wakeInTheaterMode && theaterModeEnabled) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6643 | return false; |
| 6644 | } |
| 6645 | |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 6646 | if (theaterModeEnabled) { |
| 6647 | Settings.Global.putInt(mContext.getContentResolver(), |
| 6648 | Settings.Global.THEATER_MODE_ON, 0); |
| 6649 | } |
| 6650 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6651 | mPowerManager.wakeUp(wakeTime, reason); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6652 | return true; |
| 6653 | } |
| 6654 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6655 | private void finishKeyguardDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6656 | synchronized (mLock) { |
Jorim Jaggi | f325548 | 2015-07-24 12:32:42 -0700 | [diff] [blame] | 6657 | if (!mScreenOnEarly || mKeyguardDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6658 | 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] | 6659 | } |
| 6660 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6661 | mKeyguardDrawComplete = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6662 | if (mKeyguardDelegate != null) { |
| 6663 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 6664 | } |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6665 | mWindowManagerDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6666 | } |
| 6667 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6668 | // ... eventually calls finishWindowsDrawn which will finalize our screen turn on |
| 6669 | // as well as enabling the orientation change logic/sensor. |
| 6670 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, |
| 6671 | WAITING_FOR_DRAWN_TIMEOUT); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6672 | } |
| 6673 | |
| 6674 | // Called on the DisplayManager's DisplayPowerController thread. |
| 6675 | @Override |
| 6676 | public void screenTurnedOff() { |
| 6677 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); |
| 6678 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6679 | updateScreenOffSleepToken(true); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6680 | synchronized (mLock) { |
| 6681 | mScreenOnEarly = false; |
| 6682 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 6683 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6684 | mWindowManagerDrawComplete = false; |
| 6685 | mScreenOnListener = null; |
| 6686 | updateOrientationListenerLp(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 6687 | |
| 6688 | if (mKeyguardDelegate != null) { |
| 6689 | mKeyguardDelegate.onScreenTurnedOff(); |
| 6690 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6691 | } |
Ruben Brunk | fecb615 | 2016-10-28 20:18:57 -0700 | [diff] [blame] | 6692 | reportScreenStateToVrManager(false); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6693 | } |
| 6694 | |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 6695 | private long getKeyguardDrawnTimeout() { |
| 6696 | final boolean bootCompleted = |
| 6697 | LocalServices.getService(SystemServiceManager.class).isBootCompleted(); |
| 6698 | // Set longer timeout if it has not booted yet to prevent showing empty window. |
| 6699 | return bootCompleted ? 1000 : 5000; |
| 6700 | } |
| 6701 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6702 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6703 | @Override |
| 6704 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6705 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6706 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6707 | updateScreenOffSleepToken(false); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6708 | synchronized (mLock) { |
| 6709 | mScreenOnEarly = true; |
| 6710 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 6711 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6712 | mWindowManagerDrawComplete = false; |
| 6713 | mScreenOnListener = screenOnListener; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6714 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6715 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | a4b51bc | 2015-08-10 18:20:43 -0700 | [diff] [blame] | 6716 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 6717 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, |
| 6718 | getKeyguardDrawnTimeout()); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6719 | mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback); |
| 6720 | } else { |
| 6721 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 6722 | "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
| 6723 | finishKeyguardDrawn(); |
| 6724 | } |
| 6725 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6726 | } |
| 6727 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 6728 | // Called on the DisplayManager's DisplayPowerController thread. |
| 6729 | @Override |
| 6730 | public void screenTurnedOn() { |
| 6731 | synchronized (mLock) { |
| 6732 | if (mKeyguardDelegate != null) { |
| 6733 | mKeyguardDelegate.onScreenTurnedOn(); |
| 6734 | } |
| 6735 | } |
Ruben Brunk | fecb615 | 2016-10-28 20:18:57 -0700 | [diff] [blame] | 6736 | reportScreenStateToVrManager(true); |
| 6737 | } |
| 6738 | |
Jorim Jaggi | 51304d7 | 2017-05-17 17:25:32 +0200 | [diff] [blame] | 6739 | @Override |
| 6740 | public void screenTurningOff(ScreenOffListener screenOffListener) { |
| 6741 | mWindowManagerFuncs.screenTurningOff(screenOffListener); |
Adrian Roos | 369907f | 2017-07-14 14:53:39 +0200 | [diff] [blame] | 6742 | synchronized (mLock) { |
| 6743 | if (mKeyguardDelegate != null) { |
| 6744 | mKeyguardDelegate.onScreenTurningOff(); |
| 6745 | } |
| 6746 | } |
Jorim Jaggi | 51304d7 | 2017-05-17 17:25:32 +0200 | [diff] [blame] | 6747 | } |
| 6748 | |
Ruben Brunk | fecb615 | 2016-10-28 20:18:57 -0700 | [diff] [blame] | 6749 | private void reportScreenStateToVrManager(boolean isScreenOn) { |
Zak Cohen | 732aeb0 | 2017-01-29 14:19:52 -0800 | [diff] [blame] | 6750 | if (mVrManagerInternal == null) { |
Ruben Brunk | fecb615 | 2016-10-28 20:18:57 -0700 | [diff] [blame] | 6751 | return; |
| 6752 | } |
Zak Cohen | 732aeb0 | 2017-01-29 14:19:52 -0800 | [diff] [blame] | 6753 | mVrManagerInternal.onScreenStateChanged(isScreenOn); |
| 6754 | } |
| 6755 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6756 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6757 | synchronized (mLock) { |
| 6758 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6759 | 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] | 6760 | } |
| 6761 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6762 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6763 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6764 | |
| 6765 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6766 | } |
| 6767 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 6768 | private void finishScreenTurningOn() { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6769 | synchronized (mLock) { |
| 6770 | // We have just finished drawing screen content. Since the orientation listener |
| 6771 | // gets only installed when all windows are drawn, we try to install it again. |
| 6772 | updateOrientationListenerLp(); |
| 6773 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6774 | final ScreenOnListener listener; |
| 6775 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6776 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6777 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 6778 | "finishScreenTurningOn: mAwake=" + mAwake |
| 6779 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 6780 | + ", mScreenOnFully=" + mScreenOnFully |
| 6781 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 6782 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 6783 | |
| 6784 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 6785 | || (mAwake && !mKeyguardDrawComplete)) { |
| 6786 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6787 | } |
| 6788 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6789 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 6790 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 6791 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6792 | mScreenOnFully = true; |
| 6793 | |
| 6794 | // Remember the first time we draw the keyguard so we know when we're done with |
| 6795 | // the main part of booting and can enable the screen and hide boot messages. |
| 6796 | if (!mKeyguardDrawnOnce && mAwake) { |
| 6797 | mKeyguardDrawnOnce = true; |
| 6798 | enableScreen = true; |
| 6799 | if (mBootMessageNeedsHiding) { |
| 6800 | mBootMessageNeedsHiding = false; |
| 6801 | hideBootMessages(); |
| 6802 | } |
| 6803 | } else { |
| 6804 | enableScreen = false; |
| 6805 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6806 | } |
| 6807 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6808 | if (listener != null) { |
| 6809 | listener.onScreenOn(); |
| 6810 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 6811 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6812 | if (enableScreen) { |
| 6813 | try { |
| 6814 | mWindowManager.enableScreenIfNeeded(); |
| 6815 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6816 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6817 | } |
| 6818 | } |
| 6819 | |
| 6820 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6821 | synchronized (mLock) { |
| 6822 | if (!mKeyguardDrawnOnce) { |
| 6823 | mBootMessageNeedsHiding = true; |
| 6824 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 6825 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6826 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6827 | |
| 6828 | if (mBootMsgDialog != null) { |
| 6829 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 6830 | mBootMsgDialog.dismiss(); |
| 6831 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6832 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6833 | } |
| 6834 | |
| 6835 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6836 | public boolean isScreenOn() { |
Jorim Jaggi | 67b29d5 | 2017-06-09 18:00:00 -0700 | [diff] [blame] | 6837 | synchronized (mLock) { |
| 6838 | return mScreenOnEarly; |
| 6839 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 6840 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6841 | |
Adrian Roos | e94c15c | 2017-05-09 13:17:54 -0700 | [diff] [blame] | 6842 | @Override |
Adrian Roos | 7c89480 | 2017-07-19 12:25:34 +0200 | [diff] [blame] | 6843 | public boolean okToAnimate() { |
| 6844 | return mAwake && !mGoingToSleep; |
Adrian Roos | e94c15c | 2017-05-09 13:17:54 -0700 | [diff] [blame] | 6845 | } |
| 6846 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 6847 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6848 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6849 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6850 | if (mKeyguardDelegate != null) { |
| 6851 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6852 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6853 | } |
| 6854 | |
| 6855 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6856 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6857 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6858 | if (mKeyguardDelegate != null) { |
| 6859 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6860 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6861 | } |
| 6862 | |
Tony Mak | 2c0d6dc | 2016-04-29 16:16:54 +0100 | [diff] [blame] | 6863 | @Override |
| 6864 | public boolean isKeyguardShowingAndNotOccluded() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6865 | if (mKeyguardDelegate == null) return false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6866 | return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6867 | } |
| 6868 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 6869 | @Override |
| 6870 | public boolean isKeyguardTrustedLw() { |
| 6871 | if (mKeyguardDelegate == null) return false; |
| 6872 | return mKeyguardDelegate.isTrusted(); |
| 6873 | } |
| 6874 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6875 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6876 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6877 | public boolean isKeyguardLocked() { |
| 6878 | return keyguardOn(); |
| 6879 | } |
| 6880 | |
| 6881 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6882 | @Override |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 6883 | public boolean isKeyguardSecure(int userId) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6884 | if (mKeyguardDelegate == null) return false; |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 6885 | return mKeyguardDelegate.isSecure(userId); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6886 | } |
| 6887 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6888 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6889 | @Override |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 6890 | public boolean isKeyguardOccluded() { |
| 6891 | if (mKeyguardDelegate == null) return false; |
| 6892 | return mKeyguardOccluded; |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 6893 | } |
| 6894 | |
| 6895 | /** {@inheritDoc} */ |
| 6896 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6897 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6898 | if (mKeyguardDelegate == null) return false; |
| 6899 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6900 | } |
| 6901 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6902 | @Override |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 6903 | public void dismissKeyguardLw(IKeyguardDismissCallback callback) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 6904 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 6905 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 6906 | |
| 6907 | // ask the keyguard to prompt the user to authenticate if necessary |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 6908 | mKeyguardDelegate.dismiss(callback); |
| 6909 | } else if (callback != null) { |
| 6910 | try { |
| 6911 | callback.onDismissError(); |
| 6912 | } catch (RemoteException e) { |
| 6913 | Slog.w(TAG, "Failed to call callback", e); |
| 6914 | } |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 6915 | } |
| 6916 | } |
| 6917 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 6918 | @Override |
| 6919 | public boolean isKeyguardDrawnLw() { |
| 6920 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6921 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 6922 | } |
| 6923 | } |
| 6924 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6925 | @Override |
Jorim Jaggi | 77e1043 | 2016-10-26 17:43:56 -0700 | [diff] [blame] | 6926 | public boolean isShowingDreamLw() { |
| 6927 | return mShowingDream; |
| 6928 | } |
| 6929 | |
| 6930 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 6931 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6932 | if (mKeyguardDelegate != null) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 6933 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 6934 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6935 | } |
| 6936 | } |
| 6937 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6938 | @Override |
| 6939 | public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
| 6940 | Rect outInsets) { |
| 6941 | outInsets.setEmpty(); |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 6942 | |
| 6943 | // Navigation bar and status bar. |
| 6944 | getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets); |
Matthew Ng | ca4c1a3 | 2016-12-13 16:55:09 -0800 | [diff] [blame] | 6945 | outInsets.top = mStatusBarHeight; |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 6946 | } |
| 6947 | |
| 6948 | @Override |
| 6949 | public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
| 6950 | Rect outInsets) { |
| 6951 | outInsets.setEmpty(); |
| 6952 | |
| 6953 | // Only navigation bar |
Matthew Ng | ca4c1a3 | 2016-12-13 16:55:09 -0800 | [diff] [blame] | 6954 | if (mHasNavigationBar) { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 6955 | int position = navigationBarPosition(displayWidth, displayHeight, displayRotation); |
| 6956 | if (position == NAV_BAR_BOTTOM) { |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6957 | outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode); |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 6958 | } else if (position == NAV_BAR_RIGHT) { |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6959 | outInsets.right = getNavigationBarWidth(displayRotation, mUiMode); |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 6960 | } else if (position == NAV_BAR_LEFT) { |
| 6961 | outInsets.left = getNavigationBarWidth(displayRotation, mUiMode); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6962 | } |
| 6963 | } |
| 6964 | } |
| 6965 | |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 6966 | @Override |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6967 | public boolean isNavBarForcedShownLw(WindowState windowState) { |
Jorim Jaggi | e5638a6 | 2016-03-25 22:57:01 -0700 | [diff] [blame] | 6968 | return mForceShowSystemBars; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6969 | } |
| 6970 | |
| 6971 | @Override |
Andrii Kulian | 3a1619d | 2017-07-07 14:38:09 -0700 | [diff] [blame] | 6972 | public int getNavBarPosition() { |
| 6973 | // TODO(multi-display): Support system decor on secondary displays. |
| 6974 | return mNavigationBarPosition; |
| 6975 | } |
| 6976 | |
| 6977 | @Override |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 6978 | public boolean isDockSideAllowed(int dockSide) { |
| 6979 | |
| 6980 | // We do not allow all dock sides at which the navigation bar touches the docked stack. |
| 6981 | if (!mNavigationBarCanMove) { |
| 6982 | return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT; |
| 6983 | } else { |
| 6984 | return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT; |
| 6985 | } |
| 6986 | } |
| 6987 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6988 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 6989 | PhoneWindow.sendCloseSystemWindows(mContext, null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6990 | } |
| 6991 | |
| 6992 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 6993 | PhoneWindow.sendCloseSystemWindows(mContext, reason); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6994 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 6995 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6996 | @Override |
| 6997 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6998 | if (false) { |
| 6999 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 7000 | + orientation + ", last=" + lastRotation |
| 7001 | + "); user=" + mUserRotation + " " |
| 7002 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 7003 | ? "USER_ROTATION_LOCKED" : "") |
| 7004 | ); |
| 7005 | } |
| 7006 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 7007 | if (mForceDefaultOrientation) { |
| 7008 | return Surface.ROTATION_0; |
| 7009 | } |
| 7010 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 7011 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7012 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 7013 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 7014 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7015 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7016 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 7017 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 7018 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7019 | // Ignore sensor when lid switch is open and rotation is forced. |
| 7020 | preferredRotation = mLidOpenRotation; |
| 7021 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7022 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7023 | // Ignore sensor when in car dock unless explicitly enabled. |
| 7024 | // This case can override the behavior of NOSENSOR, and can also |
| 7025 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7026 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7027 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 7028 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 7029 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 7030 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7031 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7032 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 7033 | // This case can override the behavior of NOSENSOR, and can also |
| 7034 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7035 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7036 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 7037 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 7038 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 7039 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 7040 | preferredRotation = mDemoHdmiRotation; |
| 7041 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 7042 | && mUndockedHdmiRotation >= 0) { |
| 7043 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 7044 | // been specified in the configuration (only for legacy devices without |
| 7045 | // full multi-display support). |
| 7046 | // Note that the dock orientation overrides the HDMI orientation. |
| 7047 | preferredRotation = mUndockedHdmiRotation; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 7048 | } else if (mDemoRotationLock) { |
| 7049 | // Ignore sensor when demo rotation lock is enabled. |
| 7050 | // Note that the dock orientation and HDMI rotation lock override this. |
| 7051 | preferredRotation = mDemoRotation; |
Santos Cordon | 0b5d969 | 2017-07-21 12:08:53 -0700 | [diff] [blame] | 7052 | } else if (mPersistentVrModeEnabled) { |
| 7053 | // While in VR, apps always prefer a portrait rotation. This does not change |
| 7054 | // any apps that explicitly set landscape, but does cause sensors be ignored, |
| 7055 | // and ignored any orientation lock that the user has set (this conditional |
| 7056 | // should remain above the ORIENTATION_LOCKED conditional below). |
| 7057 | preferredRotation = mPortraitRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 7058 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 7059 | // Application just wants to remain locked in the last rotation. |
| 7060 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 7061 | } else if (!mSupportAutoRotation) { |
| 7062 | // If we don't support auto-rotation then bail out here and ignore |
| 7063 | // the sensor and any rotation lock settings. |
| 7064 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 7065 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7066 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 7067 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 7068 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 7069 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 7070 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7071 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 7072 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 7073 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 7074 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 7075 | // Otherwise, use sensor only if requested by the application or enabled |
| 7076 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 7077 | if (mAllowAllRotations < 0) { |
| 7078 | // Can't read this during init() because the context doesn't |
| 7079 | // have display metrics at that time so we cannot determine |
| 7080 | // tablet vs. phone then. |
| 7081 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 7082 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 7083 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7084 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 7085 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 7086 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 7087 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Santos Cordon | 0b5d969 | 2017-07-21 12:08:53 -0700 | [diff] [blame] | 7088 | preferredRotation = sensorRotation; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7089 | } else { |
| 7090 | preferredRotation = lastRotation; |
| 7091 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 7092 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 7093 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 7094 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 7095 | // The idea is that the user rotation expresses a weak preference for the direction |
| 7096 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 7097 | // 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] | 7098 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 7099 | } else { |
| 7100 | // No overriding preference. |
| 7101 | // We will do exactly what the application asked us to do. |
| 7102 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7103 | } |
| 7104 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 7105 | switch (orientation) { |
| 7106 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 7107 | // Return portrait unless overridden. |
| 7108 | if (isAnyPortrait(preferredRotation)) { |
| 7109 | return preferredRotation; |
| 7110 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 7111 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 7112 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7113 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 7114 | // Return landscape unless overridden. |
| 7115 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 7116 | return preferredRotation; |
| 7117 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7118 | return mLandscapeRotation; |
| 7119 | |
| 7120 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 7121 | // Return reverse portrait unless overridden. |
| 7122 | if (isAnyPortrait(preferredRotation)) { |
| 7123 | return preferredRotation; |
| 7124 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7125 | return mUpsideDownRotation; |
| 7126 | |
| 7127 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 7128 | // Return seascape unless overridden. |
| 7129 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 7130 | return preferredRotation; |
| 7131 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7132 | return mSeascapeRotation; |
| 7133 | |
| 7134 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 7135 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7136 | // Return either landscape rotation. |
| 7137 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 7138 | return preferredRotation; |
| 7139 | } |
| 7140 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 7141 | return lastRotation; |
| 7142 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7143 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7144 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7145 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 7146 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7147 | // Return either portrait rotation. |
| 7148 | if (isAnyPortrait(preferredRotation)) { |
| 7149 | return preferredRotation; |
| 7150 | } |
| 7151 | if (isAnyPortrait(lastRotation)) { |
| 7152 | return lastRotation; |
| 7153 | } |
| 7154 | return mPortraitRotation; |
| 7155 | |
| 7156 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 7157 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 7158 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7159 | if (preferredRotation >= 0) { |
| 7160 | return preferredRotation; |
| 7161 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 7162 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 7163 | } |
| 7164 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 7165 | } |
| 7166 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7167 | @Override |
| 7168 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 7169 | switch (orientation) { |
| 7170 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 7171 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 7172 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 7173 | return isAnyPortrait(rotation); |
| 7174 | |
| 7175 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 7176 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 7177 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 7178 | return isLandscapeOrSeascape(rotation); |
| 7179 | |
| 7180 | default: |
| 7181 | return true; |
| 7182 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 7183 | } |
| 7184 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 7185 | @Override |
| 7186 | public void setRotationLw(int rotation) { |
| 7187 | mOrientationListener.setCurrentRotation(rotation); |
| 7188 | } |
| 7189 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7190 | private boolean isLandscapeOrSeascape(int rotation) { |
| 7191 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 7192 | } |
| 7193 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7194 | private boolean isAnyPortrait(int rotation) { |
| 7195 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 7196 | } |
| 7197 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7198 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7199 | public int getUserRotationMode() { |
| 7200 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 7201 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 7202 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 7203 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7204 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7205 | |
| 7206 | // 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] | 7207 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7208 | public void setUserRotationMode(int mode, int rot) { |
| 7209 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 7210 | |
| 7211 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7212 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7213 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7214 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7215 | rot, |
| 7216 | UserHandle.USER_CURRENT); |
| 7217 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 7218 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7219 | 0, |
| 7220 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7221 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7222 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7223 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7224 | 1, |
| 7225 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 7226 | } |
| 7227 | } |
| 7228 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7229 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 7230 | public void setSafeMode(boolean safeMode) { |
| 7231 | mSafeMode = safeMode; |
Michael Wright | 33d6c08 | 2017-07-21 16:40:58 +0100 | [diff] [blame] | 7232 | if (safeMode) { |
| 7233 | performHapticFeedbackLw(null, HapticFeedbackConstants.SAFE_MODE_ENABLED, true); |
| 7234 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7235 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7236 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 7237 | static long[] getLongIntArray(Resources r, int resid) { |
| 7238 | int[] ar = r.getIntArray(resid); |
| 7239 | if (ar == null) { |
| 7240 | return null; |
| 7241 | } |
| 7242 | long[] out = new long[ar.length]; |
| 7243 | for (int i=0; i<ar.length; i++) { |
| 7244 | out[i] = ar[i]; |
| 7245 | } |
| 7246 | return out; |
| 7247 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7248 | |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 7249 | private void bindKeyguard() { |
| 7250 | synchronized (mLock) { |
| 7251 | if (mKeyguardBound) { |
| 7252 | return; |
| 7253 | } |
| 7254 | mKeyguardBound = true; |
| 7255 | } |
| 7256 | mKeyguardDelegate.bindService(mContext); |
| 7257 | } |
| 7258 | |
| 7259 | @Override |
| 7260 | public void onSystemUiStarted() { |
| 7261 | bindKeyguard(); |
| 7262 | } |
| 7263 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7264 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7265 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7266 | public void systemReady() { |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 7267 | // In normal flow, systemReady is called before other system services are ready. |
| 7268 | // So it is better not to bind keyguard here. |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 7269 | mKeyguardDelegate.onSystemReady(); |
| 7270 | |
Zak Cohen | 732aeb0 | 2017-01-29 14:19:52 -0800 | [diff] [blame] | 7271 | mVrManagerInternal = LocalServices.getService(VrManagerInternal.class); |
Santos Cordon | c09d89c | 2017-04-13 16:12:02 -0700 | [diff] [blame] | 7272 | if (mVrManagerInternal != null) { |
| 7273 | mVrManagerInternal.addPersistentVrModeStateListener(mPersistentVrModeListener); |
| 7274 | } |
Zak Cohen | 732aeb0 | 2017-01-29 14:19:52 -0800 | [diff] [blame] | 7275 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 7276 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 7277 | updateUiMode(); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 7278 | synchronized (mLock) { |
| 7279 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 7280 | mSystemReady = true; |
| 7281 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7282 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 7283 | public void run() { |
| 7284 | updateSettings(); |
| 7285 | } |
| 7286 | }); |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 7287 | // If this happens, for whatever reason, systemReady came later than systemBooted. |
| 7288 | // And keyguard should be already bound from systemBooted |
| 7289 | if (mSystemBooted) { |
| 7290 | mKeyguardDelegate.onBootCompleted(); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 7291 | } |
| 7292 | } |
| 7293 | |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 7294 | mSystemGestures.systemReady(); |
Amith Yamasani | 02a0381 | 2016-04-22 17:32:00 -0700 | [diff] [blame] | 7295 | mImmersiveModeConfirmation.systemReady(); |
Felipe Leme | 5f97880 | 2017-06-08 13:01:13 -0700 | [diff] [blame] | 7296 | |
| 7297 | mAutofillManagerInternal = LocalServices.getService(AutofillManagerInternal.class); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7298 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7299 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7300 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7301 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7302 | public void systemBooted() { |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 7303 | bindKeyguard(); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7304 | synchronized (mLock) { |
| 7305 | mSystemBooted = true; |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 7306 | if (mSystemReady) { |
| 7307 | mKeyguardDelegate.onBootCompleted(); |
| 7308 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7309 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 7310 | startedWakingUp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 7311 | screenTurningOn(null); |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 7312 | screenTurnedOn(); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7313 | } |
| 7314 | |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 7315 | @Override |
| 7316 | public boolean canDismissBootAnimation() { |
| 7317 | synchronized (mLock) { |
| 7318 | return mKeyguardDrawComplete; |
| 7319 | } |
| 7320 | } |
| 7321 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7322 | ProgressDialog mBootMsgDialog = null; |
| 7323 | |
| 7324 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7325 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7326 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 7327 | mHandler.post(new Runnable() { |
| 7328 | @Override public void run() { |
| 7329 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 7330 | int theme; |
Dmitri Plotnikov | 82e6dfc | 2017-02-24 18:10:54 -0800 | [diff] [blame] | 7331 | if (mContext.getPackageManager().hasSystemFeature(FEATURE_LEANBACK)) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 7332 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 7333 | } else { |
| 7334 | theme = 0; |
| 7335 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 7336 | |
| 7337 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 7338 | // This dialog will consume all events coming in to |
| 7339 | // it, to avoid it trying to do things too early in boot. |
| 7340 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 7341 | return true; |
| 7342 | } |
| 7343 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 7344 | return true; |
| 7345 | } |
| 7346 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 7347 | return true; |
| 7348 | } |
| 7349 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 7350 | return true; |
| 7351 | } |
| 7352 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 7353 | return true; |
| 7354 | } |
| 7355 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 7356 | AccessibilityEvent event) { |
| 7357 | return true; |
| 7358 | } |
| 7359 | }; |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 7360 | if (mContext.getPackageManager().isUpgrade()) { |
| 7361 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 7362 | } else { |
| 7363 | mBootMsgDialog.setTitle(R.string.android_start_title); |
| 7364 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7365 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 7366 | mBootMsgDialog.setIndeterminate(true); |
| 7367 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 7368 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7369 | mBootMsgDialog.getWindow().addFlags( |
| 7370 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 7371 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 7372 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 7373 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 7374 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 7375 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7376 | mBootMsgDialog.setCancelable(false); |
| 7377 | mBootMsgDialog.show(); |
| 7378 | } |
| 7379 | mBootMsgDialog.setMessage(msg); |
| 7380 | } |
| 7381 | }); |
| 7382 | } |
| 7383 | |
| 7384 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7385 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7386 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 7387 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7388 | } |
| 7389 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7390 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7391 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7392 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7393 | // *************************************** |
| 7394 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 7395 | // *************************************** |
| 7396 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 7397 | // WITH ITS LOCKS HELD. |
| 7398 | // |
| 7399 | // This code must be VERY careful about the locks |
| 7400 | // it acquires. |
| 7401 | // In fact, the current code acquires way too many, |
| 7402 | // and probably has lurking deadlocks. |
| 7403 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7404 | synchronized (mScreenLockTimeout) { |
| 7405 | if (mLockScreenTimerActive) { |
| 7406 | // reset the timer |
| 7407 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 7408 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 7409 | } |
| 7410 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 7411 | } |
| 7412 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7413 | class ScreenLockTimeout implements Runnable { |
| 7414 | Bundle options; |
| 7415 | |
| 7416 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7417 | public void run() { |
| 7418 | synchronized (this) { |
| 7419 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 7420 | if (mKeyguardDelegate != null) { |
| 7421 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 7422 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7423 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7424 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7425 | } |
| 7426 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7427 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7428 | public void setLockOptions(Bundle options) { |
| 7429 | this.options = options; |
| 7430 | } |
| 7431 | } |
| 7432 | |
| 7433 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 7434 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 7435 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7436 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 7437 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 7438 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 7439 | if (options != null) { |
| 7440 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 7441 | // until the runnable actually executes. |
| 7442 | mScreenLockTimeout.setLockOptions(options); |
| 7443 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 7444 | mHandler.post(mScreenLockTimeout); |
| 7445 | } |
| 7446 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7447 | private void updateLockScreenTimeout() { |
| 7448 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7449 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | e4044bb | 2016-05-10 18:38:25 -0700 | [diff] [blame] | 7450 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure(mCurrentUserId)); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7451 | if (mLockScreenTimerActive != enable) { |
| 7452 | if (enable) { |
| 7453 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
Jim Miller | 2967f48 | 2016-01-07 15:05:32 -0800 | [diff] [blame] | 7454 | mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 7455 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 7456 | } else { |
| 7457 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 7458 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 7459 | } |
| 7460 | mLockScreenTimerActive = enable; |
| 7461 | } |
| 7462 | } |
| 7463 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7464 | |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 7465 | private void updateDreamingSleepToken(boolean acquire) { |
| 7466 | if (acquire) { |
| 7467 | if (mDreamingSleepToken == null) { |
| 7468 | mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream"); |
| 7469 | } |
| 7470 | } else { |
| 7471 | if (mDreamingSleepToken != null) { |
| 7472 | mDreamingSleepToken.release(); |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 7473 | mDreamingSleepToken = null; |
| 7474 | } |
| 7475 | } |
| 7476 | } |
| 7477 | |
| 7478 | private void updateScreenOffSleepToken(boolean acquire) { |
| 7479 | if (acquire) { |
| 7480 | if (mScreenOffSleepToken == null) { |
| 7481 | mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff"); |
| 7482 | } |
| 7483 | } else { |
| 7484 | if (mScreenOffSleepToken != null) { |
| 7485 | mScreenOffSleepToken.release(); |
| 7486 | mScreenOffSleepToken = null; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 7487 | } |
| 7488 | } |
| 7489 | } |
| 7490 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7491 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7492 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7493 | public void enableScreenAfterBoot() { |
| 7494 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7495 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7496 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7497 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 7498 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7499 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7500 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7501 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 7502 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7503 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 7504 | } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) { |
| 7505 | mWindowManagerFuncs.lockDeviceNow(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7506 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 7507 | |
| 7508 | synchronized (mLock) { |
| 7509 | updateWakeGestureListenerLp(); |
| 7510 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7511 | } |
| 7512 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 7513 | void updateUiMode() { |
| 7514 | if (mUiModeManager == null) { |
| 7515 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 7516 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 7517 | } |
| 7518 | try { |
| 7519 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 7520 | } catch (RemoteException e) { |
| 7521 | } |
| 7522 | } |
| 7523 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 7524 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7525 | try { |
| 7526 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 7527 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 7528 | } catch (RemoteException e) { |
| 7529 | // Ignore |
| 7530 | } |
| 7531 | } |
| 7532 | |
| 7533 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 7534 | try { |
| 7535 | //set orientation on WindowManager |
| 7536 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7537 | } catch (RemoteException e) { |
| 7538 | // Ignore |
| 7539 | } |
| 7540 | } |
| 7541 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7542 | /** |
| 7543 | * Return an Intent to launch the currently active dock app as home. Returns |
| 7544 | * null if the standard home should be launched, which is the case if any of the following is |
| 7545 | * true: |
| 7546 | * <ul> |
| 7547 | * <li>The device is not in either car mode or desk mode |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 7548 | * <li>The device is in car mode but mEnableCarDockHomeCapture is false |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7549 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 7550 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 7551 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 7552 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7553 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7554 | */ |
| 7555 | Intent createHomeDockIntent() { |
| 7556 | Intent intent = null; |
| 7557 | |
| 7558 | // What home does is based on the mode, not the dock state. That |
| 7559 | // is, when in car mode you should be taken to car home regardless |
| 7560 | // of whether we are actually in a car dock. |
| 7561 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 7562 | if (mEnableCarDockHomeCapture) { |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7563 | intent = mCarDockIntent; |
| 7564 | } |
| 7565 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 7566 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 7567 | intent = mDeskDockIntent; |
| 7568 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 7569 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 7570 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 7571 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 7572 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 7573 | // Always launch dock home from home when watch is docked, if it exists. |
| 7574 | intent = mDeskDockIntent; |
Zak Cohen | db6ca49 | 2017-01-26 14:09:00 -0800 | [diff] [blame] | 7575 | } else if (mUiMode == Configuration.UI_MODE_TYPE_VR_HEADSET) { |
| 7576 | if (ENABLE_VR_HEADSET_HOME_CAPTURE) { |
| 7577 | intent = mVrHeadsetHomeIntent; |
| 7578 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7579 | } |
| 7580 | |
| 7581 | if (intent == null) { |
| 7582 | return null; |
| 7583 | } |
| 7584 | |
| 7585 | ActivityInfo ai = null; |
| 7586 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 7587 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 7588 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 7589 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7590 | if (info != null) { |
| 7591 | ai = info.activityInfo; |
| 7592 | } |
| 7593 | if (ai != null |
| 7594 | && ai.metaData != null |
| 7595 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 7596 | intent = new Intent(intent); |
| 7597 | intent.setClassName(ai.packageName, ai.name); |
| 7598 | return intent; |
| 7599 | } |
| 7600 | |
| 7601 | return null; |
| 7602 | } |
| 7603 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 7604 | void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { |
| 7605 | if (awakenFromDreams) { |
| 7606 | awakenDreams(); |
| 7607 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7608 | |
| 7609 | Intent dock = createHomeDockIntent(); |
| 7610 | if (dock != null) { |
| 7611 | try { |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 7612 | if (fromHomeKey) { |
| 7613 | dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 7614 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 7615 | startActivityAsUser(dock, UserHandle.CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7616 | return; |
| 7617 | } catch (ActivityNotFoundException e) { |
| 7618 | } |
| 7619 | } |
| 7620 | |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 7621 | Intent intent; |
| 7622 | |
| 7623 | if (fromHomeKey) { |
| 7624 | intent = new Intent(mHomeIntent); |
| 7625 | intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 7626 | } else { |
| 7627 | intent = mHomeIntent; |
| 7628 | } |
| 7629 | |
Bryce Lee | 9fc0b6f | 2015-03-19 21:37:45 +0000 | [diff] [blame] | 7630 | startActivityAsUser(intent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 7631 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7632 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 7633 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7634 | * goes to the home screen |
| 7635 | * @return whether it did anything |
| 7636 | */ |
| 7637 | boolean goHome() { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 7638 | if (!isUserSetupComplete()) { |
| 7639 | Slog.i(TAG, "Not going home because user setup is in progress."); |
| 7640 | return false; |
| 7641 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7642 | if (false) { |
| 7643 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 7644 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7645 | ActivityManager.getService().stopAppSwitches(); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 7646 | } catch (RemoteException e) { |
| 7647 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 7648 | sendCloseSystemWindows(); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 7649 | startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7650 | } else { |
| 7651 | // This code brings home to the front or, if it is already |
| 7652 | // at the front, puts the device to sleep. |
| 7653 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 7654 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 7655 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 7656 | Log.d(TAG, "UTS-TEST-MODE"); |
| 7657 | } else { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7658 | ActivityManager.getService().stopAppSwitches(); |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 7659 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7660 | Intent dock = createHomeDockIntent(); |
| 7661 | if (dock != null) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7662 | int result = ActivityManager.getService() |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7663 | .startActivityAsUser(null, null, dock, |
| 7664 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 7665 | null, null, 0, |
| 7666 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 7667 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7668 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 7669 | return false; |
| 7670 | } |
| 7671 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 7672 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7673 | int result = ActivityManager.getService() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 7674 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7675 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 7676 | null, null, 0, |
| 7677 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 7678 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 7679 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7680 | return false; |
| 7681 | } |
| 7682 | } catch (RemoteException ex) { |
| 7683 | // bummer, the activity manager, which is in this process, is dead |
| 7684 | } |
| 7685 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7686 | return true; |
| 7687 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7688 | |
| 7689 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 7690 | public void setCurrentOrientationLw(int newOrientation) { |
| 7691 | synchronized (mLock) { |
| 7692 | if (newOrientation != mCurrentAppOrientation) { |
| 7693 | mCurrentAppOrientation = newOrientation; |
| 7694 | updateOrientationListenerLp(); |
| 7695 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7696 | } |
| 7697 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7698 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 7699 | private boolean isTheaterModeEnabled() { |
| 7700 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 7701 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 7702 | } |
| 7703 | |
Doris Ling | 628cea4 | 2016-06-09 10:35:02 -0700 | [diff] [blame] | 7704 | private boolean areSystemNavigationKeysEnabled() { |
Doris Ling | 34331b7 | 2016-08-09 12:02:28 -0700 | [diff] [blame] | 7705 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
Kevin Chyn | 76096e7 | 2017-07-24 14:00:22 -0700 | [diff] [blame] | 7706 | Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0, UserHandle.USER_CURRENT) == 1; |
Doris Ling | 628cea4 | 2016-06-09 10:35:02 -0700 | [diff] [blame] | 7707 | } |
| 7708 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7709 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 7710 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 7711 | if (!mVibrator.hasVibrator()) { |
| 7712 | return false; |
| 7713 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7714 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 7715 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 7716 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7717 | return false; |
| 7718 | } |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 7719 | |
| 7720 | VibrationEffect effect = getVibrationEffect(effectId); |
| 7721 | if (effect == null) { |
| 7722 | return false; |
| 7723 | } |
| 7724 | |
| 7725 | int owningUid; |
| 7726 | String owningPackage; |
| 7727 | if (win != null) { |
| 7728 | owningUid = win.getOwningUid(); |
| 7729 | owningPackage = win.getOwningPackage(); |
| 7730 | } else { |
| 7731 | owningUid = android.os.Process.myUid(); |
| 7732 | owningPackage = mContext.getOpPackageName(); |
| 7733 | } |
| 7734 | mVibrator.vibrate(owningUid, owningPackage, effect, VIBRATION_ATTRIBUTES); |
| 7735 | return true; |
| 7736 | } |
| 7737 | |
| 7738 | private VibrationEffect getVibrationEffect(int effectId) { |
| 7739 | long[] pattern; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7740 | switch (effectId) { |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 7741 | case HapticFeedbackConstants.VIRTUAL_KEY: |
| 7742 | return VibrationEffect.get(VibrationEffect.EFFECT_CLICK); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7743 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7744 | pattern = mLongPressVibePattern; |
| 7745 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7746 | case HapticFeedbackConstants.KEYBOARD_TAP: |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 7747 | return VibrationEffect.get(VibrationEffect.EFFECT_CLICK); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 7748 | case HapticFeedbackConstants.CLOCK_TICK: |
Michael Wright | 57d94d9 | 2017-05-31 14:44:45 +0100 | [diff] [blame] | 7749 | return VibrationEffect.get(VibrationEffect.EFFECT_TICK); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 7750 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 7751 | pattern = mCalendarDateVibePattern; |
| 7752 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 7753 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7754 | pattern = mSafeModeEnabledVibePattern; |
| 7755 | break; |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 7756 | case HapticFeedbackConstants.CONTEXT_CLICK: |
Michael Wright | 57d94d9 | 2017-05-31 14:44:45 +0100 | [diff] [blame] | 7757 | return VibrationEffect.get(VibrationEffect.EFFECT_TICK); |
Michael Wright | e14b064 | 2017-06-02 19:13:58 +0100 | [diff] [blame] | 7758 | case HapticFeedbackConstants.VIRTUAL_KEY_RELEASE: |
| 7759 | return VibrationEffect.get(VibrationEffect.EFFECT_TICK); |
Yohei Yukawa | da5b4a3 | 2017-06-09 12:01:51 -0700 | [diff] [blame] | 7760 | case HapticFeedbackConstants.TEXT_HANDLE_MOVE: |
| 7761 | return VibrationEffect.get(VibrationEffect.EFFECT_TICK); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7762 | default: |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 7763 | return null; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 7764 | } |
Erik Wolsheimer | 017939e | 2017-05-24 11:18:25 -0700 | [diff] [blame] | 7765 | if (pattern.length == 0) { |
| 7766 | // No vibration |
| 7767 | return null; |
| 7768 | } else if (pattern.length == 1) { |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7769 | // One-shot vibration |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 7770 | return VibrationEffect.createOneShot(pattern[0], VibrationEffect.DEFAULT_AMPLITUDE); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7771 | } else { |
| 7772 | // Pattern vibration |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 7773 | return VibrationEffect.createWaveform(pattern, -1); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7774 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7775 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 7776 | |
| 7777 | @Override |
| 7778 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 7779 | } |
| 7780 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 7781 | @Override |
| 7782 | public void keepScreenOnStoppedLw() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 7783 | if (isKeyguardShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 7784 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7785 | } |
| 7786 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 7787 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7788 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7789 | // If there is no window focused, there will be nobody to handle the events |
| 7790 | // 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] | 7791 | WindowState winCandidate = mFocusedWindow != null ? mFocusedWindow |
Adrian Roos | 53f28ec | 2014-10-29 17:26:12 +0100 | [diff] [blame] | 7792 | : mTopFullscreenOpaqueWindowState; |
Adrian Roos | dab1516 | 2016-09-12 15:08:35 -0700 | [diff] [blame] | 7793 | if (winCandidate == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7794 | return 0; |
| 7795 | } |
Adrian Roos | dab1516 | 2016-09-12 15:08:35 -0700 | [diff] [blame] | 7796 | if (winCandidate.getAttrs().token == mImmersiveModeConfirmation.getWindowToken()) { |
| 7797 | // The immersive mode confirmation should never affect the system bar visibility, |
| 7798 | // otherwise it will unhide the navigation bar and hide itself. |
| 7799 | winCandidate = isStatusBarKeyguard() ? mStatusBar : mTopFullscreenOpaqueWindowState; |
| 7800 | if (winCandidate == null) { |
| 7801 | return 0; |
| 7802 | } |
| 7803 | } |
| 7804 | final WindowState win = winCandidate; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 7805 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mKeyguardOccluded) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 7806 | // We are updating at a point where the keyguard has gotten |
| 7807 | // focus, but we were last in a state where the top window is |
| 7808 | // hiding it. This is probably because the keyguard as been |
| 7809 | // shown while the top window was displayed, so we want to ignore |
| 7810 | // it here because this is just a very transient change and it |
| 7811 | // will quickly lose focus once it correctly gets hidden. |
| 7812 | return 0; |
| 7813 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 7814 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 7815 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 7816 | & ~mResettingSystemUiFlags |
| 7817 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7818 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 7819 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 7820 | } |
Thanh Hai Mai | 6c009f5 | 2015-09-01 16:27:32 -0700 | [diff] [blame] | 7821 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7822 | final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */, |
| 7823 | mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState); |
| 7824 | final int dockedVisibility = updateLightStatusBarLw(0 /* vis */, |
| 7825 | mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState); |
| 7826 | mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds); |
| 7827 | mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7828 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7829 | final int diff = visibility ^ mLastSystemUiFlags; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7830 | final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags; |
| 7831 | final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7832 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7833 | if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu |
| 7834 | && mFocusedApp == win.getAppToken() |
| 7835 | && mLastNonDockedStackBounds.equals(mNonDockedStackBounds) |
| 7836 | && mLastDockedStackBounds.equals(mDockedStackBounds)) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7837 | return 0; |
| 7838 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 7839 | mLastSystemUiFlags = visibility; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7840 | mLastFullscreenStackSysUiFlags = fullscreenVisibility; |
| 7841 | mLastDockedStackSysUiFlags = dockedVisibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 7842 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7843 | mFocusedApp = win.getAppToken(); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7844 | final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds); |
| 7845 | final Rect dockedStackBounds = new Rect(mDockedStackBounds); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7846 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7847 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7848 | public void run() { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7849 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 7850 | if (statusbar != null) { |
| 7851 | statusbar.setSystemUiVisibility(visibility, fullscreenVisibility, |
| 7852 | dockedVisibility, 0xffffffff, fullscreenStackBounds, |
| 7853 | dockedStackBounds, win.toString()); |
| 7854 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7855 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7856 | } |
| 7857 | }); |
| 7858 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7859 | } |
| 7860 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7861 | private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) { |
Jorim Jaggi | ff46d4c | 2017-07-17 16:46:00 +0200 | [diff] [blame] | 7862 | final boolean onKeyguard = isStatusBarKeyguard() && !mKeyguardOccluded; |
| 7863 | final WindowState statusColorWin = onKeyguard ? mStatusBar : opaqueOrDimming; |
| 7864 | if (statusColorWin != null && (statusColorWin == opaque || onKeyguard)) { |
| 7865 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 7866 | // its light flag. |
| 7867 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 7868 | vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) |
| 7869 | & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 7870 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 7871 | // Otherwise if it's dimming, clear the light flag. |
| 7872 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7873 | } |
| 7874 | return vis; |
| 7875 | } |
| 7876 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 7877 | private int updateLightNavigationBarLw(int vis, WindowState opaque, |
| 7878 | WindowState opaqueOrDimming) { |
| 7879 | final WindowState imeWin = mWindowManagerFuncs.getInputMethodWindowLw(); |
| 7880 | |
| 7881 | final WindowState navColorWin; |
Jorim Jaggi | ff46d4c | 2017-07-17 16:46:00 +0200 | [diff] [blame] | 7882 | if (imeWin != null && imeWin.isVisibleLw() && mNavigationBarPosition == NAV_BAR_BOTTOM) { |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 7883 | navColorWin = imeWin; |
| 7884 | } else { |
| 7885 | navColorWin = opaqueOrDimming; |
| 7886 | } |
| 7887 | |
| 7888 | if (navColorWin != null) { |
| 7889 | if (navColorWin == opaque) { |
| 7890 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 7891 | // its light flag. |
| 7892 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 7893 | vis |= PolicyControl.getSystemUiVisibility(navColorWin, null) |
| 7894 | & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 7895 | } else if (navColorWin.isDimming() || navColorWin == imeWin) { |
| 7896 | // Otherwise if it's dimming or it's the IME window, clear the light flag. |
| 7897 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 7898 | } |
| 7899 | } |
| 7900 | return vis; |
| 7901 | } |
| 7902 | |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 7903 | private boolean drawsSystemBarBackground(WindowState win) { |
| 7904 | return win == null || (win.getAttrs().flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0; |
| 7905 | } |
| 7906 | |
| 7907 | private boolean forcesDrawStatusBarBackground(WindowState win) { |
| 7908 | return win == null || (win.getAttrs().privateFlags |
| 7909 | & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) != 0; |
| 7910 | } |
| 7911 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7912 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7913 | final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID); |
| 7914 | final boolean freeformStackVisible = |
| 7915 | mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 7916 | final boolean resizing = mWindowManagerInternal.isDockedDividerResizing(); |
| 7917 | |
| 7918 | // We need to force system bars when the docked stack is visible, when the freeform stack |
| 7919 | // is visible but also when we are resizing for the transitions when docked stack |
| 7920 | // visibility changes. |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7921 | mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing; |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7922 | final boolean forceOpaqueStatusBar = mForceShowSystemBars && !mForceStatusBarFromKeyguard; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7923 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7924 | // apply translucent bar vis flags |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 7925 | WindowState fullscreenTransWin = isStatusBarKeyguard() && !mKeyguardOccluded |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 7926 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7927 | : mTopFullscreenOpaqueWindowState; |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 7928 | vis = mStatusBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); |
| 7929 | vis = mNavigationBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); |
| 7930 | final int dockedVis = mStatusBarController.applyTranslucentFlagLw( |
| 7931 | mTopDockedOpaqueWindowState, 0, 0); |
| 7932 | |
| 7933 | final boolean fullscreenDrawsStatusBarBackground = |
| 7934 | (drawsSystemBarBackground(mTopFullscreenOpaqueWindowState) |
| 7935 | && (vis & View.STATUS_BAR_TRANSLUCENT) == 0) |
| 7936 | || forcesDrawStatusBarBackground(mTopFullscreenOpaqueWindowState); |
| 7937 | final boolean dockedDrawsStatusBarBackground = |
| 7938 | (drawsSystemBarBackground(mTopDockedOpaqueWindowState) |
| 7939 | && (dockedVis & View.STATUS_BAR_TRANSLUCENT) == 0) |
| 7940 | || forcesDrawStatusBarBackground(mTopDockedOpaqueWindowState); |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7941 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7942 | // prevent status bar interaction from clearing certain flags |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 7943 | int type = win.getAttrs().type; |
| 7944 | boolean statusBarHasFocus = type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 7945 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7946 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 7947 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 7948 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 73fef8d | 2015-02-16 17:32:28 +0100 | [diff] [blame] | 7949 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 7950 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 7951 | if (mKeyguardOccluded) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 7952 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 7953 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7954 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7955 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7956 | |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 7957 | if (fullscreenDrawsStatusBarBackground && dockedDrawsStatusBarBackground) { |
| 7958 | vis |= View.STATUS_BAR_TRANSPARENT; |
| 7959 | vis &= ~View.STATUS_BAR_TRANSLUCENT; |
| 7960 | } else if ((!areTranslucentBarsAllowed() && fullscreenTransWin != mStatusBar) |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7961 | || forceOpaqueStatusBar) { |
| 7962 | vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7963 | } |
| 7964 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7965 | vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing); |
Yorke Lee | 2e4b732 | 2016-03-02 17:33:06 -0800 | [diff] [blame] | 7966 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7967 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7968 | boolean immersiveSticky = |
| 7969 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7970 | final boolean hideStatusBarWM = |
| 7971 | mTopFullscreenOpaqueWindowState != null |
| 7972 | && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7973 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7974 | final boolean hideStatusBarSysui = |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7975 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7976 | final boolean hideNavBarSysui = |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7977 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7978 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7979 | final boolean transientStatusBarAllowed = mStatusBar != null |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7980 | && (statusBarHasFocus || (!mForceShowSystemBars |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7981 | && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky)))); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7982 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7983 | final boolean transientNavBarAllowed = mNavigationBar != null |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7984 | && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7985 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 7986 | final long now = SystemClock.uptimeMillis(); |
| 7987 | final boolean pendingPanic = mPendingPanicGestureUptime != 0 |
| 7988 | && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION; |
| 7989 | if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) { |
| 7990 | // The user performed the panic gesture recently, we're about to hide the bars, |
| 7991 | // we're no longer on the Keyguard and the screen is ready. We can now request the bars. |
| 7992 | mPendingPanicGestureUptime = 0; |
| 7993 | mStatusBarController.showTransient(); |
Adrian Roos | 1f42590 | 2016-07-22 10:37:50 -0700 | [diff] [blame] | 7994 | if (!isNavBarEmpty(vis)) { |
| 7995 | mNavigationBarController.showTransient(); |
| 7996 | } |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 7997 | } |
| 7998 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7999 | final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8000 | && !transientStatusBarAllowed && hideStatusBarSysui; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 8001 | final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8002 | && !transientNavBarAllowed; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 8003 | if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8004 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8005 | clearClearableFlagsLw(); |
tiger_huang | c58d756 | 2014-10-23 20:24:19 +0800 | [diff] [blame] | 8006 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 8007 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8008 | |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 8009 | final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 8010 | immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 8011 | final boolean navAllowedHidden = immersive || immersiveSticky; |
| 8012 | |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 8013 | if (hideNavBarSysui && !navAllowedHidden |
| 8014 | && getWindowLayerLw(win) > getWindowLayerFromTypeLw(TYPE_INPUT_CONSUMER)) { |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 8015 | // We can't hide the navbar from this window otherwise the input consumer would not get |
| 8016 | // the input events. |
| 8017 | vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); |
| 8018 | } |
| 8019 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8020 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 8021 | |
| 8022 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8023 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 8024 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 8025 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 8026 | final String pkg = win.getOwningPackage(); |
Amith Yamasani | 02a0381 | 2016-04-22 17:32:00 -0700 | [diff] [blame] | 8027 | mImmersiveModeConfirmation.immersiveModeChangedLw(pkg, newImmersiveMode, |
Adrian Roos | 7aaa551 | 2016-07-12 15:27:24 -0700 | [diff] [blame] | 8028 | isUserSetupComplete(), isNavBarEmpty(win.getSystemUiVisibility())); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 8029 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8030 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8031 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 8032 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 8033 | vis = updateLightNavigationBarLw(vis, mTopFullscreenOpaqueWindowState, |
| 8034 | mTopFullscreenOpaqueOrDimmingWindowState); |
| 8035 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 8036 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 8037 | } |
| 8038 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 8039 | /** |
| 8040 | * @return the current visibility flags with the nav-bar opacity related flags toggled based |
| 8041 | * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}. |
| 8042 | */ |
| 8043 | private int configureNavBarOpacity(int visibility, boolean dockedStackVisible, |
| 8044 | boolean freeformStackVisible, boolean isDockedDividerResizing) { |
| 8045 | if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) { |
| 8046 | if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) { |
| 8047 | visibility = setNavBarOpaqueFlag(visibility); |
| 8048 | } |
| 8049 | } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) { |
| 8050 | if (isDockedDividerResizing) { |
| 8051 | visibility = setNavBarOpaqueFlag(visibility); |
| 8052 | } else if (freeformStackVisible) { |
| 8053 | visibility = setNavBarTranslucentFlag(visibility); |
| 8054 | } else { |
| 8055 | visibility = setNavBarOpaqueFlag(visibility); |
| 8056 | } |
| 8057 | } |
| 8058 | |
| 8059 | if (!areTranslucentBarsAllowed()) { |
| 8060 | visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT; |
| 8061 | } |
| 8062 | return visibility; |
| 8063 | } |
| 8064 | |
| 8065 | private int setNavBarOpaqueFlag(int visibility) { |
| 8066 | return visibility &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT); |
| 8067 | } |
| 8068 | |
| 8069 | private int setNavBarTranslucentFlag(int visibility) { |
| 8070 | visibility &= ~View.NAVIGATION_BAR_TRANSPARENT; |
| 8071 | return visibility |= View.NAVIGATION_BAR_TRANSLUCENT; |
| 8072 | } |
| 8073 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 8074 | private void clearClearableFlagsLw() { |
| 8075 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 8076 | if (newVal != mResettingSystemUiFlags) { |
| 8077 | mResettingSystemUiFlags = newVal; |
| 8078 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 8079 | } |
| 8080 | } |
| 8081 | |
| 8082 | private boolean isImmersiveMode(int vis) { |
| 8083 | 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] | 8084 | return mNavigationBar != null |
| 8085 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 8086 | && (vis & flags) != 0 |
| 8087 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 8088 | } |
| 8089 | |
Adrian Roos | 7aaa551 | 2016-07-12 15:27:24 -0700 | [diff] [blame] | 8090 | private static boolean isNavBarEmpty(int systemUiFlags) { |
| 8091 | final int disableNavigationBar = (View.STATUS_BAR_DISABLE_HOME |
| 8092 | | View.STATUS_BAR_DISABLE_BACK |
| 8093 | | View.STATUS_BAR_DISABLE_RECENT); |
| 8094 | |
| 8095 | return (systemUiFlags & disableNavigationBar) == disableNavigationBar; |
| 8096 | } |
| 8097 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 8098 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 8099 | * @return whether the navigation or status bar can be made translucent |
| 8100 | * |
| 8101 | * This should return true unless touch exploration is not enabled or |
| 8102 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 8103 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 8104 | private boolean areTranslucentBarsAllowed() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 8105 | return mTranslucentDecorEnabled; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 8106 | } |
| 8107 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 8108 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 8109 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 8110 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 8111 | public boolean hasNavigationBar() { |
| 8112 | return mHasNavigationBar; |
| 8113 | } |
| 8114 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 8115 | @Override |
| 8116 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 8117 | mLastInputMethodWindow = ime; |
| 8118 | mLastInputMethodTargetWindow = target; |
| 8119 | } |
| 8120 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 8121 | @Override |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 8122 | public void setDismissImeOnBackKeyPressed(boolean newValue) { |
Yohei Yukawa | abbe1ac | 2017-04-18 09:43:05 -0700 | [diff] [blame] | 8123 | mDismissImeOnBackKeyPressed = newValue; |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 8124 | } |
| 8125 | |
| 8126 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 8127 | public int getInputMethodWindowVisibleHeightLw() { |
| 8128 | return mDockBottom - mCurBottom; |
| 8129 | } |
| 8130 | |
| 8131 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 8132 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 8133 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 8134 | if (mKeyguardDelegate != null) { |
| 8135 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 8136 | } |
Phil Weaver | ce687c5 | 2017-03-15 08:51:52 -0700 | [diff] [blame] | 8137 | if (mAccessibilityShortcutController != null) { |
| 8138 | mAccessibilityShortcutController.setCurrentUser(newUserId); |
| 8139 | } |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 8140 | StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); |
Adrian Roos | 2a62910 | 2016-04-15 16:28:03 -0700 | [diff] [blame] | 8141 | if (statusBar != null) { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 8142 | statusBar.setCurrentUser(newUserId); |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 8143 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8144 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 8145 | } |
| 8146 | |
| 8147 | @Override |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 8148 | public void setSwitchingUser(boolean switching) { |
| 8149 | mKeyguardDelegate.setSwitchingUser(switching); |
| 8150 | } |
| 8151 | |
| 8152 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 8153 | public boolean canMagnifyWindow(int windowType) { |
| 8154 | switch (windowType) { |
| 8155 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 8156 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 8157 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 8158 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 8159 | return false; |
| 8160 | } |
| 8161 | } |
| 8162 | return true; |
| 8163 | } |
| 8164 | |
| 8165 | @Override |
| 8166 | public boolean isTopLevelWindow(int windowType) { |
| 8167 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 8168 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 8169 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 8170 | } |
| 8171 | return true; |
| 8172 | } |
| 8173 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 8174 | @Override |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 8175 | public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) { |
| 8176 | // For the upside down rotation we don't rotate seamlessly as the navigation |
| 8177 | // bar moves position. |
| 8178 | // Note most apps (using orientation:sensor or user as opposed to fullSensor) |
| 8179 | // will not enter the reverse portrait orientation, so actually the |
| 8180 | // orientation won't change at all. |
| 8181 | if (oldRotation == mUpsideDownRotation || newRotation == mUpsideDownRotation) { |
| 8182 | return false; |
| 8183 | } |
Robert Carr | 0b9ac5a | 2016-10-26 14:12:14 -0700 | [diff] [blame] | 8184 | // If the navigation bar can't change sides, then it will |
| 8185 | // jump when we change orientations and we don't rotate |
| 8186 | // seamlessly. |
| 8187 | if (!mNavigationBarCanMove) { |
| 8188 | return false; |
| 8189 | } |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 8190 | int delta = newRotation - oldRotation; |
| 8191 | if (delta < 0) delta += 4; |
| 8192 | // Likewise we don't rotate seamlessly for 180 degree rotations |
Geoffrey Pitsch | b2d6ed3 | 2016-08-24 10:37:19 -0400 | [diff] [blame] | 8193 | // in this case the surfaces never resize, and our logic to |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 8194 | // revert the transformations on size change will fail. We could |
| 8195 | // fix this in the future with the "tagged" frames idea. |
| 8196 | if (delta == Surface.ROTATION_180) { |
| 8197 | return false; |
| 8198 | } |
| 8199 | |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 8200 | final WindowState w = mTopFullscreenOpaqueWindowState; |
Robert Carr | 828ec3dc | 2016-08-22 13:32:34 -0700 | [diff] [blame] | 8201 | if (w != mFocusedWindow) { |
| 8202 | return false; |
| 8203 | } |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 8204 | |
Robert Carr | 606f4d5 | 2016-06-30 14:36:27 -0700 | [diff] [blame] | 8205 | // We only enable seamless rotation if the top window has requested |
| 8206 | // it and is in the fullscreen opaque state. Seamless rotation |
| 8207 | // requires freezing various Surface states and won't work well |
| 8208 | // with animations, so we disable it in the animation case for now. |
Robert Carr | 1ccd425 | 2016-08-15 12:05:21 -0700 | [diff] [blame] | 8209 | if (w != null && !w.isAnimatingLw() && |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 8210 | ((w.getAttrs().rotationAnimation == ROTATION_ANIMATION_JUMPCUT) || |
| 8211 | (w.getAttrs().rotationAnimation == ROTATION_ANIMATION_SEAMLESS))) { |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 8212 | return true; |
| 8213 | } |
| 8214 | return false; |
| 8215 | } |
| 8216 | |
| 8217 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 8218 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8219 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 8220 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 8221 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 8222 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8223 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 8224 | pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8225 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 8226 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 8227 | || mForceClearedSystemUiFlags != 0) { |
| 8228 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 8229 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 8230 | pw.print(" mResettingSystemUiFlags=0x"); |
| 8231 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 8232 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 8233 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 8234 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 8235 | if (mLastFocusNeedsMenu) { |
| 8236 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 8237 | pw.println(mLastFocusNeedsMenu); |
| 8238 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 8239 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 8240 | pw.println(mWakeGestureEnabledSetting); |
| 8241 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 8242 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 8243 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 8244 | pw.print(" mDockMode="); pw.print(mDockMode); |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 8245 | pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8246 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 8247 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 8248 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 8249 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 8250 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 8251 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8252 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 8253 | pw.print(mCarDockEnablesAccelerometer); |
| 8254 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 8255 | pw.println(mDeskDockEnablesAccelerometer); |
| 8256 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 8257 | pw.print(mLidKeyboardAccessibility); |
| 8258 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 8259 | pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 8260 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 8261 | pw.print(prefix); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 8262 | pw.print(" mLongPressOnBackBehavior="); pw.println(mLongPressOnBackBehavior); |
| 8263 | pw.print(prefix); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 8264 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 8265 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 8266 | pw.print(prefix); |
| 8267 | pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); |
| 8268 | pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 8269 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 8270 | pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); |
| 8271 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 8272 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 8273 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 8274 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 8275 | pw.print(prefix); pw.print("mOrientationSensorEnabled="); |
| 8276 | pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 8277 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 8278 | pw.print(","); pw.print(mOverscanScreenTop); |
| 8279 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 8280 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 8281 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 8282 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 8283 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 8284 | pw.print(" top="); pw.print(mOverscanTop); |
| 8285 | pw.print(" right="); pw.print(mOverscanRight); |
| 8286 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 8287 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 8288 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 8289 | pw.print(mRestrictedOverscanScreenLeft); |
| 8290 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 8291 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 8292 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8293 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 8294 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 8295 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 8296 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 8297 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 8298 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 8299 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 8300 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 8301 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 8302 | pw.print(","); pw.print(mStableFullscreenTop); |
| 8303 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 8304 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 8305 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 8306 | pw.print(","); pw.print(mStableTop); |
| 8307 | pw.print(")-("); pw.print(mStableRight); |
| 8308 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 8309 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 8310 | pw.print(","); pw.print(mSystemTop); |
| 8311 | pw.print(")-("); pw.print(mSystemRight); |
| 8312 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8313 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 8314 | pw.print(","); pw.print(mCurTop); |
| 8315 | pw.print(")-("); pw.print(mCurRight); |
| 8316 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 8317 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 8318 | pw.print(","); pw.print(mContentTop); |
| 8319 | pw.print(")-("); pw.print(mContentRight); |
| 8320 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 8321 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 8322 | pw.print(","); pw.print(mVoiceContentTop); |
| 8323 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 8324 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8325 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 8326 | pw.print(","); pw.print(mDockTop); |
| 8327 | pw.print(")-("); pw.print(mDockRight); |
| 8328 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 8329 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 8330 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 8331 | pw.print(prefix); pw.print("mShowingDream="); pw.print(mShowingDream); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 8332 | pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); |
| 8333 | pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8334 | if (mLastInputMethodWindow != null) { |
| 8335 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 8336 | pw.println(mLastInputMethodWindow); |
| 8337 | } |
| 8338 | if (mLastInputMethodTargetWindow != null) { |
| 8339 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 8340 | pw.println(mLastInputMethodTargetWindow); |
| 8341 | } |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 8342 | pw.print(prefix); pw.print("mDismissImeOnBackKeyPressed="); |
| 8343 | pw.println(mDismissImeOnBackKeyPressed); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8344 | if (mStatusBar != null) { |
| 8345 | pw.print(prefix); pw.print("mStatusBar="); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 8346 | pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); |
| 8347 | pw.println(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8348 | } |
| 8349 | if (mNavigationBar != null) { |
| 8350 | pw.print(prefix); pw.print("mNavigationBar="); |
| 8351 | pw.println(mNavigationBar); |
| 8352 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8353 | if (mFocusedWindow != null) { |
| 8354 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 8355 | pw.println(mFocusedWindow); |
| 8356 | } |
| 8357 | if (mFocusedApp != null) { |
| 8358 | pw.print(prefix); pw.print("mFocusedApp="); |
| 8359 | pw.println(mFocusedApp); |
| 8360 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 8361 | if (mTopFullscreenOpaqueWindowState != null) { |
| 8362 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 8363 | pw.println(mTopFullscreenOpaqueWindowState); |
| 8364 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 8365 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 8366 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 8367 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 8368 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 8369 | if (mForcingShowNavBar) { |
| 8370 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 8371 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 8372 | pw.println(mForcingShowNavBarLayer); |
| 8373 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 8374 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 8375 | pw.print(" mKeyguardOccluded="); pw.println(mKeyguardOccluded); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 8376 | pw.print(" mKeyguardOccludedChanged="); pw.println(mKeyguardOccludedChanged); |
| 8377 | pw.print(" mPendingKeyguardOccluded="); pw.println(mPendingKeyguardOccluded); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 8378 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 8379 | pw.print(" mForceStatusBarFromKeyguard="); |
| 8380 | pw.println(mForceStatusBarFromKeyguard); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 8381 | pw.print(prefix); pw.print("mHomePressed="); pw.println(mHomePressed); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8382 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 8383 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 8384 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 8385 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 8386 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
Bryce Lee | db776ce | 2016-09-03 15:02:00 -0700 | [diff] [blame] | 8387 | pw.print(" mIncallBackBehavior="); pw.print(mIncallBackBehavior); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8388 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 8389 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 8390 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 8391 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 8392 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 8393 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 8394 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 8395 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Sujith Ramakrishnan | 6bed9bd | 2017-04-26 12:33:37 -0700 | [diff] [blame] | 8396 | if (mHasFeatureLeanback) { |
| 8397 | pw.print(prefix); |
| 8398 | pw.print("mAccessibilityTvKey1Pressed="); pw.println(mAccessibilityTvKey1Pressed); |
| 8399 | pw.print(prefix); |
| 8400 | pw.print("mAccessibilityTvKey2Pressed="); pw.println(mAccessibilityTvKey2Pressed); |
| 8401 | pw.print(prefix); |
| 8402 | pw.print("mAccessibilityTvScheduled="); pw.println(mAccessibilityTvScheduled); |
| 8403 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 8404 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 8405 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 8406 | mStatusBarController.dump(pw, prefix); |
| 8407 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 8408 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 8409 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 8410 | if (mWakeGestureListener != null) { |
| 8411 | mWakeGestureListener.dump(pw, prefix); |
| 8412 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 8413 | if (mOrientationListener != null) { |
| 8414 | mOrientationListener.dump(pw, prefix); |
| 8415 | } |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 8416 | if (mBurnInProtectionHelper != null) { |
| 8417 | mBurnInProtectionHelper.dump(prefix, pw); |
| 8418 | } |
Jorim Jaggi | 84dc08a | 2015-09-11 17:45:22 -0700 | [diff] [blame] | 8419 | if (mKeyguardDelegate != null) { |
| 8420 | mKeyguardDelegate.dump(prefix, pw); |
| 8421 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8422 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 8423 | } |