The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
Jeff Brown | 37df39a9 | 2015-02-25 15:42:31 -0800 | [diff] [blame] | 2 | * Copyright (C) 2006 The Android Open Source Project |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 17 | package com.android.server.policy; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 18 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 20 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 21 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
| 22 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 23 | import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; |
| 24 | import static android.content.pm.PackageManager.FEATURE_TELEVISION; |
| 25 | import static android.content.pm.PackageManager.FEATURE_WATCH; |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 26 | import static android.content.res.Configuration.UI_MODE_TYPE_CAR; |
| 27 | import static android.content.res.Configuration.UI_MODE_TYPE_MASK; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.*; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 29 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 30 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; |
| 31 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 32 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 33 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
| 34 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 35 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 36 | import android.app.ActivityManager; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 37 | import android.app.ActivityManager.StackId; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 38 | import android.app.ActivityManagerInternal; |
| 39 | import android.app.ActivityManagerInternal.SleepToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 40 | import android.app.ActivityManagerNative; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 41 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 42 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 43 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 44 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 45 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 46 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 47 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 48 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 49 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 50 | import android.content.ContentResolver; |
| 51 | import android.content.Context; |
| 52 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 53 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 54 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 55 | import android.content.pm.ActivityInfo; |
| 56 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 57 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 58 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 59 | import android.content.res.Configuration; |
| 60 | import android.content.res.Resources; |
| 61 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 62 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 63 | import android.graphics.Rect; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 64 | import android.hardware.hdmi.HdmiControlManager; |
| 65 | import android.hardware.hdmi.HdmiPlaybackClient; |
| 66 | import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 67 | import android.media.AudioAttributes; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 68 | import android.media.AudioManager; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 69 | import android.media.AudioSystem; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 70 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 71 | import android.media.Ringtone; |
| 72 | import android.media.RingtoneManager; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 73 | import android.media.session.MediaSessionLegacyHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 74 | import android.os.Binder; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 75 | import android.os.Bundle; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 76 | import android.os.Debug; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 77 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 78 | import android.os.Handler; |
| 79 | import android.os.IBinder; |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 80 | import android.os.IDeviceIdleController; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 81 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 82 | import android.os.Message; |
| 83 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 84 | import android.os.PowerManager; |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 85 | import android.os.PowerManagerInternal; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 86 | import android.os.Process; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 87 | import android.os.RemoteException; |
| 88 | import android.os.ServiceManager; |
| 89 | import android.os.SystemClock; |
| 90 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 91 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 92 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 93 | import android.os.Vibrator; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 94 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 95 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 96 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 97 | import android.service.dreams.DreamService; |
| 98 | import android.service.dreams.IDreamManager; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 99 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 100 | import android.telecom.TelecomManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 101 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 102 | import android.util.EventLog; |
| 103 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 104 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 105 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 106 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 107 | import android.view.Gravity; |
| 108 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 109 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 110 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 111 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 112 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 113 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 114 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 115 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 116 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 117 | import android.view.KeyEvent; |
| 118 | import android.view.MotionEvent; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 119 | import android.view.Surface; |
| 120 | import android.view.View; |
| 121 | import android.view.ViewConfiguration; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 122 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 123 | import android.view.WindowManagerGlobal; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 124 | import android.view.WindowManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 125 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 126 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 127 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 128 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 129 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 130 | import android.view.animation.AnimationUtils; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 131 | import com.android.internal.R; |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 132 | import com.android.internal.logging.MetricsLogger; |
| 133 | import com.android.internal.policy.PhoneWindow; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 134 | import com.android.internal.statusbar.IStatusBarService; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 135 | import com.android.internal.util.ScreenShapeHelper; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 136 | import com.android.internal.widget.PointerLocationView; |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 137 | import com.android.server.GestureLauncherService; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 138 | import com.android.server.LocalServices; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 139 | import com.android.server.policy.keyguard.KeyguardServiceDelegate; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 140 | import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 141 | import com.android.server.statusbar.StatusBarManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 142 | |
| 143 | import java.io.File; |
| 144 | import java.io.FileReader; |
| 145 | import java.io.IOException; |
| 146 | import java.io.PrintWriter; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 147 | import java.util.HashSet; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 148 | import java.util.List; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 149 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 150 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 151 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 152 | * introduces a new method suffix, Lp, for an internal lock of the |
| 153 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 154 | * 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] | 155 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 156 | */ |
| 157 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 158 | static final String TAG = "WindowManager"; |
| 159 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 160 | static final boolean localLOGV = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 161 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 162 | static final boolean DEBUG_KEYGUARD = false; |
| 163 | static final boolean DEBUG_LAYOUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 164 | static final boolean DEBUG_STARTING_WINDOW = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 165 | static final boolean DEBUG_WAKEUP = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 166 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 167 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 168 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 169 | // 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] | 170 | // No longer recommended for desk docks; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 171 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 172 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 173 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 174 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 175 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 176 | 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] | 177 | static final int SHORT_PRESS_POWER_GO_HOME = 4; |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 178 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 179 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 180 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 181 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 182 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 183 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 184 | static final int MULTI_PRESS_POWER_NOTHING = 0; |
| 185 | static final int MULTI_PRESS_POWER_THEATER_MODE = 1; |
| 186 | static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2; |
| 187 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 188 | // These need to match the documentation/constant in |
| 189 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 190 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 191 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 192 | static final int LONG_PRESS_HOME_ASSIST = 2; |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 193 | static final int LONG_PRESS_HOME_PICTURE_IN_PICTURE = 3; |
| 194 | static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_PICTURE_IN_PICTURE; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 195 | |
| 196 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 197 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 198 | |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 199 | static final int SHORT_PRESS_WINDOW_NOTHING = 0; |
| 200 | static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1; |
| 201 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 202 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0; |
| 203 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1; |
| 204 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 205 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 206 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 207 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 208 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 209 | static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 210 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 211 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 212 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 213 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 214 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 215 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 216 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 217 | /** |
| 218 | * These are the system UI flags that, when changing, can cause the layout |
| 219 | * of the screen to change. |
| 220 | */ |
| 221 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 222 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 223 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 224 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 225 | | View.NAVIGATION_BAR_TRANSLUCENT |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 226 | | View.STATUS_BAR_TRANSPARENT |
| 227 | | View.NAVIGATION_BAR_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 228 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 229 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 230 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 231 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 232 | .build(); |
| 233 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 234 | // The panic gesture may become active only after the keyguard is dismissed and the immersive |
| 235 | // app shows again. If that doesn't happen for 30s we drop the gesture. |
| 236 | private static final long PANIC_GESTURE_EXPIRATION = 30000; |
| 237 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 238 | /** |
| 239 | * Keyguard stuff |
| 240 | */ |
| 241 | private WindowState mKeyguardScrim; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 242 | private boolean mKeyguardHidden; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 243 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 244 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 245 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 246 | * |
| 247 | * These are special keys that are used to launch particular kinds of applications, |
| 248 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 249 | * usage page. We don't support quite that many yet... |
| 250 | */ |
| 251 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 252 | static { |
| 253 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 254 | sApplicationLaunchKeyCategories.append( |
| 255 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 256 | sApplicationLaunchKeyCategories.append( |
| 257 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 258 | sApplicationLaunchKeyCategories.append( |
| 259 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 260 | sApplicationLaunchKeyCategories.append( |
| 261 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 262 | sApplicationLaunchKeyCategories.append( |
| 263 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 264 | sApplicationLaunchKeyCategories.append( |
| 265 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 266 | } |
| 267 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 268 | /** 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] | 269 | static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 270 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 271 | /** |
| 272 | * Lock protecting internal state. Must not call out into window |
| 273 | * manager with lock held. (This lock will be acquired in places |
| 274 | * where the window manager is calling in with its own lock held.) |
| 275 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 276 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 277 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 278 | Context mContext; |
| 279 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 280 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 281 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 282 | PowerManager mPowerManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 283 | ActivityManagerInternal mActivityManagerInternal; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 284 | DreamManagerInternal mDreamManagerInternal; |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 285 | PowerManagerInternal mPowerManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 286 | IStatusBarService mStatusBarService; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 287 | StatusBarManagerInternal mStatusBarManagerInternal; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 288 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 289 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 290 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 291 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 292 | AccessibilityManager mAccessibilityManager; |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 293 | BurnInProtectionHelper mBurnInProtectionHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 294 | AppOpsManager mAppOpsManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 295 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 296 | // Vibrator pattern for haptic feedback of a long press. |
| 297 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 298 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 299 | // Vibrator pattern for haptic feedback of virtual key press. |
| 300 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 301 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 302 | // Vibrator pattern for a short vibration. |
| 303 | long[] mKeyboardTapVibePattern; |
| 304 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 305 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 306 | long[] mClockTickVibePattern; |
| 307 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 308 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 309 | long[] mCalendarDateVibePattern; |
| 310 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 311 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 312 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 313 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 314 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 315 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 316 | |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 317 | // Vibrator pattern for haptic feedback of a context click. |
| 318 | long[] mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 319 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 320 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 321 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 322 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 323 | boolean mSafeMode; |
| 324 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 325 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 326 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 327 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 328 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 329 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 330 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 331 | int[] mNavigationBarHeightForRotationDefault = new int[4]; |
| 332 | int[] mNavigationBarWidthForRotationDefault = new int[4]; |
| 333 | int[] mNavigationBarHeightForRotationInCarMode = new int[4]; |
| 334 | int[] mNavigationBarWidthForRotationInCarMode = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 335 | |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 336 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 337 | // This is for car dock and this is updated from resource. |
| 338 | private boolean mEnableCarDockHomeCapture = true; |
| 339 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 340 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 341 | KeyguardServiceDelegate mKeyguardDelegate; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 342 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 343 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 344 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 345 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 346 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 347 | } |
| 348 | }; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 349 | final DrawnListener mKeyguardDrawnCallback = new DrawnListener() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 350 | @Override |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 351 | public void onDrawn() { |
| 352 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 353 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 354 | } |
| 355 | }; |
| 356 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 357 | GlobalActions mGlobalActions; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 358 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 359 | WindowState mLastInputMethodWindow = null; |
| 360 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 361 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 362 | // FIXME This state is shared between the input reader and handler thread. |
| 363 | // Technically it's broken and buggy but it has been like this for many years |
| 364 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 365 | // so that only one thread is involved in handling input policy. Unfortunately |
| 366 | // it's on a critical path for power management so we can't just post the work to the |
| 367 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 368 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 369 | volatile boolean mPowerKeyHandled; |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 370 | volatile boolean mBeganFromNonInteractive; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 371 | volatile int mPowerKeyPressCounter; |
| 372 | volatile boolean mEndCallKeyHandled; |
| 373 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 374 | boolean mRecentsVisible; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 375 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 376 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 377 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 378 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 379 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 380 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 381 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 382 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 383 | boolean mSystemBooted; |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 384 | private boolean mDeferBindKeyguard; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 385 | boolean mHdmiPlugged; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 386 | HdmiControl mHdmiControl; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 387 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 388 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 389 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 390 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 391 | int mCarDockRotation; |
| 392 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 393 | int mUndockedHdmiRotation; |
| 394 | int mDemoHdmiRotation; |
| 395 | boolean mDemoHdmiRotationLock; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 396 | int mDemoRotation; |
| 397 | boolean mDemoRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 398 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 399 | boolean mWakeGestureEnabledSetting; |
| 400 | MyWakeGestureListener mWakeGestureListener; |
| 401 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 402 | // Default display does not rotate, apps that require non-default orientation will have to |
| 403 | // have the orientation emulated. |
| 404 | private boolean mForceDefaultOrientation = false; |
| 405 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 406 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 407 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 408 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 409 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 410 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 411 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 412 | boolean mCarDockEnablesAccelerometer; |
| 413 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 414 | int mLidKeyboardAccessibility; |
| 415 | int mLidNavigationAccessibility; |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 416 | boolean mLidControlsScreenLock; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 417 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 418 | int mShortPressOnPowerBehavior; |
| 419 | int mLongPressOnPowerBehavior; |
| 420 | int mDoublePressOnPowerBehavior; |
| 421 | int mTriplePressOnPowerBehavior; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 422 | int mShortPressOnSleepBehavior; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 423 | int mShortPressWindowBehavior; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 424 | boolean mAwake; |
| 425 | boolean mScreenOnEarly; |
| 426 | boolean mScreenOnFully; |
| 427 | ScreenOnListener mScreenOnListener; |
| 428 | boolean mKeyguardDrawComplete; |
| 429 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 430 | boolean mOrientationSensorEnabled = false; |
| 431 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 432 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 433 | boolean mTranslucentDecorEnabled = true; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 434 | boolean mUseTvRouting; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 435 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 436 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 437 | |
| 438 | // The last window we were told about in focusChanged. |
| 439 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 440 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 441 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 442 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 443 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 444 | // The current size of the screen; really; extends into the overscan area of |
| 445 | // the screen and doesn't account for any system elements like the status bar. |
| 446 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 447 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 448 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 449 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 450 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 451 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 452 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 453 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 454 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 455 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 456 | // if the status bar can't be hidden; in that case it effectively carves out |
| 457 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 458 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 459 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 460 | // During layout, the current screen borders accounting for any currently |
| 461 | // visible system UI elements. |
| 462 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 463 | // For applications requesting stable content insets, these are them. |
| 464 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 465 | // For applications requesting stable content insets but have also set the |
| 466 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 467 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 468 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 469 | // During layout, the current screen borders with all outer decoration |
| 470 | // (status bar, input method dock) accounted for. |
| 471 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 472 | // During layout, the frame in which content should be displayed |
| 473 | // to the user, accounting for all screen decoration except for any |
| 474 | // space they deem as available for other content. This is usually |
| 475 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 476 | // content insets. |
| 477 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 478 | // During layout, the frame in which voice content should be displayed |
| 479 | // to the user, accounting for all screen decoration except for any |
| 480 | // space they deem as available for other content. |
| 481 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 482 | // 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] | 483 | // windows are placed. |
| 484 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 485 | // During layout, the layer at which the doc window is placed. |
| 486 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 487 | // During layout, this is the layer of the status bar. |
| 488 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 489 | int mLastSystemUiFlags; |
| 490 | // Bits that we are in the process of clearing, so we want to prevent |
| 491 | // them from being set by applications until everything has been updated |
| 492 | // to have them clear. |
| 493 | int mResettingSystemUiFlags = 0; |
| 494 | // Bits that we are currently always keeping cleared. |
| 495 | int mForceClearedSystemUiFlags = 0; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 496 | int mLastFullscreenStackSysUiFlags; |
| 497 | int mLastDockedStackSysUiFlags; |
| 498 | final Rect mNonDockedStackBounds = new Rect(); |
| 499 | final Rect mDockedStackBounds = new Rect(); |
| 500 | final Rect mLastNonDockedStackBounds = new Rect(); |
| 501 | final Rect mLastDockedStackBounds = new Rect(); |
| 502 | |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 503 | // What we last reported to system UI about whether the compatibility |
| 504 | // menu needs to be displayed. |
| 505 | boolean mLastFocusNeedsMenu = false; |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 506 | // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending. |
| 507 | private long mPendingPanicGestureUptime; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 508 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 509 | InputConsumer mInputConsumer = null; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 510 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 511 | static final Rect mTmpParentFrame = new Rect(); |
| 512 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 513 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 514 | static final Rect mTmpContentFrame = new Rect(); |
| 515 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 516 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 517 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 518 | static final Rect mTmpNavigationFrame = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 519 | static final Rect mTmpOutsetFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 520 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 521 | WindowState mTopFullscreenOpaqueWindowState; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 522 | WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 523 | WindowState mTopDockedOpaqueWindowState; |
| 524 | WindowState mTopDockedOpaqueOrDimmingWindowState; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 525 | HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 526 | HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 527 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 528 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 529 | boolean mForceStatusBarFromKeyguard; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 530 | private boolean mForceStatusBarTransparent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 531 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 532 | boolean mForcingShowNavBar; |
| 533 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 534 | |
| 535 | // States of keyguard dismiss. |
| 536 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 537 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 538 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 539 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 540 | |
| 541 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 542 | * be done once per window. */ |
| 543 | private WindowState mWinDismissingKeyguard; |
| 544 | |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 545 | /** When window is currently dismissing the keyguard, dismissing the keyguard must handle |
| 546 | * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN |
| 547 | * lock SIM card. This variable is used to record the previous keyguard secure state for |
| 548 | * monitoring secure state change on window dismissing keyguard. */ |
| 549 | private boolean mSecureDismissingKeyguard; |
| 550 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 551 | /** The window that is currently showing "over" the keyguard. If there is an app window |
| 552 | * belonging to another app on top of this the keyguard shows. If there is a fullscreen |
| 553 | * app window under this, still dismiss the keyguard but don't show the app underneath. Show |
| 554 | * the wallpaper. */ |
| 555 | private WindowState mWinShowWhenLocked; |
| 556 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 557 | boolean mShowingLockscreen; |
| 558 | boolean mShowingDream; |
| 559 | boolean mDreamingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 560 | boolean mDreamingSleepTokenNeeded; |
| 561 | SleepToken mDreamingSleepToken; |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 562 | SleepToken mScreenOffSleepToken; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 563 | boolean mKeyguardSecure; |
| 564 | boolean mKeyguardSecureIncludingHidden; |
| 565 | volatile boolean mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 566 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 567 | boolean mHomeConsumed; |
| 568 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 569 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 570 | Intent mCarDockIntent; |
| 571 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 572 | boolean mSearchKeyShortcutPending; |
| 573 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 574 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 575 | boolean mPendingMetaAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 576 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 577 | // support for activating the lock screen while the screen is on |
| 578 | boolean mAllowLockscreenWhenOn; |
| 579 | int mLockScreenTimeout; |
| 580 | boolean mLockScreenTimerActive; |
| 581 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 582 | // 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] | 583 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 584 | |
| 585 | // Behavior of POWER button while in-call and screen on. |
| 586 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 587 | int mIncallPowerBehavior; |
| 588 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 589 | Display mDisplay; |
| 590 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 591 | private int mDisplayRotation; |
| 592 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 593 | int mLandscapeRotation = 0; // default landscape rotation |
| 594 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 595 | int mPortraitRotation = 0; // default portrait rotation |
| 596 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 597 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 598 | int mOverscanLeft = 0; |
| 599 | int mOverscanTop = 0; |
| 600 | int mOverscanRight = 0; |
| 601 | int mOverscanBottom = 0; |
| 602 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 603 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 604 | private int mLongPressOnHomeBehavior; |
| 605 | |
| 606 | // What we do when the user double-taps on home |
| 607 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 608 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 609 | // Allowed theater mode wake actions |
| 610 | private boolean mAllowTheaterModeWakeFromKey; |
| 611 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 612 | private boolean mAllowTheaterModeWakeFromMotion; |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 613 | private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 614 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 615 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 616 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 617 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 618 | // Whether to support long press from power button in non-interactive mode |
| 619 | private boolean mSupportLongPressPowerWhenNonInteractive; |
| 620 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 621 | // Whether to go to sleep entering theater mode from power button |
| 622 | private boolean mGoToSleepOnButtonPressTheaterMode; |
| 623 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 624 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 625 | // Time to volume and power must be pressed within this interval of each other. |
| 626 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 627 | // Increase the chord delay when taking a screenshot from the keyguard |
| 628 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 629 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 630 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 631 | private long mScreenshotChordVolumeDownKeyTime; |
| 632 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
| 633 | private boolean mScreenshotChordVolumeUpKeyTriggered; |
| 634 | private boolean mScreenshotChordPowerKeyTriggered; |
| 635 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 636 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 637 | /* The number of steps between min and max brightness */ |
| 638 | private static final int BRIGHTNESS_STEPS = 10; |
| 639 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 640 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 641 | ShortcutManager mShortcutManager; |
| 642 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 643 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 644 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 645 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 646 | private int mCurrentUserId; |
| 647 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 648 | // Maps global key codes to the components that will handle them. |
| 649 | private GlobalKeyManager mGlobalKeyManager; |
| 650 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 651 | // Fallback actions by key code. |
| 652 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 653 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 654 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 655 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 656 | = new LogDecelerateInterpolator(100, 0); |
| 657 | |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 658 | private boolean mForceWindowDrawsStatusBarBackground; |
| 659 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 660 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 661 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 662 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 663 | 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] | 664 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 665 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 666 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 667 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 668 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 669 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 670 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 671 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 672 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 673 | private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 674 | private static final int MSG_REQUEST_TRANSIENT_BARS = 16; |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 675 | private static final int MSG_REQUEST_TV_PICTURE_IN_PICTURE = 17; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 676 | |
| 677 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0; |
| 678 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 679 | |
| 680 | private class PolicyHandler extends Handler { |
| 681 | @Override |
| 682 | public void handleMessage(Message msg) { |
| 683 | switch (msg.what) { |
| 684 | case MSG_ENABLE_POINTER_LOCATION: |
| 685 | enablePointerLocation(); |
| 686 | break; |
| 687 | case MSG_DISABLE_POINTER_LOCATION: |
| 688 | disablePointerLocation(); |
| 689 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 690 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 691 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 692 | break; |
| 693 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 694 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 695 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 696 | case MSG_DISPATCH_SHOW_RECENTS: |
| 697 | showRecentApps(false); |
| 698 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 699 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 700 | showGlobalActionsInternal(); |
| 701 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 702 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 703 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 704 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 705 | break; |
| 706 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 707 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 708 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 709 | break; |
| 710 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 711 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 712 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 713 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 714 | case MSG_HIDE_BOOT_MESSAGE: |
| 715 | handleHideBootMessage(); |
| 716 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 717 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 718 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 719 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 720 | case MSG_POWER_DELAYED_PRESS: |
| 721 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 722 | finishPowerKeyPress(); |
| 723 | break; |
| 724 | case MSG_POWER_LONG_PRESS: |
| 725 | powerLongPress(); |
| 726 | break; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 727 | case MSG_UPDATE_DREAMING_SLEEP_TOKEN: |
| 728 | updateDreamingSleepToken(msg.arg1 != 0); |
| 729 | break; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 730 | case MSG_REQUEST_TRANSIENT_BARS: |
| 731 | WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ? |
| 732 | mStatusBar : mNavigationBar; |
| 733 | if (targetBar != null) { |
| 734 | requestTransientBars(targetBar); |
| 735 | } |
| 736 | break; |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 737 | case MSG_REQUEST_TV_PICTURE_IN_PICTURE: |
| 738 | requestTvPictureInPictureInternal(); |
| 739 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 744 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 745 | @Override |
| 746 | public void onUEvent(UEventObserver.UEvent event) { |
| 747 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 748 | } |
| 749 | }; |
| 750 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 751 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 752 | SettingsObserver(Handler handler) { |
| 753 | super(handler); |
| 754 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 755 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 756 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 757 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 758 | ContentResolver resolver = mContext.getContentResolver(); |
| 759 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 760 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 761 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 762 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 763 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 764 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 765 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 766 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 767 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 768 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 769 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 770 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 771 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 772 | Settings.System.USER_ROTATION), false, this, |
| 773 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 774 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 775 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 776 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 777 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 778 | Settings.System.POINTER_LOCATION), false, this, |
| 779 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 780 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 781 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 782 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 783 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 784 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 785 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 786 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 787 | Settings.Global.POLICY_CONTROL), false, this, |
| 788 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 789 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 793 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 794 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 795 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 796 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 797 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 798 | class MyWakeGestureListener extends WakeGestureListener { |
| 799 | MyWakeGestureListener(Context context, Handler handler) { |
| 800 | super(context, handler); |
| 801 | } |
| 802 | |
| 803 | @Override |
| 804 | public void onWakeUp() { |
| 805 | synchronized (mLock) { |
| 806 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 807 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 808 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture, |
| 809 | "android.policy:GESTURE"); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 810 | } |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 815 | class MyOrientationListener extends WindowOrientationListener { |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 816 | private final Runnable mUpdateRotationRunnable = new Runnable() { |
| 817 | @Override |
| 818 | public void run() { |
Tim Murray | 1f40764 | 2015-10-01 17:07:12 -0700 | [diff] [blame] | 819 | // send interaction hint to improve redraw performance |
| 820 | mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 821 | updateRotation(false); |
| 822 | } |
| 823 | }; |
| 824 | |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 825 | MyOrientationListener(Context context, Handler handler) { |
| 826 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 827 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 828 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 829 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 830 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 831 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 832 | mHandler.post(mUpdateRotationRunnable); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 833 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 834 | } |
| 835 | MyOrientationListener mOrientationListener; |
| 836 | |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 837 | private final StatusBarController mStatusBarController = new StatusBarController(); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 838 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 839 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 840 | View.NAVIGATION_BAR_TRANSIENT, |
| 841 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 842 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 843 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 844 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, |
| 845 | View.NAVIGATION_BAR_TRANSPARENT); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 846 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 847 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 848 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 849 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 850 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 851 | IStatusBarService getStatusBarService() { |
| 852 | synchronized (mServiceAquireLock) { |
| 853 | if (mStatusBarService == null) { |
| 854 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 855 | ServiceManager.getService("statusbar")); |
| 856 | } |
| 857 | return mStatusBarService; |
| 858 | } |
| 859 | } |
| 860 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 861 | StatusBarManagerInternal getStatusBarManagerInternal() { |
| 862 | synchronized (mServiceAquireLock) { |
| 863 | if (mStatusBarManagerInternal == null) { |
| 864 | mStatusBarManagerInternal = |
| 865 | LocalServices.getService(StatusBarManagerInternal.class); |
| 866 | } |
| 867 | return mStatusBarManagerInternal; |
| 868 | } |
| 869 | } |
| 870 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 871 | /* |
| 872 | * We always let the sensor be switched on by default except when |
| 873 | * the user has explicitly disabled sensor based rotation or when the |
| 874 | * screen is switched off. |
| 875 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 876 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 877 | if (mSupportAutoRotation) { |
| 878 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 879 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 880 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 881 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 882 | // If the application has explicitly requested to follow the |
| 883 | // orientation, then we need to turn the sensor on. |
| 884 | return true; |
| 885 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 886 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 887 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 888 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 889 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 890 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 891 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 892 | // orientation management, |
| 893 | return true; |
| 894 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 895 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 896 | // If the setting for using the sensor by default is enabled, then |
| 897 | // we will always leave it on. Note that the user could go to |
| 898 | // a window that forces an orientation that does not use the |
| 899 | // sensor and in theory we could turn it off... however, when next |
| 900 | // turning it on we won't have a good value for the current |
| 901 | // orientation for a little bit, which can cause orientation |
| 902 | // changes to lag, so we'd like to keep it always on. (It will |
| 903 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 904 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 905 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 906 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 907 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 908 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 909 | /* |
| 910 | * Various use cases for invoking this function |
| 911 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 912 | * 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] | 913 | * if not already enabled |
| 914 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 915 | * already enabled |
| 916 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 917 | * screen turning on and current app has nosensor based orientation, do nothing |
| 918 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 919 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 920 | if (!mOrientationListener.canDetectOrientation()) { |
| 921 | // If sensor is turned off or nonexistent for some reason |
| 922 | return; |
| 923 | } |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 924 | // Could have been invoked due to screen turning on or off or |
| 925 | // change of the currently visible window's orientation. |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 926 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 927 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 928 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled |
| 929 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 930 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 931 | boolean disable = true; |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 932 | // Note: We postpone the rotating of the screen until the keyguard as well as the |
| 933 | // window manager have reported a draw complete. |
| 934 | if (mScreenOnEarly && mAwake && |
| 935 | mKeyguardDrawComplete && mWindowManagerDrawComplete) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 936 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 937 | disable = false; |
| 938 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 939 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 940 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 941 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 942 | mOrientationSensorEnabled = true; |
| 943 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 944 | } |
| 945 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 946 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 947 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 948 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 949 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 950 | mOrientationSensorEnabled = false; |
| 951 | } |
| 952 | } |
| 953 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 954 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 955 | // Hold a wake lock until the power key is released. |
| 956 | if (!mPowerKeyWakeLock.isHeld()) { |
| 957 | mPowerKeyWakeLock.acquire(); |
| 958 | } |
| 959 | |
| 960 | // Cancel multi-press detection timeout. |
| 961 | if (mPowerKeyPressCounter != 0) { |
| 962 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 963 | } |
| 964 | |
| 965 | // Detect user pressing the power button in panic when an application has |
| 966 | // taken over the whole screen. |
| 967 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
Craig Mautner | 0124980e9 | 2014-11-30 21:15:34 -0800 | [diff] [blame] | 968 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags)); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 969 | if (panic) { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 970 | mHandler.post(mHiddenNavPanic); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | // Latch power key state to detect screenshot chord. |
| 974 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 975 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 976 | mScreenshotChordPowerKeyTriggered = true; |
| 977 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 978 | interceptScreenshotChord(); |
| 979 | } |
| 980 | |
| 981 | // Stop ringing or end call if configured to do so when power is pressed. |
| 982 | TelecomManager telecomManager = getTelecommService(); |
| 983 | boolean hungUp = false; |
| 984 | if (telecomManager != null) { |
| 985 | if (telecomManager.isRinging()) { |
| 986 | // Pressing Power while there's a ringing incoming |
| 987 | // call should silence the ringer. |
| 988 | telecomManager.silenceRinger(); |
| 989 | } else if ((mIncallPowerBehavior |
| 990 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 991 | && telecomManager.isInCall() && interactive) { |
| 992 | // Otherwise, if "Power button ends call" is enabled, |
| 993 | // the Power button will hang up any current active call. |
| 994 | hungUp = telecomManager.endCall(); |
| 995 | } |
| 996 | } |
| 997 | |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 998 | GestureLauncherService gestureService = LocalServices.getService( |
| 999 | GestureLauncherService.class); |
| 1000 | boolean gesturedServiceIntercepted = false; |
| 1001 | if (gestureService != null) { |
| 1002 | gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive); |
| 1003 | } |
| 1004 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1005 | // If the power key has still not yet been handled, then detect short |
| 1006 | // press, long press, or multi press and decide what to do. |
| 1007 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1008 | || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1009 | if (!mPowerKeyHandled) { |
| 1010 | if (interactive) { |
| 1011 | // When interactive, we're already awake. |
| 1012 | // Wait for a long press or for the button to be released to decide what to do. |
| 1013 | if (hasLongPressOnPowerBehavior()) { |
| 1014 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 1015 | msg.setAsynchronous(true); |
| 1016 | mHandler.sendMessageDelayed(msg, |
| 1017 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 1018 | } |
| 1019 | } else { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1020 | wakeUpFromPowerKey(event.getDownTime()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1021 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1022 | if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { |
| 1023 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 1024 | msg.setAsynchronous(true); |
| 1025 | mHandler.sendMessageDelayed(msg, |
| 1026 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1027 | mBeganFromNonInteractive = true; |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1028 | } else { |
| 1029 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1030 | |
| 1031 | if (maxCount <= 1) { |
| 1032 | mPowerKeyHandled = true; |
| 1033 | } else { |
| 1034 | mBeganFromNonInteractive = true; |
| 1035 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1036 | } |
| 1037 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1038 | } |
| 1039 | } |
| 1040 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1041 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 1042 | final boolean handled = canceled || mPowerKeyHandled; |
| 1043 | mScreenshotChordPowerKeyTriggered = false; |
| 1044 | cancelPendingScreenshotChordAction(); |
| 1045 | cancelPendingPowerKeyAction(); |
| 1046 | |
| 1047 | if (!handled) { |
| 1048 | // Figure out how to handle the key now that it has been released. |
| 1049 | mPowerKeyPressCounter += 1; |
| 1050 | |
| 1051 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1052 | final long eventTime = event.getDownTime(); |
| 1053 | if (mPowerKeyPressCounter < maxCount) { |
| 1054 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 1055 | // Continue holding the wake lock. |
| 1056 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 1057 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 1058 | msg.setAsynchronous(true); |
| 1059 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout()); |
| 1060 | return; |
| 1061 | } |
| 1062 | |
| 1063 | // No other actions. Handle it immediately. |
| 1064 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1065 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1066 | |
| 1067 | // Done. Reset our state. |
| 1068 | finishPowerKeyPress(); |
| 1069 | } |
| 1070 | |
| 1071 | private void finishPowerKeyPress() { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1072 | mBeganFromNonInteractive = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1073 | mPowerKeyPressCounter = 0; |
| 1074 | if (mPowerKeyWakeLock.isHeld()) { |
| 1075 | mPowerKeyWakeLock.release(); |
| 1076 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | private void cancelPendingPowerKeyAction() { |
| 1080 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1081 | mPowerKeyHandled = true; |
| 1082 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1083 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 1087 | if (mScreenOnEarly && !mScreenOnFully) { |
| 1088 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 1089 | + "already in the process of turning the screen on."); |
| 1090 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 1091 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1092 | |
| 1093 | if (count == 2) { |
| 1094 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 1095 | } else if (count == 3) { |
| 1096 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1097 | } else if (interactive && !mBeganFromNonInteractive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1098 | switch (mShortPressOnPowerBehavior) { |
| 1099 | case SHORT_PRESS_POWER_NOTHING: |
| 1100 | break; |
| 1101 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 1102 | mPowerManager.goToSleep(eventTime, |
| 1103 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1104 | break; |
| 1105 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 1106 | mPowerManager.goToSleep(eventTime, |
| 1107 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1108 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1109 | break; |
| 1110 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 1111 | mPowerManager.goToSleep(eventTime, |
| 1112 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1113 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1114 | launchHomeFromHotKey(); |
| 1115 | break; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1116 | case SHORT_PRESS_POWER_GO_HOME: |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 1117 | launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/); |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1118 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 1124 | switch (behavior) { |
| 1125 | case MULTI_PRESS_POWER_NOTHING: |
| 1126 | break; |
| 1127 | case MULTI_PRESS_POWER_THEATER_MODE: |
Bryce Lee | 3ae447e | 2015-06-30 12:31:41 -0700 | [diff] [blame] | 1128 | if (!isUserSetupComplete()) { |
| 1129 | Slog.i(TAG, "Ignoring toggling theater mode - device not setup."); |
| 1130 | break; |
| 1131 | } |
| 1132 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1133 | if (isTheaterModeEnabled()) { |
| 1134 | Slog.i(TAG, "Toggling theater mode off."); |
| 1135 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1136 | Settings.Global.THEATER_MODE_ON, 0); |
| 1137 | if (!interactive) { |
| 1138 | wakeUpFromPowerKey(eventTime); |
| 1139 | } |
| 1140 | } else { |
| 1141 | Slog.i(TAG, "Toggling theater mode on."); |
| 1142 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1143 | Settings.Global.THEATER_MODE_ON, 1); |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1144 | |
| 1145 | if (mGoToSleepOnButtonPressTheaterMode && interactive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1146 | mPowerManager.goToSleep(eventTime, |
| 1147 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1148 | } |
| 1149 | } |
| 1150 | break; |
| 1151 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
Jeff Brown | 7b5be5e | 2014-11-12 18:45:31 -0800 | [diff] [blame] | 1152 | Slog.i(TAG, "Starting brightness boost."); |
| 1153 | if (!interactive) { |
| 1154 | wakeUpFromPowerKey(eventTime); |
| 1155 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1156 | mPowerManager.boostScreenBrightness(eventTime); |
| 1157 | break; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | private int getMaxMultiPressPowerCount() { |
| 1162 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1163 | return 3; |
| 1164 | } |
| 1165 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1166 | return 2; |
| 1167 | } |
| 1168 | return 1; |
| 1169 | } |
| 1170 | |
| 1171 | private void powerLongPress() { |
| 1172 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1173 | switch (behavior) { |
| 1174 | case LONG_PRESS_POWER_NOTHING: |
| 1175 | break; |
| 1176 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1177 | mPowerKeyHandled = true; |
| 1178 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1179 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 1180 | } |
| 1181 | showGlobalActionsInternal(); |
| 1182 | break; |
| 1183 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1184 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1185 | mPowerKeyHandled = true; |
| 1186 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1187 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1188 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1189 | break; |
| 1190 | } |
| 1191 | } |
| 1192 | |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1193 | private void sleepPress(long eventTime) { |
| 1194 | if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) { |
| 1195 | launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | private void sleepRelease(long eventTime) { |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1200 | switch (mShortPressOnSleepBehavior) { |
| 1201 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1202 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1203 | Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)"); |
| 1204 | mPowerManager.goToSleep(eventTime, |
| 1205 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1206 | break; |
| 1207 | } |
| 1208 | } |
| 1209 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1210 | private int getResolvedLongPressOnPowerBehavior() { |
| 1211 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1212 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1213 | } |
| 1214 | return mLongPressOnPowerBehavior; |
| 1215 | } |
| 1216 | |
| 1217 | private boolean hasLongPressOnPowerBehavior() { |
| 1218 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1222 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1223 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
| 1224 | && !mScreenshotChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1225 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1226 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1227 | && now <= mScreenshotChordPowerKeyTime |
| 1228 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1229 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1230 | cancelPendingPowerKeyAction(); |
| 1231 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1232 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1237 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1238 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1239 | // Double the time it takes to take a screenshot from the keyguard |
| 1240 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1241 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1242 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1243 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1246 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1247 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1250 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1251 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1252 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1253 | mEndCallKeyHandled = true; |
| 1254 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1255 | performAuditoryFeedbackForAccessibilityIfNeed(); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 1256 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1257 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1258 | } |
| 1259 | }; |
| 1260 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1261 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1262 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1263 | public void run() { |
| 1264 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1265 | } |
| 1266 | }; |
| 1267 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1268 | @Override |
| 1269 | public void showGlobalActions() { |
| 1270 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1271 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1272 | } |
| 1273 | |
| 1274 | void showGlobalActionsInternal() { |
| 1275 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1276 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1277 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1278 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1279 | final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1280 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1281 | if (keyguardShowing) { |
| 1282 | // since it took two seconds of long press to bring this up, |
| 1283 | // 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] | 1284 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1289 | return Settings.Global.getInt( |
| 1290 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1291 | } |
| 1292 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1293 | boolean isUserSetupComplete() { |
| 1294 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1295 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 1296 | } |
| 1297 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1298 | private void handleShortPressOnHome() { |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1299 | // Turn on the connected TV and switch HDMI input if we're a HDMI playback device. |
| 1300 | getHdmiControl().turnOnTv(); |
| 1301 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1302 | // If there's a dream running then use home to escape the dream |
| 1303 | // but don't actually go home. |
| 1304 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1305 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1306 | return; |
| 1307 | } |
| 1308 | |
| 1309 | // Go home! |
| 1310 | launchHomeFromHotKey(); |
| 1311 | } |
| 1312 | |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1313 | /** |
| 1314 | * Creates an accessor to HDMI control service that performs the operation of |
| 1315 | * turning on TV (optional) and switching input to us. If HDMI control service |
| 1316 | * is not available or we're not a HDMI playback device, the operation is no-op. |
| 1317 | */ |
| 1318 | private HdmiControl getHdmiControl() { |
| 1319 | if (null == mHdmiControl) { |
| 1320 | HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService( |
| 1321 | Context.HDMI_CONTROL_SERVICE); |
| 1322 | HdmiPlaybackClient client = null; |
| 1323 | if (manager != null) { |
| 1324 | client = manager.getPlaybackClient(); |
| 1325 | } |
| 1326 | mHdmiControl = new HdmiControl(client); |
| 1327 | } |
| 1328 | return mHdmiControl; |
| 1329 | } |
| 1330 | |
| 1331 | private static class HdmiControl { |
| 1332 | private final HdmiPlaybackClient mClient; |
| 1333 | |
| 1334 | private HdmiControl(HdmiPlaybackClient client) { |
| 1335 | mClient = client; |
| 1336 | } |
| 1337 | |
| 1338 | public void turnOnTv() { |
| 1339 | if (mClient == null) { |
| 1340 | return; |
| 1341 | } |
| 1342 | mClient.oneTouchPlay(new OneTouchPlayCallback() { |
| 1343 | @Override |
| 1344 | public void onComplete(int result) { |
| 1345 | if (result != HdmiControlManager.RESULT_SUCCESS) { |
| 1346 | Log.w(TAG, "One touch play failed: " + result); |
| 1347 | } |
| 1348 | } |
| 1349 | }); |
| 1350 | } |
| 1351 | } |
| 1352 | |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1353 | private void handleLongPressOnHome(int deviceId, KeyEvent event) { |
| 1354 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) { |
| 1355 | return; |
| 1356 | } |
| 1357 | mHomeConsumed = true; |
| 1358 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1359 | |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1360 | switch (mLongPressOnHomeBehavior) { |
| 1361 | case LONG_PRESS_HOME_RECENT_SYSTEM_UI: |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1362 | toggleRecentApps(); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1363 | break; |
| 1364 | case LONG_PRESS_HOME_ASSIST: |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 1365 | launchAssistAction(null, deviceId); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1366 | break; |
| 1367 | case LONG_PRESS_HOME_PICTURE_IN_PICTURE: |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1368 | requestTvPictureInPicture(event); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1369 | break; |
| 1370 | default: |
| 1371 | Log.w(TAG, "Not defined home long press behavior: " + mLongPressOnHomeBehavior); |
| 1372 | break; |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1373 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1374 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1375 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1376 | private void handleDoubleTapOnHome() { |
| 1377 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1378 | mHomeConsumed = true; |
| 1379 | toggleRecentApps(); |
| 1380 | } |
| 1381 | } |
| 1382 | |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1383 | private void requestTvPictureInPicture(KeyEvent event) { |
| 1384 | if (DEBUG_INPUT) Log.d(TAG, "requestTvPictureInPicture event=" + event); |
| 1385 | mHandler.removeMessages(MSG_REQUEST_TV_PICTURE_IN_PICTURE); |
| 1386 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TV_PICTURE_IN_PICTURE); |
| 1387 | msg.setAsynchronous(true); |
| 1388 | msg.sendToTarget(); |
| 1389 | } |
| 1390 | |
| 1391 | private void requestTvPictureInPictureInternal() { |
| 1392 | try { |
| 1393 | IStatusBarService statusbar = getStatusBarService(); |
| 1394 | if (statusbar != null) { |
| 1395 | statusbar.requestTvPictureInPicture(); |
| 1396 | } |
| 1397 | } catch (RemoteException|IllegalArgumentException e) { |
| 1398 | Slog.e(TAG, "Cannot handle picture-in-picture key", e); |
| 1399 | // re-acquire status bar service next time it is needed. |
| 1400 | mStatusBarService = null; |
| 1401 | } |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1402 | } |
| 1403 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1404 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1405 | @Override |
| 1406 | public void run() { |
| 1407 | if (mHomeDoubleTapPending) { |
| 1408 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1409 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1410 | } |
| 1411 | } |
| 1412 | }; |
| 1413 | |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1414 | private boolean isRoundWindow() { |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1415 | return mContext.getResources().getConfiguration().isScreenRound(); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1416 | } |
| 1417 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1418 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1419 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1420 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1421 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1422 | mContext = context; |
| 1423 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1424 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1425 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 1426 | mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1427 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1428 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1429 | mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1430 | |
| 1431 | // Init display burn-in protection |
| 1432 | boolean burnInProtectionEnabled = context.getResources().getBoolean( |
| 1433 | com.android.internal.R.bool.config_enableBurnInProtection); |
| 1434 | // Allow a system property to override this. Used by developer settings. |
| 1435 | boolean burnInProtectionDevMode = |
| 1436 | SystemProperties.getBoolean("persist.debug.force_burn_in", false); |
| 1437 | if (burnInProtectionEnabled || burnInProtectionDevMode) { |
| 1438 | final int minHorizontal; |
| 1439 | final int maxHorizontal; |
| 1440 | final int minVertical; |
| 1441 | final int maxVertical; |
| 1442 | final int maxRadius; |
| 1443 | if (burnInProtectionDevMode) { |
| 1444 | minHorizontal = -8; |
| 1445 | maxHorizontal = 8; |
| 1446 | minVertical = -8; |
| 1447 | maxVertical = -4; |
| 1448 | maxRadius = (isRoundWindow()) ? 6 : -1; |
| 1449 | } else { |
| 1450 | Resources resources = context.getResources(); |
| 1451 | minHorizontal = resources.getInteger( |
| 1452 | com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); |
| 1453 | maxHorizontal = resources.getInteger( |
| 1454 | com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); |
| 1455 | minVertical = resources.getInteger( |
| 1456 | com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); |
| 1457 | maxVertical = resources.getInteger( |
| 1458 | com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); |
| 1459 | maxRadius = resources.getInteger( |
| 1460 | com.android.internal.R.integer.config_burnInProtectionMaxRadius); |
| 1461 | } |
| 1462 | mBurnInProtectionHelper = new BurnInProtectionHelper( |
| 1463 | context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 1464 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1465 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1466 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1467 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1468 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1469 | try { |
| 1470 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 1471 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1472 | mSettingsObserver = new SettingsObserver(mHandler); |
| 1473 | mSettingsObserver.observe(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1474 | mShortcutManager = new ShortcutManager(context); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 1475 | mUiMode = context.getResources().getInteger( |
| 1476 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1477 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1478 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 1479 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1480 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 1481 | mEnableCarDockHomeCapture = context.getResources().getBoolean( |
| 1482 | com.android.internal.R.bool.config_enableCarDockHomeLaunch); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1483 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1484 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 1485 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1486 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1487 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1488 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1489 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1490 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1491 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1492 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1493 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1494 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1495 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1496 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1497 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1498 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1499 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1500 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1501 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1502 | mCarDockRotation = readRotation( |
| 1503 | com.android.internal.R.integer.config_carDockRotation); |
| 1504 | mDeskDockRotation = readRotation( |
| 1505 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1506 | mUndockedHdmiRotation = readRotation( |
| 1507 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1508 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1509 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1510 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1511 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1512 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1513 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1514 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1515 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 1516 | mLidControlsScreenLock = mContext.getResources().getBoolean( |
| 1517 | com.android.internal.R.bool.config_lidControlsScreenLock); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1518 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1519 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1520 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1521 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1522 | |
| 1523 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 1524 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 1525 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 1526 | || mContext.getResources().getBoolean( |
| 1527 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 1528 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 1529 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 1530 | mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( |
| 1531 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1532 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 1533 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 1534 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 1535 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 1536 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 1537 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 1538 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1539 | mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( |
| 1540 | com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); |
| 1541 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1542 | mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( |
| 1543 | com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); |
| 1544 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1545 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1546 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 1547 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1548 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 1549 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1550 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 1551 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1552 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1553 | mShortPressOnSleepBehavior = mContext.getResources().getInteger( |
| 1554 | com.android.internal.R.integer.config_shortPressOnSleepBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1555 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 1556 | mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 1557 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1558 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1559 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1560 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1561 | Context.ACCESSIBILITY_SERVICE); |
| 1562 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1563 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1564 | IntentFilter filter = new IntentFilter(); |
| 1565 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1566 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1567 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1568 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1569 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1570 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1571 | if (intent != null) { |
| 1572 | // Retrieve current sticky dock event broadcast. |
| 1573 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1574 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1575 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1576 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1577 | // register for dream-related broadcasts |
| 1578 | filter = new IntentFilter(); |
| 1579 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1580 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1581 | context.registerReceiver(mDreamReceiver, filter); |
| 1582 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1583 | // register for multiuser-relevant broadcasts |
| 1584 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1585 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1586 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1587 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1588 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1589 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1590 | @Override |
| 1591 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1592 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1593 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1594 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1595 | } |
| 1596 | @Override |
| 1597 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1598 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1599 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1600 | } |
| 1601 | } |
| 1602 | @Override |
| 1603 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1604 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1605 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1606 | } |
| 1607 | } |
| 1608 | @Override |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1609 | public void onFling(int duration) { |
| 1610 | if (mPowerManagerInternal != null) { |
| 1611 | mPowerManagerInternal.powerHint( |
| 1612 | PowerManagerInternal.POWER_HINT_INTERACTION, duration); |
| 1613 | } |
| 1614 | } |
| 1615 | @Override |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1616 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1617 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1618 | } |
Adrian Roos | 3595be4 | 2015-03-05 16:31:15 +0100 | [diff] [blame] | 1619 | @Override |
| 1620 | public void onDown() { |
| 1621 | mOrientationListener.onTouchStart(); |
| 1622 | } |
| 1623 | @Override |
| 1624 | public void onUpOrCancel() { |
| 1625 | mOrientationListener.onTouchEnd(); |
| 1626 | } |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 1627 | @Override |
| 1628 | public void onMouseHoverAtTop() { |
| 1629 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1630 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 1631 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS; |
| 1632 | mHandler.sendMessageDelayed(msg, 500); |
| 1633 | } |
| 1634 | @Override |
| 1635 | public void onMouseHoverAtBottom() { |
| 1636 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1637 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 1638 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION; |
| 1639 | mHandler.sendMessageDelayed(msg, 500); |
| 1640 | } |
| 1641 | @Override |
| 1642 | public void onMouseLeaveFromEdge() { |
| 1643 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1644 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1645 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1646 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1647 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1648 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1649 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1650 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1651 | com.android.internal.R.array.config_longPressVibePattern); |
| 1652 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1653 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1654 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1655 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1656 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1657 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1658 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1659 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1660 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1661 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1662 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1663 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 1664 | mContextClickVibePattern = getLongIntArray(mContext.getResources(), |
| 1665 | com.android.internal.R.array.config_contextClickVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1666 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1667 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1668 | com.android.internal.R.bool.config_enableScreenshotChord); |
Jorim Jaggi | 406585a | 2015-12-21 10:58:56 +0100 | [diff] [blame] | 1669 | mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean( |
| 1670 | R.bool.config_forceWindowDrawsStatusBarBackground); |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1671 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1672 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1673 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1674 | // Controls rotation and the like. |
| 1675 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1676 | |
| 1677 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1678 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 1679 | startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 1680 | finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1681 | } |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 1682 | |
| 1683 | mWindowManagerInternal.registerAppTransitionListener( |
| 1684 | mStatusBarController.getAppTransitionListener()); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1687 | /** |
| 1688 | * Read values from config.xml that may be overridden depending on |
| 1689 | * the configuration of the device. |
| 1690 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1691 | */ |
| 1692 | private void readConfigurationDependentBehaviors() { |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1693 | final Resources res = mContext.getResources(); |
| 1694 | |
| 1695 | mLongPressOnHomeBehavior = res.getInteger( |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1696 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1697 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1698 | mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) { |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1699 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1700 | } |
| 1701 | |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1702 | mDoubleTapOnHomeBehavior = res.getInteger( |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1703 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1704 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1705 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1706 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1707 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 1708 | |
| 1709 | mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING; |
| 1710 | if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) { |
| 1711 | mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE; |
| 1712 | } |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1715 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1716 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1717 | // This method might be called before the policy has been fully initialized |
| 1718 | // or for other displays we don't care about. |
| 1719 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1720 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1721 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1722 | mDisplay = display; |
| 1723 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1724 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1725 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1726 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1727 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1728 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1729 | mLandscapeRotation = Surface.ROTATION_0; |
| 1730 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1731 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1732 | mPortraitRotation = Surface.ROTATION_90; |
| 1733 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1734 | } else { |
| 1735 | mPortraitRotation = Surface.ROTATION_270; |
| 1736 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1737 | } |
| 1738 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1739 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1740 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1741 | mPortraitRotation = Surface.ROTATION_0; |
| 1742 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1743 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1744 | mLandscapeRotation = Surface.ROTATION_270; |
| 1745 | mSeascapeRotation = Surface.ROTATION_90; |
| 1746 | } else { |
| 1747 | mLandscapeRotation = Surface.ROTATION_90; |
| 1748 | mSeascapeRotation = Surface.ROTATION_270; |
| 1749 | } |
| 1750 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1751 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1752 | mStatusBarHeight = |
| 1753 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1754 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1755 | // Height of the navigation bar when presented horizontally at bottom |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1756 | mNavigationBarHeightForRotationDefault[mPortraitRotation] = |
| 1757 | mNavigationBarHeightForRotationDefault[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1758 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1759 | mNavigationBarHeightForRotationDefault[mLandscapeRotation] = |
| 1760 | mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize( |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1761 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1762 | |
| 1763 | // Width of the navigation bar when presented vertically along one side |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1764 | mNavigationBarWidthForRotationDefault[mPortraitRotation] = |
| 1765 | mNavigationBarWidthForRotationDefault[mUpsideDownRotation] = |
| 1766 | mNavigationBarWidthForRotationDefault[mLandscapeRotation] = |
| 1767 | mNavigationBarWidthForRotationDefault[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1768 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1769 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1770 | // Height of the navigation bar when presented horizontally at bottom |
| 1771 | mNavigationBarHeightForRotationInCarMode[mPortraitRotation] = |
| 1772 | mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] = |
| 1773 | res.getDimensionPixelSize( |
| 1774 | com.android.internal.R.dimen.navigation_bar_height_car_mode); |
| 1775 | mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] = |
| 1776 | mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1777 | com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode); |
| 1778 | |
| 1779 | // Width of the navigation bar when presented vertically along one side |
| 1780 | mNavigationBarWidthForRotationInCarMode[mPortraitRotation] = |
| 1781 | mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] = |
| 1782 | mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] = |
| 1783 | mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] = |
| 1784 | res.getDimensionPixelSize( |
| 1785 | com.android.internal.R.dimen.navigation_bar_width_car_mode); |
| 1786 | |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1787 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1788 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1789 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1790 | |
Devin Kim | d7b12b4 | 2014-05-05 14:34:58 -0700 | [diff] [blame] | 1791 | // Allow the navigation bar to move on non-square small devices (phones). |
| 1792 | mNavigationBarCanMove = width != height && shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1793 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1794 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1795 | // Allow a system property to override this. Used by the emulator. |
| 1796 | // See also hasNavigationBar(). |
| 1797 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1798 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1799 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1800 | } else if ("0".equals(navBarOverride)) { |
| 1801 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1802 | } |
| 1803 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1804 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1805 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1806 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1807 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1808 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1809 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1810 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1811 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1812 | |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 1813 | // For demo purposes, allow the rotation of the remote display to be controlled. |
| 1814 | // By default, remote display locks rotation to landscape. |
| 1815 | if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { |
| 1816 | mDemoRotation = mPortraitRotation; |
| 1817 | } else { |
| 1818 | mDemoRotation = mLandscapeRotation; |
| 1819 | } |
| 1820 | mDemoRotationLock = SystemProperties.getBoolean( |
| 1821 | "persist.demo.rotationlock", false); |
| 1822 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1823 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1824 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1825 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1826 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1827 | // For debug purposes the next line turns this feature off with: |
| 1828 | // $ adb shell setprop config.override_forced_orient true |
| 1829 | // $ adb shell wm size reset |
| 1830 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1831 | } |
| 1832 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1833 | /** |
| 1834 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1835 | * navigation bar and touch exploration is not enabled |
| 1836 | */ |
| 1837 | private boolean canHideNavigationBar() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 1838 | return mHasNavigationBar; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1839 | } |
| 1840 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1841 | @Override |
| 1842 | public boolean isDefaultOrientationForced() { |
| 1843 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1846 | @Override |
| 1847 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1848 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1849 | mOverscanLeft = left; |
| 1850 | mOverscanTop = top; |
| 1851 | mOverscanRight = right; |
| 1852 | mOverscanBottom = bottom; |
| 1853 | } |
| 1854 | } |
| 1855 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1856 | public void updateSettings() { |
| 1857 | ContentResolver resolver = mContext.getContentResolver(); |
| 1858 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1859 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1860 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1861 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1862 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1863 | UserHandle.USER_CURRENT); |
| 1864 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1865 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1866 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1867 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1868 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1869 | // Configure wake gesture. |
| 1870 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 1871 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 1872 | UserHandle.USER_CURRENT) != 0; |
| 1873 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 1874 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 1875 | updateWakeGestureListenerLp(); |
| 1876 | } |
| 1877 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1878 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1879 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1880 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1881 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1882 | if (mUserRotation != userRotation) { |
| 1883 | mUserRotation = userRotation; |
| 1884 | updateRotation = true; |
| 1885 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1886 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1887 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1888 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1889 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1890 | if (mUserRotationMode != userRotationMode) { |
| 1891 | mUserRotationMode = userRotationMode; |
| 1892 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1893 | updateOrientationListenerLp(); |
| 1894 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1895 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1896 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1897 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1898 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1899 | if (mPointerLocationMode != pointerLocation) { |
| 1900 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1901 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1902 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1903 | } |
| 1904 | } |
| 1905 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1906 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1907 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1908 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1909 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1910 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1911 | if (mHasSoftInput != hasSoftInput) { |
| 1912 | mHasSoftInput = hasSoftInput; |
| 1913 | updateRotation = true; |
| 1914 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1915 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1916 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1917 | } |
tiger_huang | cc6366d | 2015-06-29 17:17:30 +0800 | [diff] [blame] | 1918 | } |
| 1919 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1920 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1921 | } |
| 1922 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1923 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1924 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1927 | private void updateWakeGestureListenerLp() { |
| 1928 | if (shouldEnableWakeGestureLp()) { |
| 1929 | mWakeGestureListener.requestWakeUpTrigger(); |
| 1930 | } else { |
| 1931 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1936 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1937 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 1938 | && mWakeGestureListener.isSupported(); |
| 1939 | } |
| 1940 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1941 | private void enablePointerLocation() { |
| 1942 | if (mPointerLocationView == null) { |
| 1943 | mPointerLocationView = new PointerLocationView(mContext); |
| 1944 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1945 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1946 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1947 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1948 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1949 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1950 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1951 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1952 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1953 | if (ActivityManager.isHighEndGfx()) { |
| 1954 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1955 | lp.privateFlags |= |
| 1956 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1957 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1958 | lp.format = PixelFormat.TRANSLUCENT; |
| 1959 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1960 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1961 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1962 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1963 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1964 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1965 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1966 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1967 | |
| 1968 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1969 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1970 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 1971 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1972 | wm.removeView(mPointerLocationView); |
| 1973 | mPointerLocationView = null; |
| 1974 | } |
| 1975 | } |
| 1976 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1977 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1978 | try { |
| 1979 | int rotation = mContext.getResources().getInteger(resID); |
| 1980 | switch (rotation) { |
| 1981 | case 0: |
| 1982 | return Surface.ROTATION_0; |
| 1983 | case 90: |
| 1984 | return Surface.ROTATION_90; |
| 1985 | case 180: |
| 1986 | return Surface.ROTATION_180; |
| 1987 | case 270: |
| 1988 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1989 | } |
| 1990 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1991 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1992 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1993 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1997 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1998 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1999 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2000 | |
| 2001 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 2002 | |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 2003 | if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) |
| 2004 | || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) |
| 2005 | || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { |
| 2006 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
| 2007 | } |
| 2008 | |
| 2009 | if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { |
| 2010 | // Window manager will make sure these are okay. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2011 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2012 | } |
| 2013 | String permission = null; |
| 2014 | switch (type) { |
| 2015 | case TYPE_TOAST: |
| 2016 | // XXX right now the app process has complete control over |
| 2017 | // this... should introduce a token to let the system |
| 2018 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2019 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2020 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2021 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2022 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 2023 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2024 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2025 | case TYPE_VOICE_INTERACTION: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2026 | case TYPE_ACCESSIBILITY_OVERLAY: |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 2027 | case TYPE_QS_DIALOG: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 2028 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2029 | break; |
| 2030 | case TYPE_PHONE: |
| 2031 | case TYPE_PRIORITY_PHONE: |
| 2032 | case TYPE_SYSTEM_ALERT: |
| 2033 | case TYPE_SYSTEM_ERROR: |
| 2034 | case TYPE_SYSTEM_OVERLAY: |
| 2035 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2036 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2037 | break; |
| 2038 | default: |
| 2039 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 2040 | } |
| 2041 | if (permission != null) { |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2042 | if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) { |
| 2043 | final int callingUid = Binder.getCallingUid(); |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2044 | // system processes will be automatically allowed privilege to draw |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2045 | if (callingUid == Process.SYSTEM_UID) { |
| 2046 | return WindowManagerGlobal.ADD_OKAY; |
| 2047 | } |
| 2048 | |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2049 | // check if user has enabled this operation. SecurityException will be thrown if |
| 2050 | // this app has not been allowed by the user |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2051 | final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid, |
| 2052 | attrs.packageName); |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2053 | switch (mode) { |
| 2054 | case AppOpsManager.MODE_ALLOWED: |
| 2055 | case AppOpsManager.MODE_IGNORED: |
| 2056 | // although we return ADD_OKAY for MODE_IGNORED, the added window will |
| 2057 | // actually be hidden in WindowManagerService |
| 2058 | return WindowManagerGlobal.ADD_OKAY; |
| 2059 | case AppOpsManager.MODE_ERRORED: |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2060 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2061 | default: |
| 2062 | // in the default mode, we will make a decision here based on |
| 2063 | // checkCallingPermission() |
| 2064 | if (mContext.checkCallingPermission(permission) != |
| 2065 | PackageManager.PERMISSION_GRANTED) { |
| 2066 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
| 2067 | } else { |
| 2068 | return WindowManagerGlobal.ADD_OKAY; |
| 2069 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2070 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2071 | } |
| 2072 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2073 | if (mContext.checkCallingOrSelfPermission(permission) |
| 2074 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2075 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2076 | } |
| 2077 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2078 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2079 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2080 | |
| 2081 | @Override |
| 2082 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 2083 | |
| 2084 | // If this switch statement is modified, modify the comment in the declarations of |
| 2085 | // the type in {@link WindowManager.LayoutParams} as well. |
| 2086 | switch (attrs.type) { |
| 2087 | default: |
| 2088 | // These are the windows that by default are shown only to the user that created |
| 2089 | // them. If this needs to be overridden, set |
| 2090 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 2091 | // {@link WindowManager.LayoutParams}. Note that permission |
| 2092 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 2093 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 2094 | return true; |
| 2095 | } |
| 2096 | break; |
| 2097 | |
| 2098 | // These are the windows that by default are shown to all users. However, to |
| 2099 | // protect against spoofing, check permissions below. |
| 2100 | case TYPE_APPLICATION_STARTING: |
| 2101 | case TYPE_BOOT_PROGRESS: |
| 2102 | case TYPE_DISPLAY_OVERLAY: |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2103 | case TYPE_INPUT_CONSUMER: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2104 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2105 | case TYPE_KEYGUARD_DIALOG: |
| 2106 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2107 | case TYPE_NAVIGATION_BAR: |
| 2108 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2109 | case TYPE_PHONE: |
| 2110 | case TYPE_POINTER: |
| 2111 | case TYPE_PRIORITY_PHONE: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2112 | case TYPE_SEARCH_BAR: |
| 2113 | case TYPE_STATUS_BAR: |
| 2114 | case TYPE_STATUS_BAR_PANEL: |
| 2115 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 2116 | case TYPE_SYSTEM_DIALOG: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2117 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2118 | case TYPE_PRIVATE_PRESENTATION: |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2119 | case TYPE_DOCK_DIVIDER: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2120 | break; |
| 2121 | } |
| 2122 | |
| 2123 | // Check if third party app has set window to system window type. |
| 2124 | return mContext.checkCallingOrSelfPermission( |
| 2125 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 2126 | != PackageManager.PERMISSION_GRANTED; |
| 2127 | } |
| 2128 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2129 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2130 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 2131 | switch (attrs.type) { |
| 2132 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 2133 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2134 | // These types of windows can't receive input events. |
| 2135 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 2136 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 2137 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2138 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2139 | case TYPE_STATUS_BAR: |
| 2140 | |
| 2141 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 2142 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 2143 | // the keyguard as occluded wouldn't set these flags again. |
| 2144 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 2145 | if (mKeyguardHidden) { |
| 2146 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 2147 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2148 | } |
| 2149 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2150 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 2151 | |
| 2152 | if (attrs.type != TYPE_STATUS_BAR) { |
| 2153 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 2154 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2155 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2156 | |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2157 | if (ActivityManager.isHighEndGfx()) { |
| 2158 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
| 2159 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 2160 | } |
| 2161 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 |
Jorim Jaggi | 406585a | 2015-12-21 10:58:56 +0100 | [diff] [blame] | 2162 | || (mForceWindowDrawsStatusBarBackground |
| 2163 | && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) { |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2164 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 2165 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2166 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2167 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2168 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2169 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 2170 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2171 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2172 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 2173 | private void readCameraLensCoverState() { |
| 2174 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 2175 | } |
| 2176 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2177 | private boolean isHidden(int accessibilityMode) { |
| 2178 | switch (accessibilityMode) { |
| 2179 | case 1: |
| 2180 | return mLidState == LID_CLOSED; |
| 2181 | case 2: |
| 2182 | return mLidState == LID_OPEN; |
| 2183 | default: |
| 2184 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2185 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2186 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2187 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2188 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2189 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2190 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 2191 | int navigationPresence) { |
| 2192 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 2193 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2194 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2195 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 2196 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2197 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2198 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 2199 | || (keyboardPresence == PRESENCE_INTERNAL |
| 2200 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2201 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2202 | if (!mHasSoftInput) { |
| 2203 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 2204 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2205 | } |
| 2206 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2207 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 2208 | || (navigationPresence == PRESENCE_INTERNAL |
| 2209 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2210 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2211 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2212 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2213 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2214 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2215 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2216 | public int windowTypeToLayerLw(int type) { |
| 2217 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2218 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2219 | } |
| 2220 | switch (type) { |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2221 | case TYPE_PRIVATE_PRESENTATION: |
| 2222 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2223 | case TYPE_WALLPAPER: |
| 2224 | // wallpaper is at the bottom, though the window manager may move it. |
| 2225 | return 2; |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2226 | case TYPE_DOCK_DIVIDER: |
| 2227 | return 2; |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 2228 | case TYPE_QS_DIALOG: |
| 2229 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2230 | case TYPE_PHONE: |
| 2231 | return 3; |
| 2232 | case TYPE_SEARCH_BAR: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2233 | case TYPE_VOICE_INTERACTION_STARTING: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2234 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2235 | case TYPE_VOICE_INTERACTION: |
| 2236 | // voice interaction layer is almost immediately above apps. |
| 2237 | return 5; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2238 | case TYPE_INPUT_CONSUMER: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2239 | return 6; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2240 | case TYPE_SYSTEM_DIALOG: |
| 2241 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2242 | case TYPE_TOAST: |
| 2243 | // toasts and the plugged-in battery thing |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2244 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2245 | case TYPE_PRIORITY_PHONE: |
| 2246 | // SIM errors and unlock. Not sure if this really should be in a high layer. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2247 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2248 | case TYPE_DREAM: |
| 2249 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2250 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2251 | case TYPE_SYSTEM_ALERT: |
| 2252 | // like the ANR / app crashed dialogs |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2253 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2254 | case TYPE_INPUT_METHOD: |
| 2255 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2256 | return 12; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2257 | case TYPE_INPUT_METHOD_DIALOG: |
| 2258 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2259 | return 13; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2260 | case TYPE_KEYGUARD_SCRIM: |
| 2261 | // the safety window that shows behind keyguard while keyguard is starting |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2262 | return 14; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2263 | case TYPE_STATUS_BAR_SUB_PANEL: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2264 | return 15; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2265 | case TYPE_STATUS_BAR: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2266 | return 16; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2267 | case TYPE_STATUS_BAR_PANEL: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2268 | return 17; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2269 | case TYPE_KEYGUARD_DIALOG: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2270 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2271 | case TYPE_VOLUME_OVERLAY: |
| 2272 | // the on-screen volume indicator and controller shown when the user |
| 2273 | // changes the device volume |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2274 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2275 | case TYPE_SYSTEM_OVERLAY: |
| 2276 | // the on-screen volume indicator and controller shown when the user |
| 2277 | // changes the device volume |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2278 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2279 | case TYPE_NAVIGATION_BAR: |
| 2280 | // the navigation bar, if available, shows atop most things |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2281 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2282 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2283 | // some panels (e.g. search) need to show on top of the navigation bar |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2284 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2285 | case TYPE_SYSTEM_ERROR: |
| 2286 | // system-level error dialogs |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2287 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2288 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2289 | // used to highlight the magnified portion of a display |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2290 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2291 | case TYPE_DISPLAY_OVERLAY: |
| 2292 | // used to simulate secondary display devices |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2293 | return 25; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2294 | case TYPE_DRAG: |
| 2295 | // the drag layer: input for drag-and-drop is associated with this window, |
| 2296 | // which sits above all other focusable windows |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2297 | return 26; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2298 | case TYPE_ACCESSIBILITY_OVERLAY: |
| 2299 | // overlay put by accessibility services to intercept user interaction |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2300 | return 27; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2301 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2302 | return 28; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2303 | case TYPE_BOOT_PROGRESS: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2304 | return 29; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2305 | case TYPE_POINTER: |
| 2306 | // the (mouse) pointer layer |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2307 | return 30; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2308 | } |
| 2309 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2310 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2314 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2315 | public int subWindowTypeToLayerLw(int type) { |
| 2316 | switch (type) { |
| 2317 | case TYPE_APPLICATION_PANEL: |
| 2318 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 2319 | return APPLICATION_PANEL_SUBLAYER; |
| 2320 | case TYPE_APPLICATION_MEDIA: |
| 2321 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 2322 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 2323 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2324 | case TYPE_APPLICATION_SUB_PANEL: |
| 2325 | return APPLICATION_SUB_PANEL_SUBLAYER; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 2326 | case TYPE_APPLICATION_ABOVE_SUB_PANEL: |
| 2327 | return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2328 | } |
| 2329 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 2330 | return 0; |
| 2331 | } |
| 2332 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2333 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2334 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2335 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2336 | } |
| 2337 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2338 | private int getNavigationBarWidth(int rotation, int uiMode) { |
| 2339 | if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) { |
| 2340 | return mNavigationBarWidthForRotationInCarMode[rotation]; |
| 2341 | } else { |
| 2342 | return mNavigationBarWidthForRotationDefault[rotation]; |
| 2343 | } |
| 2344 | } |
| 2345 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2346 | @Override |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2347 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, |
| 2348 | int uiMode) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2349 | if (mHasNavigationBar) { |
| 2350 | // For a basic navigation bar, when we are in landscape mode we place |
| 2351 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2352 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2353 | return fullWidth - getNavigationBarWidth(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2354 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2355 | } |
| 2356 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2357 | } |
| 2358 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2359 | private int getNavigationBarHeight(int rotation, int uiMode) { |
| 2360 | if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) { |
| 2361 | return mNavigationBarHeightForRotationInCarMode[rotation]; |
| 2362 | } else { |
| 2363 | return mNavigationBarHeightForRotationDefault[rotation]; |
| 2364 | } |
| 2365 | } |
| 2366 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2367 | @Override |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2368 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, |
| 2369 | int uiMode) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2370 | if (mHasNavigationBar) { |
| 2371 | // For a basic navigation bar, when we are in portrait mode we place |
| 2372 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2373 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2374 | return fullHeight - getNavigationBarHeight(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2375 | } |
| 2376 | } |
| 2377 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2380 | @Override |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2381 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) { |
| 2382 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2385 | @Override |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2386 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2387 | // There is a separate status bar at the top of the display. We don't count that as part |
| 2388 | // 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] | 2389 | // we do want to exclude it since applications can't generally use that part |
| 2390 | // of the screen. |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2391 | return getNonDecorDisplayHeight( |
| 2392 | fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2393 | } |
| 2394 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2395 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 2396 | public boolean isForceHiding(WindowManager.LayoutParams attrs) { |
| 2397 | return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2398 | (isKeyguardHostWindow(attrs) && |
| 2399 | (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) || |
Adrian Roos | 69e510d | 2014-07-13 14:57:59 +0200 | [diff] [blame] | 2400 | (attrs.type == TYPE_KEYGUARD_SCRIM); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2401 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2402 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2403 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2404 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 2405 | return attrs.type == TYPE_STATUS_BAR; |
| 2406 | } |
| 2407 | |
| 2408 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2409 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2410 | switch (attrs.type) { |
| 2411 | case TYPE_STATUS_BAR: |
| 2412 | case TYPE_NAVIGATION_BAR: |
| 2413 | case TYPE_WALLPAPER: |
| 2414 | case TYPE_DREAM: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2415 | case TYPE_KEYGUARD_SCRIM: |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2416 | case TYPE_DOCK_DIVIDER: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2417 | return false; |
| 2418 | default: |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 2419 | // Hide only windows below the keyguard host window. |
| 2420 | return windowTypeToLayerLw(win.getBaseType()) |
| 2421 | < windowTypeToLayerLw(TYPE_STATUS_BAR); |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2422 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2423 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2424 | |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 2425 | @Override |
| 2426 | public WindowState getWinShowWhenLockedLw() { |
| 2427 | return mWinShowWhenLocked; |
| 2428 | } |
| 2429 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2430 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2431 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2432 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 2433 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2434 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2435 | if (!SHOW_STARTING_ANIMATIONS) { |
| 2436 | return null; |
| 2437 | } |
| 2438 | if (packageName == null) { |
| 2439 | return null; |
| 2440 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2441 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2442 | WindowManager wm = null; |
| 2443 | View view = null; |
| 2444 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2445 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2446 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2447 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 2448 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 2449 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2450 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2451 | try { |
| 2452 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2453 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2454 | } catch (PackageManager.NameNotFoundException e) { |
| 2455 | // Ignore |
| 2456 | } |
| 2457 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2458 | |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 2459 | PhoneWindow win = new PhoneWindow(context); |
| 2460 | win.setIsStartingWindow(true); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2461 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2462 | Resources r = context.getResources(); |
| 2463 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2464 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2465 | win.setType( |
| 2466 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2467 | |
| 2468 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2469 | // Assumes it's safe to show starting windows of launched apps while |
| 2470 | // the keyguard is being hidden. This is okay because starting windows never show |
| 2471 | // secret information. |
| 2472 | if (mKeyguardHidden) { |
| 2473 | windowFlags |= FLAG_SHOW_WHEN_LOCKED; |
| 2474 | } |
| 2475 | } |
| 2476 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2477 | // Force the window flags: this is a fake window, so it is not really |
| 2478 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 2479 | // flag because we do know that the next window will take input |
| 2480 | // focus, so we want to get the IME window up on top of us right away. |
| 2481 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2482 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2483 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2484 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2485 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2486 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2487 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2488 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2489 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2490 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2491 | win.setDefaultIcon(icon); |
| 2492 | win.setDefaultLogo(logo); |
| 2493 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2494 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2495 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2496 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2497 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 2498 | params.token = appToken; |
| 2499 | params.packageName = packageName; |
| 2500 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 2501 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2502 | params.privateFlags |= |
| 2503 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2504 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2505 | |
| 2506 | if (!compatInfo.supportsScreen()) { |
| 2507 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 2508 | } |
| 2509 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2510 | params.setTitle("Starting " + packageName); |
| 2511 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2512 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 2513 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2514 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2515 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2516 | TAG, "Adding starting window for " + packageName |
| 2517 | + " / " + appToken + ": " |
| 2518 | + (view.getParent() != null ? view : null)); |
| 2519 | |
| 2520 | wm.addView(view, params); |
| 2521 | |
| 2522 | // Only return the view if it was successfully added to the |
| 2523 | // window manager... which we can tell by it having a parent. |
| 2524 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2525 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2526 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 2527 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 2528 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2529 | } catch (RuntimeException e) { |
| 2530 | // don't crash if something else bad happens, for example a |
| 2531 | // failure loading resources because we are loading from an app |
| 2532 | // on external storage that has been unmounted. |
| 2533 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2534 | } finally { |
| 2535 | if (view != null && view.getParent() == null) { |
| 2536 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 2537 | wm.removeViewImmediate(view); |
| 2538 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | return null; |
| 2542 | } |
| 2543 | |
| 2544 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2545 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2546 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2547 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": " |
| 2548 | + window + " Callers=" + Debug.getCallers(4)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2549 | |
| 2550 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2551 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2552 | wm.removeView(window); |
| 2553 | } |
| 2554 | } |
| 2555 | |
| 2556 | /** |
| 2557 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2558 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2559 | * Currently enforces that three window types are singletons: |
| 2560 | * <ul> |
| 2561 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2562 | * <li>KEYGUARD_TYPE</li> |
| 2563 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2564 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2565 | * @param win The window to be added |
| 2566 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2567 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2568 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 2569 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2570 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2571 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2572 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 2573 | switch (attrs.type) { |
| 2574 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 2575 | mContext.enforceCallingOrSelfPermission( |
| 2576 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2577 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2578 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2579 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2580 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2581 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2582 | } |
| 2583 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2584 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2585 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2586 | case TYPE_NAVIGATION_BAR: |
| 2587 | mContext.enforceCallingOrSelfPermission( |
| 2588 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2589 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2590 | if (mNavigationBar != null) { |
| 2591 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2592 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2593 | } |
| 2594 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2595 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2596 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2597 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2598 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 2599 | case TYPE_NAVIGATION_BAR_PANEL: |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2600 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2601 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2602 | case TYPE_VOICE_INTERACTION_STARTING: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2603 | mContext.enforceCallingOrSelfPermission( |
| 2604 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2605 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2606 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2607 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 2608 | if (mKeyguardScrim != null) { |
| 2609 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 2610 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2611 | mKeyguardScrim = win; |
| 2612 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2613 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2614 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2618 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2619 | public void removeWindowLw(WindowState win) { |
| 2620 | if (mStatusBar == win) { |
| 2621 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2622 | mStatusBarController.setWindow(null); |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 2623 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2624 | } else if (mKeyguardScrim == win) { |
| 2625 | Log.v(TAG, "Removing keyguard scrim"); |
| 2626 | mKeyguardScrim = null; |
| 2627 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2628 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2629 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2630 | } |
| 2631 | } |
| 2632 | |
| 2633 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2634 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2635 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2636 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2637 | public int selectAnimationLw(WindowState win, int transit) { |
| 2638 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 2639 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2640 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2641 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2642 | if (transit == TRANSIT_EXIT |
| 2643 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2644 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2645 | } else if (transit == TRANSIT_ENTER |
| 2646 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2647 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2648 | } |
| 2649 | } else if (win == mNavigationBar) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2650 | if (win.getAttrs().windowAnimations != 0) { |
| 2651 | return 0; |
| 2652 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2653 | // This can be on either the bottom or the right. |
| 2654 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2655 | if (transit == TRANSIT_EXIT |
| 2656 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2657 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2658 | } else if (transit == TRANSIT_ENTER |
| 2659 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2660 | return R.anim.dock_bottom_enter; |
| 2661 | } |
| 2662 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2663 | if (transit == TRANSIT_EXIT |
| 2664 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2665 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2666 | } else if (transit == TRANSIT_ENTER |
| 2667 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2668 | return R.anim.dock_right_enter; |
| 2669 | } |
| 2670 | } |
Filip Gruszczynski | 57f76f1 | 2015-11-04 16:10:54 -0800 | [diff] [blame] | 2671 | } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) { |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 2672 | return selectDockedDividerAnimationLw(win, transit); |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2676 | if (win.hasAppShownWindows()) { |
| 2677 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 2678 | return com.android.internal.R.anim.app_starting_exit; |
| 2679 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 2680 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2681 | && transit == TRANSIT_ENTER) { |
| 2682 | // Special case: we are animating in a dream, while the keyguard |
| 2683 | // is shown. We don't want an animation on the dream, because |
| 2684 | // we need it shown immediately with the keyguard animating away |
| 2685 | // to reveal it. |
| 2686 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | return 0; |
| 2690 | } |
| 2691 | |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 2692 | private int selectDockedDividerAnimationLw(WindowState win, int transit) { |
| 2693 | int insets = mWindowManagerFuncs.getDockedDividerInsetsLw(); |
| 2694 | |
| 2695 | // If the divider is behind the navigation bar, don't animate. |
| 2696 | if (mNavigationBar != null |
| 2697 | && (win.getFrameLw().top + insets >= mNavigationBar.getFrameLw().top |
| 2698 | || win.getFrameLw().left + insets >= mNavigationBar.getFrameLw().left)) { |
| 2699 | return 0; |
| 2700 | } |
| 2701 | if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) { |
| 2702 | return R.anim.fade_in; |
| 2703 | } else if (transit == TRANSIT_EXIT) { |
| 2704 | return R.anim.fade_out; |
| 2705 | } else { |
| 2706 | return 0; |
| 2707 | } |
| 2708 | } |
| 2709 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 2710 | @Override |
| 2711 | public void selectRotationAnimationLw(int anim[]) { |
| 2712 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 2713 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 2714 | + (mTopFullscreenOpaqueWindowState == null ? |
| 2715 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 2716 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 2717 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 2718 | case ROTATION_ANIMATION_CROSSFADE: |
| 2719 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 2720 | anim[1] = R.anim.rotation_animation_enter; |
| 2721 | break; |
| 2722 | case ROTATION_ANIMATION_JUMPCUT: |
| 2723 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 2724 | anim[1] = R.anim.rotation_animation_enter; |
| 2725 | break; |
| 2726 | case ROTATION_ANIMATION_ROTATE: |
| 2727 | default: |
| 2728 | anim[0] = anim[1] = 0; |
| 2729 | break; |
| 2730 | } |
| 2731 | } else { |
| 2732 | anim[0] = anim[1] = 0; |
| 2733 | } |
| 2734 | } |
| 2735 | |
| 2736 | @Override |
| 2737 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 2738 | boolean forceDefault) { |
| 2739 | switch (exitAnimId) { |
| 2740 | case R.anim.rotation_animation_xfade_exit: |
| 2741 | case R.anim.rotation_animation_jump_exit: |
| 2742 | // These are the only cases that matter. |
| 2743 | if (forceDefault) { |
| 2744 | return false; |
| 2745 | } |
| 2746 | int anim[] = new int[2]; |
| 2747 | selectRotationAnimationLw(anim); |
| 2748 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 2749 | default: |
| 2750 | return true; |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2755 | public Animation createForceHideEnterAnimation(boolean onWallpaper, |
| 2756 | boolean goingToNotificationShade) { |
| 2757 | if (goingToNotificationShade) { |
| 2758 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
Craig Mautner | b834080 | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2759 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2760 | |
| 2761 | AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? |
| 2762 | R.anim.lock_screen_behind_enter_wallpaper : |
| 2763 | R.anim.lock_screen_behind_enter); |
| 2764 | |
| 2765 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2766 | final List<Animation> animations = set.getAnimations(); |
| 2767 | for (int i = animations.size() - 1; i >= 0; --i) { |
| 2768 | animations.get(i).setInterpolator(mLogDecelerateInterpolator); |
| 2769 | } |
| 2770 | |
| 2771 | return set; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | |
| 2775 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2776 | public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) { |
| 2777 | if (goingToNotificationShade) { |
| 2778 | return null; |
| 2779 | } else { |
| 2780 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 2781 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2782 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 2783 | |
| 2784 | private static void awakenDreams() { |
| 2785 | IDreamManager dreamManager = getDreamManager(); |
| 2786 | if (dreamManager != null) { |
| 2787 | try { |
| 2788 | dreamManager.awaken(); |
| 2789 | } catch (RemoteException e) { |
| 2790 | // fine, stay asleep then |
| 2791 | } |
| 2792 | } |
| 2793 | } |
| 2794 | |
| 2795 | static IDreamManager getDreamManager() { |
| 2796 | return IDreamManager.Stub.asInterface( |
| 2797 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 2798 | } |
| 2799 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 2800 | TelecomManager getTelecommService() { |
| 2801 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2802 | } |
| 2803 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2804 | static IAudioService getAudioService() { |
| 2805 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 2806 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 2807 | if (audioService == null) { |
| 2808 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 2809 | } |
| 2810 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | boolean keyguardOn() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2814 | return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 2818 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 2819 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 2820 | }; |
| 2821 | |
| 2822 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2823 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2824 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2825 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2826 | final int keyCode = event.getKeyCode(); |
| 2827 | final int repeatCount = event.getRepeatCount(); |
| 2828 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2829 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2830 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 2831 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2832 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2833 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2834 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2835 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 2836 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2837 | } |
| 2838 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2839 | // If we think we might have a volume down & power key chord on the way |
| 2840 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 2841 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2842 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2843 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2844 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2845 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 2846 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2847 | if (now < timeoutTime) { |
| 2848 | return timeoutTime - now; |
| 2849 | } |
| 2850 | } |
| 2851 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2852 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2853 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2854 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2855 | } |
| 2856 | return -1; |
| 2857 | } |
| 2858 | } |
| 2859 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2860 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 2861 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 2862 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2863 | mPendingMetaAction = false; |
| 2864 | } |
| 2865 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2866 | // First we always handle the home key here, so applications |
| 2867 | // can never break it, although if keyguard is on, we do let |
| 2868 | // it handle it, because that gives us the correct 5 second |
| 2869 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2870 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2871 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2872 | // If we have released the home key, and didn't do anything else |
| 2873 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2874 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2875 | cancelPreloadRecentApps(); |
| 2876 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2877 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2878 | if (mHomeConsumed) { |
| 2879 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2880 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2881 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2882 | |
| 2883 | if (canceled) { |
| 2884 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 2885 | return -1; |
| 2886 | } |
| 2887 | |
Yorke Lee | 4f80324 | 2014-12-15 23:22:06 +0000 | [diff] [blame] | 2888 | // If an incoming call is ringing, HOME is totally disabled. |
| 2889 | // (The user is already on the InCallUI at this point, |
| 2890 | // and his ONLY options are to answer or reject the call.) |
| 2891 | TelecomManager telecomManager = getTelecommService(); |
| 2892 | if (telecomManager != null && telecomManager.isRinging()) { |
| 2893 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2894 | return -1; |
| 2895 | } |
| 2896 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2897 | // Delay handling home if a double-tap is possible. |
| 2898 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2899 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2900 | mHomeDoubleTapPending = true; |
| 2901 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2902 | ViewConfiguration.getDoubleTapTimeout()); |
| 2903 | return -1; |
| 2904 | } |
| 2905 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2906 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2907 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2908 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2909 | |
| 2910 | // If a system window has focus, then it doesn't make sense |
| 2911 | // right now to interact with applications. |
| 2912 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2913 | if (attrs != null) { |
| 2914 | final int type = attrs.type; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2915 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 2916 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG |
| 2917 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2918 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2919 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2920 | } |
| 2921 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2922 | for (int i=0; i<typeCount; i++) { |
| 2923 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2924 | // 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] | 2925 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2926 | } |
| 2927 | } |
| 2928 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2929 | |
| 2930 | // Remember that home is pressed and handle special actions. |
| 2931 | if (repeatCount == 0) { |
| 2932 | mHomePressed = true; |
| 2933 | if (mHomeDoubleTapPending) { |
| 2934 | mHomeDoubleTapPending = false; |
| 2935 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2936 | handleDoubleTapOnHome(); |
| 2937 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2938 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2939 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2940 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2941 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2942 | if (!keyguardOn) { |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 2943 | handleLongPressOnHome(event.getDeviceId(), event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2944 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2945 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2946 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2947 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2948 | // Hijack modified menu keys for debugging features |
| 2949 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2950 | |
| 2951 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2952 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2953 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2954 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2955 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2956 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2957 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2958 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2959 | Intent service = new Intent(); |
| 2960 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2961 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2962 | boolean shown = Settings.Global.getInt( |
| 2963 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2964 | if (!shown) { |
| 2965 | mContext.startService(service); |
| 2966 | } else { |
| 2967 | mContext.stopService(service); |
| 2968 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2969 | Settings.Global.putInt( |
| 2970 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2971 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2972 | } |
| 2973 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2974 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2975 | if (down) { |
| 2976 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2977 | mSearchKeyShortcutPending = true; |
| 2978 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2979 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2980 | } else { |
| 2981 | mSearchKeyShortcutPending = false; |
| 2982 | if (mConsumeSearchKeyUp) { |
| 2983 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2984 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2985 | } |
| 2986 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2987 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2988 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2989 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2990 | if (down && repeatCount == 0) { |
| 2991 | preloadRecentApps(); |
| 2992 | } else if (!down) { |
| 2993 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2994 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2995 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2996 | return -1; |
Jun Mukai | d21b3c8 | 2015-04-23 14:09:34 -0700 | [diff] [blame] | 2997 | } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) { |
| 2998 | if (down) { |
| 2999 | IStatusBarService service = getStatusBarService(); |
| 3000 | if (service != null) { |
| 3001 | try { |
| 3002 | service.expandNotificationsPanel(); |
| 3003 | } catch (RemoteException e) { |
| 3004 | // do nothing. |
| 3005 | } |
| 3006 | } |
| 3007 | } |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3008 | } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) { |
| 3009 | if (down) { |
| 3010 | if (repeatCount == 0) { |
Andrei Stingaceanu | c22ab79 | 2016-01-07 12:39:38 +0000 | [diff] [blame] | 3011 | toggleKeyboardShortcutsMenu(); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3012 | } |
| 3013 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3014 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 3015 | if (down) { |
| 3016 | if (repeatCount == 0) { |
| 3017 | mAssistKeyLongPressed = false; |
| 3018 | } else if (repeatCount == 1) { |
| 3019 | mAssistKeyLongPressed = true; |
| 3020 | if (!keyguardOn) { |
| 3021 | launchAssistLongPressAction(); |
| 3022 | } |
| 3023 | } |
| 3024 | } else { |
| 3025 | if (mAssistKeyLongPressed) { |
| 3026 | mAssistKeyLongPressed = false; |
| 3027 | } else { |
| 3028 | if (!keyguardOn) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3029 | launchAssistAction(null, event.getDeviceId()); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3030 | } |
| 3031 | } |
| 3032 | } |
| 3033 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3034 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 3035 | if (!down) { |
| 3036 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 3037 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3038 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3039 | } else { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 3040 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 3041 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 3042 | if (dic != null) { |
| 3043 | try { |
| 3044 | dic.exitIdle("voice-search"); |
| 3045 | } catch (RemoteException e) { |
| 3046 | } |
| 3047 | } |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3048 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 3049 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3050 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3051 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3052 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 3053 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 3054 | if (down && repeatCount == 0) { |
| 3055 | mHandler.post(mScreenshotRunnable); |
| 3056 | } |
| 3057 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 3058 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 3059 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 3060 | if (down) { |
| 3061 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 3062 | |
| 3063 | // Disable autobrightness if it's on |
| 3064 | int auto = Settings.System.getIntForUser( |
| 3065 | mContext.getContentResolver(), |
| 3066 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 3067 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 3068 | UserHandle.USER_CURRENT_OR_SELF); |
| 3069 | if (auto != 0) { |
| 3070 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3071 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 3072 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 3073 | UserHandle.USER_CURRENT_OR_SELF); |
| 3074 | } |
| 3075 | |
| 3076 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 3077 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 3078 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 3079 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 3080 | Settings.System.SCREEN_BRIGHTNESS, |
| 3081 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 3082 | UserHandle.USER_CURRENT_OR_SELF); |
| 3083 | brightness += step; |
| 3084 | // Make sure we don't go beyond the limits. |
| 3085 | brightness = Math.min(max, brightness); |
| 3086 | brightness = Math.max(min, brightness); |
| 3087 | |
| 3088 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3089 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 3090 | UserHandle.USER_CURRENT_OR_SELF); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3091 | startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 3092 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 3093 | } |
| 3094 | return -1; |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 3095 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 3096 | || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 3097 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { |
| 3098 | if (mUseTvRouting) { |
| 3099 | // On TVs volume keys never go to the foreground app. |
| 3100 | dispatchDirectAudioEvent(event); |
| 3101 | return -1; |
| 3102 | } |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 3103 | } else if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3104 | if (down) { |
| 3105 | mPendingMetaAction = true; |
| 3106 | } else if (mPendingMetaAction) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3107 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId()); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3108 | } |
| 3109 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3110 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3111 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3112 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3113 | // Any printing key that is chorded with Search should be consumed |
| 3114 | // even if no shortcut was invoked. This prevents text from being |
| 3115 | // inadvertently inserted when using a keyboard that has built-in macro |
| 3116 | // 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] | 3117 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3118 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 3119 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3120 | mConsumeSearchKeyUp = true; |
| 3121 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3122 | if (down && repeatCount == 0 && !keyguardOn) { |
| 3123 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 3124 | if (shortcutIntent != null) { |
| 3125 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3126 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3127 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3128 | } catch (ActivityNotFoundException ex) { |
| 3129 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3130 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3131 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3132 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3133 | } else { |
| 3134 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3135 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3136 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3137 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3138 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3139 | } |
| 3140 | } |
| 3141 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3142 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3143 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3144 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 3145 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3146 | if (kcm.isPrintingKey(keyCode)) { |
| 3147 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 3148 | metaState & ~(KeyEvent.META_META_ON |
| 3149 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 3150 | if (shortcutIntent != null) { |
| 3151 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3152 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3153 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3154 | } catch (ActivityNotFoundException ex) { |
| 3155 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3156 | + "the activity to which it is registered was not found: " |
| 3157 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 3158 | } |
| 3159 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3160 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3161 | } |
| 3162 | } |
| 3163 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3164 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3165 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3166 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 3167 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 3168 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3169 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3170 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3171 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3172 | } catch (ActivityNotFoundException ex) { |
| 3173 | Slog.w(TAG, "Dropping application launch key because " |
| 3174 | + "the activity to which it is registered was not found: " |
| 3175 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 3176 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3177 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3178 | } |
| 3179 | } |
| 3180 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3181 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3182 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Michael Wright | d847ad5 | 2015-10-24 13:24:15 +0100 | [diff] [blame] | 3183 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3184 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3185 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3186 | mRecentAppsHeldModifiers = shiftlessModifiers; |
| 3187 | showRecentApps(true); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3188 | return -1; |
| 3189 | } |
| 3190 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3191 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 3192 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 3193 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3194 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3195 | } |
| 3196 | |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3197 | // Handle input method switching. |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3198 | if (down && repeatCount == 0 |
| 3199 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3200 | || (keyCode == KeyEvent.KEYCODE_SPACE |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3201 | && (metaState & KeyEvent.META_META_MASK) != 0))) { |
| 3202 | final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0; |
| 3203 | mWindowManagerFuncs.switchInputMethod(forwardDirection); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3204 | return -1; |
| 3205 | } |
| 3206 | if (mLanguageSwitchKeyPressed && !down |
| 3207 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3208 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 3209 | mLanguageSwitchKeyPressed = false; |
| 3210 | return -1; |
| 3211 | } |
| 3212 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3213 | if (isValidGlobalKey(keyCode) |
| 3214 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 3215 | return -1; |
| 3216 | } |
| 3217 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3218 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 3219 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3220 | return -1; |
| 3221 | } |
| 3222 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3223 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3224 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3225 | } |
| 3226 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3227 | /** {@inheritDoc} */ |
| 3228 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3229 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3230 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3231 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3232 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 3233 | + ", flags=" + event.getFlags() |
| 3234 | + ", keyCode=" + event.getKeyCode() |
| 3235 | + ", scanCode=" + event.getScanCode() |
| 3236 | + ", metaState=" + event.getMetaState() |
| 3237 | + ", repeatCount=" + event.getRepeatCount() |
| 3238 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3239 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3240 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3241 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3242 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3243 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3244 | final int keyCode = event.getKeyCode(); |
| 3245 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3246 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 3247 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3248 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3249 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3250 | final FallbackAction fallbackAction; |
| 3251 | if (initialDown) { |
| 3252 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 3253 | } else { |
| 3254 | fallbackAction = mFallbackActions.get(keyCode); |
| 3255 | } |
| 3256 | |
| 3257 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3258 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3259 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 3260 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3261 | } |
| 3262 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3263 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 3264 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3265 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3266 | event.getAction(), fallbackAction.keyCode, |
| 3267 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3268 | event.getDeviceId(), event.getScanCode(), |
| 3269 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3270 | |
| 3271 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 3272 | fallbackEvent.recycle(); |
| 3273 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3274 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3275 | |
| 3276 | if (initialDown) { |
| 3277 | mFallbackActions.put(keyCode, fallbackAction); |
| 3278 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 3279 | mFallbackActions.remove(keyCode); |
| 3280 | fallbackAction.recycle(); |
| 3281 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3282 | } |
| 3283 | } |
| 3284 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3285 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3286 | if (fallbackEvent == null) { |
| 3287 | Slog.d(TAG, "No fallback."); |
| 3288 | } else { |
| 3289 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 3290 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3291 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3292 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3293 | } |
| 3294 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3295 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3296 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3297 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 3298 | long delayMillis = interceptKeyBeforeDispatching( |
| 3299 | win, fallbackEvent, policyFlags); |
| 3300 | if (delayMillis == 0) { |
| 3301 | return true; |
| 3302 | } |
| 3303 | } |
| 3304 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3305 | } |
| 3306 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3307 | private void launchAssistLongPressAction() { |
| 3308 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 3309 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 3310 | |
| 3311 | // launch the search activity |
| 3312 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 3313 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3314 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3315 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 3316 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3317 | SearchManager searchManager = getSearchManager(); |
| 3318 | if (searchManager != null) { |
| 3319 | searchManager.stopSearch(); |
| 3320 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3321 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3322 | } catch (ActivityNotFoundException e) { |
| 3323 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 3324 | } |
| 3325 | } |
| 3326 | |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3327 | private void launchAssistAction(String hint, int deviceId) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3328 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Maurice Lam | 39d1381 | 2015-07-23 20:49:20 -0700 | [diff] [blame] | 3329 | if (!isUserSetupComplete()) { |
| 3330 | // Disable opening assist window during setup |
| 3331 | return; |
| 3332 | } |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3333 | Bundle args = null; |
| 3334 | if (deviceId > Integer.MIN_VALUE) { |
| 3335 | args = new Bundle(); |
| 3336 | args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3337 | } |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 3338 | if ((mContext.getResources().getConfiguration().uiMode |
| 3339 | & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) { |
| 3340 | // On TV, use legacy handling until assistants are implemented in the proper way. |
| 3341 | ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
| 3342 | .launchLegacyAssist(hint, UserHandle.myUserId(), args); |
| 3343 | } else { |
| 3344 | try { |
| 3345 | if (hint != null) { |
| 3346 | if (args == null) { |
| 3347 | args = new Bundle(); |
| 3348 | } |
| 3349 | args.putBoolean(hint, true); |
| 3350 | } |
| 3351 | IStatusBarService statusbar = getStatusBarService(); |
| 3352 | if (statusbar != null) { |
| 3353 | statusbar.startAssist(args); |
| 3354 | } |
| 3355 | } catch (RemoteException e) { |
| 3356 | Slog.e(TAG, "RemoteException when starting assist", e); |
| 3357 | // re-acquire status bar service next time it is needed. |
| 3358 | mStatusBarService = null; |
| 3359 | } |
| 3360 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3361 | } |
| 3362 | |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3363 | private void startActivityAsUser(Intent intent, UserHandle handle) { |
| 3364 | if (isUserSetupComplete()) { |
| 3365 | mContext.startActivityAsUser(intent, handle); |
| 3366 | } else { |
| 3367 | Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); |
| 3368 | } |
| 3369 | } |
| 3370 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3371 | private SearchManager getSearchManager() { |
| 3372 | if (mSearchManager == null) { |
| 3373 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 3374 | } |
| 3375 | return mSearchManager; |
| 3376 | } |
| 3377 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3378 | private void preloadRecentApps() { |
| 3379 | mPreloadedRecentApps = true; |
| 3380 | try { |
| 3381 | IStatusBarService statusbar = getStatusBarService(); |
| 3382 | if (statusbar != null) { |
| 3383 | statusbar.preloadRecentApps(); |
| 3384 | } |
| 3385 | } catch (RemoteException e) { |
| 3386 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 3387 | // re-acquire status bar service next time it is needed. |
| 3388 | mStatusBarService = null; |
| 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | private void cancelPreloadRecentApps() { |
| 3393 | if (mPreloadedRecentApps) { |
| 3394 | mPreloadedRecentApps = false; |
| 3395 | try { |
| 3396 | IStatusBarService statusbar = getStatusBarService(); |
| 3397 | if (statusbar != null) { |
| 3398 | statusbar.cancelPreloadRecentApps(); |
| 3399 | } |
| 3400 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3401 | Slog.e(TAG, "RemoteException when cancelling recent apps preload", e); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3402 | // re-acquire status bar service next time it is needed. |
| 3403 | mStatusBarService = null; |
| 3404 | } |
| 3405 | } |
| 3406 | } |
| 3407 | |
| 3408 | private void toggleRecentApps() { |
| 3409 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3410 | try { |
| 3411 | IStatusBarService statusbar = getStatusBarService(); |
| 3412 | if (statusbar != null) { |
| 3413 | statusbar.toggleRecentApps(); |
| 3414 | } |
| 3415 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3416 | Slog.e(TAG, "RemoteException when toggling recent apps", e); |
| 3417 | // re-acquire status bar service next time it is needed. |
| 3418 | mStatusBarService = null; |
| 3419 | } |
| 3420 | } |
| 3421 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3422 | @Override |
| 3423 | public void showRecentApps() { |
| 3424 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
| 3425 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS); |
| 3426 | } |
| 3427 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3428 | private void showRecentApps(boolean triggeredFromAltTab) { |
| 3429 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3430 | try { |
| 3431 | IStatusBarService statusbar = getStatusBarService(); |
| 3432 | if (statusbar != null) { |
| 3433 | statusbar.showRecentApps(triggeredFromAltTab); |
| 3434 | } |
| 3435 | } catch (RemoteException e) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3436 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 3437 | // re-acquire status bar service next time it is needed. |
| 3438 | mStatusBarService = null; |
| 3439 | } |
| 3440 | } |
| 3441 | |
Andrei Stingaceanu | c22ab79 | 2016-01-07 12:39:38 +0000 | [diff] [blame] | 3442 | private void toggleKeyboardShortcutsMenu() { |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3443 | try { |
| 3444 | IStatusBarService statusbar = getStatusBarService(); |
| 3445 | if (statusbar != null) { |
Andrei Stingaceanu | c22ab79 | 2016-01-07 12:39:38 +0000 | [diff] [blame] | 3446 | statusbar.toggleKeyboardShortcutsMenu(); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3447 | } |
| 3448 | } catch (RemoteException e) { |
| 3449 | Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e); |
| 3450 | } |
| 3451 | } |
| 3452 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3453 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3454 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3455 | try { |
| 3456 | IStatusBarService statusbar = getStatusBarService(); |
| 3457 | if (statusbar != null) { |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3458 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3459 | } |
| 3460 | } catch (RemoteException e) { |
| 3461 | Slog.e(TAG, "RemoteException when closing recent apps", e); |
| 3462 | // re-acquire status bar service next time it is needed. |
| 3463 | mStatusBarService = null; |
| 3464 | } |
| 3465 | } |
| 3466 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3467 | void launchHomeFromHotKey() { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3468 | launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3469 | } |
| 3470 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3471 | /** |
| 3472 | * A home key -> launch home action was detected. Take the appropriate action |
| 3473 | * given the situation with the keyguard. |
| 3474 | */ |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3475 | void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) { |
| 3476 | if (respectKeyguard) { |
| 3477 | if (isKeyguardShowingAndNotOccluded()) { |
| 3478 | // don't launch home if keyguard showing |
| 3479 | return; |
| 3480 | } |
| 3481 | |
| 3482 | if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
| 3483 | // when in keyguard restricted mode, must first verify unlock |
| 3484 | // before launching home |
| 3485 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
| 3486 | @Override |
| 3487 | public void onKeyguardExitResult(boolean success) { |
| 3488 | if (success) { |
| 3489 | try { |
| 3490 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3491 | } catch (RemoteException e) { |
| 3492 | } |
| 3493 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3494 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 3495 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3496 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3497 | }); |
| 3498 | return; |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | // no keyguard stuff to worry about, just launch home! |
| 3503 | try { |
| 3504 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3505 | } catch (RemoteException e) { |
| 3506 | } |
| 3507 | if (mRecentsVisible) { |
| 3508 | // Hide Recents and notify it to launch Home |
| 3509 | if (awakenFromDreams) { |
| 3510 | awakenDreams(); |
| 3511 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3512 | hideRecentApps(false, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3513 | } else { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3514 | // Otherwise, just launch Home |
| 3515 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3516 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3517 | } |
| 3518 | } |
| 3519 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3520 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 3521 | @Override |
| 3522 | public void run() { |
| 3523 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 3524 | // Clear flags. |
| 3525 | mForceClearedSystemUiFlags &= |
| 3526 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 3527 | } |
| 3528 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3529 | } |
| 3530 | }; |
| 3531 | |
| 3532 | /** |
| 3533 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 3534 | * to determine when the nav bar should be shown and prevent applications from |
| 3535 | * receiving those touches. |
| 3536 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3537 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 3538 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 3539 | super(inputChannel, looper); |
| 3540 | } |
| 3541 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3542 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3543 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3544 | boolean handled = false; |
| 3545 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 3546 | if (event instanceof MotionEvent |
| 3547 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3548 | final MotionEvent motionEvent = (MotionEvent)event; |
| 3549 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3550 | // When the user taps down, we re-show the nav bar. |
| 3551 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3552 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3553 | // Any user activity always causes us to show the |
| 3554 | // navigation controls, if they had been hidden. |
| 3555 | // We also clear the low profile and only content |
| 3556 | // flags so that tapping on the screen will atomically |
| 3557 | // restore all currently hidden screen decorations. |
| 3558 | int newVal = mResettingSystemUiFlags | |
| 3559 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 3560 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 3561 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3562 | if (mResettingSystemUiFlags != newVal) { |
| 3563 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3564 | changed = true; |
| 3565 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3566 | // We don't allow the system's nav bar to be hidden |
| 3567 | // again for 1 second, to prevent applications from |
| 3568 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3569 | newVal = mForceClearedSystemUiFlags | |
| 3570 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3571 | if (mForceClearedSystemUiFlags != newVal) { |
| 3572 | mForceClearedSystemUiFlags = newVal; |
| 3573 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3574 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3575 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3576 | } |
| 3577 | if (changed) { |
| 3578 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 3579 | } |
| 3580 | } |
| 3581 | } |
| 3582 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3583 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3584 | } |
| 3585 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3586 | } |
| 3587 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 3588 | new InputEventReceiver.Factory() { |
| 3589 | @Override |
| 3590 | public InputEventReceiver createInputEventReceiver( |
| 3591 | InputChannel inputChannel, Looper looper) { |
| 3592 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 3593 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3594 | }; |
| 3595 | |
| 3596 | @Override |
| 3597 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 3598 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 3599 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 3600 | mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3601 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3602 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 3603 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3604 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3605 | // Clear any bits in the new visibility that are currently being |
| 3606 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3607 | return visibility & ~mResettingSystemUiFlags |
| 3608 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3609 | } |
| 3610 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3611 | @Override |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3612 | public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation, |
| 3613 | Rect outContentInsets, Rect outStableInsets, Rect outOutsets) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3614 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3615 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 3616 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3617 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3618 | final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl); |
| 3619 | if (useOutsets) { |
| 3620 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 3621 | if (outset > 0) { |
| 3622 | if (displayRotation == Surface.ROTATION_0) { |
| 3623 | outOutsets.bottom += outset; |
| 3624 | } else if (displayRotation == Surface.ROTATION_90) { |
| 3625 | outOutsets.right += outset; |
| 3626 | } else if (displayRotation == Surface.ROTATION_180) { |
| 3627 | outOutsets.top += outset; |
| 3628 | } else if (displayRotation == Surface.ROTATION_270) { |
| 3629 | outOutsets.left += outset; |
| 3630 | } |
| 3631 | } |
| 3632 | } |
| 3633 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3634 | 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] | 3635 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3636 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3637 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3638 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3639 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3640 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 3641 | } else { |
| 3642 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3643 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 3644 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3645 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3646 | if ((fl & FLAG_FULLSCREEN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3647 | outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3648 | availRight - mStableFullscreenRight, |
| 3649 | availBottom - mStableFullscreenBottom); |
| 3650 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3651 | outContentInsets.set(mStableLeft, mStableTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3652 | availRight - mStableRight, availBottom - mStableBottom); |
| 3653 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3654 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3655 | outContentInsets.setEmpty(); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3656 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3657 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3658 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3659 | availRight - mCurRight, availBottom - mCurBottom); |
| 3660 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3661 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3662 | availRight - mCurRight, availBottom - mCurBottom); |
| 3663 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3664 | |
| 3665 | outStableInsets.set(mStableLeft, mStableTop, |
| 3666 | availRight - mStableRight, availBottom - mStableBottom); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3667 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3668 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3669 | outContentInsets.setEmpty(); |
| 3670 | outStableInsets.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3671 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3672 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3673 | private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) { |
| 3674 | return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 3675 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0; |
| 3676 | } |
| 3677 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3678 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3679 | @Override |
| 3680 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 3681 | int displayRotation, int uiMode) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3682 | mDisplayRotation = displayRotation; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3683 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 3684 | if (isDefaultDisplay) { |
| 3685 | switch (displayRotation) { |
| 3686 | case Surface.ROTATION_90: |
| 3687 | overscanLeft = mOverscanTop; |
| 3688 | overscanTop = mOverscanRight; |
| 3689 | overscanRight = mOverscanBottom; |
| 3690 | overscanBottom = mOverscanLeft; |
| 3691 | break; |
| 3692 | case Surface.ROTATION_180: |
| 3693 | overscanLeft = mOverscanRight; |
| 3694 | overscanTop = mOverscanBottom; |
| 3695 | overscanRight = mOverscanLeft; |
| 3696 | overscanBottom = mOverscanTop; |
| 3697 | break; |
| 3698 | case Surface.ROTATION_270: |
| 3699 | overscanLeft = mOverscanBottom; |
| 3700 | overscanTop = mOverscanLeft; |
| 3701 | overscanRight = mOverscanTop; |
| 3702 | overscanBottom = mOverscanRight; |
| 3703 | break; |
| 3704 | default: |
| 3705 | overscanLeft = mOverscanLeft; |
| 3706 | overscanTop = mOverscanTop; |
| 3707 | overscanRight = mOverscanRight; |
| 3708 | overscanBottom = mOverscanBottom; |
| 3709 | break; |
| 3710 | } |
| 3711 | } else { |
| 3712 | overscanLeft = 0; |
| 3713 | overscanTop = 0; |
| 3714 | overscanRight = 0; |
| 3715 | overscanBottom = 0; |
| 3716 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3717 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 3718 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 3719 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 3720 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3721 | mSystemLeft = 0; |
| 3722 | mSystemTop = 0; |
| 3723 | mSystemRight = displayWidth; |
| 3724 | mSystemBottom = displayHeight; |
| 3725 | mUnrestrictedScreenLeft = overscanLeft; |
| 3726 | mUnrestrictedScreenTop = overscanTop; |
| 3727 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 3728 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 3729 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 3730 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3731 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 3732 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3733 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3734 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3735 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3736 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3737 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3738 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3739 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3740 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3741 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3742 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3743 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3744 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 3745 | final Rect pf = mTmpParentFrame; |
| 3746 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3747 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3748 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3749 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3750 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 3751 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 3752 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 3753 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3754 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3755 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3756 | if (isDefaultDisplay) { |
| 3757 | // For purposes of putting out fake window up to steal focus, we will |
| 3758 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3759 | final int sysui = mLastSystemUiFlags; |
| 3760 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3761 | boolean navTranslucent = (sysui |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 3762 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3763 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 3764 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 3765 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 3766 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3767 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen; |
| 3768 | if (!isKeyguardShowing) { |
| 3769 | navTranslucent &= areTranslucentBarsAllowed(); |
| 3770 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3771 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3772 | // When the navigation bar isn't visible, we put up a fake |
| 3773 | // input window to catch all touch events. This way we can |
| 3774 | // detect when the user presses anywhere to bring back the nav |
| 3775 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3776 | if (navVisible || navAllowedHidden) { |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3777 | if (mInputConsumer != null) { |
| 3778 | mInputConsumer.dismiss(); |
| 3779 | mInputConsumer = null; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3780 | } |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3781 | } else if (mInputConsumer == null) { |
| 3782 | mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(), |
| 3783 | mHideNavInputEventReceiverFactory); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3784 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3785 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3786 | // For purposes of positioning and showing the nav bar, if we have |
| 3787 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 3788 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3789 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3790 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3791 | boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight, |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 3792 | displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent, |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3793 | navAllowedHidden); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3794 | 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] | 3795 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3796 | updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3797 | if (updateSysUiVisibility) { |
| 3798 | updateSystemUiVisibilityLw(); |
| 3799 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3800 | } |
| 3801 | } |
| 3802 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3803 | private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui, |
| 3804 | boolean isKeyguardShowing) { |
| 3805 | // decide where the status bar goes ahead of time |
| 3806 | if (mStatusBar != null) { |
| 3807 | // apply any navigation bar insets |
| 3808 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3809 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3810 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3811 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 3812 | + mUnrestrictedScreenTop; |
| 3813 | vf.left = mStableLeft; |
| 3814 | vf.top = mStableTop; |
| 3815 | vf.right = mStableRight; |
| 3816 | vf.bottom = mStableBottom; |
| 3817 | |
| 3818 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 3819 | |
| 3820 | // Let the status bar determine its size. |
| 3821 | mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */, |
| 3822 | vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */, |
| 3823 | dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */); |
| 3824 | |
| 3825 | // For layout, the status bar is always at the top with our fixed height. |
| 3826 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3827 | |
| 3828 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
| 3829 | boolean statusBarTranslucent = (sysui |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 3830 | & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0; |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3831 | if (!isKeyguardShowing) { |
| 3832 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 3833 | } |
| 3834 | |
| 3835 | // If the status bar is hidden, we don't want to cause |
| 3836 | // windows behind it to scroll. |
| 3837 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
| 3838 | // Status bar may go away, so the screen area it occupies |
| 3839 | // is available to apps but just covering them when the |
| 3840 | // status bar is visible. |
| 3841 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3842 | |
| 3843 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3844 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3845 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3846 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 3847 | |
| 3848 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
| 3849 | String.format( |
| 3850 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 3851 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 3852 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 3853 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 3854 | } |
| 3855 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
| 3856 | && !statusBarTransient && !statusBarTranslucent |
| 3857 | && !mStatusBarController.wasRecentlyTranslucent()) { |
| 3858 | // If the opaque status bar is currently requested to be visible, |
| 3859 | // and not in the process of animating on or off, then |
| 3860 | // we can tell the app that it is covered by it. |
| 3861 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3862 | } |
| 3863 | if (mStatusBarController.checkHiddenLw()) { |
| 3864 | return true; |
| 3865 | } |
| 3866 | } |
| 3867 | return false; |
| 3868 | } |
| 3869 | |
| 3870 | private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation, |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 3871 | int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible, |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3872 | boolean navTranslucent, boolean navAllowedHidden) { |
| 3873 | if (mNavigationBar != null) { |
| 3874 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
| 3875 | // Force the navigation bar to its appropriate place and |
| 3876 | // size. We need to do this directly, instead of relying on |
| 3877 | // it to bubble up from the nav bar, because this needs to |
| 3878 | // change atomically with screen rotations. |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 3879 | mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3880 | if (mNavigationBarOnBottom) { |
| 3881 | // It's a system nav bar or a portrait screen; nav bar goes on bottom. |
| 3882 | int top = displayHeight - overscanBottom |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 3883 | - getNavigationBarHeight(displayRotation, uiMode); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3884 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
| 3885 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
| 3886 | if (transientNavBarShowing) { |
| 3887 | mNavigationBarController.setBarShowingLw(true); |
| 3888 | } else if (navVisible) { |
| 3889 | mNavigationBarController.setBarShowingLw(true); |
| 3890 | mDockBottom = mTmpNavigationFrame.top; |
| 3891 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 3892 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
| 3893 | } else { |
| 3894 | // We currently want to hide the navigation UI. |
| 3895 | mNavigationBarController.setBarShowingLw(false); |
| 3896 | } |
| 3897 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3898 | && !mNavigationBar.isAnimatingLw() |
| 3899 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 3900 | // If the opaque nav bar is currently requested to be visible, |
| 3901 | // and not in the process of animating on or off, then |
| 3902 | // we can tell the app that it is covered by it. |
| 3903 | mSystemBottom = mTmpNavigationFrame.top; |
| 3904 | } |
| 3905 | } else { |
| 3906 | // Landscape screen; nav bar goes to the right. |
| 3907 | int left = displayWidth - overscanRight |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 3908 | - getNavigationBarWidth(displayRotation, uiMode); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3909 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
| 3910 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
| 3911 | if (transientNavBarShowing) { |
| 3912 | mNavigationBarController.setBarShowingLw(true); |
| 3913 | } else if (navVisible) { |
| 3914 | mNavigationBarController.setBarShowingLw(true); |
| 3915 | mDockRight = mTmpNavigationFrame.left; |
| 3916 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 3917 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
| 3918 | } else { |
| 3919 | // We currently want to hide the navigation UI. |
| 3920 | mNavigationBarController.setBarShowingLw(false); |
| 3921 | } |
| 3922 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3923 | && !mNavigationBar.isAnimatingLw() |
| 3924 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 3925 | // If the nav bar is currently requested to be visible, |
| 3926 | // and not in the process of animating on or off, then |
| 3927 | // we can tell the app that it is covered by it. |
| 3928 | mSystemRight = mTmpNavigationFrame.left; |
| 3929 | } |
| 3930 | } |
| 3931 | // Make sure the content and current rectangles are updated to |
| 3932 | // account for the restrictions from the navigation bar. |
| 3933 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3934 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3935 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3936 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 3937 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 3938 | // And compute the final frame. |
| 3939 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
| 3940 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
| 3941 | mTmpNavigationFrame, mTmpNavigationFrame); |
| 3942 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
| 3943 | if (mNavigationBarController.checkHiddenLw()) { |
| 3944 | return true; |
| 3945 | } |
| 3946 | } |
| 3947 | return false; |
| 3948 | } |
| 3949 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 3950 | private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) { |
| 3951 | return !mNavigationBarCanMove || displayWidth < displayHeight; |
| 3952 | } |
| 3953 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3954 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3955 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3956 | public int getSystemDecorLayerLw() { |
Bryce Lee | 2ed3e5f | 2015-04-01 22:09:19 +0000 | [diff] [blame] | 3957 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 3958 | return mStatusBar.getSurfaceLayer(); |
| 3959 | } |
| 3960 | |
| 3961 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { |
| 3962 | return mNavigationBar.getSurfaceLayer(); |
| 3963 | } |
| 3964 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3965 | return 0; |
| 3966 | } |
| 3967 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3968 | @Override |
| 3969 | public void getContentRectLw(Rect r) { |
| 3970 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 3971 | } |
| 3972 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3973 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 3974 | 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] | 3975 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 3976 | // Here's a special case: if this attached window is a panel that is |
| 3977 | // above the dock window, and the window it is attached to is below |
| 3978 | // the dock window, then the frames we computed for the window it is |
| 3979 | // attached to can not be used because the dock is effectively part |
| 3980 | // of the underlying window and the attached window is floating on top |
| 3981 | // of the whole thing. So, we ignore the attached window and explicitly |
| 3982 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3983 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3984 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 3985 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 3986 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3987 | } else { |
| 3988 | // The effective display frame of the attached window depends on |
| 3989 | // whether it is taking care of insetting its content. If not, |
| 3990 | // we need to use the parent's content frame so that the entire |
| 3991 | // window is positioned within that content. Otherwise we can use |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3992 | // 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] | 3993 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3994 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3995 | // Set the content frame of the attached window to the parent's decor frame |
| 3996 | // (same as content frame when IME isn't present) if specifically requested by |
| 3997 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 3998 | // Otherwise, use the overscan frame. |
| 3999 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
| 4000 | ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4001 | } else { |
| 4002 | // If the window is resizing, then we want to base the content |
| 4003 | // frame on our attached content frame to resize... however, |
| 4004 | // things can be tricky if the attached window is NOT in resize |
| 4005 | // mode, in which case its content frame will be larger. |
| 4006 | // Ungh. So to deal with that, make sure the content frame |
| 4007 | // we end up using is not covering the IM dock. |
| 4008 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4009 | if (attached.isVoiceInteraction()) { |
| 4010 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 4011 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 4012 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 4013 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 4014 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4015 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 4016 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 4017 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 4018 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 4019 | } |
| 4020 | } |
| 4021 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4022 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4023 | vf.set(attached.getVisibleFrameLw()); |
| 4024 | } |
| 4025 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 4026 | // window should be positioned relative to its parent or the entire |
| 4027 | // screen. |
| 4028 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 4029 | ? attached.getFrameLw() : df); |
| 4030 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4031 | |
| 4032 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 4033 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 4034 | // If app is requesting a stable layout, don't let the |
| 4035 | // content insets go below the stable values. |
| 4036 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 4037 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 4038 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 4039 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 4040 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 4041 | } else { |
| 4042 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 4043 | if (r.top < mStableTop) r.top = mStableTop; |
| 4044 | if (r.right > mStableRight) r.right = mStableRight; |
| 4045 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 4046 | } |
| 4047 | } |
| 4048 | } |
| 4049 | |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4050 | private boolean canReceiveInput(WindowState win) { |
| 4051 | boolean notFocusable = |
| 4052 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0; |
| 4053 | boolean altFocusableIm = |
| 4054 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0; |
| 4055 | boolean notFocusableForIm = notFocusable ^ altFocusableIm; |
| 4056 | return !notFocusableForIm; |
| 4057 | } |
| 4058 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4059 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4060 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4061 | public void layoutWindowLw(WindowState win, WindowState attached) { |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4062 | // We've already done the navigation bar and status bar. If the status bar can receive |
| 4063 | // input, we need to layout it again to accomodate for the IME window. |
| 4064 | if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4065 | return; |
| 4066 | } |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4067 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4068 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 4069 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4070 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 4071 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4072 | 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] | 4073 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 4074 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4075 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4076 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4077 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 4078 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4079 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4080 | final Rect pf = mTmpParentFrame; |
| 4081 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4082 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4083 | final Rect cf = mTmpContentFrame; |
| 4084 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4085 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4086 | final Rect sf = mTmpStableFrame; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4087 | Rect osf = null; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4088 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4089 | |
| 4090 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 4091 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4092 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 4093 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 4094 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4095 | if (isDefaultDisplay) { |
| 4096 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 4097 | } else { |
| 4098 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 4099 | } |
| 4100 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4101 | if (!isDefaultDisplay) { |
| 4102 | if (attached != null) { |
| 4103 | // If this window is attached to another, our display |
| 4104 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4105 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4106 | } else { |
| 4107 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4108 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4109 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4110 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4111 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4112 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4113 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4114 | } |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4115 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4116 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 4117 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 4118 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 4119 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 4120 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 4121 | // ...with content insets above the nav bar |
| 4122 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4123 | // IM dock windows always go to the bottom of the screen. |
| 4124 | attrs.gravity = Gravity.BOTTOM; |
| 4125 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4126 | } else if (attrs.type == TYPE_VOICE_INTERACTION) { |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4127 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4128 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4129 | pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4130 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4131 | cf.bottom = vf.bottom = mStableBottom; |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4132 | // Note: In Phone landscape mode, the button bar should also be excluded. |
| 4133 | cf.right = vf.right = mStableRight; |
| 4134 | cf.left = vf.left = mStableLeft; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4135 | cf.top = vf.top = mStableTop; |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4136 | } else if (win == mStatusBar) { |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 4137 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4138 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4139 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 4140 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 4141 | cf.left = vf.left = mStableLeft; |
| 4142 | cf.top = vf.top = mStableTop; |
| 4143 | cf.right = vf.right = mStableRight; |
| 4144 | vf.bottom = mStableBottom; |
Adrian Roos | dc5b453 | 2016-01-06 20:49:41 +0100 | [diff] [blame] | 4145 | |
| 4146 | if (adjust == SOFT_INPUT_ADJUST_RESIZE) { |
| 4147 | cf.bottom = mContentBottom; |
| 4148 | } else { |
| 4149 | cf.bottom = mDockBottom; |
| 4150 | vf.bottom = mContentBottom; |
| 4151 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4152 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4153 | |
| 4154 | // Default policy decor for the default display |
| 4155 | dcf.left = mSystemLeft; |
| 4156 | dcf.top = mSystemTop; |
| 4157 | dcf.right = mSystemRight; |
| 4158 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4159 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 4160 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 4161 | final boolean isAppWindow = |
| 4162 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 4163 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 4164 | final boolean topAtRest = |
| 4165 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 4166 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4167 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 4168 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4169 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 4170 | && (fl & WindowManager.LayoutParams. |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4171 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0 |
| 4172 | && !mForceWindowDrawsStatusBarBackground) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4173 | // Ensure policy decor includes status bar |
| 4174 | dcf.top = mStableTop; |
| 4175 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4176 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4177 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 4178 | && (fl & WindowManager.LayoutParams. |
| 4179 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4180 | // Ensure policy decor includes navigation bar |
| 4181 | dcf.bottom = mStableBottom; |
| 4182 | dcf.right = mStableRight; |
| 4183 | } |
| 4184 | } |
| 4185 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4186 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 4187 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4188 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4189 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4190 | // This is the case for a normal activity window: we want it |
| 4191 | // to cover all of the screen space, and it can take care of |
| 4192 | // moving its contents to account for screen decorations that |
| 4193 | // intrude into that space. |
| 4194 | if (attached != null) { |
| 4195 | // If this window is attached to another, our display |
| 4196 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4197 | 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] | 4198 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4199 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 4200 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4201 | // Status bar panels are the only windows who can go on top of |
| 4202 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 4203 | // permission, so they have the same privileges as the status |
| 4204 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4205 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4206 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4207 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4208 | pf.left = df.left = of.left = hasNavBar |
| 4209 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 4210 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4211 | pf.right = df.right = of.right = hasNavBar |
| 4212 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 4213 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4214 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 4215 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 4216 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4217 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4218 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4219 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 4220 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4221 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4222 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4223 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4224 | // Asking to layout into the overscan region, so give it that pure |
| 4225 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4226 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 4227 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 4228 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4229 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 4230 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4231 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4232 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4233 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4234 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4235 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4236 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4237 | // only do this for application windows to ensure no window that |
| 4238 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4239 | pf.left = df.left = mOverscanScreenLeft; |
| 4240 | pf.top = df.top = mOverscanScreenTop; |
| 4241 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4242 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4243 | // We need to tell the app about where the frame inside the overscan |
| 4244 | // is, so it can inset its content by that amount -- it didn't ask |
| 4245 | // to actually extend itself into the overscan region. |
| 4246 | of.left = mUnrestrictedScreenLeft; |
| 4247 | of.top = mUnrestrictedScreenTop; |
| 4248 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4249 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4250 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4251 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 4252 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 4253 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 4254 | + mRestrictedOverscanScreenWidth; |
| 4255 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 4256 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4257 | // We need to tell the app about where the frame inside the overscan |
| 4258 | // is, so it can inset its content by that amount -- it didn't ask |
| 4259 | // to actually extend itself into the overscan region. |
| 4260 | of.left = mUnrestrictedScreenLeft; |
| 4261 | of.top = mUnrestrictedScreenTop; |
| 4262 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4263 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4264 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4265 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4266 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4267 | if (win.isVoiceInteraction()) { |
| 4268 | cf.left = mVoiceContentLeft; |
| 4269 | cf.top = mVoiceContentTop; |
| 4270 | cf.right = mVoiceContentRight; |
| 4271 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4272 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4273 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 4274 | cf.left = mDockLeft; |
| 4275 | cf.top = mDockTop; |
| 4276 | cf.right = mDockRight; |
| 4277 | cf.bottom = mDockBottom; |
| 4278 | } else { |
| 4279 | cf.left = mContentLeft; |
| 4280 | cf.top = mContentTop; |
| 4281 | cf.right = mContentRight; |
| 4282 | cf.bottom = mContentBottom; |
| 4283 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4284 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4285 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4286 | // Full screen windows are always given a layout that is as if the |
| 4287 | // status bar and other transient decors are gone. This is to avoid |
| 4288 | // bad states when moving from a window that is not hding the |
| 4289 | // status bar to one that is. |
| 4290 | cf.left = mRestrictedScreenLeft; |
| 4291 | cf.top = mRestrictedScreenTop; |
| 4292 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 4293 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4294 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4295 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4296 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4297 | vf.left = mCurLeft; |
| 4298 | vf.top = mCurTop; |
| 4299 | vf.right = mCurRight; |
| 4300 | vf.bottom = mCurBottom; |
| 4301 | } else { |
| 4302 | vf.set(cf); |
| 4303 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4304 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4305 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 4306 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 4307 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4308 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4309 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4310 | // A window that has requested to fill the entire screen just |
| 4311 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4312 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4313 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL |
| 4314 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4315 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 4316 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 4317 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 4318 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4319 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4320 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4321 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4322 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4323 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4324 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 4325 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 4326 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 4327 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 4328 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4329 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4330 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4331 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4332 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 4333 | + mUnrestrictedScreenWidth; |
| 4334 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 4335 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4336 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4337 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 4338 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 4339 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 4340 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 4341 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 4342 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4343 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4344 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4345 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 4346 | + mOverscanScreenWidth; |
| 4347 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 4348 | + mOverscanScreenHeight; |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 4349 | } else if (attrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 4350 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4351 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4352 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4353 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 4354 | + mOverscanScreenWidth; |
| 4355 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 4356 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 4357 | } else if (attrs.type == TYPE_WALLPAPER) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 4358 | // The wallpaper also has Real Ultimate Power, but we want to tell |
| 4359 | // it about the overscan area. |
| 4360 | pf.left = df.left = mOverscanScreenLeft; |
| 4361 | pf.top = df.top = mOverscanScreenTop; |
| 4362 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4363 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
| 4364 | of.left = cf.left = mUnrestrictedScreenLeft; |
| 4365 | of.top = cf.top = mUnrestrictedScreenTop; |
| 4366 | of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4367 | of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4368 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4369 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4370 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4371 | // Asking to layout into the overscan region, so give it that pure |
| 4372 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4373 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4374 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4375 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4376 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4377 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4378 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4379 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4380 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 4381 | && (attrs.type == TYPE_STATUS_BAR |
| 4382 | || attrs.type == TYPE_TOAST |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 4383 | || attrs.type == TYPE_DOCK_DIVIDER |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 4384 | || attrs.type == TYPE_VOICE_INTERACTION_STARTING |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 4385 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4386 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4387 | // Asking for layout as if the nav bar is hidden, lets the |
| 4388 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 4389 | // 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] | 4390 | // can be above the nav bar can do this. |
| 4391 | // XXX This assumes that an app asking for this will also |
| 4392 | // ask for layout in only content. We can't currently figure out |
| 4393 | // 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] | 4394 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 4395 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 4396 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 4397 | + mUnrestrictedScreenWidth; |
| 4398 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 4399 | + mUnrestrictedScreenHeight; |
Jorim Jaggi | 9f6798a | 2016-02-10 22:16:06 -0800 | [diff] [blame^] | 4400 | } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) { |
| 4401 | pf.left = df.left = of.left = mRestrictedScreenLeft; |
| 4402 | pf.top = df.top = of.top = mRestrictedScreenTop; |
| 4403 | pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 4404 | pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop |
| 4405 | + mRestrictedScreenHeight; |
| 4406 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 4407 | cf.left = mDockLeft; |
| 4408 | cf.top = mDockTop; |
| 4409 | cf.right = mDockRight; |
| 4410 | cf.bottom = mDockBottom; |
| 4411 | } else { |
| 4412 | cf.left = mContentLeft; |
| 4413 | cf.top = mContentTop; |
| 4414 | cf.right = mContentRight; |
| 4415 | cf.bottom = mContentBottom; |
| 4416 | } |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4417 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4418 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4419 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4420 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4421 | + mRestrictedScreenWidth; |
| 4422 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4423 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4424 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4425 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4426 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4427 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4428 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4429 | vf.left = mCurLeft; |
| 4430 | vf.top = mCurTop; |
| 4431 | vf.right = mCurRight; |
| 4432 | vf.bottom = mCurBottom; |
| 4433 | } else { |
| 4434 | vf.set(cf); |
| 4435 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4436 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4437 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4438 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4439 | // A child window should be placed inside of the same visible |
| 4440 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4441 | 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] | 4442 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4443 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4444 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4445 | // Otherwise, a normal window must be placed inside the content |
| 4446 | // of all screen decorations. |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4447 | if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 4448 | // Status bar panels and the volume dialog are the only windows who can go on |
| 4449 | // 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] | 4450 | // permission, so they have the same privileges as the status |
| 4451 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4452 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4453 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4454 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4455 | + mRestrictedScreenWidth; |
| 4456 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4457 | + mRestrictedScreenHeight; |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4458 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) { |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4459 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4460 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 4461 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 4462 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 4463 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4464 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4465 | pf.left = mContentLeft; |
| 4466 | pf.top = mContentTop; |
| 4467 | pf.right = mContentRight; |
| 4468 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 4469 | if (win.isVoiceInteraction()) { |
| 4470 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 4471 | df.top = of.top = cf.top = mVoiceContentTop; |
| 4472 | df.right = of.right = cf.right = mVoiceContentRight; |
| 4473 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 4474 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4475 | df.left = of.left = cf.left = mDockLeft; |
| 4476 | df.top = of.top = cf.top = mDockTop; |
| 4477 | df.right = of.right = cf.right = mDockRight; |
| 4478 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4479 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4480 | df.left = of.left = cf.left = mContentLeft; |
| 4481 | df.top = of.top = cf.top = mContentTop; |
| 4482 | df.right = of.right = cf.right = mContentRight; |
| 4483 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4484 | } |
| 4485 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4486 | vf.left = mCurLeft; |
| 4487 | vf.top = mCurTop; |
| 4488 | vf.right = mCurRight; |
| 4489 | vf.bottom = mCurBottom; |
| 4490 | } else { |
| 4491 | vf.set(cf); |
| 4492 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4493 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4494 | } |
| 4495 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4496 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 4497 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 4498 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 4499 | df.left = df.top = -10000; |
| 4500 | df.right = df.bottom = 10000; |
| 4501 | if (attrs.type != TYPE_WALLPAPER) { |
| 4502 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 4503 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 4504 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4505 | } |
| 4506 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4507 | // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we |
| 4508 | // 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] | 4509 | // We only want to apply outsets to certain types of windows. For example, we never want to |
| 4510 | // 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] | 4511 | final boolean useOutsets = shouldUseOutsets(attrs, fl); |
Filip Gruszczynski | b0c673b | 2015-06-05 09:43:06 -0700 | [diff] [blame] | 4512 | if (isDefaultDisplay && useOutsets) { |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4513 | osf = mTmpOutsetFrame; |
| 4514 | osf.set(cf.left, cf.top, cf.right, cf.bottom); |
| 4515 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 4516 | if (outset > 0) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4517 | int rotation = mDisplayRotation; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4518 | if (rotation == Surface.ROTATION_0) { |
| 4519 | osf.bottom += outset; |
| 4520 | } else if (rotation == Surface.ROTATION_90) { |
| 4521 | osf.right += outset; |
| 4522 | } else if (rotation == Surface.ROTATION_180) { |
| 4523 | osf.top -= outset; |
| 4524 | } else if (rotation == Surface.ROTATION_270) { |
| 4525 | osf.left -= outset; |
| 4526 | } |
| 4527 | if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset |
| 4528 | + " with rotation " + rotation + ", result: " + osf); |
| 4529 | } |
| 4530 | } |
| 4531 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4532 | 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] | 4533 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4534 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4535 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 4536 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4537 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4538 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4539 | + " dcf=" + dcf.toShortString() |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4540 | + " sf=" + sf.toShortString() |
| 4541 | + " osf=" + (osf == null ? "null" : osf.toShortString())); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4542 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4543 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4544 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4545 | // Dock windows carve out the bottom of the screen, so normal windows |
| 4546 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 4547 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 4548 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4549 | setLastInputMethodWindowLw(null, null); |
| 4550 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4551 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4552 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw() |
| 4553 | && !win.getGivenInsetsPendingLw()) { |
| 4554 | offsetVoiceInputWindowLw(win); |
| 4555 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4556 | } |
| 4557 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4558 | private void offsetInputMethodWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4559 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4560 | top += win.getGivenContentInsetsLw().top; |
| 4561 | if (mContentBottom > top) { |
| 4562 | mContentBottom = top; |
| 4563 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4564 | if (mVoiceContentBottom > top) { |
| 4565 | mVoiceContentBottom = top; |
| 4566 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4567 | top = win.getVisibleFrameLw().top; |
| 4568 | top += win.getGivenVisibleInsetsLw().top; |
| 4569 | if (mCurBottom > top) { |
| 4570 | mCurBottom = top; |
| 4571 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4572 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4573 | + mDockBottom + " mContentBottom=" |
| 4574 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 4575 | } |
| 4576 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4577 | private void offsetVoiceInputWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4578 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 4579 | top += win.getGivenContentInsetsLw().top; |
| 4580 | if (mVoiceContentBottom > top) { |
| 4581 | mVoiceContentBottom = top; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4582 | } |
| 4583 | } |
| 4584 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4585 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 4586 | @Override |
| 4587 | public void finishLayoutLw() { |
| 4588 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4592 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4593 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4594 | mTopFullscreenOpaqueWindowState = null; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4595 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 4596 | mTopDockedOpaqueWindowState = null; |
| 4597 | mTopDockedOpaqueOrDimmingWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4598 | mAppsToBeHidden.clear(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4599 | mAppsThatDismissKeyguard.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4600 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4601 | mForceStatusBarFromKeyguard = false; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4602 | mForceStatusBarTransparent = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4603 | mForcingShowNavBar = false; |
| 4604 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4605 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4606 | mHideLockScreen = false; |
| 4607 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4608 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4609 | mShowingLockscreen = false; |
| 4610 | mShowingDream = false; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4611 | mWinShowWhenLocked = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4612 | mKeyguardSecure = isKeyguardSecure(); |
| 4613 | mKeyguardSecureIncludingHidden = mKeyguardSecure |
| 4614 | && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4615 | } |
| 4616 | |
| 4617 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4618 | @Override |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 4619 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs, |
| 4620 | WindowState attached) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4621 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 4622 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4623 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4624 | if (mTopFullscreenOpaqueWindowState == null |
| 4625 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 4626 | mForcingShowNavBar = true; |
| 4627 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4628 | } |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4629 | if (attrs.type == TYPE_STATUS_BAR) { |
| 4630 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 4631 | mForceStatusBarFromKeyguard = true; |
Jorim Jaggi | e1de9f6 | 2015-09-23 14:59:50 -0700 | [diff] [blame] | 4632 | mShowingLockscreen = true; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4633 | } |
| 4634 | if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) { |
| 4635 | mForceStatusBarTransparent = true; |
| 4636 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 4637 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4638 | |
| 4639 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
| 4640 | && attrs.type < FIRST_SYSTEM_WINDOW; |
| 4641 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
| 4642 | final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 4643 | final int stackId = win.getStackId(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4644 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 4645 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4646 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4647 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4648 | mForceStatusBarFromKeyguard = true; |
| 4649 | } else { |
| 4650 | mForceStatusBar = true; |
| 4651 | } |
| 4652 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4653 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4654 | // If the lockscreen was showing when the dream started then wait |
| 4655 | // for the dream to draw before hiding the lockscreen. |
| 4656 | if (!mDreamingLockscreen |
| 4657 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 4658 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4659 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4660 | } |
| 4661 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4662 | |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 4663 | final IApplicationToken appToken = win.getAppToken(); |
| 4664 | |
| 4665 | // For app windows that are not attached, we decide if all windows in the app they |
| 4666 | // represent should be hidden or if we should hide the lockscreen. For attached app |
| 4667 | // windows we defer the decision to the window it is attached to. |
| 4668 | if (appWindow && attached == null) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4669 | if (showWhenLocked) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4670 | // Remove any previous windows with the same appToken. |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4671 | mAppsToBeHidden.remove(appToken); |
| 4672 | mAppsThatDismissKeyguard.remove(appToken); |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4673 | if (mAppsToBeHidden.isEmpty()) { |
Craig Mautner | 192d604 | 2014-12-02 23:24:48 -0800 | [diff] [blame] | 4674 | if (dismissKeyguard && !mKeyguardSecure) { |
| 4675 | mAppsThatDismissKeyguard.add(appToken); |
Selim Cinek | 90b5e07 | 2015-08-28 17:05:56 -0700 | [diff] [blame] | 4676 | } else if (win.isDrawnLw() || win.hasAppShownWindows()) { |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4677 | mWinShowWhenLocked = win; |
| 4678 | mHideLockScreen = true; |
| 4679 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4680 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4681 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4682 | } else if (dismissKeyguard) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4683 | if (mKeyguardSecure) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4684 | mAppsToBeHidden.add(appToken); |
| 4685 | } else { |
| 4686 | mAppsToBeHidden.remove(appToken); |
| 4687 | } |
| 4688 | mAppsThatDismissKeyguard.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4689 | } else { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4690 | mAppsToBeHidden.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4691 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 4692 | if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4693 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 4694 | mTopFullscreenOpaqueWindowState = win; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4695 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 4696 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4697 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4698 | if (!mAppsThatDismissKeyguard.isEmpty() && |
| 4699 | mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
| 4700 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4701 | "Setting mDismissKeyguard true by win " + win); |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4702 | mDismissKeyguard = (mWinDismissingKeyguard == win |
| 4703 | && mSecureDismissingKeyguard == mKeyguardSecure) |
| 4704 | ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4705 | mWinDismissingKeyguard = win; |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4706 | mSecureDismissingKeyguard = mKeyguardSecure; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4707 | mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure; |
Selim Cinek | 90b5e07 | 2015-08-28 17:05:56 -0700 | [diff] [blame] | 4708 | } else if (mAppsToBeHidden.isEmpty() && showWhenLocked |
| 4709 | && (win.isDrawnLw() || win.hasAppShownWindows())) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4710 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4711 | "Setting mHideLockScreen to true by win " + win); |
| 4712 | mHideLockScreen = true; |
| 4713 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4714 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 4715 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4716 | mAllowLockscreenWhenOn = true; |
| 4717 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4718 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4719 | |
| 4720 | if (mWinShowWhenLocked != null && |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4721 | mWinShowWhenLocked.getAppToken() != win.getAppToken() && |
| 4722 | (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4723 | win.hideLw(false); |
| 4724 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4725 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4726 | } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) { |
| 4727 | // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window |
| 4728 | // that is being hidden in an animation - keep the |
| 4729 | // keyguard hidden until the new window shows up and |
| 4730 | // we know whether to show the keyguard or not. |
Adrian Roos | b85e1ec | 2015-05-29 15:23:18 -0700 | [diff] [blame] | 4731 | if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) { |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4732 | mHideLockScreen = true; |
| 4733 | mWinShowWhenLocked = win; |
| 4734 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4735 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 4736 | |
| 4737 | // Keep track of the window if it's dimming but not necessarily fullscreen. |
| 4738 | final boolean reallyVisible = win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw(); |
| 4739 | if (mTopFullscreenOpaqueOrDimmingWindowState == null && reallyVisible |
| 4740 | && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) { |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4741 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4742 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 4743 | |
| 4744 | // We need to keep track of the top "fullscreen" opaque window for the docked stack |
| 4745 | // separately, because both the "real fullscreen" opaque window and the one for the docked |
| 4746 | // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR. |
| 4747 | if (mTopDockedOpaqueWindowState == null && reallyVisible && appWindow && attached == null |
| 4748 | && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) { |
| 4749 | mTopDockedOpaqueWindowState = win; |
| 4750 | if (mTopDockedOpaqueOrDimmingWindowState == null) { |
| 4751 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 4752 | } |
| 4753 | } |
| 4754 | |
| 4755 | // Also keep track of any windows that are dimming but not necessarily fullscreen in the |
| 4756 | // docked stack. |
| 4757 | if (mTopDockedOpaqueOrDimmingWindowState == null && reallyVisible && win.isDimming() |
| 4758 | && stackId == DOCKED_STACK_ID) { |
| 4759 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 4760 | } |
| 4761 | } |
| 4762 | |
| 4763 | private boolean isFullscreen(WindowManager.LayoutParams attrs) { |
| 4764 | return attrs.x == 0 && attrs.y == 0 |
| 4765 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 4766 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4767 | } |
| 4768 | |
| 4769 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4770 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4771 | public int finishPostLayoutPolicyLw() { |
Craig Mautner | c5e73bf | 2015-04-21 15:41:26 +0000 | [diff] [blame] | 4772 | if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null && |
| 4773 | mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken() |
| 4774 | && isKeyguardLocked()) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4775 | // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the |
| 4776 | // fullscreen window. |
| 4777 | // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not. |
| 4778 | mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4779 | mTopFullscreenOpaqueWindowState.hideLw(false); |
| 4780 | mTopFullscreenOpaqueWindowState = mWinShowWhenLocked; |
| 4781 | } |
| 4782 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4783 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4784 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4785 | |
| 4786 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 4787 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 4788 | : null; |
| 4789 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4790 | // If we are not currently showing a dream then remember the current |
| 4791 | // lockscreen state. We will use this to determine whether the dream |
| 4792 | // started while the lockscreen was showing and remember this state |
| 4793 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4794 | if (!mShowingDream) { |
| 4795 | mDreamingLockscreen = mShowingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 4796 | if (mDreamingSleepTokenNeeded) { |
| 4797 | mDreamingSleepTokenNeeded = false; |
| 4798 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget(); |
| 4799 | } |
| 4800 | } else { |
| 4801 | if (!mDreamingSleepTokenNeeded) { |
| 4802 | mDreamingSleepTokenNeeded = true; |
| 4803 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget(); |
| 4804 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4805 | } |
| 4806 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4807 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4808 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4809 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 4810 | + " top=" + mTopFullscreenOpaqueWindowState); |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4811 | boolean shouldBeTransparent = mForceStatusBarTransparent |
| 4812 | && !mForceStatusBar |
| 4813 | && !mForceStatusBarFromKeyguard; |
| 4814 | if (!shouldBeTransparent) { |
| 4815 | mStatusBarController.setShowTransparent(false /* transparent */); |
| 4816 | } else if (!mStatusBar.isVisibleLw()) { |
| 4817 | mStatusBarController.setShowTransparent(true /* transparent */); |
| 4818 | } |
| 4819 | if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4820 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4821 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4822 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4823 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4824 | // Maintain fullscreen layout until incoming animation is complete. |
| 4825 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 4826 | // Transient status bar on the lockscreen is not allowed |
| 4827 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 4828 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 4829 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 4830 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4831 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4832 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4833 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4834 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 4835 | + " shown position: " |
| 4836 | + mTopFullscreenOpaqueWindowState.getShownPositionLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4837 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4838 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4839 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4840 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4841 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4842 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 4843 | // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4844 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 4845 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4846 | if (mStatusBarController.isTransientShowing()) { |
| 4847 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4848 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4849 | } |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 4850 | } else if (topIsFullscreen |
| 4851 | && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID) |
| 4852 | && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4853 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4854 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4855 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4856 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 4857 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 4858 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4859 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4860 | 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] | 4861 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4862 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4863 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4864 | } |
| 4865 | } |
| 4866 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4867 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4868 | if (mTopIsFullscreen != topIsFullscreen) { |
| 4869 | if (!topIsFullscreen) { |
| 4870 | // Force another layout when status bar becomes fully shown. |
| 4871 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4872 | } |
| 4873 | mTopIsFullscreen = topIsFullscreen; |
| 4874 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4875 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4876 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 4877 | // displayed when the screen is locked. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4878 | if (mKeyguardDelegate != null && mStatusBar != null) { |
| 4879 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 4880 | + mHideLockScreen); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4881 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4882 | mKeyguardHidden = true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4883 | if (setKeyguardOccludedLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4884 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4885 | | FINISH_LAYOUT_REDO_CONFIG |
| 4886 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4887 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4888 | if (mKeyguardDelegate.isShowing()) { |
| 4889 | mHandler.post(new Runnable() { |
| 4890 | @Override |
| 4891 | public void run() { |
| 4892 | mKeyguardDelegate.keyguardDone(false, false); |
| 4893 | } |
| 4894 | }); |
| 4895 | } |
| 4896 | } else if (mHideLockScreen) { |
| 4897 | mKeyguardHidden = true; |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 4898 | mWinDismissingKeyguard = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4899 | if (setKeyguardOccludedLw(true)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4900 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4901 | | FINISH_LAYOUT_REDO_CONFIG |
| 4902 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4903 | } |
| 4904 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 4905 | mKeyguardHidden = false; |
| 4906 | if (setKeyguardOccludedLw(false)) { |
| 4907 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4908 | | FINISH_LAYOUT_REDO_CONFIG |
| 4909 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4910 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4911 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 4912 | // Only launch the next keyguard unlock window once per window. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4913 | mHandler.post(new Runnable() { |
| 4914 | @Override |
| 4915 | public void run() { |
| 4916 | mKeyguardDelegate.dismiss(); |
| 4917 | } |
| 4918 | }); |
| 4919 | } |
| 4920 | } else { |
| 4921 | mWinDismissingKeyguard = null; |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4922 | mSecureDismissingKeyguard = false; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4923 | mKeyguardHidden = false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4924 | if (setKeyguardOccludedLw(false)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4925 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4926 | | FINISH_LAYOUT_REDO_CONFIG |
| 4927 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4928 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 4929 | } |
| 4930 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4931 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4932 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4933 | // If the navigation bar has been hidden or shown, we need to do another |
| 4934 | // layout pass to update that window. |
| 4935 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4936 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4937 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4938 | // update since mAllowLockscreenWhenOn might have changed |
| 4939 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4940 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4941 | } |
| 4942 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4943 | /** |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4944 | * Updates the occluded state of the Keyguard. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4945 | * |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4946 | * @return Whether the flags have changed and we have to redo the layout. |
| 4947 | */ |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4948 | private boolean setKeyguardOccludedLw(boolean isOccluded) { |
| 4949 | boolean wasOccluded = mKeyguardOccluded; |
| 4950 | boolean showing = mKeyguardDelegate.isShowing(); |
| 4951 | if (wasOccluded && !isOccluded && showing) { |
| 4952 | mKeyguardOccluded = false; |
| 4953 | mKeyguardDelegate.setOccluded(false); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4954 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 4955 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4956 | return true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4957 | } else if (!wasOccluded && isOccluded && showing) { |
| 4958 | mKeyguardOccluded = true; |
| 4959 | mKeyguardDelegate.setOccluded(true); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4960 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 4961 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 4962 | return true; |
| 4963 | } else { |
| 4964 | return false; |
| 4965 | } |
| 4966 | } |
| 4967 | |
| 4968 | private boolean isStatusBarKeyguard() { |
| 4969 | return mStatusBar != null |
| 4970 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 4971 | } |
| 4972 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4973 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4974 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4975 | if (isStatusBarKeyguard() || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 4976 | // 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] | 4977 | return false; |
| 4978 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4979 | return true; |
| 4980 | } |
| 4981 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4982 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4983 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4984 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4985 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4986 | // If the navigation bar has been hidden or shown, we need to do another |
| 4987 | // layout pass to update that window. |
| 4988 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 4989 | } |
| 4990 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4991 | } |
| 4992 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 4993 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4994 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4995 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 4996 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4997 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 4998 | if (newLidState == mLidState) { |
| 4999 | return; |
| 5000 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5001 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5002 | mLidState = newLidState; |
| 5003 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5004 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5005 | |
| 5006 | if (lidOpen) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5007 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch, |
| 5008 | "android.policy:LID"); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5009 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 5010 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5011 | } |
| 5012 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5013 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5014 | @Override |
| 5015 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 5016 | int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; |
| 5017 | if (mCameraLensCoverState == lensCoverState) { |
| 5018 | return; |
| 5019 | } |
| 5020 | if (mCameraLensCoverState == CAMERA_LENS_COVERED && |
| 5021 | lensCoverState == CAMERA_LENS_UNCOVERED) { |
| 5022 | Intent intent; |
| 5023 | final boolean keyguardActive = mKeyguardDelegate == null ? false : |
| 5024 | mKeyguardDelegate.isShowing(); |
| 5025 | if (keyguardActive) { |
| 5026 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); |
| 5027 | } else { |
| 5028 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 5029 | } |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5030 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens, |
| 5031 | "android.policy:CAMERA_COVER"); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5032 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5033 | } |
| 5034 | mCameraLensCoverState = lensCoverState; |
| 5035 | } |
| 5036 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5037 | void setHdmiPlugged(boolean plugged) { |
| 5038 | if (mHdmiPlugged != plugged) { |
| 5039 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5040 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5041 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5042 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5043 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 5044 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5045 | } |
| 5046 | } |
| 5047 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5048 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 5049 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5050 | // watch for HDMI plug messages if the hdmi switch exists |
| 5051 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 5052 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 5053 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5054 | final String filename = "/sys/class/switch/hdmi/state"; |
| 5055 | FileReader reader = null; |
| 5056 | try { |
| 5057 | reader = new FileReader(filename); |
| 5058 | char[] buf = new char[15]; |
| 5059 | int n = reader.read(buf); |
| 5060 | if (n > 1) { |
| 5061 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 5062 | } |
| 5063 | } catch (IOException ex) { |
| 5064 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 5065 | } catch (NumberFormatException ex) { |
| 5066 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 5067 | } finally { |
| 5068 | if (reader != null) { |
| 5069 | try { |
| 5070 | reader.close(); |
| 5071 | } catch (IOException ex) { |
| 5072 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5073 | } |
| 5074 | } |
| 5075 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 5076 | // This dance forces the code in setHdmiPlugged to run. |
| 5077 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 5078 | mHdmiPlugged = !plugged; |
| 5079 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5080 | } |
| 5081 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 5082 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 5083 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 5084 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5085 | final Runnable mScreenshotTimeout = new Runnable() { |
| 5086 | @Override public void run() { |
| 5087 | synchronized (mScreenshotLock) { |
| 5088 | if (mScreenshotConnection != null) { |
| 5089 | mContext.unbindService(mScreenshotConnection); |
| 5090 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 5091 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 5092 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5093 | } |
| 5094 | }; |
| 5095 | |
| 5096 | // Assume this is called from the Handler thread. |
| 5097 | private void takeScreenshot() { |
| 5098 | synchronized (mScreenshotLock) { |
| 5099 | if (mScreenshotConnection != null) { |
| 5100 | return; |
| 5101 | } |
| 5102 | ComponentName cn = new ComponentName("com.android.systemui", |
| 5103 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 5104 | Intent intent = new Intent(); |
| 5105 | intent.setComponent(cn); |
| 5106 | ServiceConnection conn = new ServiceConnection() { |
| 5107 | @Override |
| 5108 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 5109 | synchronized (mScreenshotLock) { |
| 5110 | if (mScreenshotConnection != this) { |
| 5111 | return; |
| 5112 | } |
| 5113 | Messenger messenger = new Messenger(service); |
| 5114 | Message msg = Message.obtain(null, 1); |
| 5115 | final ServiceConnection myConn = this; |
| 5116 | Handler h = new Handler(mHandler.getLooper()) { |
| 5117 | @Override |
| 5118 | public void handleMessage(Message msg) { |
| 5119 | synchronized (mScreenshotLock) { |
| 5120 | if (mScreenshotConnection == myConn) { |
| 5121 | mContext.unbindService(mScreenshotConnection); |
| 5122 | mScreenshotConnection = null; |
| 5123 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 5124 | } |
| 5125 | } |
| 5126 | } |
| 5127 | }; |
| 5128 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 5129 | msg.arg1 = msg.arg2 = 0; |
| 5130 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 5131 | msg.arg1 = 1; |
| 5132 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 5133 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5134 | try { |
| 5135 | messenger.send(msg); |
| 5136 | } catch (RemoteException e) { |
| 5137 | } |
| 5138 | } |
| 5139 | } |
| 5140 | @Override |
| 5141 | public void onServiceDisconnected(ComponentName name) {} |
| 5142 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 5143 | if (mContext.bindServiceAsUser( |
| 5144 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5145 | mScreenshotConnection = conn; |
| 5146 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 5147 | } |
| 5148 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 5149 | } |
| 5150 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5151 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5152 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5153 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 5154 | if (!mSystemBooted) { |
| 5155 | // If we have not yet booted, don't let key events do anything. |
| 5156 | return 0; |
| 5157 | } |
| 5158 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5159 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 5160 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 5161 | final boolean canceled = event.isCanceled(); |
| 5162 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 5163 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 5164 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 5165 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 5166 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 5167 | // the same as if it were open and in front. |
| 5168 | // This will prevent any keys other than the power button from waking the screen |
| 5169 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5170 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5171 | (interactive ? |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5172 | isKeyguardShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5173 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5174 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5175 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5176 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5177 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5178 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5179 | } |
| 5180 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5181 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5182 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 5183 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 5184 | || event.isWakeKey(); |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 5185 | if (interactive || (isInjected && !isWakeKey)) { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 5186 | // When the device is interactive or the key is injected pass the |
| 5187 | // key to the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5188 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5189 | isWakeKey = false; |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 5190 | } else if (!interactive && shouldDispatchInputWhenNonInteractive()) { |
| 5191 | // If we're currently dozing with the screen on and the keyguard showing, pass the key |
| 5192 | // to the application but preserve its wake key status to make sure we still move |
| 5193 | // from dozing to fully interactive if we would normally go from off to fully |
| 5194 | // interactive. |
| 5195 | result = ACTION_PASS_TO_USER; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5196 | } else { |
| 5197 | // When the screen is off and the key is not injected, determine whether |
| 5198 | // to wake the device but don't pass the key to the application. |
| 5199 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5200 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 5201 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5202 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5203 | } |
| 5204 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 5205 | // If the key would be handled globally, just return the result, don't worry about special |
| 5206 | // key processing. |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5207 | if (isValidGlobalKey(keyCode) |
| 5208 | && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 5209 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5210 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 5211 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 5212 | return result; |
| 5213 | } |
| 5214 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5215 | boolean useHapticFeedback = down |
| 5216 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 5217 | && event.getRepeatCount() == 0; |
| 5218 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5219 | // Handle special keys. |
| 5220 | switch (keyCode) { |
| 5221 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 5222 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5223 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5224 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 5225 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5226 | if (interactive && !mScreenshotChordVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5227 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5228 | mScreenshotChordVolumeDownKeyTriggered = true; |
| 5229 | mScreenshotChordVolumeDownKeyTime = event.getDownTime(); |
| 5230 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5231 | cancelPendingPowerKeyAction(); |
| 5232 | interceptScreenshotChord(); |
| 5233 | } |
| 5234 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5235 | mScreenshotChordVolumeDownKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5236 | cancelPendingScreenshotChordAction(); |
| 5237 | } |
| 5238 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 5239 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5240 | if (interactive && !mScreenshotChordVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5241 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5242 | mScreenshotChordVolumeUpKeyTriggered = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5243 | cancelPendingPowerKeyAction(); |
| 5244 | cancelPendingScreenshotChordAction(); |
| 5245 | } |
| 5246 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5247 | mScreenshotChordVolumeUpKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5248 | cancelPendingScreenshotChordAction(); |
| 5249 | } |
| 5250 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5251 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5252 | TelecomManager telecomManager = getTelecommService(); |
| 5253 | if (telecomManager != null) { |
| 5254 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5255 | // If an incoming call is ringing, either VOLUME key means |
| 5256 | // "silence ringer". We handle these keys here, rather than |
| 5257 | // in the InCallScreen, to make sure we'll respond to them |
| 5258 | // even if the InCallScreen hasn't come to the foreground yet. |
| 5259 | // Look for the DOWN event here, to agree with the "fallback" |
| 5260 | // behavior in the InCallScreen. |
| 5261 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 5262 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5263 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5264 | // Silence the ringer. (It's safe to call this |
| 5265 | // even if the ringer has already been silenced.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5266 | telecomManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5267 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5268 | // And *don't* pass this key thru to the current activity |
| 5269 | // (which is probably the InCallScreen.) |
| 5270 | result &= ~ACTION_PASS_TO_USER; |
| 5271 | break; |
| 5272 | } |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5273 | if (telecomManager.isInCall() |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5274 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 5275 | // If we are in call but we decided not to pass the key to |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 5276 | // the application, just pass it to the session service. |
| 5277 | |
| 5278 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 5279 | .sendVolumeKeyEvent(event, false); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5280 | break; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5281 | } |
| 5282 | } |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 5283 | } |
| 5284 | if (mUseTvRouting) { |
| 5285 | // On TVs, defer special key handlings to |
| 5286 | // {@link interceptKeyBeforeDispatching()}. |
| 5287 | result |= ACTION_PASS_TO_USER; |
| 5288 | } else if ((result & ACTION_PASS_TO_USER) == 0) { |
| 5289 | // If we aren't passing to the user and no one else |
| 5290 | // handled it send it to the session manager to |
| 5291 | // figure out. |
| 5292 | MediaSessionLegacyHelper.getHelper(mContext) |
| 5293 | .sendVolumeKeyEvent(event, true); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5294 | } |
| 5295 | break; |
| 5296 | } |
| 5297 | |
| 5298 | case KeyEvent.KEYCODE_ENDCALL: { |
| 5299 | result &= ~ACTION_PASS_TO_USER; |
| 5300 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5301 | TelecomManager telecomManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5302 | boolean hungUp = false; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5303 | if (telecomManager != null) { |
| 5304 | hungUp = telecomManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5305 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5306 | if (interactive && !hungUp) { |
| 5307 | mEndCallKeyHandled = false; |
| 5308 | mHandler.postDelayed(mEndCallLongPress, |
| 5309 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 5310 | } else { |
| 5311 | mEndCallKeyHandled = true; |
| 5312 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5313 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5314 | if (!mEndCallKeyHandled) { |
| 5315 | mHandler.removeCallbacks(mEndCallLongPress); |
| 5316 | if (!canceled) { |
| 5317 | if ((mEndcallBehavior |
| 5318 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 5319 | if (goHome()) { |
| 5320 | break; |
| 5321 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 5322 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5323 | if ((mEndcallBehavior |
| 5324 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 5325 | mPowerManager.goToSleep(event.getEventTime(), |
| 5326 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 5327 | isWakeKey = false; |
| 5328 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5329 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5330 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5331 | } |
| 5332 | break; |
| 5333 | } |
| 5334 | |
| 5335 | case KeyEvent.KEYCODE_POWER: { |
| 5336 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5337 | isWakeKey = false; // wake-up will be handled separately |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5338 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5339 | interceptPowerKeyDown(event, interactive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5340 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5341 | interceptPowerKeyUp(event, interactive, canceled); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5342 | } |
| 5343 | break; |
| 5344 | } |
| 5345 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5346 | case KeyEvent.KEYCODE_SLEEP: { |
| 5347 | result &= ~ACTION_PASS_TO_USER; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 5348 | isWakeKey = false; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5349 | if (!mPowerManager.isInteractive()) { |
| 5350 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 5351 | } |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 5352 | if (down) { |
| 5353 | sleepPress(event.getEventTime()); |
| 5354 | } else { |
| 5355 | sleepRelease(event.getEventTime()); |
| 5356 | } |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5357 | break; |
| 5358 | } |
| 5359 | |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 5360 | case KeyEvent.KEYCODE_SOFT_SLEEP: { |
| 5361 | result &= ~ACTION_PASS_TO_USER; |
| 5362 | isWakeKey = false; |
| 5363 | if (!down) { |
| 5364 | mPowerManagerInternal.setUserInactiveOverrideFromWindowManager(); |
| 5365 | } |
| 5366 | break; |
| 5367 | } |
| 5368 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5369 | case KeyEvent.KEYCODE_WAKEUP: { |
| 5370 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5371 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5372 | break; |
| 5373 | } |
| 5374 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5375 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 5376 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 5377 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5378 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 5379 | case KeyEvent.KEYCODE_MUTE: |
| 5380 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 5381 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 5382 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 5383 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 5384 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 5385 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 5386 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 5387 | if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { |
| 5388 | // If the global session is active pass all media keys to it |
| 5389 | // instead of the active window. |
| 5390 | result &= ~ACTION_PASS_TO_USER; |
| 5391 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5392 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 5393 | // Only do this if we would otherwise not pass it to the user. In that |
| 5394 | // case, the PhoneWindow class will do the same thing, except it will |
| 5395 | // 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] | 5396 | // Note that we need to make a copy of the key event here because the |
| 5397 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5398 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5399 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 5400 | new KeyEvent(event)); |
| 5401 | msg.setAsynchronous(true); |
| 5402 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5403 | } |
| 5404 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5405 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5406 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5407 | case KeyEvent.KEYCODE_CALL: { |
| 5408 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5409 | TelecomManager telecomManager = getTelecommService(); |
| 5410 | if (telecomManager != null) { |
| 5411 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5412 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 5413 | + " CALL key-down while ringing: Answer the call!"); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5414 | telecomManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5415 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5416 | // And *don't* pass this key thru to the current activity |
| 5417 | // (which is presumably the InCallScreen.) |
| 5418 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5419 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5420 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5421 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5422 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5423 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5424 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 5425 | // Only do this if we would otherwise not pass it to the user. In that case, |
| 5426 | // interceptKeyBeforeDispatching would apply a similar but different policy in |
| 5427 | // order to invoke voice assist actions. Note that we need to make a copy of the |
| 5428 | // key event here because the original key event will be recycled when we return. |
| 5429 | if ((result & ACTION_PASS_TO_USER) == 0 && !down) { |
| 5430 | mBroadcastWakeLock.acquire(); |
| 5431 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, |
| 5432 | keyguardActive ? 1 : 0, 0); |
| 5433 | msg.setAsynchronous(true); |
| 5434 | msg.sendToTarget(); |
| 5435 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 5436 | break; |
| 5437 | } |
| 5438 | case KeyEvent.KEYCODE_WINDOW: { |
| 5439 | if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) { |
| 5440 | if (!down) { |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 5441 | requestTvPictureInPicture(event); |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 5442 | } |
| 5443 | result &= ~ACTION_PASS_TO_USER; |
| 5444 | } |
| 5445 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5446 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5447 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5448 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5449 | if (useHapticFeedback) { |
| 5450 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 5451 | } |
| 5452 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5453 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5454 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5455 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 5456 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5457 | return result; |
| 5458 | } |
| 5459 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5460 | /** |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5461 | * Returns true if the key can have global actions attached to it. |
| 5462 | * We reserve all power management keys for the system since they require |
| 5463 | * very careful handling. |
| 5464 | */ |
| 5465 | private static boolean isValidGlobalKey(int keyCode) { |
| 5466 | switch (keyCode) { |
| 5467 | case KeyEvent.KEYCODE_POWER: |
| 5468 | case KeyEvent.KEYCODE_WAKEUP: |
| 5469 | case KeyEvent.KEYCODE_SLEEP: |
| 5470 | return false; |
| 5471 | default: |
| 5472 | return true; |
| 5473 | } |
| 5474 | } |
| 5475 | |
| 5476 | /** |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5477 | * When the screen is off we ignore some keys that might otherwise typically |
| 5478 | * be considered wake keys. We filter them out here. |
| 5479 | * |
| 5480 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 5481 | * is always considered a wake key. |
| 5482 | */ |
| 5483 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 5484 | switch (keyCode) { |
| 5485 | // ignore volume keys unless docked |
| 5486 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5487 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5488 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5489 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 5490 | |
| 5491 | // ignore media and camera keys |
| 5492 | case KeyEvent.KEYCODE_MUTE: |
| 5493 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 5494 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 5495 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 5496 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 5497 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 5498 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 5499 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 5500 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 5501 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 5502 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 5503 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5504 | case KeyEvent.KEYCODE_CAMERA: |
| 5505 | return false; |
| 5506 | } |
| 5507 | return true; |
| 5508 | } |
| 5509 | |
| 5510 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5511 | /** {@inheritDoc} */ |
| 5512 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5513 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 5514 | if ((policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5515 | if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion, |
| 5516 | "android.policy:MOTION")) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5517 | return 0; |
| 5518 | } |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5519 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5520 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5521 | if (shouldDispatchInputWhenNonInteractive()) { |
| 5522 | return ACTION_PASS_TO_USER; |
| 5523 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5524 | |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 5525 | // If we have not passed the action up and we are in theater mode without dreaming, |
| 5526 | // there will be no dream to intercept the touch and wake into ambient. The device should |
| 5527 | // wake up in this case. |
| 5528 | if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5529 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming, |
| 5530 | "android.policy:MOTION"); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 5531 | } |
| 5532 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5533 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5534 | } |
| 5535 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5536 | private boolean shouldDispatchInputWhenNonInteractive() { |
Joe LaPenna | f2b9b2d | 2015-11-17 22:22:37 +0000 | [diff] [blame] | 5537 | // Send events to keyguard while the screen is on. |
| 5538 | if (isKeyguardShowingAndNotOccluded() && mDisplay != null |
| 5539 | && mDisplay.getState() != Display.STATE_OFF) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5540 | return true; |
| 5541 | } |
| 5542 | |
| 5543 | // Send events to a dozing dream even if the screen is off since the dream |
| 5544 | // is in control of the state of the screen. |
| 5545 | IDreamManager dreamManager = getDreamManager(); |
| 5546 | |
| 5547 | try { |
| 5548 | if (dreamManager != null && dreamManager.isDreaming()) { |
| 5549 | return true; |
| 5550 | } |
| 5551 | } catch (RemoteException e) { |
| 5552 | Slog.e(TAG, "RemoteException when checking if dreaming", e); |
| 5553 | } |
| 5554 | |
| 5555 | // Otherwise, consume events since the user can't see what is being |
| 5556 | // interacted with. |
| 5557 | return false; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5558 | } |
| 5559 | |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5560 | private void dispatchDirectAudioEvent(KeyEvent event) { |
| 5561 | if (event.getAction() != KeyEvent.ACTION_DOWN) { |
| 5562 | return; |
| 5563 | } |
| 5564 | int keyCode = event.getKeyCode(); |
John Spurlock | b94f2d6 | 2015-03-17 14:11:57 -0400 | [diff] [blame] | 5565 | int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND |
| 5566 | | AudioManager.FLAG_FROM_KEY; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5567 | String pkgName = mContext.getOpPackageName(); |
| 5568 | switch (keyCode) { |
| 5569 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5570 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5571 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5572 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5573 | } catch (RemoteException e) { |
| 5574 | Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e); |
| 5575 | } |
| 5576 | break; |
| 5577 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5578 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5579 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5580 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5581 | } catch (RemoteException e) { |
| 5582 | Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e); |
| 5583 | } |
| 5584 | break; |
| 5585 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5586 | try { |
| 5587 | if (event.getRepeatCount() == 0) { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5588 | getAudioService().adjustSuggestedStreamVolume( |
| 5589 | AudioManager.ADJUST_TOGGLE_MUTE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5590 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5591 | } |
| 5592 | } catch (RemoteException e) { |
| 5593 | Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e); |
| 5594 | } |
| 5595 | break; |
| 5596 | } |
| 5597 | } |
| 5598 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5599 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 5600 | if (DEBUG_INPUT) { |
| 5601 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5602 | } |
| 5603 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5604 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 5605 | if (DEBUG_INPUT) { |
| 5606 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 5607 | } |
| 5608 | |
| 5609 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 5610 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5611 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 5612 | } |
| 5613 | |
| 5614 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 5615 | |
| 5616 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 5617 | && event.getRepeatCount() == 0) { |
| 5618 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 5619 | |
| 5620 | Message msg = mHandler.obtainMessage( |
| 5621 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 5622 | msg.setAsynchronous(true); |
| 5623 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 5624 | } else { |
| 5625 | mBroadcastWakeLock.release(); |
| 5626 | } |
| 5627 | } |
| 5628 | |
| 5629 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 5630 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5631 | |
| 5632 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 5633 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 5634 | if (DEBUG_INPUT) { |
| 5635 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 5636 | } |
| 5637 | |
| 5638 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 5639 | mBroadcastWakeLock.release(); |
| 5640 | } |
| 5641 | |
| 5642 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 5643 | if (ActivityManagerNative.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 5644 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5645 | } |
| 5646 | } |
| 5647 | |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5648 | void launchVoiceAssistWithWakeLock(boolean keyguardActive) { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 5649 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 5650 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 5651 | if (dic != null) { |
| 5652 | try { |
| 5653 | dic.exitIdle("voice-search"); |
| 5654 | } catch (RemoteException e) { |
| 5655 | } |
| 5656 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5657 | Intent voiceIntent = |
| 5658 | new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 5659 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5660 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5661 | mBroadcastWakeLock.release(); |
| 5662 | } |
| 5663 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5664 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5665 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5666 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 5667 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 5668 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 5669 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5670 | } else { |
| 5671 | try { |
| 5672 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 5673 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5674 | mUiMode = uiModeService.getCurrentModeType(); |
| 5675 | } catch (RemoteException e) { |
| 5676 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 5677 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5678 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5679 | synchronized (mLock) { |
| 5680 | updateOrientationListenerLp(); |
| 5681 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5682 | } |
| 5683 | }; |
| 5684 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5685 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 5686 | @Override |
| 5687 | public void onReceive(Context context, Intent intent) { |
| 5688 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5689 | if (mKeyguardDelegate != null) { |
| 5690 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5691 | } |
| 5692 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5693 | if (mKeyguardDelegate != null) { |
| 5694 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5695 | } |
| 5696 | } |
| 5697 | } |
| 5698 | }; |
| 5699 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5700 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 5701 | @Override |
| 5702 | public void onReceive(Context context, Intent intent) { |
| 5703 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 5704 | // tickle the settings observer: this first ensures that we're |
| 5705 | // observing the relevant settings for the newly-active user, |
| 5706 | // and then updates our own bookkeeping based on the now- |
| 5707 | // current user. |
| 5708 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5709 | |
| 5710 | // force a re-application of focused window sysui visibility. |
| 5711 | // the window may never have been shown for this user |
| 5712 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5713 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5714 | mLastSystemUiFlags = 0; |
| 5715 | updateSystemUiVisibilityLw(); |
| 5716 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5717 | } |
| 5718 | } |
| 5719 | }; |
| 5720 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5721 | private final Runnable mHiddenNavPanic = new Runnable() { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5722 | @Override |
| 5723 | public void run() { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5724 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 5725 | if (!isUserSetupComplete()) { |
| 5726 | // Swipe-up for navigation bar is disabled during setup |
| 5727 | return; |
| 5728 | } |
| 5729 | mPendingPanicGestureUptime = SystemClock.uptimeMillis(); |
| 5730 | mNavigationBarController.showTransient(); |
| 5731 | } |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5732 | } |
| 5733 | }; |
| 5734 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5735 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5736 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 5737 | if (!isUserSetupComplete()) { |
| 5738 | // Swipe-up for navigation bar is disabled during setup |
| 5739 | return; |
| 5740 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5741 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 5742 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5743 | if (sb || nb) { |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 5744 | // Don't show status bar when swiping on already visible navigation bar |
| 5745 | if (!nb && swipeTarget == mNavigationBar) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5746 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5747 | return; |
| 5748 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5749 | if (sb) mStatusBarController.showTransient(); |
| 5750 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5751 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5752 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5753 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5754 | } |
| 5755 | } |
| 5756 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5757 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5758 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5759 | public void startedGoingToSleep(int why) { |
| 5760 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")"); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 5761 | if (mKeyguardDelegate != null) { |
| 5762 | mKeyguardDelegate.onStartedGoingToSleep(why); |
| 5763 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5764 | } |
| 5765 | |
| 5766 | // Called on the PowerManager's Notifier thread. |
| 5767 | @Override |
| 5768 | public void finishedGoingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5769 | EventLog.writeEvent(70000, 0); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5770 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")"); |
Chris Wren | 9bb290b | 2015-06-29 12:02:13 -0400 | [diff] [blame] | 5771 | MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5772 | |
| 5773 | // We must get this work done here because the power manager will drop |
| 5774 | // 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] | 5775 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5776 | mAwake = false; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5777 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5778 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5779 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5780 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5781 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 5782 | mKeyguardDelegate.onFinishedGoingToSleep(why); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5783 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5784 | } |
| 5785 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5786 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5787 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5788 | public void startedWakingUp() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5789 | EventLog.writeEvent(70000, 1); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5790 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up..."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5791 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5792 | // Since goToSleep performs these functions synchronously, we must |
| 5793 | // do the same here. We cannot post this work to a handler because |
| 5794 | // that might cause it to become reordered with respect to what |
| 5795 | // may happen in a future call to goToSleep. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5796 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5797 | mAwake = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5798 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5799 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5800 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5801 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5802 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5803 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5804 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5805 | mKeyguardDelegate.onStartedWakingUp(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5806 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5807 | } |
| 5808 | |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5809 | // Called on the PowerManager's Notifier thread. |
| 5810 | @Override |
| 5811 | public void finishedWakingUp() { |
| 5812 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up..."); |
| 5813 | } |
| 5814 | |
| 5815 | private void wakeUpFromPowerKey(long eventTime) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5816 | wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER"); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5817 | } |
| 5818 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5819 | private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) { |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 5820 | final boolean theaterModeEnabled = isTheaterModeEnabled(); |
| 5821 | if (!wakeInTheaterMode && theaterModeEnabled) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5822 | return false; |
| 5823 | } |
| 5824 | |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 5825 | if (theaterModeEnabled) { |
| 5826 | Settings.Global.putInt(mContext.getContentResolver(), |
| 5827 | Settings.Global.THEATER_MODE_ON, 0); |
| 5828 | } |
| 5829 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5830 | mPowerManager.wakeUp(wakeTime, reason); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5831 | return true; |
| 5832 | } |
| 5833 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5834 | private void finishKeyguardDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5835 | synchronized (mLock) { |
Jorim Jaggi | f325548 | 2015-07-24 12:32:42 -0700 | [diff] [blame] | 5836 | if (!mScreenOnEarly || mKeyguardDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 5837 | 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] | 5838 | } |
| 5839 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5840 | mKeyguardDrawComplete = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5841 | if (mKeyguardDelegate != null) { |
| 5842 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5843 | } |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5844 | mWindowManagerDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5845 | } |
| 5846 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5847 | // ... eventually calls finishWindowsDrawn which will finalize our screen turn on |
| 5848 | // as well as enabling the orientation change logic/sensor. |
| 5849 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, |
| 5850 | WAITING_FOR_DRAWN_TIMEOUT); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5851 | } |
| 5852 | |
| 5853 | // Called on the DisplayManager's DisplayPowerController thread. |
| 5854 | @Override |
| 5855 | public void screenTurnedOff() { |
| 5856 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); |
| 5857 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 5858 | updateScreenOffSleepToken(true); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5859 | synchronized (mLock) { |
| 5860 | mScreenOnEarly = false; |
| 5861 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 5862 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5863 | mWindowManagerDrawComplete = false; |
| 5864 | mScreenOnListener = null; |
| 5865 | updateOrientationListenerLp(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 5866 | |
| 5867 | if (mKeyguardDelegate != null) { |
| 5868 | mKeyguardDelegate.onScreenTurnedOff(); |
| 5869 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5870 | } |
| 5871 | } |
| 5872 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5873 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5874 | @Override |
| 5875 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5876 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5877 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 5878 | updateScreenOffSleepToken(false); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5879 | synchronized (mLock) { |
| 5880 | mScreenOnEarly = true; |
| 5881 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 5882 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5883 | mWindowManagerDrawComplete = false; |
| 5884 | mScreenOnListener = screenOnListener; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5885 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5886 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | a4b51bc | 2015-08-10 18:20:43 -0700 | [diff] [blame] | 5887 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5888 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5889 | mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback); |
| 5890 | } else { |
| 5891 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 5892 | "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
| 5893 | finishKeyguardDrawn(); |
| 5894 | } |
| 5895 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5896 | } |
| 5897 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 5898 | // Called on the DisplayManager's DisplayPowerController thread. |
| 5899 | @Override |
| 5900 | public void screenTurnedOn() { |
| 5901 | synchronized (mLock) { |
| 5902 | if (mKeyguardDelegate != null) { |
| 5903 | mKeyguardDelegate.onScreenTurnedOn(); |
| 5904 | } |
| 5905 | } |
| 5906 | } |
| 5907 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5908 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5909 | synchronized (mLock) { |
| 5910 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 5911 | 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] | 5912 | } |
| 5913 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5914 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5915 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5916 | |
| 5917 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5918 | } |
| 5919 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5920 | private void finishScreenTurningOn() { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 5921 | synchronized (mLock) { |
| 5922 | // We have just finished drawing screen content. Since the orientation listener |
| 5923 | // gets only installed when all windows are drawn, we try to install it again. |
| 5924 | updateOrientationListenerLp(); |
| 5925 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5926 | final ScreenOnListener listener; |
| 5927 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5928 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5929 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 5930 | "finishScreenTurningOn: mAwake=" + mAwake |
| 5931 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 5932 | + ", mScreenOnFully=" + mScreenOnFully |
| 5933 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 5934 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 5935 | |
| 5936 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 5937 | || (mAwake && !mKeyguardDrawComplete)) { |
| 5938 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5939 | } |
| 5940 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5941 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 5942 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 5943 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5944 | mScreenOnFully = true; |
| 5945 | |
| 5946 | // Remember the first time we draw the keyguard so we know when we're done with |
| 5947 | // the main part of booting and can enable the screen and hide boot messages. |
| 5948 | if (!mKeyguardDrawnOnce && mAwake) { |
| 5949 | mKeyguardDrawnOnce = true; |
| 5950 | enableScreen = true; |
| 5951 | if (mBootMessageNeedsHiding) { |
| 5952 | mBootMessageNeedsHiding = false; |
| 5953 | hideBootMessages(); |
| 5954 | } |
| 5955 | } else { |
| 5956 | enableScreen = false; |
| 5957 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5958 | } |
| 5959 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5960 | if (listener != null) { |
| 5961 | listener.onScreenOn(); |
| 5962 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 5963 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5964 | if (enableScreen) { |
| 5965 | try { |
| 5966 | mWindowManager.enableScreenIfNeeded(); |
| 5967 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5968 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5969 | } |
| 5970 | } |
| 5971 | |
| 5972 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5973 | synchronized (mLock) { |
| 5974 | if (!mKeyguardDrawnOnce) { |
| 5975 | mBootMessageNeedsHiding = true; |
| 5976 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 5977 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5978 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5979 | |
| 5980 | if (mBootMsgDialog != null) { |
| 5981 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 5982 | mBootMsgDialog.dismiss(); |
| 5983 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5984 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5985 | } |
| 5986 | |
| 5987 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5988 | public boolean isScreenOn() { |
| 5989 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5990 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5991 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5992 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5993 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5994 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5995 | if (mKeyguardDelegate != null) { |
| 5996 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5997 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5998 | } |
| 5999 | |
| 6000 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6001 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6002 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6003 | if (mKeyguardDelegate != null) { |
| 6004 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6005 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6006 | } |
| 6007 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6008 | private boolean isKeyguardShowingAndNotOccluded() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6009 | if (mKeyguardDelegate == null) return false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6010 | return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6011 | } |
| 6012 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6013 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6014 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6015 | public boolean isKeyguardLocked() { |
| 6016 | return keyguardOn(); |
| 6017 | } |
| 6018 | |
| 6019 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6020 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6021 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6022 | if (mKeyguardDelegate == null) return false; |
| 6023 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6024 | } |
| 6025 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6026 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6027 | @Override |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 6028 | public boolean isKeyguardShowingOrOccluded() { |
| 6029 | return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing(); |
| 6030 | } |
| 6031 | |
| 6032 | /** {@inheritDoc} */ |
| 6033 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6034 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6035 | if (mKeyguardDelegate == null) return false; |
| 6036 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6037 | } |
| 6038 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6039 | @Override |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 6040 | public void dismissKeyguardLw() { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 6041 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 6042 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 6043 | mHandler.post(new Runnable() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6044 | @Override |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 6045 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 6046 | // ask the keyguard to prompt the user to authenticate if necessary |
| 6047 | mKeyguardDelegate.dismiss(); |
| 6048 | } |
| 6049 | }); |
| 6050 | } |
| 6051 | } |
| 6052 | |
| 6053 | public void notifyActivityDrawnForKeyguardLw() { |
| 6054 | if (mKeyguardDelegate != null) { |
| 6055 | mHandler.post(new Runnable() { |
| 6056 | @Override |
| 6057 | public void run() { |
| 6058 | mKeyguardDelegate.onActivityDrawn(); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 6059 | } |
| 6060 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 6061 | } |
| 6062 | } |
| 6063 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 6064 | @Override |
| 6065 | public boolean isKeyguardDrawnLw() { |
| 6066 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6067 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 6068 | } |
| 6069 | } |
| 6070 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6071 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 6072 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6073 | if (mKeyguardDelegate != null) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 6074 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 6075 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6076 | } |
| 6077 | } |
| 6078 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6079 | @Override |
| 6080 | public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
| 6081 | Rect outInsets) { |
| 6082 | outInsets.setEmpty(); |
| 6083 | if (mStatusBar != null) { |
| 6084 | outInsets.top = mStatusBarHeight; |
| 6085 | } |
| 6086 | if (mNavigationBar != null) { |
| 6087 | if (isNavigationBarOnBottom(displayWidth, displayHeight)) { |
| 6088 | outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode); |
| 6089 | } else { |
| 6090 | outInsets.right = getNavigationBarWidth(displayRotation, mUiMode); |
| 6091 | } |
| 6092 | } |
| 6093 | } |
| 6094 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6095 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 6096 | PhoneWindow.sendCloseSystemWindows(mContext, null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6097 | } |
| 6098 | |
| 6099 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 6100 | PhoneWindow.sendCloseSystemWindows(mContext, reason); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6101 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 6102 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6103 | @Override |
| 6104 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6105 | if (false) { |
| 6106 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 6107 | + orientation + ", last=" + lastRotation |
| 6108 | + "); user=" + mUserRotation + " " |
| 6109 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 6110 | ? "USER_ROTATION_LOCKED" : "") |
| 6111 | ); |
| 6112 | } |
| 6113 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 6114 | if (mForceDefaultOrientation) { |
| 6115 | return Surface.ROTATION_0; |
| 6116 | } |
| 6117 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6118 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6119 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 6120 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 6121 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6122 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6123 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6124 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 6125 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6126 | // Ignore sensor when lid switch is open and rotation is forced. |
| 6127 | preferredRotation = mLidOpenRotation; |
| 6128 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6129 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6130 | // Ignore sensor when in car dock unless explicitly enabled. |
| 6131 | // This case can override the behavior of NOSENSOR, and can also |
| 6132 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6133 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6134 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 6135 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 6136 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 6137 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6138 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6139 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 6140 | // This case can override the behavior of NOSENSOR, and can also |
| 6141 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6142 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6143 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6144 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 6145 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 6146 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6147 | preferredRotation = mDemoHdmiRotation; |
| 6148 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 6149 | && mUndockedHdmiRotation >= 0) { |
| 6150 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 6151 | // been specified in the configuration (only for legacy devices without |
| 6152 | // full multi-display support). |
| 6153 | // Note that the dock orientation overrides the HDMI orientation. |
| 6154 | preferredRotation = mUndockedHdmiRotation; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 6155 | } else if (mDemoRotationLock) { |
| 6156 | // Ignore sensor when demo rotation lock is enabled. |
| 6157 | // Note that the dock orientation and HDMI rotation lock override this. |
| 6158 | preferredRotation = mDemoRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6159 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 6160 | // Application just wants to remain locked in the last rotation. |
| 6161 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 6162 | } else if (!mSupportAutoRotation) { |
| 6163 | // If we don't support auto-rotation then bail out here and ignore |
| 6164 | // the sensor and any rotation lock settings. |
| 6165 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 6166 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6167 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6168 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 6169 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 6170 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 6171 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6172 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 6173 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 6174 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 6175 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 6176 | // Otherwise, use sensor only if requested by the application or enabled |
| 6177 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 6178 | if (mAllowAllRotations < 0) { |
| 6179 | // Can't read this during init() because the context doesn't |
| 6180 | // have display metrics at that time so we cannot determine |
| 6181 | // tablet vs. phone then. |
| 6182 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 6183 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 6184 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6185 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 6186 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6187 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 6188 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6189 | preferredRotation = sensorRotation; |
| 6190 | } else { |
| 6191 | preferredRotation = lastRotation; |
| 6192 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 6193 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 6194 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 6195 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 6196 | // The idea is that the user rotation expresses a weak preference for the direction |
| 6197 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 6198 | // 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] | 6199 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6200 | } else { |
| 6201 | // No overriding preference. |
| 6202 | // We will do exactly what the application asked us to do. |
| 6203 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6204 | } |
| 6205 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6206 | switch (orientation) { |
| 6207 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6208 | // Return portrait unless overridden. |
| 6209 | if (isAnyPortrait(preferredRotation)) { |
| 6210 | return preferredRotation; |
| 6211 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6212 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6213 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6214 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6215 | // Return landscape unless overridden. |
| 6216 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6217 | return preferredRotation; |
| 6218 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6219 | return mLandscapeRotation; |
| 6220 | |
| 6221 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6222 | // Return reverse portrait unless overridden. |
| 6223 | if (isAnyPortrait(preferredRotation)) { |
| 6224 | return preferredRotation; |
| 6225 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6226 | return mUpsideDownRotation; |
| 6227 | |
| 6228 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6229 | // Return seascape unless overridden. |
| 6230 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6231 | return preferredRotation; |
| 6232 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6233 | return mSeascapeRotation; |
| 6234 | |
| 6235 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6236 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6237 | // Return either landscape rotation. |
| 6238 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6239 | return preferredRotation; |
| 6240 | } |
| 6241 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 6242 | return lastRotation; |
| 6243 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6244 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6245 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6246 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6247 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6248 | // Return either portrait rotation. |
| 6249 | if (isAnyPortrait(preferredRotation)) { |
| 6250 | return preferredRotation; |
| 6251 | } |
| 6252 | if (isAnyPortrait(lastRotation)) { |
| 6253 | return lastRotation; |
| 6254 | } |
| 6255 | return mPortraitRotation; |
| 6256 | |
| 6257 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 6258 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 6259 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6260 | if (preferredRotation >= 0) { |
| 6261 | return preferredRotation; |
| 6262 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6263 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 6264 | } |
| 6265 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 6266 | } |
| 6267 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6268 | @Override |
| 6269 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 6270 | switch (orientation) { |
| 6271 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 6272 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 6273 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 6274 | return isAnyPortrait(rotation); |
| 6275 | |
| 6276 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 6277 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 6278 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 6279 | return isLandscapeOrSeascape(rotation); |
| 6280 | |
| 6281 | default: |
| 6282 | return true; |
| 6283 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 6284 | } |
| 6285 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6286 | @Override |
| 6287 | public void setRotationLw(int rotation) { |
| 6288 | mOrientationListener.setCurrentRotation(rotation); |
| 6289 | } |
| 6290 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6291 | private boolean isLandscapeOrSeascape(int rotation) { |
| 6292 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6293 | } |
| 6294 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6295 | private boolean isAnyPortrait(int rotation) { |
| 6296 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6297 | } |
| 6298 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6299 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6300 | public int getUserRotationMode() { |
| 6301 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 6302 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 6303 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 6304 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6305 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6306 | |
| 6307 | // 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] | 6308 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6309 | public void setUserRotationMode(int mode, int rot) { |
| 6310 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6311 | |
| 6312 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6313 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6314 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6315 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6316 | rot, |
| 6317 | UserHandle.USER_CURRENT); |
| 6318 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6319 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6320 | 0, |
| 6321 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6322 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6323 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6324 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6325 | 1, |
| 6326 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6327 | } |
| 6328 | } |
| 6329 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6330 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6331 | public void setSafeMode(boolean safeMode) { |
| 6332 | mSafeMode = safeMode; |
| 6333 | performHapticFeedbackLw(null, safeMode |
| 6334 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 6335 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6336 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6337 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 6338 | static long[] getLongIntArray(Resources r, int resid) { |
| 6339 | int[] ar = r.getIntArray(resid); |
| 6340 | if (ar == null) { |
| 6341 | return null; |
| 6342 | } |
| 6343 | long[] out = new long[ar.length]; |
| 6344 | for (int i=0; i<ar.length; i++) { |
| 6345 | out[i] = ar[i]; |
| 6346 | } |
| 6347 | return out; |
| 6348 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6349 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6350 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6351 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6352 | public void systemReady() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6353 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext); |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 6354 | mKeyguardDelegate.onSystemReady(); |
| 6355 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 6356 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6357 | updateUiMode(); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6358 | boolean bindKeyguardNow; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6359 | synchronized (mLock) { |
| 6360 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 6361 | mSystemReady = true; |
| 6362 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6363 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 6364 | public void run() { |
| 6365 | updateSettings(); |
| 6366 | } |
| 6367 | }); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6368 | |
| 6369 | bindKeyguardNow = mDeferBindKeyguard; |
| 6370 | if (bindKeyguardNow) { |
| 6371 | // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now. |
| 6372 | mDeferBindKeyguard = false; |
| 6373 | } |
| 6374 | } |
| 6375 | |
| 6376 | if (bindKeyguardNow) { |
| 6377 | mKeyguardDelegate.bindService(mContext); |
| 6378 | mKeyguardDelegate.onBootCompleted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6379 | } |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 6380 | mSystemGestures.systemReady(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6381 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6382 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6383 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6384 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6385 | public void systemBooted() { |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6386 | boolean bindKeyguardNow = false; |
| 6387 | synchronized (mLock) { |
| 6388 | // Time to bind Keyguard; take care to only bind it once, either here if ready or |
| 6389 | // in systemReady if not. |
| 6390 | if (mKeyguardDelegate != null) { |
| 6391 | bindKeyguardNow = true; |
| 6392 | } else { |
| 6393 | // Because mKeyguardDelegate is null, we know that the synchronized block in |
| 6394 | // systemReady didn't run yet and setting this will actually have an effect. |
| 6395 | mDeferBindKeyguard = true; |
| 6396 | } |
| 6397 | } |
| 6398 | if (bindKeyguardNow) { |
Jason Monk | 5eeebf5 | 2014-09-26 12:36:51 -0400 | [diff] [blame] | 6399 | mKeyguardDelegate.bindService(mContext); |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 6400 | mKeyguardDelegate.onBootCompleted(); |
| 6401 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6402 | synchronized (mLock) { |
| 6403 | mSystemBooted = true; |
| 6404 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6405 | startedWakingUp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6406 | screenTurningOn(null); |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 6407 | screenTurnedOn(); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6408 | } |
| 6409 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6410 | ProgressDialog mBootMsgDialog = null; |
| 6411 | |
| 6412 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6413 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6414 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 6415 | mHandler.post(new Runnable() { |
| 6416 | @Override public void run() { |
| 6417 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 6418 | int theme; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 6419 | if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 6420 | theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 6421 | } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 6422 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 6423 | } else { |
| 6424 | theme = 0; |
| 6425 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 6426 | |
| 6427 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 6428 | // This dialog will consume all events coming in to |
| 6429 | // it, to avoid it trying to do things too early in boot. |
| 6430 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 6431 | return true; |
| 6432 | } |
| 6433 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 6434 | return true; |
| 6435 | } |
| 6436 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 6437 | return true; |
| 6438 | } |
| 6439 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 6440 | return true; |
| 6441 | } |
| 6442 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 6443 | return true; |
| 6444 | } |
| 6445 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 6446 | AccessibilityEvent event) { |
| 6447 | return true; |
| 6448 | } |
| 6449 | }; |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 6450 | if (mContext.getPackageManager().isUpgrade()) { |
| 6451 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 6452 | } else { |
| 6453 | mBootMsgDialog.setTitle(R.string.android_start_title); |
| 6454 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6455 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 6456 | mBootMsgDialog.setIndeterminate(true); |
| 6457 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 6458 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6459 | mBootMsgDialog.getWindow().addFlags( |
| 6460 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 6461 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 6462 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 6463 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 6464 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 6465 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6466 | mBootMsgDialog.setCancelable(false); |
| 6467 | mBootMsgDialog.show(); |
| 6468 | } |
| 6469 | mBootMsgDialog.setMessage(msg); |
| 6470 | } |
| 6471 | }); |
| 6472 | } |
| 6473 | |
| 6474 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6475 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6476 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6477 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6478 | } |
| 6479 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6480 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6481 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6482 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6483 | // *************************************** |
| 6484 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 6485 | // *************************************** |
| 6486 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 6487 | // WITH ITS LOCKS HELD. |
| 6488 | // |
| 6489 | // This code must be VERY careful about the locks |
| 6490 | // it acquires. |
| 6491 | // In fact, the current code acquires way too many, |
| 6492 | // and probably has lurking deadlocks. |
| 6493 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6494 | synchronized (mScreenLockTimeout) { |
| 6495 | if (mLockScreenTimerActive) { |
| 6496 | // reset the timer |
| 6497 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 6498 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 6499 | } |
| 6500 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 6501 | } |
| 6502 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6503 | class ScreenLockTimeout implements Runnable { |
| 6504 | Bundle options; |
| 6505 | |
| 6506 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6507 | public void run() { |
| 6508 | synchronized (this) { |
| 6509 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6510 | if (mKeyguardDelegate != null) { |
| 6511 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6512 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6513 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6514 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6515 | } |
| 6516 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6517 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6518 | public void setLockOptions(Bundle options) { |
| 6519 | this.options = options; |
| 6520 | } |
| 6521 | } |
| 6522 | |
| 6523 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 6524 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6525 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6526 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 6527 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 6528 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6529 | if (options != null) { |
| 6530 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 6531 | // until the runnable actually executes. |
| 6532 | mScreenLockTimeout.setLockOptions(options); |
| 6533 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 6534 | mHandler.post(mScreenLockTimeout); |
| 6535 | } |
| 6536 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6537 | private void updateLockScreenTimeout() { |
| 6538 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6539 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6540 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6541 | if (mLockScreenTimerActive != enable) { |
| 6542 | if (enable) { |
| 6543 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
Jim Miller | 2967f48 | 2016-01-07 15:05:32 -0800 | [diff] [blame] | 6544 | mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6545 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 6546 | } else { |
| 6547 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 6548 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 6549 | } |
| 6550 | mLockScreenTimerActive = enable; |
| 6551 | } |
| 6552 | } |
| 6553 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6554 | |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6555 | private void updateDreamingSleepToken(boolean acquire) { |
| 6556 | if (acquire) { |
| 6557 | if (mDreamingSleepToken == null) { |
| 6558 | mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream"); |
| 6559 | } |
| 6560 | } else { |
| 6561 | if (mDreamingSleepToken != null) { |
| 6562 | mDreamingSleepToken.release(); |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6563 | mDreamingSleepToken = null; |
| 6564 | } |
| 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | private void updateScreenOffSleepToken(boolean acquire) { |
| 6569 | if (acquire) { |
| 6570 | if (mScreenOffSleepToken == null) { |
| 6571 | mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff"); |
| 6572 | } |
| 6573 | } else { |
| 6574 | if (mScreenOffSleepToken != null) { |
| 6575 | mScreenOffSleepToken.release(); |
| 6576 | mScreenOffSleepToken = null; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6577 | } |
| 6578 | } |
| 6579 | } |
| 6580 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6581 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6582 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6583 | public void enableScreenAfterBoot() { |
| 6584 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6585 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6586 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6587 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 6588 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6589 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6590 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6591 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 6592 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6593 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 6594 | } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) { |
| 6595 | mWindowManagerFuncs.lockDeviceNow(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6596 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6597 | |
| 6598 | synchronized (mLock) { |
| 6599 | updateWakeGestureListenerLp(); |
| 6600 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6601 | } |
| 6602 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6603 | void updateUiMode() { |
| 6604 | if (mUiModeManager == null) { |
| 6605 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 6606 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 6607 | } |
| 6608 | try { |
| 6609 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 6610 | } catch (RemoteException e) { |
| 6611 | } |
| 6612 | } |
| 6613 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6614 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6615 | try { |
| 6616 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 6617 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 6618 | } catch (RemoteException e) { |
| 6619 | // Ignore |
| 6620 | } |
| 6621 | } |
| 6622 | |
| 6623 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 6624 | try { |
| 6625 | //set orientation on WindowManager |
| 6626 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6627 | } catch (RemoteException e) { |
| 6628 | // Ignore |
| 6629 | } |
| 6630 | } |
| 6631 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6632 | /** |
| 6633 | * Return an Intent to launch the currently active dock app as home. Returns |
| 6634 | * null if the standard home should be launched, which is the case if any of the following is |
| 6635 | * true: |
| 6636 | * <ul> |
| 6637 | * <li>The device is not in either car mode or desk mode |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 6638 | * <li>The device is in car mode but mEnableCarDockHomeCapture is false |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6639 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 6640 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 6641 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 6642 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6643 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6644 | */ |
| 6645 | Intent createHomeDockIntent() { |
| 6646 | Intent intent = null; |
| 6647 | |
| 6648 | // What home does is based on the mode, not the dock state. That |
| 6649 | // is, when in car mode you should be taken to car home regardless |
| 6650 | // of whether we are actually in a car dock. |
| 6651 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 6652 | if (mEnableCarDockHomeCapture) { |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6653 | intent = mCarDockIntent; |
| 6654 | } |
| 6655 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 6656 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 6657 | intent = mDeskDockIntent; |
| 6658 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6659 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 6660 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 6661 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 6662 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 6663 | // Always launch dock home from home when watch is docked, if it exists. |
| 6664 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6665 | } |
| 6666 | |
| 6667 | if (intent == null) { |
| 6668 | return null; |
| 6669 | } |
| 6670 | |
| 6671 | ActivityInfo ai = null; |
| 6672 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 6673 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 6674 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6675 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6676 | if (info != null) { |
| 6677 | ai = info.activityInfo; |
| 6678 | } |
| 6679 | if (ai != null |
| 6680 | && ai.metaData != null |
| 6681 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 6682 | intent = new Intent(intent); |
| 6683 | intent.setClassName(ai.packageName, ai.name); |
| 6684 | return intent; |
| 6685 | } |
| 6686 | |
| 6687 | return null; |
| 6688 | } |
| 6689 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6690 | void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { |
| 6691 | if (awakenFromDreams) { |
| 6692 | awakenDreams(); |
| 6693 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6694 | |
| 6695 | Intent dock = createHomeDockIntent(); |
| 6696 | if (dock != null) { |
| 6697 | try { |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6698 | if (fromHomeKey) { |
| 6699 | dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6700 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6701 | startActivityAsUser(dock, UserHandle.CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6702 | return; |
| 6703 | } catch (ActivityNotFoundException e) { |
| 6704 | } |
| 6705 | } |
| 6706 | |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6707 | Intent intent; |
| 6708 | |
| 6709 | if (fromHomeKey) { |
| 6710 | intent = new Intent(mHomeIntent); |
| 6711 | intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6712 | } else { |
| 6713 | intent = mHomeIntent; |
| 6714 | } |
| 6715 | |
Bryce Lee | 9fc0b6f | 2015-03-19 21:37:45 +0000 | [diff] [blame] | 6716 | startActivityAsUser(intent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6717 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6718 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6719 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6720 | * goes to the home screen |
| 6721 | * @return whether it did anything |
| 6722 | */ |
| 6723 | boolean goHome() { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6724 | if (!isUserSetupComplete()) { |
| 6725 | Slog.i(TAG, "Not going home because user setup is in progress."); |
| 6726 | return false; |
| 6727 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6728 | if (false) { |
| 6729 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 6730 | try { |
| 6731 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6732 | } catch (RemoteException e) { |
| 6733 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 6734 | sendCloseSystemWindows(); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6735 | startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6736 | } else { |
| 6737 | // This code brings home to the front or, if it is already |
| 6738 | // at the front, puts the device to sleep. |
| 6739 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 6740 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 6741 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 6742 | Log.d(TAG, "UTS-TEST-MODE"); |
| 6743 | } else { |
| 6744 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6745 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6746 | Intent dock = createHomeDockIntent(); |
| 6747 | if (dock != null) { |
| 6748 | int result = ActivityManagerNative.getDefault() |
| 6749 | .startActivityAsUser(null, null, dock, |
| 6750 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 6751 | null, null, 0, |
| 6752 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6753 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6754 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 6755 | return false; |
| 6756 | } |
| 6757 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6758 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6759 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6760 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6761 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6762 | null, null, 0, |
| 6763 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6764 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6765 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6766 | return false; |
| 6767 | } |
| 6768 | } catch (RemoteException ex) { |
| 6769 | // bummer, the activity manager, which is in this process, is dead |
| 6770 | } |
| 6771 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6772 | return true; |
| 6773 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6774 | |
| 6775 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6776 | public void setCurrentOrientationLw(int newOrientation) { |
| 6777 | synchronized (mLock) { |
| 6778 | if (newOrientation != mCurrentAppOrientation) { |
| 6779 | mCurrentAppOrientation = newOrientation; |
| 6780 | updateOrientationListenerLp(); |
| 6781 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6782 | } |
| 6783 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6784 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6785 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 6786 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 6787 | return; |
| 6788 | } |
| 6789 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 6790 | Context.AUDIO_SERVICE); |
| 6791 | if (audioManager.isSilentMode()) { |
| 6792 | return; |
| 6793 | } |
| 6794 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 6795 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 6796 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 6797 | ringTone.play(); |
| 6798 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6799 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 6800 | private boolean isTheaterModeEnabled() { |
| 6801 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6802 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 6803 | } |
| 6804 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6805 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 6806 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6807 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 6808 | } |
| 6809 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6810 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6811 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 6812 | if (!mVibrator.hasVibrator()) { |
| 6813 | return false; |
| 6814 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6815 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 6816 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 6817 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6818 | return false; |
| 6819 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6820 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6821 | switch (effectId) { |
| 6822 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6823 | pattern = mLongPressVibePattern; |
| 6824 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6825 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6826 | pattern = mVirtualKeyVibePattern; |
| 6827 | break; |
| 6828 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 6829 | pattern = mKeyboardTapVibePattern; |
| 6830 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 6831 | case HapticFeedbackConstants.CLOCK_TICK: |
| 6832 | pattern = mClockTickVibePattern; |
| 6833 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 6834 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 6835 | pattern = mCalendarDateVibePattern; |
| 6836 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6837 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6838 | pattern = mSafeModeDisabledVibePattern; |
| 6839 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6840 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6841 | pattern = mSafeModeEnabledVibePattern; |
| 6842 | break; |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 6843 | case HapticFeedbackConstants.CONTEXT_CLICK: |
| 6844 | pattern = mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 6845 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6846 | default: |
| 6847 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6848 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6849 | int owningUid; |
| 6850 | String owningPackage; |
| 6851 | if (win != null) { |
| 6852 | owningUid = win.getOwningUid(); |
| 6853 | owningPackage = win.getOwningPackage(); |
| 6854 | } else { |
| 6855 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 6856 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6857 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6858 | if (pattern.length == 1) { |
| 6859 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6860 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6861 | } else { |
| 6862 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6863 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6864 | } |
| 6865 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6866 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6867 | |
| 6868 | @Override |
| 6869 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 6870 | } |
| 6871 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6872 | @Override |
| 6873 | public void keepScreenOnStoppedLw() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6874 | if (isKeyguardShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 6875 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6876 | } |
| 6877 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 6878 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6879 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6880 | // If there is no window focused, there will be nobody to handle the events |
| 6881 | // anyway, so just hang on in whatever state we're in until things settle down. |
Adrian Roos | 53f28ec | 2014-10-29 17:26:12 +0100 | [diff] [blame] | 6882 | final WindowState win = mFocusedWindow != null ? mFocusedWindow |
| 6883 | : mTopFullscreenOpaqueWindowState; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6884 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6885 | return 0; |
| 6886 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6887 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6888 | // We are updating at a point where the keyguard has gotten |
| 6889 | // focus, but we were last in a state where the top window is |
| 6890 | // hiding it. This is probably because the keyguard as been |
| 6891 | // shown while the top window was displayed, so we want to ignore |
| 6892 | // it here because this is just a very transient change and it |
| 6893 | // will quickly lose focus once it correctly gets hidden. |
| 6894 | return 0; |
| 6895 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 6896 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 6897 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6898 | & ~mResettingSystemUiFlags |
| 6899 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6900 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6901 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6902 | } |
Thanh Hai Mai | 6c009f5 | 2015-09-01 16:27:32 -0700 | [diff] [blame] | 6903 | |
| 6904 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 6905 | tmpVisibility |= StatusBarManager.DISABLE_RECENT; |
| 6906 | } |
| 6907 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 6908 | final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */, |
| 6909 | mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState); |
| 6910 | final int dockedVisibility = updateLightStatusBarLw(0 /* vis */, |
| 6911 | mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState); |
| 6912 | mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds); |
| 6913 | mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6914 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6915 | final int diff = visibility ^ mLastSystemUiFlags; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 6916 | final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags; |
| 6917 | final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6918 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 6919 | if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu |
| 6920 | && mFocusedApp == win.getAppToken() |
| 6921 | && mLastNonDockedStackBounds.equals(mNonDockedStackBounds) |
| 6922 | && mLastDockedStackBounds.equals(mDockedStackBounds)) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6923 | return 0; |
| 6924 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6925 | mLastSystemUiFlags = visibility; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 6926 | mLastFullscreenStackSysUiFlags = fullscreenVisibility; |
| 6927 | mLastDockedStackSysUiFlags = dockedVisibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6928 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6929 | mFocusedApp = win.getAppToken(); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 6930 | final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds); |
| 6931 | final Rect dockedStackBounds = new Rect(mDockedStackBounds); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6932 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6933 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6934 | public void run() { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 6935 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 6936 | if (statusbar != null) { |
| 6937 | statusbar.setSystemUiVisibility(visibility, fullscreenVisibility, |
| 6938 | dockedVisibility, 0xffffffff, fullscreenStackBounds, |
| 6939 | dockedStackBounds, win.toString()); |
| 6940 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6941 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6942 | } |
| 6943 | }); |
| 6944 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6945 | } |
| 6946 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 6947 | private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) { |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6948 | WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6949 | ? mStatusBar |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 6950 | : opaqueOrDimming; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6951 | |
| 6952 | if (statusColorWin != null) { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 6953 | if (statusColorWin == opaque) { |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6954 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 6955 | // its light flag. |
| 6956 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6957 | vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) |
| 6958 | & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6959 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 6960 | // Otherwise if it's dimming, clear the light flag. |
| 6961 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6962 | } |
| 6963 | } |
| 6964 | return vis; |
| 6965 | } |
| 6966 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6967 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6968 | final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID); |
| 6969 | final boolean freeformStackVisible = |
| 6970 | mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 6971 | final boolean resizing = mWindowManagerInternal.isDockedDividerResizing(); |
| 6972 | |
| 6973 | // We need to force system bars when the docked stack is visible, when the freeform stack |
| 6974 | // is visible but also when we are resizing for the transitions when docked stack |
| 6975 | // visibility changes. |
| 6976 | final boolean forceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing; |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 6977 | final boolean forceOpaqueSystemBars = forceShowSystemBars && !mForceStatusBarFromKeyguard; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6978 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6979 | // apply translucent bar vis flags |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6980 | WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6981 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6982 | : mTopFullscreenOpaqueWindowState; |
| 6983 | vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6984 | vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6985 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6986 | // prevent status bar interaction from clearing certain flags |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 6987 | int type = win.getAttrs().type; |
| 6988 | boolean statusBarHasFocus = type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6989 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6990 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 6991 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 6992 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 73fef8d | 2015-02-16 17:32:28 +0100 | [diff] [blame] | 6993 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 6994 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6995 | if (mHideLockScreen) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 6996 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 6997 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6998 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6999 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7000 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7001 | if ((!areTranslucentBarsAllowed() && transWin != mStatusBar) |
| 7002 | || forceOpaqueSystemBars) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 7003 | vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT |
| 7004 | | View.SYSTEM_UI_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7005 | } |
| 7006 | |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 7007 | if (mForceWindowDrawsStatusBarBackground) { |
| 7008 | vis |= View.STATUS_BAR_TRANSPARENT; |
| 7009 | vis &= ~View.STATUS_BAR_TRANSLUCENT; |
| 7010 | } |
| 7011 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7012 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7013 | boolean immersiveSticky = |
| 7014 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7015 | final boolean hideStatusBarWM = |
| 7016 | mTopFullscreenOpaqueWindowState != null |
| 7017 | && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7018 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7019 | final boolean hideStatusBarSysui = |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7020 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7021 | final boolean hideNavBarSysui = |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7022 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7023 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7024 | final boolean transientStatusBarAllowed = mStatusBar != null |
| 7025 | && (statusBarHasFocus || (!forceShowSystemBars |
| 7026 | && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky)))); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7027 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7028 | final boolean transientNavBarAllowed = mNavigationBar != null |
| 7029 | && !forceShowSystemBars && hideNavBarSysui && immersiveSticky; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7030 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 7031 | final long now = SystemClock.uptimeMillis(); |
| 7032 | final boolean pendingPanic = mPendingPanicGestureUptime != 0 |
| 7033 | && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION; |
| 7034 | if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) { |
| 7035 | // The user performed the panic gesture recently, we're about to hide the bars, |
| 7036 | // we're no longer on the Keyguard and the screen is ready. We can now request the bars. |
| 7037 | mPendingPanicGestureUptime = 0; |
| 7038 | mStatusBarController.showTransient(); |
| 7039 | mNavigationBarController.showTransient(); |
| 7040 | } |
| 7041 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7042 | final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7043 | && !transientStatusBarAllowed && hideStatusBarSysui; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7044 | final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7045 | && !transientNavBarAllowed; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7046 | if (denyTransientStatus || denyTransientNav || forceShowSystemBars) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7047 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7048 | clearClearableFlagsLw(); |
tiger_huang | c58d756 | 2014-10-23 20:24:19 +0800 | [diff] [blame] | 7049 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7050 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7051 | |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 7052 | final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 7053 | immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 7054 | final boolean navAllowedHidden = immersive || immersiveSticky; |
| 7055 | |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 7056 | if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType()) |
| 7057 | > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) { |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 7058 | // We can't hide the navbar from this window otherwise the input consumer would not get |
| 7059 | // the input events. |
| 7060 | vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); |
| 7061 | } |
| 7062 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7063 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 7064 | |
| 7065 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7066 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 7067 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 7068 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7069 | final String pkg = win.getOwningPackage(); |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 7070 | mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode, |
| 7071 | isUserSetupComplete()); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 7072 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7073 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7074 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 7075 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 7076 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7077 | } |
| 7078 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7079 | private void clearClearableFlagsLw() { |
| 7080 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 7081 | if (newVal != mResettingSystemUiFlags) { |
| 7082 | mResettingSystemUiFlags = newVal; |
| 7083 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 7084 | } |
| 7085 | } |
| 7086 | |
| 7087 | private boolean isImmersiveMode(int vis) { |
| 7088 | 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] | 7089 | return mNavigationBar != null |
| 7090 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 7091 | && (vis & flags) != 0 |
| 7092 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 7093 | } |
| 7094 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7095 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 7096 | * @return whether the navigation or status bar can be made translucent |
| 7097 | * |
| 7098 | * This should return true unless touch exploration is not enabled or |
| 7099 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7100 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 7101 | private boolean areTranslucentBarsAllowed() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 7102 | return mTranslucentDecorEnabled; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7103 | } |
| 7104 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 7105 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 7106 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7107 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 7108 | public boolean hasNavigationBar() { |
| 7109 | return mHasNavigationBar; |
| 7110 | } |
| 7111 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 7112 | @Override |
| 7113 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 7114 | mLastInputMethodWindow = ime; |
| 7115 | mLastInputMethodTargetWindow = target; |
| 7116 | } |
| 7117 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7118 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 7119 | public int getInputMethodWindowVisibleHeightLw() { |
| 7120 | return mDockBottom - mCurBottom; |
| 7121 | } |
| 7122 | |
| 7123 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7124 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 7125 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 7126 | if (mKeyguardDelegate != null) { |
| 7127 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7128 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 7129 | if (mStatusBarService != null) { |
| 7130 | try { |
| 7131 | mStatusBarService.setCurrentUser(newUserId); |
| 7132 | } catch (RemoteException e) { |
| 7133 | // oh well |
| 7134 | } |
| 7135 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7136 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7137 | } |
| 7138 | |
| 7139 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 7140 | public boolean canMagnifyWindow(int windowType) { |
| 7141 | switch (windowType) { |
| 7142 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 7143 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 7144 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 7145 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 7146 | return false; |
| 7147 | } |
| 7148 | } |
| 7149 | return true; |
| 7150 | } |
| 7151 | |
| 7152 | @Override |
| 7153 | public boolean isTopLevelWindow(int windowType) { |
| 7154 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 7155 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 7156 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 7157 | } |
| 7158 | return true; |
| 7159 | } |
| 7160 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 7161 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 7162 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7163 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7164 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 7165 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 7166 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7167 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 7168 | pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7169 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 7170 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 7171 | || mForceClearedSystemUiFlags != 0) { |
| 7172 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 7173 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 7174 | pw.print(" mResettingSystemUiFlags=0x"); |
| 7175 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 7176 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 7177 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7178 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 7179 | if (mLastFocusNeedsMenu) { |
| 7180 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 7181 | pw.println(mLastFocusNeedsMenu); |
| 7182 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 7183 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 7184 | pw.println(mWakeGestureEnabledSetting); |
| 7185 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 7186 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7187 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 7188 | pw.print(" mDockMode="); pw.print(mDockMode); |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 7189 | pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7190 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 7191 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 7192 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 7193 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 7194 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 7195 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7196 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 7197 | pw.print(mCarDockEnablesAccelerometer); |
| 7198 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 7199 | pw.println(mDeskDockEnablesAccelerometer); |
| 7200 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 7201 | pw.print(mLidKeyboardAccessibility); |
| 7202 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 7203 | pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 7204 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7205 | pw.print(prefix); |
| 7206 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 7207 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 7208 | pw.print(prefix); |
| 7209 | pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); |
| 7210 | pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7211 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7212 | pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); |
| 7213 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 7214 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 7215 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 7216 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 7217 | pw.print(prefix); pw.print("mOrientationSensorEnabled="); |
| 7218 | pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 7219 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 7220 | pw.print(","); pw.print(mOverscanScreenTop); |
| 7221 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 7222 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 7223 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 7224 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 7225 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 7226 | pw.print(" top="); pw.print(mOverscanTop); |
| 7227 | pw.print(" right="); pw.print(mOverscanRight); |
| 7228 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 7229 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 7230 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 7231 | pw.print(mRestrictedOverscanScreenLeft); |
| 7232 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 7233 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 7234 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7235 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 7236 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 7237 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 7238 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 7239 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 7240 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 7241 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 7242 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 7243 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 7244 | pw.print(","); pw.print(mStableFullscreenTop); |
| 7245 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 7246 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7247 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 7248 | pw.print(","); pw.print(mStableTop); |
| 7249 | pw.print(")-("); pw.print(mStableRight); |
| 7250 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 7251 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 7252 | pw.print(","); pw.print(mSystemTop); |
| 7253 | pw.print(")-("); pw.print(mSystemRight); |
| 7254 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7255 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 7256 | pw.print(","); pw.print(mCurTop); |
| 7257 | pw.print(")-("); pw.print(mCurRight); |
| 7258 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 7259 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 7260 | pw.print(","); pw.print(mContentTop); |
| 7261 | pw.print(")-("); pw.print(mContentRight); |
| 7262 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 7263 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 7264 | pw.print(","); pw.print(mVoiceContentTop); |
| 7265 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 7266 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7267 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 7268 | pw.print(","); pw.print(mDockTop); |
| 7269 | pw.print(")-("); pw.print(mDockRight); |
| 7270 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 7271 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 7272 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 7273 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 7274 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 7275 | pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); |
| 7276 | pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7277 | if (mLastInputMethodWindow != null) { |
| 7278 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 7279 | pw.println(mLastInputMethodWindow); |
| 7280 | } |
| 7281 | if (mLastInputMethodTargetWindow != null) { |
| 7282 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 7283 | pw.println(mLastInputMethodTargetWindow); |
| 7284 | } |
| 7285 | if (mStatusBar != null) { |
| 7286 | pw.print(prefix); pw.print("mStatusBar="); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 7287 | pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); |
| 7288 | pw.println(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7289 | } |
| 7290 | if (mNavigationBar != null) { |
| 7291 | pw.print(prefix); pw.print("mNavigationBar="); |
| 7292 | pw.println(mNavigationBar); |
| 7293 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7294 | if (mFocusedWindow != null) { |
| 7295 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 7296 | pw.println(mFocusedWindow); |
| 7297 | } |
| 7298 | if (mFocusedApp != null) { |
| 7299 | pw.print(prefix); pw.print("mFocusedApp="); |
| 7300 | pw.println(mFocusedApp); |
| 7301 | } |
| 7302 | if (mWinDismissingKeyguard != null) { |
| 7303 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 7304 | pw.println(mWinDismissingKeyguard); |
| 7305 | } |
| 7306 | if (mTopFullscreenOpaqueWindowState != null) { |
| 7307 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 7308 | pw.println(mTopFullscreenOpaqueWindowState); |
| 7309 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7310 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 7311 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 7312 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 7313 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 7314 | if (mForcingShowNavBar) { |
| 7315 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 7316 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 7317 | pw.println(mForcingShowNavBarLayer); |
| 7318 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 7319 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7320 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 7321 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 7322 | pw.print(" mForceStatusBarFromKeyguard="); |
| 7323 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7324 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 7325 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7326 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 7327 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 7328 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 7329 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 7330 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 7331 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 7332 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 7333 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 7334 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 7335 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 7336 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 7337 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 7338 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 7339 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 7340 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 7341 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7342 | mStatusBarController.dump(pw, prefix); |
| 7343 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 7344 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 7345 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 7346 | if (mWakeGestureListener != null) { |
| 7347 | mWakeGestureListener.dump(pw, prefix); |
| 7348 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 7349 | if (mOrientationListener != null) { |
| 7350 | mOrientationListener.dump(pw, prefix); |
| 7351 | } |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 7352 | if (mBurnInProtectionHelper != null) { |
| 7353 | mBurnInProtectionHelper.dump(prefix, pw); |
| 7354 | } |
Jorim Jaggi | 84dc08a | 2015-09-11 17:45:22 -0700 | [diff] [blame] | 7355 | if (mKeyguardDelegate != null) { |
| 7356 | mKeyguardDelegate.dump(prefix, pw); |
| 7357 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7358 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7359 | } |