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 | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.DOCKED_STACK_ID; |
| 20 | import static android.app.ActivityManager.FREEFORM_WORKSPACE_STACK_ID; |
| 21 | import static android.view.WindowManager.LayoutParams.*; |
| 22 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 23 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
| 24 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
| 25 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; |
| 26 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; |
| 27 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; |
| 28 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 29 | import android.app.ActivityManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 30 | import android.app.ActivityManagerInternal; |
| 31 | import android.app.ActivityManagerInternal.SleepToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 32 | import android.app.ActivityManagerNative; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 33 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 34 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 35 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 36 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 37 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 38 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 39 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 40 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 41 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 42 | import android.content.ContentResolver; |
| 43 | import android.content.Context; |
| 44 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 45 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 46 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 47 | import android.content.pm.ActivityInfo; |
| 48 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 49 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 50 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 51 | import android.content.res.Configuration; |
| 52 | import android.content.res.Resources; |
| 53 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 54 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 55 | import android.graphics.Rect; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 56 | import android.hardware.hdmi.HdmiControlManager; |
| 57 | import android.hardware.hdmi.HdmiPlaybackClient; |
| 58 | import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 59 | import android.media.AudioAttributes; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 60 | import android.media.AudioManager; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 61 | import android.media.AudioSystem; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 62 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 63 | import android.media.Ringtone; |
| 64 | import android.media.RingtoneManager; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 65 | import android.media.session.MediaSessionLegacyHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 66 | import android.os.Binder; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 67 | import android.os.Bundle; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 68 | import android.os.Debug; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 69 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 70 | import android.os.Handler; |
| 71 | import android.os.IBinder; |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 72 | import android.os.IDeviceIdleController; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 73 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 74 | import android.os.Message; |
| 75 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 76 | import android.os.PowerManager; |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 77 | import android.os.PowerManagerInternal; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 78 | import android.os.Process; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 79 | import android.os.RemoteException; |
| 80 | import android.os.ServiceManager; |
| 81 | import android.os.SystemClock; |
| 82 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 83 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 84 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 85 | import android.os.Vibrator; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 86 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 87 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 88 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 89 | import android.service.dreams.DreamService; |
| 90 | import android.service.dreams.IDreamManager; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 91 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 92 | import android.telecom.TelecomManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 93 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 94 | import android.util.EventLog; |
| 95 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 96 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 97 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 98 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 99 | import android.view.Gravity; |
| 100 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 101 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 102 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 103 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 104 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 105 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 106 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 107 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 108 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 109 | import android.view.KeyEvent; |
| 110 | import android.view.MotionEvent; |
Chris Wren | 9bb290b | 2015-06-29 12:02:13 -0400 | [diff] [blame] | 111 | |
| 112 | import com.android.internal.logging.MetricsLogger; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 113 | import com.android.internal.policy.PhoneWindow; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 114 | import android.view.Surface; |
| 115 | import android.view.View; |
| 116 | import android.view.ViewConfiguration; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 117 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 118 | import android.view.WindowManagerGlobal; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 119 | import android.view.WindowManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 120 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 121 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 122 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 123 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 124 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 125 | import android.view.animation.AnimationUtils; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 126 | import com.android.internal.R; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 127 | import com.android.internal.statusbar.IStatusBarService; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 128 | import com.android.internal.util.ScreenShapeHelper; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 129 | import com.android.internal.widget.PointerLocationView; |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 130 | import com.android.server.GestureLauncherService; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 131 | import com.android.server.LocalServices; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 132 | import com.android.server.policy.keyguard.KeyguardServiceDelegate; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 133 | import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 134 | |
| 135 | import java.io.File; |
| 136 | import java.io.FileReader; |
| 137 | import java.io.IOException; |
| 138 | import java.io.PrintWriter; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 139 | import java.util.HashSet; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 140 | import java.util.List; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 141 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 142 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 143 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 144 | * introduces a new method suffix, Lp, for an internal lock of the |
| 145 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 146 | * 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] | 147 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 148 | */ |
| 149 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 150 | static final String TAG = "WindowManager"; |
| 151 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 152 | static final boolean localLOGV = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 153 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 154 | static final boolean DEBUG_KEYGUARD = false; |
| 155 | static final boolean DEBUG_LAYOUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 156 | static final boolean DEBUG_STARTING_WINDOW = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 157 | static final boolean DEBUG_WAKEUP = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 158 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 159 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 160 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 161 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 162 | // No longer recommended for desk docks; still useful in car docks. |
| 163 | static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true; |
| 164 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 165 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 166 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 167 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 168 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 169 | 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] | 170 | static final int SHORT_PRESS_POWER_GO_HOME = 4; |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 171 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 172 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 173 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 174 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 175 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 176 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 177 | static final int MULTI_PRESS_POWER_NOTHING = 0; |
| 178 | static final int MULTI_PRESS_POWER_THEATER_MODE = 1; |
| 179 | static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2; |
| 180 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 181 | // These need to match the documentation/constant in |
| 182 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 183 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 184 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 185 | static final int LONG_PRESS_HOME_ASSIST = 2; |
| 186 | |
| 187 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 188 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 189 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 190 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0; |
| 191 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1; |
| 192 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 193 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 194 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 195 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 196 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 197 | static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 198 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 199 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 200 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 201 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 202 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 203 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 204 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 205 | /** |
| 206 | * These are the system UI flags that, when changing, can cause the layout |
| 207 | * of the screen to change. |
| 208 | */ |
| 209 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 210 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 211 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 212 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 213 | | View.NAVIGATION_BAR_TRANSLUCENT |
| 214 | | View.SYSTEM_UI_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 215 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 216 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 217 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 218 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 219 | .build(); |
| 220 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 221 | // The panic gesture may become active only after the keyguard is dismissed and the immersive |
| 222 | // app shows again. If that doesn't happen for 30s we drop the gesture. |
| 223 | private static final long PANIC_GESTURE_EXPIRATION = 30000; |
| 224 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 225 | /** |
| 226 | * Keyguard stuff |
| 227 | */ |
| 228 | private WindowState mKeyguardScrim; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 229 | private boolean mKeyguardHidden; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 230 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 231 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 232 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 233 | * |
| 234 | * These are special keys that are used to launch particular kinds of applications, |
| 235 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 236 | * usage page. We don't support quite that many yet... |
| 237 | */ |
| 238 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 239 | static { |
| 240 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 241 | sApplicationLaunchKeyCategories.append( |
| 242 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 243 | sApplicationLaunchKeyCategories.append( |
| 244 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 245 | sApplicationLaunchKeyCategories.append( |
| 246 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 247 | sApplicationLaunchKeyCategories.append( |
| 248 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 249 | sApplicationLaunchKeyCategories.append( |
| 250 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 251 | sApplicationLaunchKeyCategories.append( |
| 252 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 253 | } |
| 254 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 255 | /** 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] | 256 | static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 257 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 258 | /** |
| 259 | * Lock protecting internal state. Must not call out into window |
| 260 | * manager with lock held. (This lock will be acquired in places |
| 261 | * where the window manager is calling in with its own lock held.) |
| 262 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 263 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 264 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 265 | Context mContext; |
| 266 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 267 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 268 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 269 | PowerManager mPowerManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 270 | ActivityManagerInternal mActivityManagerInternal; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 271 | DreamManagerInternal mDreamManagerInternal; |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 272 | PowerManagerInternal mPowerManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 273 | IStatusBarService mStatusBarService; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 274 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 275 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 276 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 277 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 278 | AccessibilityManager mAccessibilityManager; |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 279 | BurnInProtectionHelper mBurnInProtectionHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 280 | AppOpsManager mAppOpsManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 281 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 282 | // Vibrator pattern for haptic feedback of a long press. |
| 283 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 284 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 285 | // Vibrator pattern for haptic feedback of virtual key press. |
| 286 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 287 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 288 | // Vibrator pattern for a short vibration. |
| 289 | long[] mKeyboardTapVibePattern; |
| 290 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 291 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 292 | long[] mClockTickVibePattern; |
| 293 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 294 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 295 | long[] mCalendarDateVibePattern; |
| 296 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 297 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 298 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 299 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 300 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 301 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 302 | |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 303 | // Vibrator pattern for haptic feedback of a context click. |
| 304 | long[] mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 305 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 306 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 307 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 308 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 309 | boolean mSafeMode; |
| 310 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 311 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 312 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 313 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 314 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 315 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 316 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
| 317 | int[] mNavigationBarHeightForRotation = new int[4]; |
| 318 | int[] mNavigationBarWidthForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 319 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 320 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 321 | KeyguardServiceDelegate mKeyguardDelegate; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 322 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 323 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 324 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 325 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 326 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 327 | } |
| 328 | }; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 329 | final DrawnListener mKeyguardDrawnCallback = new DrawnListener() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 330 | @Override |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 331 | public void onDrawn() { |
| 332 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 333 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 334 | } |
| 335 | }; |
| 336 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 337 | GlobalActions mGlobalActions; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 338 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 339 | WindowState mLastInputMethodWindow = null; |
| 340 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 341 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 342 | // FIXME This state is shared between the input reader and handler thread. |
| 343 | // Technically it's broken and buggy but it has been like this for many years |
| 344 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 345 | // so that only one thread is involved in handling input policy. Unfortunately |
| 346 | // it's on a critical path for power management so we can't just post the work to the |
| 347 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 348 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 349 | volatile boolean mPowerKeyHandled; |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 350 | volatile boolean mBeganFromNonInteractive; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 351 | volatile int mPowerKeyPressCounter; |
| 352 | volatile boolean mEndCallKeyHandled; |
| 353 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 354 | boolean mRecentsVisible; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 355 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 356 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 357 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 358 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 359 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 360 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 361 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 362 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 363 | boolean mSystemBooted; |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 364 | private boolean mDeferBindKeyguard; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 365 | boolean mHdmiPlugged; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 366 | HdmiControl mHdmiControl; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 367 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 368 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 369 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 370 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 371 | int mCarDockRotation; |
| 372 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 373 | int mUndockedHdmiRotation; |
| 374 | int mDemoHdmiRotation; |
| 375 | boolean mDemoHdmiRotationLock; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 376 | int mDemoRotation; |
| 377 | boolean mDemoRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 378 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 379 | boolean mWakeGestureEnabledSetting; |
| 380 | MyWakeGestureListener mWakeGestureListener; |
| 381 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 382 | // Default display does not rotate, apps that require non-default orientation will have to |
| 383 | // have the orientation emulated. |
| 384 | private boolean mForceDefaultOrientation = false; |
| 385 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 386 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 387 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 388 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 389 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 390 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 391 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 392 | boolean mCarDockEnablesAccelerometer; |
| 393 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 394 | int mLidKeyboardAccessibility; |
| 395 | int mLidNavigationAccessibility; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 396 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 397 | int mShortPressOnPowerBehavior; |
| 398 | int mLongPressOnPowerBehavior; |
| 399 | int mDoublePressOnPowerBehavior; |
| 400 | int mTriplePressOnPowerBehavior; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 401 | int mShortPressOnSleepBehavior; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 402 | boolean mAwake; |
| 403 | boolean mScreenOnEarly; |
| 404 | boolean mScreenOnFully; |
| 405 | ScreenOnListener mScreenOnListener; |
| 406 | boolean mKeyguardDrawComplete; |
| 407 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 408 | boolean mOrientationSensorEnabled = false; |
| 409 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 410 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 411 | boolean mTranslucentDecorEnabled = true; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 412 | boolean mUseTvRouting; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 413 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 414 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 415 | |
| 416 | // The last window we were told about in focusChanged. |
| 417 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 418 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 419 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 420 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 421 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 422 | // The current size of the screen; really; extends into the overscan area of |
| 423 | // the screen and doesn't account for any system elements like the status bar. |
| 424 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 425 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 426 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 427 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 428 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 429 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 430 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 431 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 432 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 433 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 434 | // if the status bar can't be hidden; in that case it effectively carves out |
| 435 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 436 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 437 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 438 | // During layout, the current screen borders accounting for any currently |
| 439 | // visible system UI elements. |
| 440 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 441 | // For applications requesting stable content insets, these are them. |
| 442 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 443 | // For applications requesting stable content insets but have also set the |
| 444 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 445 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 446 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 447 | // During layout, the current screen borders with all outer decoration |
| 448 | // (status bar, input method dock) accounted for. |
| 449 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 450 | // During layout, the frame in which content should be displayed |
| 451 | // to the user, accounting for all screen decoration except for any |
| 452 | // space they deem as available for other content. This is usually |
| 453 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 454 | // content insets. |
| 455 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 456 | // During layout, the frame in which voice content should be displayed |
| 457 | // to the user, accounting for all screen decoration except for any |
| 458 | // space they deem as available for other content. |
| 459 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 460 | // 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] | 461 | // windows are placed. |
| 462 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 463 | // During layout, the layer at which the doc window is placed. |
| 464 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 465 | // During layout, this is the layer of the status bar. |
| 466 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 467 | int mLastSystemUiFlags; |
| 468 | // Bits that we are in the process of clearing, so we want to prevent |
| 469 | // them from being set by applications until everything has been updated |
| 470 | // to have them clear. |
| 471 | int mResettingSystemUiFlags = 0; |
| 472 | // Bits that we are currently always keeping cleared. |
| 473 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 474 | // What we last reported to system UI about whether the compatibility |
| 475 | // menu needs to be displayed. |
| 476 | boolean mLastFocusNeedsMenu = false; |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 477 | // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending. |
| 478 | private long mPendingPanicGestureUptime; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 479 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 480 | InputConsumer mInputConsumer = null; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 481 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 482 | static final Rect mTmpParentFrame = new Rect(); |
| 483 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 484 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 485 | static final Rect mTmpContentFrame = new Rect(); |
| 486 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 487 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 488 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 489 | static final Rect mTmpNavigationFrame = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 490 | static final Rect mTmpOutsetFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 491 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 492 | WindowState mTopFullscreenOpaqueWindowState; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 493 | WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 494 | HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 495 | HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 496 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 497 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 498 | boolean mForceStatusBarFromKeyguard; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 499 | private boolean mForceStatusBarTransparent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 500 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 501 | boolean mForcingShowNavBar; |
| 502 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 503 | |
| 504 | // States of keyguard dismiss. |
| 505 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 506 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 507 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 508 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 509 | |
| 510 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 511 | * be done once per window. */ |
| 512 | private WindowState mWinDismissingKeyguard; |
| 513 | |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 514 | /** When window is currently dismissing the keyguard, dismissing the keyguard must handle |
| 515 | * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN |
| 516 | * lock SIM card. This variable is used to record the previous keyguard secure state for |
| 517 | * monitoring secure state change on window dismissing keyguard. */ |
| 518 | private boolean mSecureDismissingKeyguard; |
| 519 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 520 | /** The window that is currently showing "over" the keyguard. If there is an app window |
| 521 | * belonging to another app on top of this the keyguard shows. If there is a fullscreen |
| 522 | * app window under this, still dismiss the keyguard but don't show the app underneath. Show |
| 523 | * the wallpaper. */ |
| 524 | private WindowState mWinShowWhenLocked; |
| 525 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 526 | boolean mShowingLockscreen; |
| 527 | boolean mShowingDream; |
| 528 | boolean mDreamingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 529 | boolean mDreamingSleepTokenNeeded; |
| 530 | SleepToken mDreamingSleepToken; |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 531 | SleepToken mScreenOffSleepToken; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 532 | boolean mKeyguardSecure; |
| 533 | boolean mKeyguardSecureIncludingHidden; |
| 534 | volatile boolean mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 535 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 536 | boolean mHomeConsumed; |
| 537 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 538 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 539 | Intent mCarDockIntent; |
| 540 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 541 | boolean mSearchKeyShortcutPending; |
| 542 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 543 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 544 | boolean mPendingMetaAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 545 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 546 | // support for activating the lock screen while the screen is on |
| 547 | boolean mAllowLockscreenWhenOn; |
| 548 | int mLockScreenTimeout; |
| 549 | boolean mLockScreenTimerActive; |
| 550 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 551 | // 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] | 552 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 553 | |
| 554 | // Behavior of POWER button while in-call and screen on. |
| 555 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 556 | int mIncallPowerBehavior; |
| 557 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 558 | Display mDisplay; |
| 559 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 560 | private int mDisplayRotation; |
| 561 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 562 | int mLandscapeRotation = 0; // default landscape rotation |
| 563 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 564 | int mPortraitRotation = 0; // default portrait rotation |
| 565 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 566 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 567 | int mOverscanLeft = 0; |
| 568 | int mOverscanTop = 0; |
| 569 | int mOverscanRight = 0; |
| 570 | int mOverscanBottom = 0; |
| 571 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 572 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 573 | private int mLongPressOnHomeBehavior; |
| 574 | |
| 575 | // What we do when the user double-taps on home |
| 576 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 577 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 578 | // Allowed theater mode wake actions |
| 579 | private boolean mAllowTheaterModeWakeFromKey; |
| 580 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 581 | private boolean mAllowTheaterModeWakeFromMotion; |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 582 | private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 583 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 584 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 585 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 586 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 587 | // Whether to support long press from power button in non-interactive mode |
| 588 | private boolean mSupportLongPressPowerWhenNonInteractive; |
| 589 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 590 | // Whether to go to sleep entering theater mode from power button |
| 591 | private boolean mGoToSleepOnButtonPressTheaterMode; |
| 592 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 593 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 594 | // Time to volume and power must be pressed within this interval of each other. |
| 595 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 596 | // Increase the chord delay when taking a screenshot from the keyguard |
| 597 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 598 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 599 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 600 | private long mScreenshotChordVolumeDownKeyTime; |
| 601 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
| 602 | private boolean mScreenshotChordVolumeUpKeyTriggered; |
| 603 | private boolean mScreenshotChordPowerKeyTriggered; |
| 604 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 605 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 606 | /* The number of steps between min and max brightness */ |
| 607 | private static final int BRIGHTNESS_STEPS = 10; |
| 608 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 609 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 610 | ShortcutManager mShortcutManager; |
| 611 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 612 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 613 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 614 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 615 | private int mCurrentUserId; |
| 616 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 617 | // Maps global key codes to the components that will handle them. |
| 618 | private GlobalKeyManager mGlobalKeyManager; |
| 619 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 620 | // Fallback actions by key code. |
| 621 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 622 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 623 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 624 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 625 | = new LogDecelerateInterpolator(100, 0); |
| 626 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 627 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 628 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 629 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 630 | 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] | 631 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 632 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 633 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 634 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 635 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 636 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 637 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 638 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 639 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 640 | private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 641 | private static final int MSG_REQUEST_TRANSIENT_BARS = 16; |
| 642 | |
| 643 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0; |
| 644 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 645 | |
| 646 | private class PolicyHandler extends Handler { |
| 647 | @Override |
| 648 | public void handleMessage(Message msg) { |
| 649 | switch (msg.what) { |
| 650 | case MSG_ENABLE_POINTER_LOCATION: |
| 651 | enablePointerLocation(); |
| 652 | break; |
| 653 | case MSG_DISABLE_POINTER_LOCATION: |
| 654 | disablePointerLocation(); |
| 655 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 656 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 657 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 658 | break; |
| 659 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 660 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 661 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 662 | case MSG_DISPATCH_SHOW_RECENTS: |
| 663 | showRecentApps(false); |
| 664 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 665 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 666 | showGlobalActionsInternal(); |
| 667 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 668 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 669 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 670 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 671 | break; |
| 672 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 673 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 674 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 675 | break; |
| 676 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 677 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 678 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 679 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 680 | case MSG_HIDE_BOOT_MESSAGE: |
| 681 | handleHideBootMessage(); |
| 682 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 683 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 684 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 685 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 686 | case MSG_POWER_DELAYED_PRESS: |
| 687 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 688 | finishPowerKeyPress(); |
| 689 | break; |
| 690 | case MSG_POWER_LONG_PRESS: |
| 691 | powerLongPress(); |
| 692 | break; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 693 | case MSG_UPDATE_DREAMING_SLEEP_TOKEN: |
| 694 | updateDreamingSleepToken(msg.arg1 != 0); |
| 695 | break; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 696 | case MSG_REQUEST_TRANSIENT_BARS: |
| 697 | WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ? |
| 698 | mStatusBar : mNavigationBar; |
| 699 | if (targetBar != null) { |
| 700 | requestTransientBars(targetBar); |
| 701 | } |
| 702 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | } |
| 706 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 707 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 708 | @Override |
| 709 | public void onUEvent(UEventObserver.UEvent event) { |
| 710 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 711 | } |
| 712 | }; |
| 713 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 714 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 715 | SettingsObserver(Handler handler) { |
| 716 | super(handler); |
| 717 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 718 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 719 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 720 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 721 | ContentResolver resolver = mContext.getContentResolver(); |
| 722 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 723 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 724 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 725 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 726 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 727 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 728 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 729 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 730 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 731 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 732 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 733 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 734 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 735 | Settings.System.USER_ROTATION), false, this, |
| 736 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 737 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 738 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 739 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 740 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 741 | Settings.System.POINTER_LOCATION), false, this, |
| 742 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 743 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 744 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 745 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 746 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 747 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 748 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 749 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 750 | Settings.Global.POLICY_CONTROL), false, this, |
| 751 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 752 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 756 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 757 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 758 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 759 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 760 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 761 | class MyWakeGestureListener extends WakeGestureListener { |
| 762 | MyWakeGestureListener(Context context, Handler handler) { |
| 763 | super(context, handler); |
| 764 | } |
| 765 | |
| 766 | @Override |
| 767 | public void onWakeUp() { |
| 768 | synchronized (mLock) { |
| 769 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 770 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 771 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture, |
| 772 | "android.policy:GESTURE"); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 773 | } |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 778 | class MyOrientationListener extends WindowOrientationListener { |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 779 | private final Runnable mUpdateRotationRunnable = new Runnable() { |
| 780 | @Override |
| 781 | public void run() { |
Tim Murray | 1f40764 | 2015-10-01 17:07:12 -0700 | [diff] [blame] | 782 | // send interaction hint to improve redraw performance |
| 783 | mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 784 | updateRotation(false); |
| 785 | } |
| 786 | }; |
| 787 | |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 788 | MyOrientationListener(Context context, Handler handler) { |
| 789 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 790 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 791 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 792 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 793 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 794 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 795 | mHandler.post(mUpdateRotationRunnable); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 796 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 797 | } |
| 798 | MyOrientationListener mOrientationListener; |
| 799 | |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 800 | private final StatusBarController mStatusBarController = new StatusBarController(); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 801 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 802 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 803 | View.NAVIGATION_BAR_TRANSIENT, |
| 804 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 805 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 806 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
| 807 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 808 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 809 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 810 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 811 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 812 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 813 | IStatusBarService getStatusBarService() { |
| 814 | synchronized (mServiceAquireLock) { |
| 815 | if (mStatusBarService == null) { |
| 816 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 817 | ServiceManager.getService("statusbar")); |
| 818 | } |
| 819 | return mStatusBarService; |
| 820 | } |
| 821 | } |
| 822 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 823 | /* |
| 824 | * We always let the sensor be switched on by default except when |
| 825 | * the user has explicitly disabled sensor based rotation or when the |
| 826 | * screen is switched off. |
| 827 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 828 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 829 | if (mSupportAutoRotation) { |
| 830 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 831 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 832 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 833 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 834 | // If the application has explicitly requested to follow the |
| 835 | // orientation, then we need to turn the sensor on. |
| 836 | return true; |
| 837 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 838 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 839 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 840 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 841 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 842 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 843 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 844 | // orientation management, |
| 845 | return true; |
| 846 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 847 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 848 | // If the setting for using the sensor by default is enabled, then |
| 849 | // we will always leave it on. Note that the user could go to |
| 850 | // a window that forces an orientation that does not use the |
| 851 | // sensor and in theory we could turn it off... however, when next |
| 852 | // turning it on we won't have a good value for the current |
| 853 | // orientation for a little bit, which can cause orientation |
| 854 | // changes to lag, so we'd like to keep it always on. (It will |
| 855 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 856 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 857 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 858 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 859 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 860 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 861 | /* |
| 862 | * Various use cases for invoking this function |
| 863 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 864 | * 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] | 865 | * if not already enabled |
| 866 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 867 | * already enabled |
| 868 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 869 | * screen turning on and current app has nosensor based orientation, do nothing |
| 870 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 871 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 872 | if (!mOrientationListener.canDetectOrientation()) { |
| 873 | // If sensor is turned off or nonexistent for some reason |
| 874 | return; |
| 875 | } |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 876 | // Could have been invoked due to screen turning on or off or |
| 877 | // change of the currently visible window's orientation. |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 878 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 879 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 880 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled |
| 881 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 882 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 883 | boolean disable = true; |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 884 | // Note: We postpone the rotating of the screen until the keyguard as well as the |
| 885 | // window manager have reported a draw complete. |
| 886 | if (mScreenOnEarly && mAwake && |
| 887 | mKeyguardDrawComplete && mWindowManagerDrawComplete) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 888 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 889 | disable = false; |
| 890 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 891 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 892 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 893 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 894 | mOrientationSensorEnabled = true; |
| 895 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 896 | } |
| 897 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 898 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 899 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 900 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 901 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 902 | mOrientationSensorEnabled = false; |
| 903 | } |
| 904 | } |
| 905 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 906 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 907 | // Hold a wake lock until the power key is released. |
| 908 | if (!mPowerKeyWakeLock.isHeld()) { |
| 909 | mPowerKeyWakeLock.acquire(); |
| 910 | } |
| 911 | |
| 912 | // Cancel multi-press detection timeout. |
| 913 | if (mPowerKeyPressCounter != 0) { |
| 914 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 915 | } |
| 916 | |
| 917 | // Detect user pressing the power button in panic when an application has |
| 918 | // taken over the whole screen. |
| 919 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
Craig Mautner | 0124980e9 | 2014-11-30 21:15:34 -0800 | [diff] [blame] | 920 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags)); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 921 | if (panic) { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 922 | mHandler.post(mHiddenNavPanic); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | // Latch power key state to detect screenshot chord. |
| 926 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 927 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 928 | mScreenshotChordPowerKeyTriggered = true; |
| 929 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 930 | interceptScreenshotChord(); |
| 931 | } |
| 932 | |
| 933 | // Stop ringing or end call if configured to do so when power is pressed. |
| 934 | TelecomManager telecomManager = getTelecommService(); |
| 935 | boolean hungUp = false; |
| 936 | if (telecomManager != null) { |
| 937 | if (telecomManager.isRinging()) { |
| 938 | // Pressing Power while there's a ringing incoming |
| 939 | // call should silence the ringer. |
| 940 | telecomManager.silenceRinger(); |
| 941 | } else if ((mIncallPowerBehavior |
| 942 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 943 | && telecomManager.isInCall() && interactive) { |
| 944 | // Otherwise, if "Power button ends call" is enabled, |
| 945 | // the Power button will hang up any current active call. |
| 946 | hungUp = telecomManager.endCall(); |
| 947 | } |
| 948 | } |
| 949 | |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 950 | GestureLauncherService gestureService = LocalServices.getService( |
| 951 | GestureLauncherService.class); |
| 952 | boolean gesturedServiceIntercepted = false; |
| 953 | if (gestureService != null) { |
| 954 | gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive); |
| 955 | } |
| 956 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 957 | // If the power key has still not yet been handled, then detect short |
| 958 | // press, long press, or multi press and decide what to do. |
| 959 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 960 | || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 961 | if (!mPowerKeyHandled) { |
| 962 | if (interactive) { |
| 963 | // When interactive, we're already awake. |
| 964 | // Wait for a long press or for the button to be released to decide what to do. |
| 965 | if (hasLongPressOnPowerBehavior()) { |
| 966 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 967 | msg.setAsynchronous(true); |
| 968 | mHandler.sendMessageDelayed(msg, |
| 969 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 970 | } |
| 971 | } else { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 972 | wakeUpFromPowerKey(event.getDownTime()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 973 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 974 | if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { |
| 975 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 976 | msg.setAsynchronous(true); |
| 977 | mHandler.sendMessageDelayed(msg, |
| 978 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 979 | mBeganFromNonInteractive = true; |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 980 | } else { |
| 981 | final int maxCount = getMaxMultiPressPowerCount(); |
| 982 | |
| 983 | if (maxCount <= 1) { |
| 984 | mPowerKeyHandled = true; |
| 985 | } else { |
| 986 | mBeganFromNonInteractive = true; |
| 987 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 988 | } |
| 989 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 993 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 994 | final boolean handled = canceled || mPowerKeyHandled; |
| 995 | mScreenshotChordPowerKeyTriggered = false; |
| 996 | cancelPendingScreenshotChordAction(); |
| 997 | cancelPendingPowerKeyAction(); |
| 998 | |
| 999 | if (!handled) { |
| 1000 | // Figure out how to handle the key now that it has been released. |
| 1001 | mPowerKeyPressCounter += 1; |
| 1002 | |
| 1003 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1004 | final long eventTime = event.getDownTime(); |
| 1005 | if (mPowerKeyPressCounter < maxCount) { |
| 1006 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 1007 | // Continue holding the wake lock. |
| 1008 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 1009 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 1010 | msg.setAsynchronous(true); |
| 1011 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout()); |
| 1012 | return; |
| 1013 | } |
| 1014 | |
| 1015 | // No other actions. Handle it immediately. |
| 1016 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1017 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1018 | |
| 1019 | // Done. Reset our state. |
| 1020 | finishPowerKeyPress(); |
| 1021 | } |
| 1022 | |
| 1023 | private void finishPowerKeyPress() { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1024 | mBeganFromNonInteractive = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1025 | mPowerKeyPressCounter = 0; |
| 1026 | if (mPowerKeyWakeLock.isHeld()) { |
| 1027 | mPowerKeyWakeLock.release(); |
| 1028 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | private void cancelPendingPowerKeyAction() { |
| 1032 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1033 | mPowerKeyHandled = true; |
| 1034 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1035 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 1039 | if (mScreenOnEarly && !mScreenOnFully) { |
| 1040 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 1041 | + "already in the process of turning the screen on."); |
| 1042 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 1043 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1044 | |
| 1045 | if (count == 2) { |
| 1046 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 1047 | } else if (count == 3) { |
| 1048 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1049 | } else if (interactive && !mBeganFromNonInteractive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1050 | switch (mShortPressOnPowerBehavior) { |
| 1051 | case SHORT_PRESS_POWER_NOTHING: |
| 1052 | break; |
| 1053 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 1054 | mPowerManager.goToSleep(eventTime, |
| 1055 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1056 | break; |
| 1057 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 1058 | mPowerManager.goToSleep(eventTime, |
| 1059 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1060 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1061 | break; |
| 1062 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 1063 | mPowerManager.goToSleep(eventTime, |
| 1064 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1065 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1066 | launchHomeFromHotKey(); |
| 1067 | break; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1068 | case SHORT_PRESS_POWER_GO_HOME: |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 1069 | launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/); |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1070 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 1076 | switch (behavior) { |
| 1077 | case MULTI_PRESS_POWER_NOTHING: |
| 1078 | break; |
| 1079 | case MULTI_PRESS_POWER_THEATER_MODE: |
Bryce Lee | 3ae447e | 2015-06-30 12:31:41 -0700 | [diff] [blame] | 1080 | if (!isUserSetupComplete()) { |
| 1081 | Slog.i(TAG, "Ignoring toggling theater mode - device not setup."); |
| 1082 | break; |
| 1083 | } |
| 1084 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1085 | if (isTheaterModeEnabled()) { |
| 1086 | Slog.i(TAG, "Toggling theater mode off."); |
| 1087 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1088 | Settings.Global.THEATER_MODE_ON, 0); |
| 1089 | if (!interactive) { |
| 1090 | wakeUpFromPowerKey(eventTime); |
| 1091 | } |
| 1092 | } else { |
| 1093 | Slog.i(TAG, "Toggling theater mode on."); |
| 1094 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1095 | Settings.Global.THEATER_MODE_ON, 1); |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1096 | |
| 1097 | if (mGoToSleepOnButtonPressTheaterMode && interactive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1098 | mPowerManager.goToSleep(eventTime, |
| 1099 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1100 | } |
| 1101 | } |
| 1102 | break; |
| 1103 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
Jeff Brown | 7b5be5e | 2014-11-12 18:45:31 -0800 | [diff] [blame] | 1104 | Slog.i(TAG, "Starting brightness boost."); |
| 1105 | if (!interactive) { |
| 1106 | wakeUpFromPowerKey(eventTime); |
| 1107 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1108 | mPowerManager.boostScreenBrightness(eventTime); |
| 1109 | break; |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | private int getMaxMultiPressPowerCount() { |
| 1114 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1115 | return 3; |
| 1116 | } |
| 1117 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1118 | return 2; |
| 1119 | } |
| 1120 | return 1; |
| 1121 | } |
| 1122 | |
| 1123 | private void powerLongPress() { |
| 1124 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1125 | switch (behavior) { |
| 1126 | case LONG_PRESS_POWER_NOTHING: |
| 1127 | break; |
| 1128 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1129 | mPowerKeyHandled = true; |
| 1130 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1131 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 1132 | } |
| 1133 | showGlobalActionsInternal(); |
| 1134 | break; |
| 1135 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1136 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1137 | mPowerKeyHandled = true; |
| 1138 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1139 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1140 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1141 | break; |
| 1142 | } |
| 1143 | } |
| 1144 | |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1145 | private void sleepPress(long eventTime) { |
| 1146 | if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) { |
| 1147 | launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | private void sleepRelease(long eventTime) { |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1152 | switch (mShortPressOnSleepBehavior) { |
| 1153 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1154 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1155 | Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)"); |
| 1156 | mPowerManager.goToSleep(eventTime, |
| 1157 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1158 | break; |
| 1159 | } |
| 1160 | } |
| 1161 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1162 | private int getResolvedLongPressOnPowerBehavior() { |
| 1163 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1164 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1165 | } |
| 1166 | return mLongPressOnPowerBehavior; |
| 1167 | } |
| 1168 | |
| 1169 | private boolean hasLongPressOnPowerBehavior() { |
| 1170 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1174 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1175 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
| 1176 | && !mScreenshotChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1177 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1178 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1179 | && now <= mScreenshotChordPowerKeyTime |
| 1180 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1181 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1182 | cancelPendingPowerKeyAction(); |
| 1183 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1184 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1185 | } |
| 1186 | } |
| 1187 | } |
| 1188 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1189 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1190 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1191 | // Double the time it takes to take a screenshot from the keyguard |
| 1192 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1193 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1194 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1195 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1198 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1199 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1202 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1203 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1204 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1205 | mEndCallKeyHandled = true; |
| 1206 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1207 | performAuditoryFeedbackForAccessibilityIfNeed(); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 1208 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1209 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1210 | } |
| 1211 | }; |
| 1212 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1213 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1214 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1215 | public void run() { |
| 1216 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1217 | } |
| 1218 | }; |
| 1219 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1220 | @Override |
| 1221 | public void showGlobalActions() { |
| 1222 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1223 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1224 | } |
| 1225 | |
| 1226 | void showGlobalActionsInternal() { |
| 1227 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1228 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1229 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1230 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1231 | final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1232 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1233 | if (keyguardShowing) { |
| 1234 | // since it took two seconds of long press to bring this up, |
| 1235 | // 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] | 1236 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1241 | return Settings.Global.getInt( |
| 1242 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1243 | } |
| 1244 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1245 | boolean isUserSetupComplete() { |
| 1246 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1247 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 1248 | } |
| 1249 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1250 | private void handleShortPressOnHome() { |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1251 | // Turn on the connected TV and switch HDMI input if we're a HDMI playback device. |
| 1252 | getHdmiControl().turnOnTv(); |
| 1253 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1254 | // If there's a dream running then use home to escape the dream |
| 1255 | // but don't actually go home. |
| 1256 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1257 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1258 | return; |
| 1259 | } |
| 1260 | |
| 1261 | // Go home! |
| 1262 | launchHomeFromHotKey(); |
| 1263 | } |
| 1264 | |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1265 | /** |
| 1266 | * Creates an accessor to HDMI control service that performs the operation of |
| 1267 | * turning on TV (optional) and switching input to us. If HDMI control service |
| 1268 | * is not available or we're not a HDMI playback device, the operation is no-op. |
| 1269 | */ |
| 1270 | private HdmiControl getHdmiControl() { |
| 1271 | if (null == mHdmiControl) { |
| 1272 | HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService( |
| 1273 | Context.HDMI_CONTROL_SERVICE); |
| 1274 | HdmiPlaybackClient client = null; |
| 1275 | if (manager != null) { |
| 1276 | client = manager.getPlaybackClient(); |
| 1277 | } |
| 1278 | mHdmiControl = new HdmiControl(client); |
| 1279 | } |
| 1280 | return mHdmiControl; |
| 1281 | } |
| 1282 | |
| 1283 | private static class HdmiControl { |
| 1284 | private final HdmiPlaybackClient mClient; |
| 1285 | |
| 1286 | private HdmiControl(HdmiPlaybackClient client) { |
| 1287 | mClient = client; |
| 1288 | } |
| 1289 | |
| 1290 | public void turnOnTv() { |
| 1291 | if (mClient == null) { |
| 1292 | return; |
| 1293 | } |
| 1294 | mClient.oneTouchPlay(new OneTouchPlayCallback() { |
| 1295 | @Override |
| 1296 | public void onComplete(int result) { |
| 1297 | if (result != HdmiControlManager.RESULT_SUCCESS) { |
| 1298 | Log.w(TAG, "One touch play failed: " + result); |
| 1299 | } |
| 1300 | } |
| 1301 | }); |
| 1302 | } |
| 1303 | } |
| 1304 | |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 1305 | private void handleLongPressOnHome(int deviceId) { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1306 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1307 | mHomeConsumed = true; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1308 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1309 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1310 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
| 1311 | toggleRecentApps(); |
| 1312 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 1313 | launchAssistAction(null, deviceId); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1314 | } |
| 1315 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1316 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1317 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1318 | private void handleDoubleTapOnHome() { |
| 1319 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1320 | mHomeConsumed = true; |
| 1321 | toggleRecentApps(); |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1326 | @Override |
| 1327 | public void run() { |
| 1328 | if (mHomeDoubleTapPending) { |
| 1329 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1330 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1331 | } |
| 1332 | } |
| 1333 | }; |
| 1334 | |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1335 | private boolean isRoundWindow() { |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1336 | return mContext.getResources().getConfiguration().isScreenRound(); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1337 | } |
| 1338 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1339 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1340 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1341 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1342 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1343 | mContext = context; |
| 1344 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1345 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1346 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 1347 | mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1348 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1349 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1350 | mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1351 | |
| 1352 | // Init display burn-in protection |
| 1353 | boolean burnInProtectionEnabled = context.getResources().getBoolean( |
| 1354 | com.android.internal.R.bool.config_enableBurnInProtection); |
| 1355 | // Allow a system property to override this. Used by developer settings. |
| 1356 | boolean burnInProtectionDevMode = |
| 1357 | SystemProperties.getBoolean("persist.debug.force_burn_in", false); |
| 1358 | if (burnInProtectionEnabled || burnInProtectionDevMode) { |
| 1359 | final int minHorizontal; |
| 1360 | final int maxHorizontal; |
| 1361 | final int minVertical; |
| 1362 | final int maxVertical; |
| 1363 | final int maxRadius; |
| 1364 | if (burnInProtectionDevMode) { |
| 1365 | minHorizontal = -8; |
| 1366 | maxHorizontal = 8; |
| 1367 | minVertical = -8; |
| 1368 | maxVertical = -4; |
| 1369 | maxRadius = (isRoundWindow()) ? 6 : -1; |
| 1370 | } else { |
| 1371 | Resources resources = context.getResources(); |
| 1372 | minHorizontal = resources.getInteger( |
| 1373 | com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); |
| 1374 | maxHorizontal = resources.getInteger( |
| 1375 | com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); |
| 1376 | minVertical = resources.getInteger( |
| 1377 | com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); |
| 1378 | maxVertical = resources.getInteger( |
| 1379 | com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); |
| 1380 | maxRadius = resources.getInteger( |
| 1381 | com.android.internal.R.integer.config_burnInProtectionMaxRadius); |
| 1382 | } |
| 1383 | mBurnInProtectionHelper = new BurnInProtectionHelper( |
| 1384 | context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 1385 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1386 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1387 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1388 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1389 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1390 | try { |
| 1391 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 1392 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1393 | mSettingsObserver = new SettingsObserver(mHandler); |
| 1394 | mSettingsObserver.observe(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1395 | mShortcutManager = new ShortcutManager(context); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 1396 | mUiMode = context.getResources().getInteger( |
| 1397 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1398 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1399 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 1400 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1401 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1402 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1403 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 1404 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1405 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1406 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1407 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1408 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1409 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1410 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1411 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1412 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1413 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1414 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1415 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1416 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1417 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1418 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1419 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1420 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1421 | mCarDockRotation = readRotation( |
| 1422 | com.android.internal.R.integer.config_carDockRotation); |
| 1423 | mDeskDockRotation = readRotation( |
| 1424 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1425 | mUndockedHdmiRotation = readRotation( |
| 1426 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1427 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1428 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1429 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1430 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1431 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1432 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1433 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1434 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1435 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1436 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1437 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1438 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1439 | |
| 1440 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 1441 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 1442 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 1443 | || mContext.getResources().getBoolean( |
| 1444 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 1445 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 1446 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 1447 | mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( |
| 1448 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1449 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 1450 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 1451 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 1452 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 1453 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 1454 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 1455 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1456 | mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( |
| 1457 | com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); |
| 1458 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1459 | mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( |
| 1460 | com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); |
| 1461 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1462 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1463 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 1464 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1465 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 1466 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1467 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 1468 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1469 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1470 | mShortPressOnSleepBehavior = mContext.getResources().getInteger( |
| 1471 | com.android.internal.R.integer.config_shortPressOnSleepBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1472 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 1473 | mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 1474 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1475 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1476 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1477 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1478 | Context.ACCESSIBILITY_SERVICE); |
| 1479 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1480 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1481 | IntentFilter filter = new IntentFilter(); |
| 1482 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1483 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1484 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1485 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1486 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1487 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1488 | if (intent != null) { |
| 1489 | // Retrieve current sticky dock event broadcast. |
| 1490 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1491 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1492 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1493 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1494 | // register for dream-related broadcasts |
| 1495 | filter = new IntentFilter(); |
| 1496 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1497 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1498 | context.registerReceiver(mDreamReceiver, filter); |
| 1499 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1500 | // register for multiuser-relevant broadcasts |
| 1501 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1502 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1503 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1504 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1505 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1506 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1507 | @Override |
| 1508 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1509 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1510 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1511 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1512 | } |
| 1513 | @Override |
| 1514 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1515 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1516 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1517 | } |
| 1518 | } |
| 1519 | @Override |
| 1520 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1521 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1522 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1523 | } |
| 1524 | } |
| 1525 | @Override |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1526 | public void onFling(int duration) { |
| 1527 | if (mPowerManagerInternal != null) { |
| 1528 | mPowerManagerInternal.powerHint( |
| 1529 | PowerManagerInternal.POWER_HINT_INTERACTION, duration); |
| 1530 | } |
| 1531 | } |
| 1532 | @Override |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1533 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1534 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1535 | } |
Adrian Roos | 3595be4 | 2015-03-05 16:31:15 +0100 | [diff] [blame] | 1536 | @Override |
| 1537 | public void onDown() { |
| 1538 | mOrientationListener.onTouchStart(); |
| 1539 | } |
| 1540 | @Override |
| 1541 | public void onUpOrCancel() { |
| 1542 | mOrientationListener.onTouchEnd(); |
| 1543 | } |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 1544 | @Override |
| 1545 | public void onMouseHoverAtTop() { |
| 1546 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1547 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 1548 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS; |
| 1549 | mHandler.sendMessageDelayed(msg, 500); |
| 1550 | } |
| 1551 | @Override |
| 1552 | public void onMouseHoverAtBottom() { |
| 1553 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1554 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 1555 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION; |
| 1556 | mHandler.sendMessageDelayed(msg, 500); |
| 1557 | } |
| 1558 | @Override |
| 1559 | public void onMouseLeaveFromEdge() { |
| 1560 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1561 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1562 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1563 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1564 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1565 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1566 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1567 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1568 | com.android.internal.R.array.config_longPressVibePattern); |
| 1569 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1570 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1571 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1572 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1573 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1574 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1575 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1576 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1577 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1578 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1579 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1580 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 1581 | mContextClickVibePattern = getLongIntArray(mContext.getResources(), |
| 1582 | com.android.internal.R.array.config_contextClickVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1583 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1584 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1585 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 1586 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1587 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1588 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1589 | // Controls rotation and the like. |
| 1590 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1591 | |
| 1592 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1593 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 1594 | startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 1595 | finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1596 | } |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 1597 | |
| 1598 | mWindowManagerInternal.registerAppTransitionListener( |
| 1599 | mStatusBarController.getAppTransitionListener()); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1602 | /** |
| 1603 | * Read values from config.xml that may be overridden depending on |
| 1604 | * the configuration of the device. |
| 1605 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1606 | */ |
| 1607 | private void readConfigurationDependentBehaviors() { |
| 1608 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 1609 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1610 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 1611 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { |
| 1612 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1613 | } |
| 1614 | |
| 1615 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 1616 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1617 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1618 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1619 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1620 | } |
| 1621 | } |
| 1622 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1623 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1624 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1625 | // This method might be called before the policy has been fully initialized |
| 1626 | // or for other displays we don't care about. |
| 1627 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1628 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1629 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1630 | mDisplay = display; |
| 1631 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1632 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1633 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1634 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1635 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1636 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1637 | mLandscapeRotation = Surface.ROTATION_0; |
| 1638 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1639 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1640 | mPortraitRotation = Surface.ROTATION_90; |
| 1641 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1642 | } else { |
| 1643 | mPortraitRotation = Surface.ROTATION_270; |
| 1644 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1645 | } |
| 1646 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1647 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1648 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1649 | mPortraitRotation = Surface.ROTATION_0; |
| 1650 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1651 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1652 | mLandscapeRotation = Surface.ROTATION_270; |
| 1653 | mSeascapeRotation = Surface.ROTATION_90; |
| 1654 | } else { |
| 1655 | mLandscapeRotation = Surface.ROTATION_90; |
| 1656 | mSeascapeRotation = Surface.ROTATION_270; |
| 1657 | } |
| 1658 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1659 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1660 | mStatusBarHeight = |
| 1661 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1662 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1663 | // Height of the navigation bar when presented horizontally at bottom |
| 1664 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 1665 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1666 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1667 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1668 | mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1669 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1670 | |
| 1671 | // Width of the navigation bar when presented vertically along one side |
| 1672 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 1673 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 1674 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 1675 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1676 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1677 | |
| 1678 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1679 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1680 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1681 | |
Devin Kim | d7b12b4 | 2014-05-05 14:34:58 -0700 | [diff] [blame] | 1682 | // Allow the navigation bar to move on non-square small devices (phones). |
| 1683 | mNavigationBarCanMove = width != height && shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1684 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1685 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1686 | // Allow a system property to override this. Used by the emulator. |
| 1687 | // See also hasNavigationBar(). |
| 1688 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1689 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1690 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1691 | } else if ("0".equals(navBarOverride)) { |
| 1692 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1693 | } |
| 1694 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1695 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1696 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1697 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1698 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1699 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1700 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1701 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1702 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1703 | |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 1704 | // For demo purposes, allow the rotation of the remote display to be controlled. |
| 1705 | // By default, remote display locks rotation to landscape. |
| 1706 | if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { |
| 1707 | mDemoRotation = mPortraitRotation; |
| 1708 | } else { |
| 1709 | mDemoRotation = mLandscapeRotation; |
| 1710 | } |
| 1711 | mDemoRotationLock = SystemProperties.getBoolean( |
| 1712 | "persist.demo.rotationlock", false); |
| 1713 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1714 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1715 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1716 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1717 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1718 | // For debug purposes the next line turns this feature off with: |
| 1719 | // $ adb shell setprop config.override_forced_orient true |
| 1720 | // $ adb shell wm size reset |
| 1721 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1722 | } |
| 1723 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1724 | /** |
| 1725 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1726 | * navigation bar and touch exploration is not enabled |
| 1727 | */ |
| 1728 | private boolean canHideNavigationBar() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 1729 | return mHasNavigationBar; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1732 | @Override |
| 1733 | public boolean isDefaultOrientationForced() { |
| 1734 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1735 | } |
| 1736 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1737 | @Override |
| 1738 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1739 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1740 | mOverscanLeft = left; |
| 1741 | mOverscanTop = top; |
| 1742 | mOverscanRight = right; |
| 1743 | mOverscanBottom = bottom; |
| 1744 | } |
| 1745 | } |
| 1746 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1747 | public void updateSettings() { |
| 1748 | ContentResolver resolver = mContext.getContentResolver(); |
| 1749 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1750 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1751 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1752 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1753 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1754 | UserHandle.USER_CURRENT); |
| 1755 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1756 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1757 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1758 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1759 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1760 | // Configure wake gesture. |
| 1761 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 1762 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 1763 | UserHandle.USER_CURRENT) != 0; |
| 1764 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 1765 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 1766 | updateWakeGestureListenerLp(); |
| 1767 | } |
| 1768 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1769 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1770 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1771 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1772 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1773 | if (mUserRotation != userRotation) { |
| 1774 | mUserRotation = userRotation; |
| 1775 | updateRotation = true; |
| 1776 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1777 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1778 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1779 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1780 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1781 | if (mUserRotationMode != userRotationMode) { |
| 1782 | mUserRotationMode = userRotationMode; |
| 1783 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1784 | updateOrientationListenerLp(); |
| 1785 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1786 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1787 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1788 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1789 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1790 | if (mPointerLocationMode != pointerLocation) { |
| 1791 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1792 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1793 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1794 | } |
| 1795 | } |
| 1796 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1797 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1798 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1799 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1800 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1801 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1802 | if (mHasSoftInput != hasSoftInput) { |
| 1803 | mHasSoftInput = hasSoftInput; |
| 1804 | updateRotation = true; |
| 1805 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1806 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1807 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1808 | } |
tiger_huang | cc6366d | 2015-06-29 17:17:30 +0800 | [diff] [blame] | 1809 | } |
| 1810 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1811 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1812 | } |
| 1813 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1814 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1815 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1818 | private void updateWakeGestureListenerLp() { |
| 1819 | if (shouldEnableWakeGestureLp()) { |
| 1820 | mWakeGestureListener.requestWakeUpTrigger(); |
| 1821 | } else { |
| 1822 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1827 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1828 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 1829 | && mWakeGestureListener.isSupported(); |
| 1830 | } |
| 1831 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1832 | private void enablePointerLocation() { |
| 1833 | if (mPointerLocationView == null) { |
| 1834 | mPointerLocationView = new PointerLocationView(mContext); |
| 1835 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1836 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1837 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1838 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1839 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1840 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1841 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1842 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1843 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1844 | if (ActivityManager.isHighEndGfx()) { |
| 1845 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1846 | lp.privateFlags |= |
| 1847 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1848 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1849 | lp.format = PixelFormat.TRANSLUCENT; |
| 1850 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1851 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1852 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1853 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1854 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1855 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1856 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1857 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1858 | |
| 1859 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1860 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1861 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 1862 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1863 | wm.removeView(mPointerLocationView); |
| 1864 | mPointerLocationView = null; |
| 1865 | } |
| 1866 | } |
| 1867 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1868 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1869 | try { |
| 1870 | int rotation = mContext.getResources().getInteger(resID); |
| 1871 | switch (rotation) { |
| 1872 | case 0: |
| 1873 | return Surface.ROTATION_0; |
| 1874 | case 90: |
| 1875 | return Surface.ROTATION_90; |
| 1876 | case 180: |
| 1877 | return Surface.ROTATION_180; |
| 1878 | case 270: |
| 1879 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1880 | } |
| 1881 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1882 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1883 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1884 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1888 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1889 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1890 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1891 | |
| 1892 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1893 | |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 1894 | if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) |
| 1895 | || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) |
| 1896 | || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { |
| 1897 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
| 1898 | } |
| 1899 | |
| 1900 | if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { |
| 1901 | // Window manager will make sure these are okay. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1902 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1903 | } |
| 1904 | String permission = null; |
| 1905 | switch (type) { |
| 1906 | case TYPE_TOAST: |
| 1907 | // XXX right now the app process has complete control over |
| 1908 | // this... should introduce a token to let the system |
| 1909 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1910 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1911 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1912 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1913 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1914 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1915 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1916 | case TYPE_VOICE_INTERACTION: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 1917 | case TYPE_ACCESSIBILITY_OVERLAY: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1918 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1919 | break; |
| 1920 | case TYPE_PHONE: |
| 1921 | case TYPE_PRIORITY_PHONE: |
| 1922 | case TYPE_SYSTEM_ALERT: |
| 1923 | case TYPE_SYSTEM_ERROR: |
| 1924 | case TYPE_SYSTEM_OVERLAY: |
| 1925 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1926 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1927 | break; |
| 1928 | default: |
| 1929 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1930 | } |
| 1931 | if (permission != null) { |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1932 | if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) { |
| 1933 | final int callingUid = Binder.getCallingUid(); |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 1934 | // system processes will be automatically allowed privilege to draw |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1935 | if (callingUid == Process.SYSTEM_UID) { |
| 1936 | return WindowManagerGlobal.ADD_OKAY; |
| 1937 | } |
| 1938 | |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 1939 | // check if user has enabled this operation. SecurityException will be thrown if |
| 1940 | // this app has not been allowed by the user |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1941 | final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid, |
| 1942 | attrs.packageName); |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 1943 | switch (mode) { |
| 1944 | case AppOpsManager.MODE_ALLOWED: |
| 1945 | case AppOpsManager.MODE_IGNORED: |
| 1946 | // although we return ADD_OKAY for MODE_IGNORED, the added window will |
| 1947 | // actually be hidden in WindowManagerService |
| 1948 | return WindowManagerGlobal.ADD_OKAY; |
| 1949 | case AppOpsManager.MODE_ERRORED: |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1950 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 1951 | default: |
| 1952 | // in the default mode, we will make a decision here based on |
| 1953 | // checkCallingPermission() |
| 1954 | if (mContext.checkCallingPermission(permission) != |
| 1955 | PackageManager.PERMISSION_GRANTED) { |
| 1956 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
| 1957 | } else { |
| 1958 | return WindowManagerGlobal.ADD_OKAY; |
| 1959 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1960 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1961 | } |
| 1962 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1963 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1964 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1965 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1966 | } |
| 1967 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1968 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1969 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1970 | |
| 1971 | @Override |
| 1972 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1973 | |
| 1974 | // If this switch statement is modified, modify the comment in the declarations of |
| 1975 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1976 | switch (attrs.type) { |
| 1977 | default: |
| 1978 | // These are the windows that by default are shown only to the user that created |
| 1979 | // them. If this needs to be overridden, set |
| 1980 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1981 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1982 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1983 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1984 | return true; |
| 1985 | } |
| 1986 | break; |
| 1987 | |
| 1988 | // These are the windows that by default are shown to all users. However, to |
| 1989 | // protect against spoofing, check permissions below. |
| 1990 | case TYPE_APPLICATION_STARTING: |
| 1991 | case TYPE_BOOT_PROGRESS: |
| 1992 | case TYPE_DISPLAY_OVERLAY: |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1993 | case TYPE_INPUT_CONSUMER: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1994 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1995 | case TYPE_KEYGUARD_DIALOG: |
| 1996 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1997 | case TYPE_NAVIGATION_BAR: |
| 1998 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1999 | case TYPE_PHONE: |
| 2000 | case TYPE_POINTER: |
| 2001 | case TYPE_PRIORITY_PHONE: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2002 | case TYPE_SEARCH_BAR: |
| 2003 | case TYPE_STATUS_BAR: |
| 2004 | case TYPE_STATUS_BAR_PANEL: |
| 2005 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 2006 | case TYPE_SYSTEM_DIALOG: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2007 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2008 | case TYPE_PRIVATE_PRESENTATION: |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2009 | case TYPE_DOCK_DIVIDER: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2010 | break; |
| 2011 | } |
| 2012 | |
| 2013 | // Check if third party app has set window to system window type. |
| 2014 | return mContext.checkCallingOrSelfPermission( |
| 2015 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 2016 | != PackageManager.PERMISSION_GRANTED; |
| 2017 | } |
| 2018 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2019 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2020 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 2021 | switch (attrs.type) { |
| 2022 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 2023 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2024 | // These types of windows can't receive input events. |
| 2025 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 2026 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 2027 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2028 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2029 | case TYPE_STATUS_BAR: |
| 2030 | |
| 2031 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 2032 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 2033 | // the keyguard as occluded wouldn't set these flags again. |
| 2034 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 2035 | if (mKeyguardHidden) { |
| 2036 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 2037 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2038 | } |
| 2039 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2040 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 2041 | |
| 2042 | if (attrs.type != TYPE_STATUS_BAR) { |
| 2043 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 2044 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2045 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2046 | |
| 2047 | if (ActivityManager.isHighEndGfx() |
| 2048 | && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
Adrian Roos | f5e9b5c | 2014-09-10 15:27:41 +0200 | [diff] [blame] | 2049 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2050 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 2051 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2052 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2053 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2054 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 2055 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2056 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2057 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 2058 | private void readCameraLensCoverState() { |
| 2059 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 2060 | } |
| 2061 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2062 | private boolean isHidden(int accessibilityMode) { |
| 2063 | switch (accessibilityMode) { |
| 2064 | case 1: |
| 2065 | return mLidState == LID_CLOSED; |
| 2066 | case 2: |
| 2067 | return mLidState == LID_OPEN; |
| 2068 | default: |
| 2069 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2070 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2071 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2072 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2073 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2074 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2075 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 2076 | int navigationPresence) { |
| 2077 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 2078 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2079 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2080 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 2081 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2082 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2083 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 2084 | || (keyboardPresence == PRESENCE_INTERNAL |
| 2085 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2086 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2087 | if (!mHasSoftInput) { |
| 2088 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 2089 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2090 | } |
| 2091 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2092 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 2093 | || (navigationPresence == PRESENCE_INTERNAL |
| 2094 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2095 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2096 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2097 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2098 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2099 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2100 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2101 | public int windowTypeToLayerLw(int type) { |
| 2102 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2103 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2104 | } |
| 2105 | switch (type) { |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2106 | case TYPE_PRIVATE_PRESENTATION: |
| 2107 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2108 | case TYPE_WALLPAPER: |
| 2109 | // wallpaper is at the bottom, though the window manager may move it. |
| 2110 | return 2; |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2111 | case TYPE_DOCK_DIVIDER: |
| 2112 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2113 | case TYPE_PHONE: |
| 2114 | return 3; |
| 2115 | case TYPE_SEARCH_BAR: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2116 | case TYPE_VOICE_INTERACTION_STARTING: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2117 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2118 | case TYPE_VOICE_INTERACTION: |
| 2119 | // voice interaction layer is almost immediately above apps. |
| 2120 | return 5; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2121 | case TYPE_INPUT_CONSUMER: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2122 | return 6; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2123 | case TYPE_SYSTEM_DIALOG: |
| 2124 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2125 | case TYPE_TOAST: |
| 2126 | // toasts and the plugged-in battery thing |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2127 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2128 | case TYPE_PRIORITY_PHONE: |
| 2129 | // 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] | 2130 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2131 | case TYPE_DREAM: |
| 2132 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2133 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2134 | case TYPE_SYSTEM_ALERT: |
| 2135 | // like the ANR / app crashed dialogs |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2136 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2137 | case TYPE_INPUT_METHOD: |
| 2138 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2139 | return 12; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2140 | case TYPE_INPUT_METHOD_DIALOG: |
| 2141 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2142 | return 13; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2143 | case TYPE_KEYGUARD_SCRIM: |
| 2144 | // the safety window that shows behind keyguard while keyguard is starting |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2145 | return 14; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2146 | case TYPE_STATUS_BAR_SUB_PANEL: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2147 | return 15; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2148 | case TYPE_STATUS_BAR: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2149 | return 16; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2150 | case TYPE_STATUS_BAR_PANEL: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2151 | return 17; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2152 | case TYPE_KEYGUARD_DIALOG: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2153 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2154 | case TYPE_VOLUME_OVERLAY: |
| 2155 | // the on-screen volume indicator and controller shown when the user |
| 2156 | // changes the device volume |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2157 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2158 | case TYPE_SYSTEM_OVERLAY: |
| 2159 | // the on-screen volume indicator and controller shown when the user |
| 2160 | // changes the device volume |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2161 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2162 | case TYPE_NAVIGATION_BAR: |
| 2163 | // the navigation bar, if available, shows atop most things |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2164 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2165 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2166 | // 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] | 2167 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2168 | case TYPE_SYSTEM_ERROR: |
| 2169 | // system-level error dialogs |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2170 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2171 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2172 | // used to highlight the magnified portion of a display |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2173 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2174 | case TYPE_DISPLAY_OVERLAY: |
| 2175 | // used to simulate secondary display devices |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2176 | return 25; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2177 | case TYPE_DRAG: |
| 2178 | // the drag layer: input for drag-and-drop is associated with this window, |
| 2179 | // which sits above all other focusable windows |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2180 | return 26; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2181 | case TYPE_ACCESSIBILITY_OVERLAY: |
| 2182 | // overlay put by accessibility services to intercept user interaction |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2183 | return 27; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2184 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2185 | return 28; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2186 | case TYPE_BOOT_PROGRESS: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2187 | return 29; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2188 | case TYPE_POINTER: |
| 2189 | // the (mouse) pointer layer |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2190 | return 30; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2191 | } |
| 2192 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2193 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2194 | } |
| 2195 | |
| 2196 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2197 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2198 | public int subWindowTypeToLayerLw(int type) { |
| 2199 | switch (type) { |
| 2200 | case TYPE_APPLICATION_PANEL: |
| 2201 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 2202 | return APPLICATION_PANEL_SUBLAYER; |
| 2203 | case TYPE_APPLICATION_MEDIA: |
| 2204 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 2205 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 2206 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2207 | case TYPE_APPLICATION_SUB_PANEL: |
| 2208 | return APPLICATION_SUB_PANEL_SUBLAYER; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 2209 | case TYPE_APPLICATION_ABOVE_SUB_PANEL: |
| 2210 | return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2211 | } |
| 2212 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 2213 | return 0; |
| 2214 | } |
| 2215 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2216 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2217 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2218 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2221 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2222 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2223 | if (mHasNavigationBar) { |
| 2224 | // For a basic navigation bar, when we are in landscape mode we place |
| 2225 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2226 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 2227 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2228 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2229 | } |
| 2230 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2231 | } |
| 2232 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2233 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2234 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2235 | if (mHasNavigationBar) { |
| 2236 | // For a basic navigation bar, when we are in portrait mode we place |
| 2237 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2238 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 2239 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2240 | } |
| 2241 | } |
| 2242 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2243 | } |
| 2244 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2245 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2246 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 2247 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2248 | } |
| 2249 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2250 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2251 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2252 | // There is a separate status bar at the top of the display. We don't count that as part |
| 2253 | // 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] | 2254 | // we do want to exclude it since applications can't generally use that part |
| 2255 | // of the screen. |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2256 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2257 | } |
| 2258 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2259 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 2260 | public boolean isForceHiding(WindowManager.LayoutParams attrs) { |
| 2261 | return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2262 | (isKeyguardHostWindow(attrs) && |
| 2263 | (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) || |
Adrian Roos | 69e510d | 2014-07-13 14:57:59 +0200 | [diff] [blame] | 2264 | (attrs.type == TYPE_KEYGUARD_SCRIM); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2265 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2266 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2267 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2268 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 2269 | return attrs.type == TYPE_STATUS_BAR; |
| 2270 | } |
| 2271 | |
| 2272 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2273 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2274 | switch (attrs.type) { |
| 2275 | case TYPE_STATUS_BAR: |
| 2276 | case TYPE_NAVIGATION_BAR: |
| 2277 | case TYPE_WALLPAPER: |
| 2278 | case TYPE_DREAM: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2279 | case TYPE_KEYGUARD_SCRIM: |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2280 | case TYPE_DOCK_DIVIDER: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2281 | return false; |
| 2282 | default: |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 2283 | // Hide only windows below the keyguard host window. |
| 2284 | return windowTypeToLayerLw(win.getBaseType()) |
| 2285 | < windowTypeToLayerLw(TYPE_STATUS_BAR); |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2286 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2287 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2288 | |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 2289 | @Override |
| 2290 | public WindowState getWinShowWhenLockedLw() { |
| 2291 | return mWinShowWhenLocked; |
| 2292 | } |
| 2293 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2294 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2295 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2296 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 2297 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2298 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2299 | if (!SHOW_STARTING_ANIMATIONS) { |
| 2300 | return null; |
| 2301 | } |
| 2302 | if (packageName == null) { |
| 2303 | return null; |
| 2304 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2305 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2306 | WindowManager wm = null; |
| 2307 | View view = null; |
| 2308 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2309 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2310 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2311 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 2312 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 2313 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2314 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2315 | try { |
| 2316 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2317 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2318 | } catch (PackageManager.NameNotFoundException e) { |
| 2319 | // Ignore |
| 2320 | } |
| 2321 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2322 | |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 2323 | PhoneWindow win = new PhoneWindow(context); |
| 2324 | win.setIsStartingWindow(true); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2325 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2326 | Resources r = context.getResources(); |
| 2327 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2328 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2329 | win.setType( |
| 2330 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2331 | |
| 2332 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2333 | // Assumes it's safe to show starting windows of launched apps while |
| 2334 | // the keyguard is being hidden. This is okay because starting windows never show |
| 2335 | // secret information. |
| 2336 | if (mKeyguardHidden) { |
| 2337 | windowFlags |= FLAG_SHOW_WHEN_LOCKED; |
| 2338 | } |
| 2339 | } |
| 2340 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2341 | // Force the window flags: this is a fake window, so it is not really |
| 2342 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 2343 | // flag because we do know that the next window will take input |
| 2344 | // focus, so we want to get the IME window up on top of us right away. |
| 2345 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2346 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2347 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2348 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2349 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2350 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2351 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2352 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2353 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2354 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2355 | win.setDefaultIcon(icon); |
| 2356 | win.setDefaultLogo(logo); |
| 2357 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2358 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2359 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2360 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2361 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 2362 | params.token = appToken; |
| 2363 | params.packageName = packageName; |
| 2364 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 2365 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2366 | params.privateFlags |= |
| 2367 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2368 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2369 | |
| 2370 | if (!compatInfo.supportsScreen()) { |
| 2371 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 2372 | } |
| 2373 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2374 | params.setTitle("Starting " + packageName); |
| 2375 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2376 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 2377 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2378 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2379 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2380 | TAG, "Adding starting window for " + packageName |
| 2381 | + " / " + appToken + ": " |
| 2382 | + (view.getParent() != null ? view : null)); |
| 2383 | |
| 2384 | wm.addView(view, params); |
| 2385 | |
| 2386 | // Only return the view if it was successfully added to the |
| 2387 | // window manager... which we can tell by it having a parent. |
| 2388 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2389 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2390 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 2391 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 2392 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2393 | } catch (RuntimeException e) { |
| 2394 | // don't crash if something else bad happens, for example a |
| 2395 | // failure loading resources because we are loading from an app |
| 2396 | // on external storage that has been unmounted. |
| 2397 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2398 | } finally { |
| 2399 | if (view != null && view.getParent() == null) { |
| 2400 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 2401 | wm.removeViewImmediate(view); |
| 2402 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | return null; |
| 2406 | } |
| 2407 | |
| 2408 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2409 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2410 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2411 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": " |
| 2412 | + window + " Callers=" + Debug.getCallers(4)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2413 | |
| 2414 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2415 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2416 | wm.removeView(window); |
| 2417 | } |
| 2418 | } |
| 2419 | |
| 2420 | /** |
| 2421 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2422 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2423 | * Currently enforces that three window types are singletons: |
| 2424 | * <ul> |
| 2425 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2426 | * <li>KEYGUARD_TYPE</li> |
| 2427 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2428 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2429 | * @param win The window to be added |
| 2430 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2431 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2432 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 2433 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2434 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2435 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2436 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 2437 | switch (attrs.type) { |
| 2438 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 2439 | mContext.enforceCallingOrSelfPermission( |
| 2440 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2441 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2442 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2443 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2444 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2445 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2446 | } |
| 2447 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2448 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2449 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2450 | case TYPE_NAVIGATION_BAR: |
| 2451 | mContext.enforceCallingOrSelfPermission( |
| 2452 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2453 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2454 | if (mNavigationBar != null) { |
| 2455 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2456 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2457 | } |
| 2458 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2459 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2460 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2461 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2462 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 2463 | case TYPE_NAVIGATION_BAR_PANEL: |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2464 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2465 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2466 | case TYPE_VOICE_INTERACTION_STARTING: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2467 | mContext.enforceCallingOrSelfPermission( |
| 2468 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2469 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2470 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2471 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 2472 | if (mKeyguardScrim != null) { |
| 2473 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 2474 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2475 | mKeyguardScrim = win; |
| 2476 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2477 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2478 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2482 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2483 | public void removeWindowLw(WindowState win) { |
| 2484 | if (mStatusBar == win) { |
| 2485 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2486 | mStatusBarController.setWindow(null); |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 2487 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2488 | } else if (mKeyguardScrim == win) { |
| 2489 | Log.v(TAG, "Removing keyguard scrim"); |
| 2490 | mKeyguardScrim = null; |
| 2491 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2492 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2493 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2494 | } |
| 2495 | } |
| 2496 | |
| 2497 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2498 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2499 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2500 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2501 | public int selectAnimationLw(WindowState win, int transit) { |
| 2502 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 2503 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2504 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2505 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2506 | if (transit == TRANSIT_EXIT |
| 2507 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2508 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2509 | } else if (transit == TRANSIT_ENTER |
| 2510 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2511 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2512 | } |
| 2513 | } else if (win == mNavigationBar) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2514 | if (win.getAttrs().windowAnimations != 0) { |
| 2515 | return 0; |
| 2516 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2517 | // This can be on either the bottom or the right. |
| 2518 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2519 | if (transit == TRANSIT_EXIT |
| 2520 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2521 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2522 | } else if (transit == TRANSIT_ENTER |
| 2523 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2524 | return R.anim.dock_bottom_enter; |
| 2525 | } |
| 2526 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2527 | if (transit == TRANSIT_EXIT |
| 2528 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2529 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2530 | } else if (transit == TRANSIT_ENTER |
| 2531 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2532 | return R.anim.dock_right_enter; |
| 2533 | } |
| 2534 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2538 | if (win.hasAppShownWindows()) { |
| 2539 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 2540 | return com.android.internal.R.anim.app_starting_exit; |
| 2541 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 2542 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2543 | && transit == TRANSIT_ENTER) { |
| 2544 | // Special case: we are animating in a dream, while the keyguard |
| 2545 | // is shown. We don't want an animation on the dream, because |
| 2546 | // we need it shown immediately with the keyguard animating away |
| 2547 | // to reveal it. |
| 2548 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | return 0; |
| 2552 | } |
| 2553 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 2554 | @Override |
| 2555 | public void selectRotationAnimationLw(int anim[]) { |
| 2556 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 2557 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 2558 | + (mTopFullscreenOpaqueWindowState == null ? |
| 2559 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 2560 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 2561 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 2562 | case ROTATION_ANIMATION_CROSSFADE: |
| 2563 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 2564 | anim[1] = R.anim.rotation_animation_enter; |
| 2565 | break; |
| 2566 | case ROTATION_ANIMATION_JUMPCUT: |
| 2567 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 2568 | anim[1] = R.anim.rotation_animation_enter; |
| 2569 | break; |
| 2570 | case ROTATION_ANIMATION_ROTATE: |
| 2571 | default: |
| 2572 | anim[0] = anim[1] = 0; |
| 2573 | break; |
| 2574 | } |
| 2575 | } else { |
| 2576 | anim[0] = anim[1] = 0; |
| 2577 | } |
| 2578 | } |
| 2579 | |
| 2580 | @Override |
| 2581 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 2582 | boolean forceDefault) { |
| 2583 | switch (exitAnimId) { |
| 2584 | case R.anim.rotation_animation_xfade_exit: |
| 2585 | case R.anim.rotation_animation_jump_exit: |
| 2586 | // These are the only cases that matter. |
| 2587 | if (forceDefault) { |
| 2588 | return false; |
| 2589 | } |
| 2590 | int anim[] = new int[2]; |
| 2591 | selectRotationAnimationLw(anim); |
| 2592 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 2593 | default: |
| 2594 | return true; |
| 2595 | } |
| 2596 | } |
| 2597 | |
| 2598 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2599 | public Animation createForceHideEnterAnimation(boolean onWallpaper, |
| 2600 | boolean goingToNotificationShade) { |
| 2601 | if (goingToNotificationShade) { |
| 2602 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
Craig Mautner | b834080 | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2603 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2604 | |
| 2605 | AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? |
| 2606 | R.anim.lock_screen_behind_enter_wallpaper : |
| 2607 | R.anim.lock_screen_behind_enter); |
| 2608 | |
| 2609 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2610 | final List<Animation> animations = set.getAnimations(); |
| 2611 | for (int i = animations.size() - 1; i >= 0; --i) { |
| 2612 | animations.get(i).setInterpolator(mLogDecelerateInterpolator); |
| 2613 | } |
| 2614 | |
| 2615 | return set; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | |
| 2619 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2620 | public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) { |
| 2621 | if (goingToNotificationShade) { |
| 2622 | return null; |
| 2623 | } else { |
| 2624 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 2625 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2626 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 2627 | |
| 2628 | private static void awakenDreams() { |
| 2629 | IDreamManager dreamManager = getDreamManager(); |
| 2630 | if (dreamManager != null) { |
| 2631 | try { |
| 2632 | dreamManager.awaken(); |
| 2633 | } catch (RemoteException e) { |
| 2634 | // fine, stay asleep then |
| 2635 | } |
| 2636 | } |
| 2637 | } |
| 2638 | |
| 2639 | static IDreamManager getDreamManager() { |
| 2640 | return IDreamManager.Stub.asInterface( |
| 2641 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 2642 | } |
| 2643 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 2644 | TelecomManager getTelecommService() { |
| 2645 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2646 | } |
| 2647 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2648 | static IAudioService getAudioService() { |
| 2649 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 2650 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 2651 | if (audioService == null) { |
| 2652 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 2653 | } |
| 2654 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2655 | } |
| 2656 | |
| 2657 | boolean keyguardOn() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2658 | return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 2662 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 2663 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 2664 | }; |
| 2665 | |
| 2666 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2667 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2668 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2669 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2670 | final int keyCode = event.getKeyCode(); |
| 2671 | final int repeatCount = event.getRepeatCount(); |
| 2672 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2673 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2674 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 2675 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2676 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2677 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2678 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2679 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 2680 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2681 | } |
| 2682 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2683 | // If we think we might have a volume down & power key chord on the way |
| 2684 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 2685 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2686 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2687 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2688 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2689 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 2690 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2691 | if (now < timeoutTime) { |
| 2692 | return timeoutTime - now; |
| 2693 | } |
| 2694 | } |
| 2695 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2696 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2697 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2698 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2699 | } |
| 2700 | return -1; |
| 2701 | } |
| 2702 | } |
| 2703 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2704 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 2705 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 2706 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2707 | mPendingMetaAction = false; |
| 2708 | } |
| 2709 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2710 | // First we always handle the home key here, so applications |
| 2711 | // can never break it, although if keyguard is on, we do let |
| 2712 | // it handle it, because that gives us the correct 5 second |
| 2713 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2714 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2715 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2716 | // If we have released the home key, and didn't do anything else |
| 2717 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2718 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2719 | cancelPreloadRecentApps(); |
| 2720 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2721 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2722 | if (mHomeConsumed) { |
| 2723 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2724 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2725 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2726 | |
| 2727 | if (canceled) { |
| 2728 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 2729 | return -1; |
| 2730 | } |
| 2731 | |
Yorke Lee | 4f80324 | 2014-12-15 23:22:06 +0000 | [diff] [blame] | 2732 | // If an incoming call is ringing, HOME is totally disabled. |
| 2733 | // (The user is already on the InCallUI at this point, |
| 2734 | // and his ONLY options are to answer or reject the call.) |
| 2735 | TelecomManager telecomManager = getTelecommService(); |
| 2736 | if (telecomManager != null && telecomManager.isRinging()) { |
| 2737 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2738 | return -1; |
| 2739 | } |
| 2740 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2741 | // Delay handling home if a double-tap is possible. |
| 2742 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2743 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2744 | mHomeDoubleTapPending = true; |
| 2745 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2746 | ViewConfiguration.getDoubleTapTimeout()); |
| 2747 | return -1; |
| 2748 | } |
| 2749 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2750 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2751 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2752 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2753 | |
| 2754 | // If a system window has focus, then it doesn't make sense |
| 2755 | // right now to interact with applications. |
| 2756 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2757 | if (attrs != null) { |
| 2758 | final int type = attrs.type; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2759 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 2760 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG |
| 2761 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2762 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2763 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2764 | } |
| 2765 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2766 | for (int i=0; i<typeCount; i++) { |
| 2767 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2768 | // 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] | 2769 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2770 | } |
| 2771 | } |
| 2772 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2773 | |
| 2774 | // Remember that home is pressed and handle special actions. |
| 2775 | if (repeatCount == 0) { |
| 2776 | mHomePressed = true; |
| 2777 | if (mHomeDoubleTapPending) { |
| 2778 | mHomeDoubleTapPending = false; |
| 2779 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2780 | handleDoubleTapOnHome(); |
| 2781 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2782 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2783 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2784 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2785 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2786 | if (!keyguardOn) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 2787 | handleLongPressOnHome(event.getDeviceId()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2788 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2789 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2790 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2791 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2792 | // Hijack modified menu keys for debugging features |
| 2793 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2794 | |
| 2795 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2796 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2797 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2798 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2799 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2800 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2801 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2802 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2803 | Intent service = new Intent(); |
| 2804 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2805 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2806 | boolean shown = Settings.Global.getInt( |
| 2807 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2808 | if (!shown) { |
| 2809 | mContext.startService(service); |
| 2810 | } else { |
| 2811 | mContext.stopService(service); |
| 2812 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2813 | Settings.Global.putInt( |
| 2814 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2815 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2816 | } |
| 2817 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2818 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2819 | if (down) { |
| 2820 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2821 | mSearchKeyShortcutPending = true; |
| 2822 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2823 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2824 | } else { |
| 2825 | mSearchKeyShortcutPending = false; |
| 2826 | if (mConsumeSearchKeyUp) { |
| 2827 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2828 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2829 | } |
| 2830 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2831 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2832 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2833 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2834 | if (down && repeatCount == 0) { |
| 2835 | preloadRecentApps(); |
| 2836 | } else if (!down) { |
| 2837 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2838 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2839 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2840 | return -1; |
Jun Mukai | d21b3c8 | 2015-04-23 14:09:34 -0700 | [diff] [blame] | 2841 | } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) { |
| 2842 | if (down) { |
| 2843 | IStatusBarService service = getStatusBarService(); |
| 2844 | if (service != null) { |
| 2845 | try { |
| 2846 | service.expandNotificationsPanel(); |
| 2847 | } catch (RemoteException e) { |
| 2848 | // do nothing. |
| 2849 | } |
| 2850 | } |
| 2851 | } |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 2852 | } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) { |
| 2853 | if (down) { |
| 2854 | if (repeatCount == 0) { |
| 2855 | showKeyboardShortcutsMenu(); |
| 2856 | } |
| 2857 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2858 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2859 | if (down) { |
| 2860 | if (repeatCount == 0) { |
| 2861 | mAssistKeyLongPressed = false; |
| 2862 | } else if (repeatCount == 1) { |
| 2863 | mAssistKeyLongPressed = true; |
| 2864 | if (!keyguardOn) { |
| 2865 | launchAssistLongPressAction(); |
| 2866 | } |
| 2867 | } |
| 2868 | } else { |
| 2869 | if (mAssistKeyLongPressed) { |
| 2870 | mAssistKeyLongPressed = false; |
| 2871 | } else { |
| 2872 | if (!keyguardOn) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 2873 | launchAssistAction(null, event.getDeviceId()); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2874 | } |
| 2875 | } |
| 2876 | } |
| 2877 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2878 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 2879 | if (!down) { |
| 2880 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2881 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2882 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 2883 | } else { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 2884 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 2885 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 2886 | if (dic != null) { |
| 2887 | try { |
| 2888 | dic.exitIdle("voice-search"); |
| 2889 | } catch (RemoteException e) { |
| 2890 | } |
| 2891 | } |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2892 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2893 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2894 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2895 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2896 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2897 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2898 | if (down && repeatCount == 0) { |
| 2899 | mHandler.post(mScreenshotRunnable); |
| 2900 | } |
| 2901 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2902 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2903 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2904 | if (down) { |
| 2905 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2906 | |
| 2907 | // Disable autobrightness if it's on |
| 2908 | int auto = Settings.System.getIntForUser( |
| 2909 | mContext.getContentResolver(), |
| 2910 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2911 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2912 | UserHandle.USER_CURRENT_OR_SELF); |
| 2913 | if (auto != 0) { |
| 2914 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2915 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2916 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2917 | UserHandle.USER_CURRENT_OR_SELF); |
| 2918 | } |
| 2919 | |
| 2920 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 2921 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 2922 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 2923 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 2924 | Settings.System.SCREEN_BRIGHTNESS, |
| 2925 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 2926 | UserHandle.USER_CURRENT_OR_SELF); |
| 2927 | brightness += step; |
| 2928 | // Make sure we don't go beyond the limits. |
| 2929 | brightness = Math.min(max, brightness); |
| 2930 | brightness = Math.max(min, brightness); |
| 2931 | |
| 2932 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2933 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 2934 | UserHandle.USER_CURRENT_OR_SELF); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2935 | startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 2936 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2937 | } |
| 2938 | return -1; |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2939 | } else if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2940 | if (down) { |
| 2941 | mPendingMetaAction = true; |
| 2942 | } else if (mPendingMetaAction) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 2943 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId()); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2944 | } |
| 2945 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2946 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2947 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2948 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2949 | // Any printing key that is chorded with Search should be consumed |
| 2950 | // even if no shortcut was invoked. This prevents text from being |
| 2951 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2952 | // 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] | 2953 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2954 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2955 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2956 | mConsumeSearchKeyUp = true; |
| 2957 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2958 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2959 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2960 | if (shortcutIntent != null) { |
| 2961 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2962 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2963 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2964 | } catch (ActivityNotFoundException ex) { |
| 2965 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2966 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2967 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2968 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2969 | } else { |
| 2970 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2971 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2972 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2973 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2974 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2975 | } |
| 2976 | } |
| 2977 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2978 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2979 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2980 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2981 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2982 | if (kcm.isPrintingKey(keyCode)) { |
| 2983 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2984 | metaState & ~(KeyEvent.META_META_ON |
| 2985 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2986 | if (shortcutIntent != null) { |
| 2987 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2988 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2989 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2990 | } catch (ActivityNotFoundException ex) { |
| 2991 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2992 | + "the activity to which it is registered was not found: " |
| 2993 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2994 | } |
| 2995 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2996 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2997 | } |
| 2998 | } |
| 2999 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3000 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3001 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3002 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 3003 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 3004 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3005 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3006 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3007 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3008 | } catch (ActivityNotFoundException ex) { |
| 3009 | Slog.w(TAG, "Dropping application launch key because " |
| 3010 | + "the activity to which it is registered was not found: " |
| 3011 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 3012 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3013 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3014 | } |
| 3015 | } |
| 3016 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3017 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3018 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Michael Wright | d847ad5 | 2015-10-24 13:24:15 +0100 | [diff] [blame] | 3019 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3020 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3021 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3022 | mRecentAppsHeldModifiers = shiftlessModifiers; |
| 3023 | showRecentApps(true); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3024 | return -1; |
| 3025 | } |
| 3026 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3027 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 3028 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 3029 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3030 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3031 | } |
| 3032 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3033 | // Handle keyboard language switching. |
| 3034 | if (down && repeatCount == 0 |
| 3035 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3036 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 3037 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 3038 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 3039 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 3040 | return -1; |
| 3041 | } |
| 3042 | if (mLanguageSwitchKeyPressed && !down |
| 3043 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3044 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 3045 | mLanguageSwitchKeyPressed = false; |
| 3046 | return -1; |
| 3047 | } |
| 3048 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3049 | if (isValidGlobalKey(keyCode) |
| 3050 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 3051 | return -1; |
| 3052 | } |
| 3053 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3054 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 3055 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3056 | return -1; |
| 3057 | } |
| 3058 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3059 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3060 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3061 | } |
| 3062 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3063 | /** {@inheritDoc} */ |
| 3064 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3065 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3066 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3067 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3068 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 3069 | + ", flags=" + event.getFlags() |
| 3070 | + ", keyCode=" + event.getKeyCode() |
| 3071 | + ", scanCode=" + event.getScanCode() |
| 3072 | + ", metaState=" + event.getMetaState() |
| 3073 | + ", repeatCount=" + event.getRepeatCount() |
| 3074 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3075 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3076 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3077 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3078 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3079 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3080 | final int keyCode = event.getKeyCode(); |
| 3081 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3082 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 3083 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3084 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3085 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3086 | final FallbackAction fallbackAction; |
| 3087 | if (initialDown) { |
| 3088 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 3089 | } else { |
| 3090 | fallbackAction = mFallbackActions.get(keyCode); |
| 3091 | } |
| 3092 | |
| 3093 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3094 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3095 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 3096 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3097 | } |
| 3098 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3099 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 3100 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3101 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3102 | event.getAction(), fallbackAction.keyCode, |
| 3103 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3104 | event.getDeviceId(), event.getScanCode(), |
| 3105 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3106 | |
| 3107 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 3108 | fallbackEvent.recycle(); |
| 3109 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3110 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3111 | |
| 3112 | if (initialDown) { |
| 3113 | mFallbackActions.put(keyCode, fallbackAction); |
| 3114 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 3115 | mFallbackActions.remove(keyCode); |
| 3116 | fallbackAction.recycle(); |
| 3117 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3118 | } |
| 3119 | } |
| 3120 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3121 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3122 | if (fallbackEvent == null) { |
| 3123 | Slog.d(TAG, "No fallback."); |
| 3124 | } else { |
| 3125 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 3126 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3127 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3128 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3129 | } |
| 3130 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3131 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3132 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3133 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 3134 | long delayMillis = interceptKeyBeforeDispatching( |
| 3135 | win, fallbackEvent, policyFlags); |
| 3136 | if (delayMillis == 0) { |
| 3137 | return true; |
| 3138 | } |
| 3139 | } |
| 3140 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3141 | } |
| 3142 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3143 | private void launchAssistLongPressAction() { |
| 3144 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 3145 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 3146 | |
| 3147 | // launch the search activity |
| 3148 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 3149 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3150 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3151 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 3152 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3153 | SearchManager searchManager = getSearchManager(); |
| 3154 | if (searchManager != null) { |
| 3155 | searchManager.stopSearch(); |
| 3156 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3157 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3158 | } catch (ActivityNotFoundException e) { |
| 3159 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 3160 | } |
| 3161 | } |
| 3162 | |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3163 | private void launchAssistAction(String hint, int deviceId) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3164 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Maurice Lam | 39d1381 | 2015-07-23 20:49:20 -0700 | [diff] [blame] | 3165 | if (!isUserSetupComplete()) { |
| 3166 | // Disable opening assist window during setup |
| 3167 | return; |
| 3168 | } |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3169 | Bundle args = null; |
| 3170 | if (deviceId > Integer.MIN_VALUE) { |
| 3171 | args = new Bundle(); |
| 3172 | args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3173 | } |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 3174 | if ((mContext.getResources().getConfiguration().uiMode |
| 3175 | & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) { |
| 3176 | // On TV, use legacy handling until assistants are implemented in the proper way. |
| 3177 | ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
| 3178 | .launchLegacyAssist(hint, UserHandle.myUserId(), args); |
| 3179 | } else { |
| 3180 | try { |
| 3181 | if (hint != null) { |
| 3182 | if (args == null) { |
| 3183 | args = new Bundle(); |
| 3184 | } |
| 3185 | args.putBoolean(hint, true); |
| 3186 | } |
| 3187 | IStatusBarService statusbar = getStatusBarService(); |
| 3188 | if (statusbar != null) { |
| 3189 | statusbar.startAssist(args); |
| 3190 | } |
| 3191 | } catch (RemoteException e) { |
| 3192 | Slog.e(TAG, "RemoteException when starting assist", e); |
| 3193 | // re-acquire status bar service next time it is needed. |
| 3194 | mStatusBarService = null; |
| 3195 | } |
| 3196 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3197 | } |
| 3198 | |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3199 | private void startActivityAsUser(Intent intent, UserHandle handle) { |
| 3200 | if (isUserSetupComplete()) { |
| 3201 | mContext.startActivityAsUser(intent, handle); |
| 3202 | } else { |
| 3203 | Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); |
| 3204 | } |
| 3205 | } |
| 3206 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3207 | private SearchManager getSearchManager() { |
| 3208 | if (mSearchManager == null) { |
| 3209 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 3210 | } |
| 3211 | return mSearchManager; |
| 3212 | } |
| 3213 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3214 | private void preloadRecentApps() { |
| 3215 | mPreloadedRecentApps = true; |
| 3216 | try { |
| 3217 | IStatusBarService statusbar = getStatusBarService(); |
| 3218 | if (statusbar != null) { |
| 3219 | statusbar.preloadRecentApps(); |
| 3220 | } |
| 3221 | } catch (RemoteException e) { |
| 3222 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 3223 | // re-acquire status bar service next time it is needed. |
| 3224 | mStatusBarService = null; |
| 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | private void cancelPreloadRecentApps() { |
| 3229 | if (mPreloadedRecentApps) { |
| 3230 | mPreloadedRecentApps = false; |
| 3231 | try { |
| 3232 | IStatusBarService statusbar = getStatusBarService(); |
| 3233 | if (statusbar != null) { |
| 3234 | statusbar.cancelPreloadRecentApps(); |
| 3235 | } |
| 3236 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3237 | Slog.e(TAG, "RemoteException when cancelling recent apps preload", e); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3238 | // re-acquire status bar service next time it is needed. |
| 3239 | mStatusBarService = null; |
| 3240 | } |
| 3241 | } |
| 3242 | } |
| 3243 | |
| 3244 | private void toggleRecentApps() { |
| 3245 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3246 | try { |
| 3247 | IStatusBarService statusbar = getStatusBarService(); |
| 3248 | if (statusbar != null) { |
| 3249 | statusbar.toggleRecentApps(); |
| 3250 | } |
| 3251 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3252 | Slog.e(TAG, "RemoteException when toggling recent apps", e); |
| 3253 | // re-acquire status bar service next time it is needed. |
| 3254 | mStatusBarService = null; |
| 3255 | } |
| 3256 | } |
| 3257 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3258 | @Override |
| 3259 | public void showRecentApps() { |
| 3260 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
| 3261 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS); |
| 3262 | } |
| 3263 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3264 | private void showRecentApps(boolean triggeredFromAltTab) { |
| 3265 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3266 | try { |
| 3267 | IStatusBarService statusbar = getStatusBarService(); |
| 3268 | if (statusbar != null) { |
| 3269 | statusbar.showRecentApps(triggeredFromAltTab); |
| 3270 | } |
| 3271 | } catch (RemoteException e) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3272 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 3273 | // re-acquire status bar service next time it is needed. |
| 3274 | mStatusBarService = null; |
| 3275 | } |
| 3276 | } |
| 3277 | |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3278 | private void showKeyboardShortcutsMenu() { |
| 3279 | try { |
| 3280 | IStatusBarService statusbar = getStatusBarService(); |
| 3281 | if (statusbar != null) { |
| 3282 | statusbar.showKeyboardShortcutsMenu(); |
| 3283 | } |
| 3284 | } catch (RemoteException e) { |
| 3285 | Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e); |
| 3286 | } |
| 3287 | } |
| 3288 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3289 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3290 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3291 | try { |
| 3292 | IStatusBarService statusbar = getStatusBarService(); |
| 3293 | if (statusbar != null) { |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3294 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3295 | } |
| 3296 | } catch (RemoteException e) { |
| 3297 | Slog.e(TAG, "RemoteException when closing recent apps", e); |
| 3298 | // re-acquire status bar service next time it is needed. |
| 3299 | mStatusBarService = null; |
| 3300 | } |
| 3301 | } |
| 3302 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3303 | void launchHomeFromHotKey() { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3304 | launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3305 | } |
| 3306 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3307 | /** |
| 3308 | * A home key -> launch home action was detected. Take the appropriate action |
| 3309 | * given the situation with the keyguard. |
| 3310 | */ |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3311 | void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) { |
| 3312 | if (respectKeyguard) { |
| 3313 | if (isKeyguardShowingAndNotOccluded()) { |
| 3314 | // don't launch home if keyguard showing |
| 3315 | return; |
| 3316 | } |
| 3317 | |
| 3318 | if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
| 3319 | // when in keyguard restricted mode, must first verify unlock |
| 3320 | // before launching home |
| 3321 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
| 3322 | @Override |
| 3323 | public void onKeyguardExitResult(boolean success) { |
| 3324 | if (success) { |
| 3325 | try { |
| 3326 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3327 | } catch (RemoteException e) { |
| 3328 | } |
| 3329 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3330 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 3331 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3332 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3333 | }); |
| 3334 | return; |
| 3335 | } |
| 3336 | } |
| 3337 | |
| 3338 | // no keyguard stuff to worry about, just launch home! |
| 3339 | try { |
| 3340 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3341 | } catch (RemoteException e) { |
| 3342 | } |
| 3343 | if (mRecentsVisible) { |
| 3344 | // Hide Recents and notify it to launch Home |
| 3345 | if (awakenFromDreams) { |
| 3346 | awakenDreams(); |
| 3347 | } |
| 3348 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3349 | hideRecentApps(false, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3350 | } else { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3351 | // Otherwise, just launch Home |
| 3352 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3353 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3354 | } |
| 3355 | } |
| 3356 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3357 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 3358 | @Override |
| 3359 | public void run() { |
| 3360 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 3361 | // Clear flags. |
| 3362 | mForceClearedSystemUiFlags &= |
| 3363 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 3364 | } |
| 3365 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3366 | } |
| 3367 | }; |
| 3368 | |
| 3369 | /** |
| 3370 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 3371 | * to determine when the nav bar should be shown and prevent applications from |
| 3372 | * receiving those touches. |
| 3373 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3374 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 3375 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 3376 | super(inputChannel, looper); |
| 3377 | } |
| 3378 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3379 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3380 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3381 | boolean handled = false; |
| 3382 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 3383 | if (event instanceof MotionEvent |
| 3384 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3385 | final MotionEvent motionEvent = (MotionEvent)event; |
| 3386 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3387 | // When the user taps down, we re-show the nav bar. |
| 3388 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3389 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3390 | // Any user activity always causes us to show the |
| 3391 | // navigation controls, if they had been hidden. |
| 3392 | // We also clear the low profile and only content |
| 3393 | // flags so that tapping on the screen will atomically |
| 3394 | // restore all currently hidden screen decorations. |
| 3395 | int newVal = mResettingSystemUiFlags | |
| 3396 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 3397 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 3398 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3399 | if (mResettingSystemUiFlags != newVal) { |
| 3400 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3401 | changed = true; |
| 3402 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3403 | // We don't allow the system's nav bar to be hidden |
| 3404 | // again for 1 second, to prevent applications from |
| 3405 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3406 | newVal = mForceClearedSystemUiFlags | |
| 3407 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3408 | if (mForceClearedSystemUiFlags != newVal) { |
| 3409 | mForceClearedSystemUiFlags = newVal; |
| 3410 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3411 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3412 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3413 | } |
| 3414 | if (changed) { |
| 3415 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 3416 | } |
| 3417 | } |
| 3418 | } |
| 3419 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3420 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3421 | } |
| 3422 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3423 | } |
| 3424 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 3425 | new InputEventReceiver.Factory() { |
| 3426 | @Override |
| 3427 | public InputEventReceiver createInputEventReceiver( |
| 3428 | InputChannel inputChannel, Looper looper) { |
| 3429 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 3430 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3431 | }; |
| 3432 | |
| 3433 | @Override |
| 3434 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 3435 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 3436 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 3437 | mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3438 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3439 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 3440 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3441 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3442 | // Clear any bits in the new visibility that are currently being |
| 3443 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3444 | return visibility & ~mResettingSystemUiFlags |
| 3445 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3446 | } |
| 3447 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3448 | @Override |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3449 | public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation, |
| 3450 | Rect outContentInsets, Rect outStableInsets, Rect outOutsets) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3451 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3452 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 3453 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3454 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3455 | final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl); |
| 3456 | if (useOutsets) { |
| 3457 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 3458 | if (outset > 0) { |
| 3459 | if (displayRotation == Surface.ROTATION_0) { |
| 3460 | outOutsets.bottom += outset; |
| 3461 | } else if (displayRotation == Surface.ROTATION_90) { |
| 3462 | outOutsets.right += outset; |
| 3463 | } else if (displayRotation == Surface.ROTATION_180) { |
| 3464 | outOutsets.top += outset; |
| 3465 | } else if (displayRotation == Surface.ROTATION_270) { |
| 3466 | outOutsets.left += outset; |
| 3467 | } |
| 3468 | } |
| 3469 | } |
| 3470 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3471 | 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] | 3472 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3473 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3474 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3475 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3476 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3477 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 3478 | } else { |
| 3479 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3480 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 3481 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3482 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3483 | if ((fl & FLAG_FULLSCREEN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3484 | outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3485 | availRight - mStableFullscreenRight, |
| 3486 | availBottom - mStableFullscreenBottom); |
| 3487 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3488 | outContentInsets.set(mStableLeft, mStableTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3489 | availRight - mStableRight, availBottom - mStableBottom); |
| 3490 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3491 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3492 | outContentInsets.setEmpty(); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3493 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3494 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3495 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3496 | availRight - mCurRight, availBottom - mCurBottom); |
| 3497 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3498 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3499 | availRight - mCurRight, availBottom - mCurBottom); |
| 3500 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3501 | |
| 3502 | outStableInsets.set(mStableLeft, mStableTop, |
| 3503 | availRight - mStableRight, availBottom - mStableBottom); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3504 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3505 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3506 | outContentInsets.setEmpty(); |
| 3507 | outStableInsets.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3508 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3509 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3510 | private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) { |
| 3511 | return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 3512 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0; |
| 3513 | } |
| 3514 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3515 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3516 | @Override |
| 3517 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 3518 | int displayRotation) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3519 | mDisplayRotation = displayRotation; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3520 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 3521 | if (isDefaultDisplay) { |
| 3522 | switch (displayRotation) { |
| 3523 | case Surface.ROTATION_90: |
| 3524 | overscanLeft = mOverscanTop; |
| 3525 | overscanTop = mOverscanRight; |
| 3526 | overscanRight = mOverscanBottom; |
| 3527 | overscanBottom = mOverscanLeft; |
| 3528 | break; |
| 3529 | case Surface.ROTATION_180: |
| 3530 | overscanLeft = mOverscanRight; |
| 3531 | overscanTop = mOverscanBottom; |
| 3532 | overscanRight = mOverscanLeft; |
| 3533 | overscanBottom = mOverscanTop; |
| 3534 | break; |
| 3535 | case Surface.ROTATION_270: |
| 3536 | overscanLeft = mOverscanBottom; |
| 3537 | overscanTop = mOverscanLeft; |
| 3538 | overscanRight = mOverscanTop; |
| 3539 | overscanBottom = mOverscanRight; |
| 3540 | break; |
| 3541 | default: |
| 3542 | overscanLeft = mOverscanLeft; |
| 3543 | overscanTop = mOverscanTop; |
| 3544 | overscanRight = mOverscanRight; |
| 3545 | overscanBottom = mOverscanBottom; |
| 3546 | break; |
| 3547 | } |
| 3548 | } else { |
| 3549 | overscanLeft = 0; |
| 3550 | overscanTop = 0; |
| 3551 | overscanRight = 0; |
| 3552 | overscanBottom = 0; |
| 3553 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3554 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 3555 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 3556 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 3557 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3558 | mSystemLeft = 0; |
| 3559 | mSystemTop = 0; |
| 3560 | mSystemRight = displayWidth; |
| 3561 | mSystemBottom = displayHeight; |
| 3562 | mUnrestrictedScreenLeft = overscanLeft; |
| 3563 | mUnrestrictedScreenTop = overscanTop; |
| 3564 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 3565 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 3566 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 3567 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3568 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 3569 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3570 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3571 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3572 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3573 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3574 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3575 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3576 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3577 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3578 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3579 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3580 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3581 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 3582 | final Rect pf = mTmpParentFrame; |
| 3583 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3584 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3585 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3586 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3587 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 3588 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 3589 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 3590 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3591 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3592 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3593 | if (isDefaultDisplay) { |
| 3594 | // For purposes of putting out fake window up to steal focus, we will |
| 3595 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3596 | final int sysui = mLastSystemUiFlags; |
| 3597 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3598 | boolean navTranslucent = (sysui |
| 3599 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3600 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 3601 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 3602 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 3603 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3604 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen; |
| 3605 | if (!isKeyguardShowing) { |
| 3606 | navTranslucent &= areTranslucentBarsAllowed(); |
| 3607 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3608 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3609 | // When the navigation bar isn't visible, we put up a fake |
| 3610 | // input window to catch all touch events. This way we can |
| 3611 | // detect when the user presses anywhere to bring back the nav |
| 3612 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3613 | if (navVisible || navAllowedHidden) { |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3614 | if (mInputConsumer != null) { |
| 3615 | mInputConsumer.dismiss(); |
| 3616 | mInputConsumer = null; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3617 | } |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3618 | } else if (mInputConsumer == null) { |
| 3619 | mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(), |
| 3620 | mHideNavInputEventReceiverFactory); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3621 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3622 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3623 | // For purposes of positioning and showing the nav bar, if we have |
| 3624 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 3625 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3626 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3627 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3628 | boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight, |
| 3629 | displayRotation, overscanRight, overscanBottom, dcf, navVisible, navTranslucent, |
| 3630 | navAllowedHidden); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3631 | 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] | 3632 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3633 | updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3634 | if (updateSysUiVisibility) { |
| 3635 | updateSystemUiVisibilityLw(); |
| 3636 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3637 | } |
| 3638 | } |
| 3639 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3640 | private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui, |
| 3641 | boolean isKeyguardShowing) { |
| 3642 | // decide where the status bar goes ahead of time |
| 3643 | if (mStatusBar != null) { |
| 3644 | // apply any navigation bar insets |
| 3645 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3646 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3647 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3648 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 3649 | + mUnrestrictedScreenTop; |
| 3650 | vf.left = mStableLeft; |
| 3651 | vf.top = mStableTop; |
| 3652 | vf.right = mStableRight; |
| 3653 | vf.bottom = mStableBottom; |
| 3654 | |
| 3655 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 3656 | |
| 3657 | // Let the status bar determine its size. |
| 3658 | mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */, |
| 3659 | vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */, |
| 3660 | dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */); |
| 3661 | |
| 3662 | // For layout, the status bar is always at the top with our fixed height. |
| 3663 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3664 | |
| 3665 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
| 3666 | boolean statusBarTranslucent = (sysui |
| 3667 | & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
| 3668 | if (!isKeyguardShowing) { |
| 3669 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 3670 | } |
| 3671 | |
| 3672 | // If the status bar is hidden, we don't want to cause |
| 3673 | // windows behind it to scroll. |
| 3674 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
| 3675 | // Status bar may go away, so the screen area it occupies |
| 3676 | // is available to apps but just covering them when the |
| 3677 | // status bar is visible. |
| 3678 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3679 | |
| 3680 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3681 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3682 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3683 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 3684 | |
| 3685 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
| 3686 | String.format( |
| 3687 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 3688 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 3689 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 3690 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 3691 | } |
| 3692 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
| 3693 | && !statusBarTransient && !statusBarTranslucent |
| 3694 | && !mStatusBarController.wasRecentlyTranslucent()) { |
| 3695 | // If the opaque status bar is currently requested to be visible, |
| 3696 | // and not in the process of animating on or off, then |
| 3697 | // we can tell the app that it is covered by it. |
| 3698 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3699 | } |
| 3700 | if (mStatusBarController.checkHiddenLw()) { |
| 3701 | return true; |
| 3702 | } |
| 3703 | } |
| 3704 | return false; |
| 3705 | } |
| 3706 | |
| 3707 | private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation, |
| 3708 | int overscanRight, int overscanBottom, Rect dcf, boolean navVisible, |
| 3709 | boolean navTranslucent, boolean navAllowedHidden) { |
| 3710 | if (mNavigationBar != null) { |
| 3711 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
| 3712 | // Force the navigation bar to its appropriate place and |
| 3713 | // size. We need to do this directly, instead of relying on |
| 3714 | // it to bubble up from the nav bar, because this needs to |
| 3715 | // change atomically with screen rotations. |
| 3716 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 3717 | if (mNavigationBarOnBottom) { |
| 3718 | // It's a system nav bar or a portrait screen; nav bar goes on bottom. |
| 3719 | int top = displayHeight - overscanBottom |
| 3720 | - mNavigationBarHeightForRotation[displayRotation]; |
| 3721 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
| 3722 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
| 3723 | if (transientNavBarShowing) { |
| 3724 | mNavigationBarController.setBarShowingLw(true); |
| 3725 | } else if (navVisible) { |
| 3726 | mNavigationBarController.setBarShowingLw(true); |
| 3727 | mDockBottom = mTmpNavigationFrame.top; |
| 3728 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 3729 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
| 3730 | } else { |
| 3731 | // We currently want to hide the navigation UI. |
| 3732 | mNavigationBarController.setBarShowingLw(false); |
| 3733 | } |
| 3734 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3735 | && !mNavigationBar.isAnimatingLw() |
| 3736 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 3737 | // If the opaque nav bar is currently requested to be visible, |
| 3738 | // and not in the process of animating on or off, then |
| 3739 | // we can tell the app that it is covered by it. |
| 3740 | mSystemBottom = mTmpNavigationFrame.top; |
| 3741 | } |
| 3742 | } else { |
| 3743 | // Landscape screen; nav bar goes to the right. |
| 3744 | int left = displayWidth - overscanRight |
| 3745 | - mNavigationBarWidthForRotation[displayRotation]; |
| 3746 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
| 3747 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
| 3748 | if (transientNavBarShowing) { |
| 3749 | mNavigationBarController.setBarShowingLw(true); |
| 3750 | } else if (navVisible) { |
| 3751 | mNavigationBarController.setBarShowingLw(true); |
| 3752 | mDockRight = mTmpNavigationFrame.left; |
| 3753 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 3754 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
| 3755 | } else { |
| 3756 | // We currently want to hide the navigation UI. |
| 3757 | mNavigationBarController.setBarShowingLw(false); |
| 3758 | } |
| 3759 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3760 | && !mNavigationBar.isAnimatingLw() |
| 3761 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 3762 | // If the nav bar is currently requested to be visible, |
| 3763 | // and not in the process of animating on or off, then |
| 3764 | // we can tell the app that it is covered by it. |
| 3765 | mSystemRight = mTmpNavigationFrame.left; |
| 3766 | } |
| 3767 | } |
| 3768 | // Make sure the content and current rectangles are updated to |
| 3769 | // account for the restrictions from the navigation bar. |
| 3770 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3771 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3772 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3773 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 3774 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 3775 | // And compute the final frame. |
| 3776 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
| 3777 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
| 3778 | mTmpNavigationFrame, mTmpNavigationFrame); |
| 3779 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
| 3780 | if (mNavigationBarController.checkHiddenLw()) { |
| 3781 | return true; |
| 3782 | } |
| 3783 | } |
| 3784 | return false; |
| 3785 | } |
| 3786 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3787 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3788 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3789 | public int getSystemDecorLayerLw() { |
Bryce Lee | 2ed3e5f | 2015-04-01 22:09:19 +0000 | [diff] [blame] | 3790 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 3791 | return mStatusBar.getSurfaceLayer(); |
| 3792 | } |
| 3793 | |
| 3794 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { |
| 3795 | return mNavigationBar.getSurfaceLayer(); |
| 3796 | } |
| 3797 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3798 | return 0; |
| 3799 | } |
| 3800 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3801 | @Override |
| 3802 | public void getContentRectLw(Rect r) { |
| 3803 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 3804 | } |
| 3805 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3806 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 3807 | 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] | 3808 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 3809 | // Here's a special case: if this attached window is a panel that is |
| 3810 | // above the dock window, and the window it is attached to is below |
| 3811 | // the dock window, then the frames we computed for the window it is |
| 3812 | // attached to can not be used because the dock is effectively part |
| 3813 | // of the underlying window and the attached window is floating on top |
| 3814 | // of the whole thing. So, we ignore the attached window and explicitly |
| 3815 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3816 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3817 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 3818 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 3819 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3820 | } else { |
| 3821 | // The effective display frame of the attached window depends on |
| 3822 | // whether it is taking care of insetting its content. If not, |
| 3823 | // we need to use the parent's content frame so that the entire |
| 3824 | // window is positioned within that content. Otherwise we can use |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3825 | // 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] | 3826 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3827 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3828 | // Set the content frame of the attached window to the parent's decor frame |
| 3829 | // (same as content frame when IME isn't present) if specifically requested by |
| 3830 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 3831 | // Otherwise, use the overscan frame. |
| 3832 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
| 3833 | ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3834 | } else { |
| 3835 | // If the window is resizing, then we want to base the content |
| 3836 | // frame on our attached content frame to resize... however, |
| 3837 | // things can be tricky if the attached window is NOT in resize |
| 3838 | // mode, in which case its content frame will be larger. |
| 3839 | // Ungh. So to deal with that, make sure the content frame |
| 3840 | // we end up using is not covering the IM dock. |
| 3841 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3842 | if (attached.isVoiceInteraction()) { |
| 3843 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 3844 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 3845 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 3846 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 3847 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3848 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 3849 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 3850 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 3851 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 3852 | } |
| 3853 | } |
| 3854 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3855 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3856 | vf.set(attached.getVisibleFrameLw()); |
| 3857 | } |
| 3858 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 3859 | // window should be positioned relative to its parent or the entire |
| 3860 | // screen. |
| 3861 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 3862 | ? attached.getFrameLw() : df); |
| 3863 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3864 | |
| 3865 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 3866 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3867 | // If app is requesting a stable layout, don't let the |
| 3868 | // content insets go below the stable values. |
| 3869 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 3870 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 3871 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 3872 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 3873 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 3874 | } else { |
| 3875 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 3876 | if (r.top < mStableTop) r.top = mStableTop; |
| 3877 | if (r.right > mStableRight) r.right = mStableRight; |
| 3878 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 3879 | } |
| 3880 | } |
| 3881 | } |
| 3882 | |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3883 | private boolean canReceiveInput(WindowState win) { |
| 3884 | boolean notFocusable = |
| 3885 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0; |
| 3886 | boolean altFocusableIm = |
| 3887 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0; |
| 3888 | boolean notFocusableForIm = notFocusable ^ altFocusableIm; |
| 3889 | return !notFocusableForIm; |
| 3890 | } |
| 3891 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3892 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3893 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3894 | public void layoutWindowLw(WindowState win, WindowState attached) { |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3895 | // We've already done the navigation bar and status bar. If the status bar can receive |
| 3896 | // input, we need to layout it again to accomodate for the IME window. |
| 3897 | if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3898 | return; |
| 3899 | } |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3900 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3901 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 3902 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3903 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 3904 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3905 | 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] | 3906 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 3907 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3908 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3909 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3910 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3911 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3912 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3913 | final Rect pf = mTmpParentFrame; |
| 3914 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3915 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3916 | final Rect cf = mTmpContentFrame; |
| 3917 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3918 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3919 | final Rect sf = mTmpStableFrame; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3920 | Rect osf = null; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3921 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3922 | |
| 3923 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3924 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3925 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 3926 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 3927 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3928 | if (isDefaultDisplay) { |
| 3929 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 3930 | } else { |
| 3931 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 3932 | } |
| 3933 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3934 | if (!isDefaultDisplay) { |
| 3935 | if (attached != null) { |
| 3936 | // If this window is attached to another, our display |
| 3937 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3938 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3939 | } else { |
| 3940 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3941 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3942 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3943 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3944 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3945 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3946 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3947 | } |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3948 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3949 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3950 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 3951 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3952 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 3953 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3954 | // ...with content insets above the nav bar |
| 3955 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3956 | // IM dock windows always go to the bottom of the screen. |
| 3957 | attrs.gravity = Gravity.BOTTOM; |
| 3958 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3959 | } else if (attrs.type == TYPE_VOICE_INTERACTION) { |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 3960 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3961 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 3962 | pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3963 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3964 | cf.bottom = vf.bottom = mStableBottom; |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 3965 | // Note: In Phone landscape mode, the button bar should also be excluded. |
| 3966 | cf.right = vf.right = mStableRight; |
| 3967 | cf.left = vf.left = mStableLeft; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3968 | cf.top = vf.top = mStableTop; |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3969 | } else if (win == mStatusBar) { |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 3970 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3971 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3972 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3973 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 3974 | cf.left = vf.left = mStableLeft; |
| 3975 | cf.top = vf.top = mStableTop; |
| 3976 | cf.right = vf.right = mStableRight; |
| 3977 | vf.bottom = mStableBottom; |
| 3978 | cf.bottom = mContentBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3979 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3980 | |
| 3981 | // Default policy decor for the default display |
| 3982 | dcf.left = mSystemLeft; |
| 3983 | dcf.top = mSystemTop; |
| 3984 | dcf.right = mSystemRight; |
| 3985 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3986 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 3987 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 3988 | final boolean isAppWindow = |
| 3989 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 3990 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 3991 | final boolean topAtRest = |
| 3992 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 3993 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3994 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 3995 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3996 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 3997 | && (fl & WindowManager.LayoutParams. |
| 3998 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3999 | // Ensure policy decor includes status bar |
| 4000 | dcf.top = mStableTop; |
| 4001 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4002 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4003 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 4004 | && (fl & WindowManager.LayoutParams. |
| 4005 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4006 | // Ensure policy decor includes navigation bar |
| 4007 | dcf.bottom = mStableBottom; |
| 4008 | dcf.right = mStableRight; |
| 4009 | } |
| 4010 | } |
| 4011 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4012 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 4013 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4014 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4015 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4016 | // This is the case for a normal activity window: we want it |
| 4017 | // to cover all of the screen space, and it can take care of |
| 4018 | // moving its contents to account for screen decorations that |
| 4019 | // intrude into that space. |
| 4020 | if (attached != null) { |
| 4021 | // If this window is attached to another, our display |
| 4022 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4023 | 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] | 4024 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4025 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 4026 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4027 | // Status bar panels are the only windows who can go on top of |
| 4028 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 4029 | // permission, so they have the same privileges as the status |
| 4030 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4031 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4032 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4033 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4034 | pf.left = df.left = of.left = hasNavBar |
| 4035 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 4036 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4037 | pf.right = df.right = of.right = hasNavBar |
| 4038 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 4039 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4040 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 4041 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 4042 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4043 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4044 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4045 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 4046 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4047 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4048 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4049 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4050 | // Asking to layout into the overscan region, so give it that pure |
| 4051 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4052 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 4053 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 4054 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4055 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 4056 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4057 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4058 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4059 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4060 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4061 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4062 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4063 | // only do this for application windows to ensure no window that |
| 4064 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4065 | pf.left = df.left = mOverscanScreenLeft; |
| 4066 | pf.top = df.top = mOverscanScreenTop; |
| 4067 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4068 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4069 | // We need to tell the app about where the frame inside the overscan |
| 4070 | // is, so it can inset its content by that amount -- it didn't ask |
| 4071 | // to actually extend itself into the overscan region. |
| 4072 | of.left = mUnrestrictedScreenLeft; |
| 4073 | of.top = mUnrestrictedScreenTop; |
| 4074 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4075 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4076 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4077 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 4078 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 4079 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 4080 | + mRestrictedOverscanScreenWidth; |
| 4081 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 4082 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4083 | // We need to tell the app about where the frame inside the overscan |
| 4084 | // is, so it can inset its content by that amount -- it didn't ask |
| 4085 | // to actually extend itself into the overscan region. |
| 4086 | of.left = mUnrestrictedScreenLeft; |
| 4087 | of.top = mUnrestrictedScreenTop; |
| 4088 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4089 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4090 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4091 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4092 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4093 | if (win.isVoiceInteraction()) { |
| 4094 | cf.left = mVoiceContentLeft; |
| 4095 | cf.top = mVoiceContentTop; |
| 4096 | cf.right = mVoiceContentRight; |
| 4097 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4098 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4099 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 4100 | cf.left = mDockLeft; |
| 4101 | cf.top = mDockTop; |
| 4102 | cf.right = mDockRight; |
| 4103 | cf.bottom = mDockBottom; |
| 4104 | } else { |
| 4105 | cf.left = mContentLeft; |
| 4106 | cf.top = mContentTop; |
| 4107 | cf.right = mContentRight; |
| 4108 | cf.bottom = mContentBottom; |
| 4109 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4110 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4111 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4112 | // Full screen windows are always given a layout that is as if the |
| 4113 | // status bar and other transient decors are gone. This is to avoid |
| 4114 | // bad states when moving from a window that is not hding the |
| 4115 | // status bar to one that is. |
| 4116 | cf.left = mRestrictedScreenLeft; |
| 4117 | cf.top = mRestrictedScreenTop; |
| 4118 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 4119 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4120 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4121 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4122 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4123 | vf.left = mCurLeft; |
| 4124 | vf.top = mCurTop; |
| 4125 | vf.right = mCurRight; |
| 4126 | vf.bottom = mCurBottom; |
| 4127 | } else { |
| 4128 | vf.set(cf); |
| 4129 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4130 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4131 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 4132 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 4133 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4134 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4135 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4136 | // A window that has requested to fill the entire screen just |
| 4137 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4138 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4139 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL |
| 4140 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4141 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 4142 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 4143 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 4144 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4145 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4146 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4147 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4148 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4149 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4150 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 4151 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 4152 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 4153 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 4154 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4155 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4156 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4157 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4158 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 4159 | + mUnrestrictedScreenWidth; |
| 4160 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 4161 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4162 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4163 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 4164 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 4165 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 4166 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 4167 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 4168 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4169 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4170 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4171 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 4172 | + mOverscanScreenWidth; |
| 4173 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 4174 | + mOverscanScreenHeight; |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 4175 | } else if (attrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 4176 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4177 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4178 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4179 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 4180 | + mOverscanScreenWidth; |
| 4181 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 4182 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 4183 | } else if (attrs.type == TYPE_WALLPAPER) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 4184 | // The wallpaper also has Real Ultimate Power, but we want to tell |
| 4185 | // it about the overscan area. |
| 4186 | pf.left = df.left = mOverscanScreenLeft; |
| 4187 | pf.top = df.top = mOverscanScreenTop; |
| 4188 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4189 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
| 4190 | of.left = cf.left = mUnrestrictedScreenLeft; |
| 4191 | of.top = cf.top = mUnrestrictedScreenTop; |
| 4192 | of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4193 | of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4194 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4195 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4196 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4197 | // Asking to layout into the overscan region, so give it that pure |
| 4198 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4199 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4200 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4201 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4202 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4203 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4204 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4205 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4206 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 4207 | && (attrs.type == TYPE_STATUS_BAR |
| 4208 | || attrs.type == TYPE_TOAST |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 4209 | || attrs.type == TYPE_VOICE_INTERACTION_STARTING |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 4210 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4211 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4212 | // Asking for layout as if the nav bar is hidden, lets the |
| 4213 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 4214 | // 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] | 4215 | // can be above the nav bar can do this. |
| 4216 | // XXX This assumes that an app asking for this will also |
| 4217 | // ask for layout in only content. We can't currently figure out |
| 4218 | // 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] | 4219 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 4220 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 4221 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 4222 | + mUnrestrictedScreenWidth; |
| 4223 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 4224 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4225 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4226 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4227 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4228 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4229 | + mRestrictedScreenWidth; |
| 4230 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4231 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4232 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4233 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4234 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4235 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4236 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4237 | vf.left = mCurLeft; |
| 4238 | vf.top = mCurTop; |
| 4239 | vf.right = mCurRight; |
| 4240 | vf.bottom = mCurBottom; |
| 4241 | } else { |
| 4242 | vf.set(cf); |
| 4243 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4244 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4245 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4246 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4247 | // A child window should be placed inside of the same visible |
| 4248 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4249 | 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] | 4250 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4251 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4252 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4253 | // Otherwise, a normal window must be placed inside the content |
| 4254 | // of all screen decorations. |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4255 | if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 4256 | // Status bar panels and the volume dialog are the only windows who can go on |
| 4257 | // 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] | 4258 | // permission, so they have the same privileges as the status |
| 4259 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4260 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4261 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4262 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4263 | + mRestrictedScreenWidth; |
| 4264 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4265 | + mRestrictedScreenHeight; |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4266 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) { |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4267 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4268 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 4269 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 4270 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 4271 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4272 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4273 | pf.left = mContentLeft; |
| 4274 | pf.top = mContentTop; |
| 4275 | pf.right = mContentRight; |
| 4276 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 4277 | if (win.isVoiceInteraction()) { |
| 4278 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 4279 | df.top = of.top = cf.top = mVoiceContentTop; |
| 4280 | df.right = of.right = cf.right = mVoiceContentRight; |
| 4281 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 4282 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4283 | df.left = of.left = cf.left = mDockLeft; |
| 4284 | df.top = of.top = cf.top = mDockTop; |
| 4285 | df.right = of.right = cf.right = mDockRight; |
| 4286 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4287 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4288 | df.left = of.left = cf.left = mContentLeft; |
| 4289 | df.top = of.top = cf.top = mContentTop; |
| 4290 | df.right = of.right = cf.right = mContentRight; |
| 4291 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4292 | } |
| 4293 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4294 | vf.left = mCurLeft; |
| 4295 | vf.top = mCurTop; |
| 4296 | vf.right = mCurRight; |
| 4297 | vf.bottom = mCurBottom; |
| 4298 | } else { |
| 4299 | vf.set(cf); |
| 4300 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4301 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4302 | } |
| 4303 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4304 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 4305 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 4306 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 4307 | df.left = df.top = -10000; |
| 4308 | df.right = df.bottom = 10000; |
| 4309 | if (attrs.type != TYPE_WALLPAPER) { |
| 4310 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 4311 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 4312 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4313 | } |
| 4314 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4315 | // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we |
| 4316 | // 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] | 4317 | // We only want to apply outsets to certain types of windows. For example, we never want to |
| 4318 | // 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] | 4319 | final boolean useOutsets = shouldUseOutsets(attrs, fl); |
Filip Gruszczynski | b0c673b | 2015-06-05 09:43:06 -0700 | [diff] [blame] | 4320 | if (isDefaultDisplay && useOutsets) { |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4321 | osf = mTmpOutsetFrame; |
| 4322 | osf.set(cf.left, cf.top, cf.right, cf.bottom); |
| 4323 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 4324 | if (outset > 0) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4325 | int rotation = mDisplayRotation; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4326 | if (rotation == Surface.ROTATION_0) { |
| 4327 | osf.bottom += outset; |
| 4328 | } else if (rotation == Surface.ROTATION_90) { |
| 4329 | osf.right += outset; |
| 4330 | } else if (rotation == Surface.ROTATION_180) { |
| 4331 | osf.top -= outset; |
| 4332 | } else if (rotation == Surface.ROTATION_270) { |
| 4333 | osf.left -= outset; |
| 4334 | } |
| 4335 | if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset |
| 4336 | + " with rotation " + rotation + ", result: " + osf); |
| 4337 | } |
| 4338 | } |
| 4339 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4340 | 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] | 4341 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4342 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4343 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 4344 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4345 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4346 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4347 | + " dcf=" + dcf.toShortString() |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4348 | + " sf=" + sf.toShortString() |
| 4349 | + " osf=" + (osf == null ? "null" : osf.toShortString())); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4350 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4351 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4352 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4353 | // Dock windows carve out the bottom of the screen, so normal windows |
| 4354 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 4355 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 4356 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4357 | setLastInputMethodWindowLw(null, null); |
| 4358 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4359 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4360 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw() |
| 4361 | && !win.getGivenInsetsPendingLw()) { |
| 4362 | offsetVoiceInputWindowLw(win); |
| 4363 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4364 | } |
| 4365 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4366 | private void offsetInputMethodWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4367 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4368 | top += win.getGivenContentInsetsLw().top; |
| 4369 | if (mContentBottom > top) { |
| 4370 | mContentBottom = top; |
| 4371 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4372 | if (mVoiceContentBottom > top) { |
| 4373 | mVoiceContentBottom = top; |
| 4374 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4375 | top = win.getVisibleFrameLw().top; |
| 4376 | top += win.getGivenVisibleInsetsLw().top; |
| 4377 | if (mCurBottom > top) { |
| 4378 | mCurBottom = top; |
| 4379 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4380 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4381 | + mDockBottom + " mContentBottom=" |
| 4382 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 4383 | } |
| 4384 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4385 | private void offsetVoiceInputWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4386 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 4387 | top += win.getGivenContentInsetsLw().top; |
| 4388 | if (mVoiceContentBottom > top) { |
| 4389 | mVoiceContentBottom = top; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4390 | } |
| 4391 | } |
| 4392 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4393 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 4394 | @Override |
| 4395 | public void finishLayoutLw() { |
| 4396 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4397 | } |
| 4398 | |
| 4399 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4400 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4401 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4402 | mTopFullscreenOpaqueWindowState = null; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4403 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4404 | mAppsToBeHidden.clear(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4405 | mAppsThatDismissKeyguard.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4406 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4407 | mForceStatusBarFromKeyguard = false; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4408 | mForceStatusBarTransparent = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4409 | mForcingShowNavBar = false; |
| 4410 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4411 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4412 | mHideLockScreen = false; |
| 4413 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4414 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4415 | mShowingLockscreen = false; |
| 4416 | mShowingDream = false; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4417 | mWinShowWhenLocked = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4418 | mKeyguardSecure = isKeyguardSecure(); |
| 4419 | mKeyguardSecureIncludingHidden = mKeyguardSecure |
| 4420 | && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4424 | @Override |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 4425 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs, |
| 4426 | WindowState attached) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4427 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 4428 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4429 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4430 | if (mTopFullscreenOpaqueWindowState == null |
| 4431 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 4432 | mForcingShowNavBar = true; |
| 4433 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4434 | } |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4435 | if (attrs.type == TYPE_STATUS_BAR) { |
| 4436 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 4437 | mForceStatusBarFromKeyguard = true; |
Jorim Jaggi | e1de9f6 | 2015-09-23 14:59:50 -0700 | [diff] [blame] | 4438 | mShowingLockscreen = true; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4439 | } |
| 4440 | if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) { |
| 4441 | mForceStatusBarTransparent = true; |
| 4442 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 4443 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4444 | |
| 4445 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
| 4446 | && attrs.type < FIRST_SYSTEM_WINDOW; |
| 4447 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
| 4448 | final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; |
| 4449 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4450 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 4451 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4452 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4453 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4454 | mForceStatusBarFromKeyguard = true; |
| 4455 | } else { |
| 4456 | mForceStatusBar = true; |
| 4457 | } |
| 4458 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4459 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4460 | // If the lockscreen was showing when the dream started then wait |
| 4461 | // for the dream to draw before hiding the lockscreen. |
| 4462 | if (!mDreamingLockscreen |
| 4463 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 4464 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4465 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4466 | } |
| 4467 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4468 | |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 4469 | final IApplicationToken appToken = win.getAppToken(); |
| 4470 | |
| 4471 | // For app windows that are not attached, we decide if all windows in the app they |
| 4472 | // represent should be hidden or if we should hide the lockscreen. For attached app |
| 4473 | // windows we defer the decision to the window it is attached to. |
| 4474 | if (appWindow && attached == null) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4475 | if (showWhenLocked) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4476 | // Remove any previous windows with the same appToken. |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4477 | mAppsToBeHidden.remove(appToken); |
| 4478 | mAppsThatDismissKeyguard.remove(appToken); |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4479 | if (mAppsToBeHidden.isEmpty()) { |
Craig Mautner | 192d604 | 2014-12-02 23:24:48 -0800 | [diff] [blame] | 4480 | if (dismissKeyguard && !mKeyguardSecure) { |
| 4481 | mAppsThatDismissKeyguard.add(appToken); |
Selim Cinek | 90b5e07 | 2015-08-28 17:05:56 -0700 | [diff] [blame] | 4482 | } else if (win.isDrawnLw() || win.hasAppShownWindows()) { |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4483 | mWinShowWhenLocked = win; |
| 4484 | mHideLockScreen = true; |
| 4485 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4486 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4487 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4488 | } else if (dismissKeyguard) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4489 | if (mKeyguardSecure) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4490 | mAppsToBeHidden.add(appToken); |
| 4491 | } else { |
| 4492 | mAppsToBeHidden.remove(appToken); |
| 4493 | } |
| 4494 | mAppsThatDismissKeyguard.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4495 | } else { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4496 | mAppsToBeHidden.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4497 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4498 | if (attrs.x == 0 && attrs.y == 0 |
| 4499 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 4500 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
| 4501 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 4502 | mTopFullscreenOpaqueWindowState = win; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4503 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 4504 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4505 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4506 | if (!mAppsThatDismissKeyguard.isEmpty() && |
| 4507 | mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
| 4508 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4509 | "Setting mDismissKeyguard true by win " + win); |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4510 | mDismissKeyguard = (mWinDismissingKeyguard == win |
| 4511 | && mSecureDismissingKeyguard == mKeyguardSecure) |
| 4512 | ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4513 | mWinDismissingKeyguard = win; |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4514 | mSecureDismissingKeyguard = mKeyguardSecure; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4515 | mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure; |
Selim Cinek | 90b5e07 | 2015-08-28 17:05:56 -0700 | [diff] [blame] | 4516 | } else if (mAppsToBeHidden.isEmpty() && showWhenLocked |
| 4517 | && (win.isDrawnLw() || win.hasAppShownWindows())) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4518 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4519 | "Setting mHideLockScreen to true by win " + win); |
| 4520 | mHideLockScreen = true; |
| 4521 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4522 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 4523 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4524 | mAllowLockscreenWhenOn = true; |
| 4525 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4526 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4527 | |
| 4528 | if (mWinShowWhenLocked != null && |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4529 | mWinShowWhenLocked.getAppToken() != win.getAppToken() && |
| 4530 | (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4531 | win.hideLw(false); |
| 4532 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4533 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4534 | } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) { |
| 4535 | // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window |
| 4536 | // that is being hidden in an animation - keep the |
| 4537 | // keyguard hidden until the new window shows up and |
| 4538 | // we know whether to show the keyguard or not. |
Adrian Roos | b85e1ec | 2015-05-29 15:23:18 -0700 | [diff] [blame] | 4539 | if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) { |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4540 | mHideLockScreen = true; |
| 4541 | mWinShowWhenLocked = win; |
| 4542 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4543 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4544 | if (mTopFullscreenOpaqueOrDimmingWindowState == null |
| 4545 | && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw() |
| 4546 | && win.isDimming()) { |
| 4547 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4548 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4549 | } |
| 4550 | |
| 4551 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4552 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4553 | public int finishPostLayoutPolicyLw() { |
Craig Mautner | c5e73bf | 2015-04-21 15:41:26 +0000 | [diff] [blame] | 4554 | if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null && |
| 4555 | mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken() |
| 4556 | && isKeyguardLocked()) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4557 | // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the |
| 4558 | // fullscreen window. |
| 4559 | // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not. |
| 4560 | mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4561 | mTopFullscreenOpaqueWindowState.hideLw(false); |
| 4562 | mTopFullscreenOpaqueWindowState = mWinShowWhenLocked; |
| 4563 | } |
| 4564 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4565 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4566 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4567 | |
| 4568 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 4569 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 4570 | : null; |
| 4571 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4572 | // If we are not currently showing a dream then remember the current |
| 4573 | // lockscreen state. We will use this to determine whether the dream |
| 4574 | // started while the lockscreen was showing and remember this state |
| 4575 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4576 | if (!mShowingDream) { |
| 4577 | mDreamingLockscreen = mShowingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 4578 | if (mDreamingSleepTokenNeeded) { |
| 4579 | mDreamingSleepTokenNeeded = false; |
| 4580 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget(); |
| 4581 | } |
| 4582 | } else { |
| 4583 | if (!mDreamingSleepTokenNeeded) { |
| 4584 | mDreamingSleepTokenNeeded = true; |
| 4585 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget(); |
| 4586 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4587 | } |
| 4588 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4589 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4590 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4591 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 4592 | + " top=" + mTopFullscreenOpaqueWindowState); |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4593 | boolean shouldBeTransparent = mForceStatusBarTransparent |
| 4594 | && !mForceStatusBar |
| 4595 | && !mForceStatusBarFromKeyguard; |
| 4596 | if (!shouldBeTransparent) { |
| 4597 | mStatusBarController.setShowTransparent(false /* transparent */); |
| 4598 | } else if (!mStatusBar.isVisibleLw()) { |
| 4599 | mStatusBarController.setShowTransparent(true /* transparent */); |
| 4600 | } |
| 4601 | if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4602 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4603 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4604 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4605 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4606 | // Maintain fullscreen layout until incoming animation is complete. |
| 4607 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 4608 | // Transient status bar on the lockscreen is not allowed |
| 4609 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 4610 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 4611 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 4612 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4613 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4614 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4615 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4616 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 4617 | + " shown position: " |
| 4618 | + mTopFullscreenOpaqueWindowState.getShownPositionLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4619 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4620 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4621 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4622 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4623 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4624 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 4625 | // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4626 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 4627 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4628 | if (mStatusBarController.isTransientShowing()) { |
| 4629 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4630 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4631 | } |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 4632 | } else if (topIsFullscreen |
| 4633 | && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID) |
| 4634 | && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4635 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4636 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4637 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4638 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 4639 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 4640 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4641 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4642 | 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] | 4643 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4644 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4645 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4646 | } |
| 4647 | } |
| 4648 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4649 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4650 | if (mTopIsFullscreen != topIsFullscreen) { |
| 4651 | if (!topIsFullscreen) { |
| 4652 | // Force another layout when status bar becomes fully shown. |
| 4653 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4654 | } |
| 4655 | mTopIsFullscreen = topIsFullscreen; |
| 4656 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4657 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4658 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 4659 | // displayed when the screen is locked. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4660 | if (mKeyguardDelegate != null && mStatusBar != null) { |
| 4661 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 4662 | + mHideLockScreen); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4663 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4664 | mKeyguardHidden = true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4665 | if (setKeyguardOccludedLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4666 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4667 | | FINISH_LAYOUT_REDO_CONFIG |
| 4668 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4669 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4670 | if (mKeyguardDelegate.isShowing()) { |
| 4671 | mHandler.post(new Runnable() { |
| 4672 | @Override |
| 4673 | public void run() { |
| 4674 | mKeyguardDelegate.keyguardDone(false, false); |
| 4675 | } |
| 4676 | }); |
| 4677 | } |
| 4678 | } else if (mHideLockScreen) { |
| 4679 | mKeyguardHidden = true; |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 4680 | mWinDismissingKeyguard = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4681 | if (setKeyguardOccludedLw(true)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4682 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4683 | | FINISH_LAYOUT_REDO_CONFIG |
| 4684 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4685 | } |
| 4686 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 4687 | mKeyguardHidden = false; |
| 4688 | if (setKeyguardOccludedLw(false)) { |
| 4689 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4690 | | FINISH_LAYOUT_REDO_CONFIG |
| 4691 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4692 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4693 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 4694 | // Only launch the next keyguard unlock window once per window. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4695 | mHandler.post(new Runnable() { |
| 4696 | @Override |
| 4697 | public void run() { |
| 4698 | mKeyguardDelegate.dismiss(); |
| 4699 | } |
| 4700 | }); |
| 4701 | } |
| 4702 | } else { |
| 4703 | mWinDismissingKeyguard = null; |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4704 | mSecureDismissingKeyguard = false; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4705 | mKeyguardHidden = false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4706 | if (setKeyguardOccludedLw(false)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4707 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4708 | | FINISH_LAYOUT_REDO_CONFIG |
| 4709 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4710 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 4711 | } |
| 4712 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4713 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4714 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4715 | // If the navigation bar has been hidden or shown, we need to do another |
| 4716 | // layout pass to update that window. |
| 4717 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4718 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4719 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4720 | // update since mAllowLockscreenWhenOn might have changed |
| 4721 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4722 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4723 | } |
| 4724 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4725 | /** |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4726 | * Updates the occluded state of the Keyguard. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4727 | * |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4728 | * @return Whether the flags have changed and we have to redo the layout. |
| 4729 | */ |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4730 | private boolean setKeyguardOccludedLw(boolean isOccluded) { |
| 4731 | boolean wasOccluded = mKeyguardOccluded; |
| 4732 | boolean showing = mKeyguardDelegate.isShowing(); |
| 4733 | if (wasOccluded && !isOccluded && showing) { |
| 4734 | mKeyguardOccluded = false; |
| 4735 | mKeyguardDelegate.setOccluded(false); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4736 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 4737 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4738 | return true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4739 | } else if (!wasOccluded && isOccluded && showing) { |
| 4740 | mKeyguardOccluded = true; |
| 4741 | mKeyguardDelegate.setOccluded(true); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4742 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 4743 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 4744 | return true; |
| 4745 | } else { |
| 4746 | return false; |
| 4747 | } |
| 4748 | } |
| 4749 | |
| 4750 | private boolean isStatusBarKeyguard() { |
| 4751 | return mStatusBar != null |
| 4752 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 4753 | } |
| 4754 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4755 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4756 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4757 | if (isStatusBarKeyguard() || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 4758 | // 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] | 4759 | return false; |
| 4760 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4761 | return true; |
| 4762 | } |
| 4763 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4764 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4765 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4766 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4767 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4768 | // If the navigation bar has been hidden or shown, we need to do another |
| 4769 | // layout pass to update that window. |
| 4770 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 4771 | } |
| 4772 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4773 | } |
| 4774 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 4775 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4776 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4777 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 4778 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4779 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 4780 | if (newLidState == mLidState) { |
| 4781 | return; |
| 4782 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4783 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4784 | mLidState = newLidState; |
| 4785 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4786 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4787 | |
| 4788 | if (lidOpen) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4789 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch, |
| 4790 | "android.policy:LID"); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4791 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4792 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4793 | } |
| 4794 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4795 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4796 | @Override |
| 4797 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 4798 | int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; |
| 4799 | if (mCameraLensCoverState == lensCoverState) { |
| 4800 | return; |
| 4801 | } |
| 4802 | if (mCameraLensCoverState == CAMERA_LENS_COVERED && |
| 4803 | lensCoverState == CAMERA_LENS_UNCOVERED) { |
| 4804 | Intent intent; |
| 4805 | final boolean keyguardActive = mKeyguardDelegate == null ? false : |
| 4806 | mKeyguardDelegate.isShowing(); |
| 4807 | if (keyguardActive) { |
| 4808 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); |
| 4809 | } else { |
| 4810 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 4811 | } |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4812 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens, |
| 4813 | "android.policy:CAMERA_COVER"); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 4814 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4815 | } |
| 4816 | mCameraLensCoverState = lensCoverState; |
| 4817 | } |
| 4818 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4819 | void setHdmiPlugged(boolean plugged) { |
| 4820 | if (mHdmiPlugged != plugged) { |
| 4821 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4822 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4823 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4824 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4825 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 4826 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4827 | } |
| 4828 | } |
| 4829 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4830 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4831 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4832 | // watch for HDMI plug messages if the hdmi switch exists |
| 4833 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 4834 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 4835 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4836 | final String filename = "/sys/class/switch/hdmi/state"; |
| 4837 | FileReader reader = null; |
| 4838 | try { |
| 4839 | reader = new FileReader(filename); |
| 4840 | char[] buf = new char[15]; |
| 4841 | int n = reader.read(buf); |
| 4842 | if (n > 1) { |
| 4843 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 4844 | } |
| 4845 | } catch (IOException ex) { |
| 4846 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4847 | } catch (NumberFormatException ex) { |
| 4848 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4849 | } finally { |
| 4850 | if (reader != null) { |
| 4851 | try { |
| 4852 | reader.close(); |
| 4853 | } catch (IOException ex) { |
| 4854 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4855 | } |
| 4856 | } |
| 4857 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4858 | // This dance forces the code in setHdmiPlugged to run. |
| 4859 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 4860 | mHdmiPlugged = !plugged; |
| 4861 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4862 | } |
| 4863 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 4864 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4865 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4866 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4867 | final Runnable mScreenshotTimeout = new Runnable() { |
| 4868 | @Override public void run() { |
| 4869 | synchronized (mScreenshotLock) { |
| 4870 | if (mScreenshotConnection != null) { |
| 4871 | mContext.unbindService(mScreenshotConnection); |
| 4872 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4873 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4874 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4875 | } |
| 4876 | }; |
| 4877 | |
| 4878 | // Assume this is called from the Handler thread. |
| 4879 | private void takeScreenshot() { |
| 4880 | synchronized (mScreenshotLock) { |
| 4881 | if (mScreenshotConnection != null) { |
| 4882 | return; |
| 4883 | } |
| 4884 | ComponentName cn = new ComponentName("com.android.systemui", |
| 4885 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 4886 | Intent intent = new Intent(); |
| 4887 | intent.setComponent(cn); |
| 4888 | ServiceConnection conn = new ServiceConnection() { |
| 4889 | @Override |
| 4890 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 4891 | synchronized (mScreenshotLock) { |
| 4892 | if (mScreenshotConnection != this) { |
| 4893 | return; |
| 4894 | } |
| 4895 | Messenger messenger = new Messenger(service); |
| 4896 | Message msg = Message.obtain(null, 1); |
| 4897 | final ServiceConnection myConn = this; |
| 4898 | Handler h = new Handler(mHandler.getLooper()) { |
| 4899 | @Override |
| 4900 | public void handleMessage(Message msg) { |
| 4901 | synchronized (mScreenshotLock) { |
| 4902 | if (mScreenshotConnection == myConn) { |
| 4903 | mContext.unbindService(mScreenshotConnection); |
| 4904 | mScreenshotConnection = null; |
| 4905 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 4906 | } |
| 4907 | } |
| 4908 | } |
| 4909 | }; |
| 4910 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 4911 | msg.arg1 = msg.arg2 = 0; |
| 4912 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 4913 | msg.arg1 = 1; |
| 4914 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 4915 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4916 | try { |
| 4917 | messenger.send(msg); |
| 4918 | } catch (RemoteException e) { |
| 4919 | } |
| 4920 | } |
| 4921 | } |
| 4922 | @Override |
| 4923 | public void onServiceDisconnected(ComponentName name) {} |
| 4924 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 4925 | if (mContext.bindServiceAsUser( |
| 4926 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4927 | mScreenshotConnection = conn; |
| 4928 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 4929 | } |
| 4930 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4931 | } |
| 4932 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4933 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4934 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4935 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4936 | if (!mSystemBooted) { |
| 4937 | // If we have not yet booted, don't let key events do anything. |
| 4938 | return 0; |
| 4939 | } |
| 4940 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4941 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 4942 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 4943 | final boolean canceled = event.isCanceled(); |
| 4944 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 4945 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4946 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4947 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 4948 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 4949 | // the same as if it were open and in front. |
| 4950 | // This will prevent any keys other than the power button from waking the screen |
| 4951 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4952 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4953 | (interactive ? |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4954 | isKeyguardShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4955 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4956 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4957 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4958 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4959 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4960 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4961 | } |
| 4962 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4963 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4964 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 4965 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 4966 | || event.isWakeKey(); |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4967 | if (interactive || (isInjected && !isWakeKey)) { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 4968 | // When the device is interactive or the key is injected pass the |
| 4969 | // key to the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4970 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4971 | isWakeKey = false; |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4972 | } else if (!interactive && shouldDispatchInputWhenNonInteractive()) { |
| 4973 | // If we're currently dozing with the screen on and the keyguard showing, pass the key |
| 4974 | // to the application but preserve its wake key status to make sure we still move |
| 4975 | // from dozing to fully interactive if we would normally go from off to fully |
| 4976 | // interactive. |
| 4977 | result = ACTION_PASS_TO_USER; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4978 | } else { |
| 4979 | // When the screen is off and the key is not injected, determine whether |
| 4980 | // to wake the device but don't pass the key to the application. |
| 4981 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4982 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 4983 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4984 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4985 | } |
| 4986 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4987 | // If the key would be handled globally, just return the result, don't worry about special |
| 4988 | // key processing. |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4989 | if (isValidGlobalKey(keyCode) |
| 4990 | && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4991 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4992 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4993 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4994 | return result; |
| 4995 | } |
| 4996 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4997 | boolean useHapticFeedback = down |
| 4998 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 4999 | && event.getRepeatCount() == 0; |
| 5000 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5001 | // Handle special keys. |
| 5002 | switch (keyCode) { |
| 5003 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 5004 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5005 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5006 | if (mUseTvRouting) { |
| 5007 | // On TVs volume keys never go to the foreground app |
| 5008 | result &= ~ACTION_PASS_TO_USER; |
| 5009 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5010 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 5011 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5012 | if (interactive && !mScreenshotChordVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5013 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5014 | mScreenshotChordVolumeDownKeyTriggered = true; |
| 5015 | mScreenshotChordVolumeDownKeyTime = event.getDownTime(); |
| 5016 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5017 | cancelPendingPowerKeyAction(); |
| 5018 | interceptScreenshotChord(); |
| 5019 | } |
| 5020 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5021 | mScreenshotChordVolumeDownKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5022 | cancelPendingScreenshotChordAction(); |
| 5023 | } |
| 5024 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 5025 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5026 | if (interactive && !mScreenshotChordVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5027 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5028 | mScreenshotChordVolumeUpKeyTriggered = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5029 | cancelPendingPowerKeyAction(); |
| 5030 | cancelPendingScreenshotChordAction(); |
| 5031 | } |
| 5032 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5033 | mScreenshotChordVolumeUpKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5034 | cancelPendingScreenshotChordAction(); |
| 5035 | } |
| 5036 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5037 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5038 | TelecomManager telecomManager = getTelecommService(); |
| 5039 | if (telecomManager != null) { |
| 5040 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5041 | // If an incoming call is ringing, either VOLUME key means |
| 5042 | // "silence ringer". We handle these keys here, rather than |
| 5043 | // in the InCallScreen, to make sure we'll respond to them |
| 5044 | // even if the InCallScreen hasn't come to the foreground yet. |
| 5045 | // Look for the DOWN event here, to agree with the "fallback" |
| 5046 | // behavior in the InCallScreen. |
| 5047 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 5048 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5049 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5050 | // Silence the ringer. (It's safe to call this |
| 5051 | // even if the ringer has already been silenced.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5052 | telecomManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5053 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5054 | // And *don't* pass this key thru to the current activity |
| 5055 | // (which is probably the InCallScreen.) |
| 5056 | result &= ~ACTION_PASS_TO_USER; |
| 5057 | break; |
| 5058 | } |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5059 | if (telecomManager.isInCall() |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5060 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 5061 | // 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] | 5062 | // the application, just pass it to the session service. |
| 5063 | |
| 5064 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 5065 | .sendVolumeKeyEvent(event, false); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5066 | break; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5067 | } |
| 5068 | } |
| 5069 | |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 5070 | if ((result & ACTION_PASS_TO_USER) == 0) { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5071 | if (mUseTvRouting) { |
| 5072 | dispatchDirectAudioEvent(event); |
| 5073 | } else { |
| 5074 | // If we aren't passing to the user and no one else |
| 5075 | // handled it send it to the session manager to |
| 5076 | // figure out. |
| 5077 | MediaSessionLegacyHelper.getHelper(mContext) |
| 5078 | .sendVolumeKeyEvent(event, true); |
| 5079 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5080 | break; |
| 5081 | } |
| 5082 | } |
| 5083 | break; |
| 5084 | } |
| 5085 | |
| 5086 | case KeyEvent.KEYCODE_ENDCALL: { |
| 5087 | result &= ~ACTION_PASS_TO_USER; |
| 5088 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5089 | TelecomManager telecomManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5090 | boolean hungUp = false; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5091 | if (telecomManager != null) { |
| 5092 | hungUp = telecomManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5093 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5094 | if (interactive && !hungUp) { |
| 5095 | mEndCallKeyHandled = false; |
| 5096 | mHandler.postDelayed(mEndCallLongPress, |
| 5097 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 5098 | } else { |
| 5099 | mEndCallKeyHandled = true; |
| 5100 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5101 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5102 | if (!mEndCallKeyHandled) { |
| 5103 | mHandler.removeCallbacks(mEndCallLongPress); |
| 5104 | if (!canceled) { |
| 5105 | if ((mEndcallBehavior |
| 5106 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 5107 | if (goHome()) { |
| 5108 | break; |
| 5109 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 5110 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5111 | if ((mEndcallBehavior |
| 5112 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 5113 | mPowerManager.goToSleep(event.getEventTime(), |
| 5114 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 5115 | isWakeKey = false; |
| 5116 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5117 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5118 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5119 | } |
| 5120 | break; |
| 5121 | } |
| 5122 | |
| 5123 | case KeyEvent.KEYCODE_POWER: { |
| 5124 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5125 | isWakeKey = false; // wake-up will be handled separately |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5126 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5127 | interceptPowerKeyDown(event, interactive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5128 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5129 | interceptPowerKeyUp(event, interactive, canceled); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5130 | } |
| 5131 | break; |
| 5132 | } |
| 5133 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5134 | case KeyEvent.KEYCODE_SLEEP: { |
| 5135 | result &= ~ACTION_PASS_TO_USER; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 5136 | isWakeKey = false; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5137 | if (!mPowerManager.isInteractive()) { |
| 5138 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 5139 | } |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 5140 | if (down) { |
| 5141 | sleepPress(event.getEventTime()); |
| 5142 | } else { |
| 5143 | sleepRelease(event.getEventTime()); |
| 5144 | } |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5145 | break; |
| 5146 | } |
| 5147 | |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 5148 | case KeyEvent.KEYCODE_SOFT_SLEEP: { |
| 5149 | result &= ~ACTION_PASS_TO_USER; |
| 5150 | isWakeKey = false; |
| 5151 | if (!down) { |
| 5152 | mPowerManagerInternal.setUserInactiveOverrideFromWindowManager(); |
| 5153 | } |
| 5154 | break; |
| 5155 | } |
| 5156 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5157 | case KeyEvent.KEYCODE_WAKEUP: { |
| 5158 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5159 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5160 | break; |
| 5161 | } |
| 5162 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5163 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 5164 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 5165 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5166 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 5167 | case KeyEvent.KEYCODE_MUTE: |
| 5168 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 5169 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 5170 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 5171 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 5172 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 5173 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 5174 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 5175 | if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { |
| 5176 | // If the global session is active pass all media keys to it |
| 5177 | // instead of the active window. |
| 5178 | result &= ~ACTION_PASS_TO_USER; |
| 5179 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5180 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 5181 | // Only do this if we would otherwise not pass it to the user. In that |
| 5182 | // case, the PhoneWindow class will do the same thing, except it will |
| 5183 | // 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] | 5184 | // Note that we need to make a copy of the key event here because the |
| 5185 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5186 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5187 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 5188 | new KeyEvent(event)); |
| 5189 | msg.setAsynchronous(true); |
| 5190 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5191 | } |
| 5192 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5193 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5194 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5195 | case KeyEvent.KEYCODE_CALL: { |
| 5196 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5197 | TelecomManager telecomManager = getTelecommService(); |
| 5198 | if (telecomManager != null) { |
| 5199 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5200 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 5201 | + " CALL key-down while ringing: Answer the call!"); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5202 | telecomManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5203 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5204 | // And *don't* pass this key thru to the current activity |
| 5205 | // (which is presumably the InCallScreen.) |
| 5206 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5207 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5208 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5209 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5210 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5211 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5212 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 5213 | // Only do this if we would otherwise not pass it to the user. In that case, |
| 5214 | // interceptKeyBeforeDispatching would apply a similar but different policy in |
| 5215 | // order to invoke voice assist actions. Note that we need to make a copy of the |
| 5216 | // key event here because the original key event will be recycled when we return. |
| 5217 | if ((result & ACTION_PASS_TO_USER) == 0 && !down) { |
| 5218 | mBroadcastWakeLock.acquire(); |
| 5219 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, |
| 5220 | keyguardActive ? 1 : 0, 0); |
| 5221 | msg.setAsynchronous(true); |
| 5222 | msg.sendToTarget(); |
| 5223 | } |
| 5224 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5225 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5226 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5227 | if (useHapticFeedback) { |
| 5228 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 5229 | } |
| 5230 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5231 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5232 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5233 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 5234 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5235 | return result; |
| 5236 | } |
| 5237 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5238 | /** |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5239 | * Returns true if the key can have global actions attached to it. |
| 5240 | * We reserve all power management keys for the system since they require |
| 5241 | * very careful handling. |
| 5242 | */ |
| 5243 | private static boolean isValidGlobalKey(int keyCode) { |
| 5244 | switch (keyCode) { |
| 5245 | case KeyEvent.KEYCODE_POWER: |
| 5246 | case KeyEvent.KEYCODE_WAKEUP: |
| 5247 | case KeyEvent.KEYCODE_SLEEP: |
| 5248 | return false; |
| 5249 | default: |
| 5250 | return true; |
| 5251 | } |
| 5252 | } |
| 5253 | |
| 5254 | /** |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5255 | * When the screen is off we ignore some keys that might otherwise typically |
| 5256 | * be considered wake keys. We filter them out here. |
| 5257 | * |
| 5258 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 5259 | * is always considered a wake key. |
| 5260 | */ |
| 5261 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 5262 | switch (keyCode) { |
| 5263 | // ignore volume keys unless docked |
| 5264 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5265 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5266 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5267 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 5268 | |
| 5269 | // ignore media and camera keys |
| 5270 | case KeyEvent.KEYCODE_MUTE: |
| 5271 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 5272 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 5273 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 5274 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 5275 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 5276 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 5277 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 5278 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 5279 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 5280 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 5281 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5282 | case KeyEvent.KEYCODE_CAMERA: |
| 5283 | return false; |
| 5284 | } |
| 5285 | return true; |
| 5286 | } |
| 5287 | |
| 5288 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5289 | /** {@inheritDoc} */ |
| 5290 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5291 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 5292 | if ((policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5293 | if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion, |
| 5294 | "android.policy:MOTION")) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5295 | return 0; |
| 5296 | } |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5297 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5298 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5299 | if (shouldDispatchInputWhenNonInteractive()) { |
| 5300 | return ACTION_PASS_TO_USER; |
| 5301 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5302 | |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 5303 | // If we have not passed the action up and we are in theater mode without dreaming, |
| 5304 | // there will be no dream to intercept the touch and wake into ambient. The device should |
| 5305 | // wake up in this case. |
| 5306 | if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5307 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming, |
| 5308 | "android.policy:MOTION"); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 5309 | } |
| 5310 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5311 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5312 | } |
| 5313 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5314 | private boolean shouldDispatchInputWhenNonInteractive() { |
Michael Wright | 2ccf0c8 | 2015-08-04 23:03:03 +0100 | [diff] [blame] | 5315 | if (mDisplay == null || mDisplay.getState() == Display.STATE_OFF) { |
| 5316 | return false; |
| 5317 | } |
| 5318 | // Send events to keyguard while the screen is on and it's showing. |
| 5319 | if (isKeyguardShowingAndNotOccluded()) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5320 | return true; |
| 5321 | } |
| 5322 | |
| 5323 | // Send events to a dozing dream even if the screen is off since the dream |
| 5324 | // is in control of the state of the screen. |
| 5325 | IDreamManager dreamManager = getDreamManager(); |
| 5326 | |
| 5327 | try { |
| 5328 | if (dreamManager != null && dreamManager.isDreaming()) { |
| 5329 | return true; |
| 5330 | } |
| 5331 | } catch (RemoteException e) { |
| 5332 | Slog.e(TAG, "RemoteException when checking if dreaming", e); |
| 5333 | } |
| 5334 | |
| 5335 | // Otherwise, consume events since the user can't see what is being |
| 5336 | // interacted with. |
| 5337 | return false; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5338 | } |
| 5339 | |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5340 | private void dispatchDirectAudioEvent(KeyEvent event) { |
| 5341 | if (event.getAction() != KeyEvent.ACTION_DOWN) { |
| 5342 | return; |
| 5343 | } |
| 5344 | int keyCode = event.getKeyCode(); |
John Spurlock | b94f2d6 | 2015-03-17 14:11:57 -0400 | [diff] [blame] | 5345 | int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND |
| 5346 | | AudioManager.FLAG_FROM_KEY; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5347 | String pkgName = mContext.getOpPackageName(); |
| 5348 | switch (keyCode) { |
| 5349 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5350 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5351 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5352 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5353 | } catch (RemoteException e) { |
| 5354 | Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e); |
| 5355 | } |
| 5356 | break; |
| 5357 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5358 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5359 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5360 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5361 | } catch (RemoteException e) { |
| 5362 | Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e); |
| 5363 | } |
| 5364 | break; |
| 5365 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5366 | try { |
| 5367 | if (event.getRepeatCount() == 0) { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5368 | getAudioService().adjustSuggestedStreamVolume( |
| 5369 | AudioManager.ADJUST_TOGGLE_MUTE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5370 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5371 | } |
| 5372 | } catch (RemoteException e) { |
| 5373 | Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e); |
| 5374 | } |
| 5375 | break; |
| 5376 | } |
| 5377 | } |
| 5378 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5379 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 5380 | if (DEBUG_INPUT) { |
| 5381 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5382 | } |
| 5383 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5384 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 5385 | if (DEBUG_INPUT) { |
| 5386 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 5387 | } |
| 5388 | |
| 5389 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 5390 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5391 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 5392 | } |
| 5393 | |
| 5394 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 5395 | |
| 5396 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 5397 | && event.getRepeatCount() == 0) { |
| 5398 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 5399 | |
| 5400 | Message msg = mHandler.obtainMessage( |
| 5401 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 5402 | msg.setAsynchronous(true); |
| 5403 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 5404 | } else { |
| 5405 | mBroadcastWakeLock.release(); |
| 5406 | } |
| 5407 | } |
| 5408 | |
| 5409 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 5410 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5411 | |
| 5412 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 5413 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 5414 | if (DEBUG_INPUT) { |
| 5415 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 5416 | } |
| 5417 | |
| 5418 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 5419 | mBroadcastWakeLock.release(); |
| 5420 | } |
| 5421 | |
| 5422 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 5423 | if (ActivityManagerNative.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 5424 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5425 | } |
| 5426 | } |
| 5427 | |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5428 | void launchVoiceAssistWithWakeLock(boolean keyguardActive) { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 5429 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 5430 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 5431 | if (dic != null) { |
| 5432 | try { |
| 5433 | dic.exitIdle("voice-search"); |
| 5434 | } catch (RemoteException e) { |
| 5435 | } |
| 5436 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5437 | Intent voiceIntent = |
| 5438 | new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 5439 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5440 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5441 | mBroadcastWakeLock.release(); |
| 5442 | } |
| 5443 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5444 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5445 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5446 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 5447 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 5448 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 5449 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5450 | } else { |
| 5451 | try { |
| 5452 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 5453 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5454 | mUiMode = uiModeService.getCurrentModeType(); |
| 5455 | } catch (RemoteException e) { |
| 5456 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 5457 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5458 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5459 | synchronized (mLock) { |
| 5460 | updateOrientationListenerLp(); |
| 5461 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5462 | } |
| 5463 | }; |
| 5464 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5465 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 5466 | @Override |
| 5467 | public void onReceive(Context context, Intent intent) { |
| 5468 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5469 | if (mKeyguardDelegate != null) { |
| 5470 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5471 | } |
| 5472 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5473 | if (mKeyguardDelegate != null) { |
| 5474 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5475 | } |
| 5476 | } |
| 5477 | } |
| 5478 | }; |
| 5479 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5480 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 5481 | @Override |
| 5482 | public void onReceive(Context context, Intent intent) { |
| 5483 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 5484 | // tickle the settings observer: this first ensures that we're |
| 5485 | // observing the relevant settings for the newly-active user, |
| 5486 | // and then updates our own bookkeeping based on the now- |
| 5487 | // current user. |
| 5488 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5489 | |
| 5490 | // force a re-application of focused window sysui visibility. |
| 5491 | // the window may never have been shown for this user |
| 5492 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5493 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5494 | mLastSystemUiFlags = 0; |
| 5495 | updateSystemUiVisibilityLw(); |
| 5496 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5497 | } |
| 5498 | } |
| 5499 | }; |
| 5500 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5501 | private final Runnable mHiddenNavPanic = new Runnable() { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5502 | @Override |
| 5503 | public void run() { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5504 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 5505 | if (!isUserSetupComplete()) { |
| 5506 | // Swipe-up for navigation bar is disabled during setup |
| 5507 | return; |
| 5508 | } |
| 5509 | mPendingPanicGestureUptime = SystemClock.uptimeMillis(); |
| 5510 | mNavigationBarController.showTransient(); |
| 5511 | } |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5512 | } |
| 5513 | }; |
| 5514 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5515 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5516 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 5517 | if (!isUserSetupComplete()) { |
| 5518 | // Swipe-up for navigation bar is disabled during setup |
| 5519 | return; |
| 5520 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5521 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 5522 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5523 | if (sb || nb) { |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 5524 | // Don't show status bar when swiping on already visible navigation bar |
| 5525 | if (!nb && swipeTarget == mNavigationBar) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5526 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5527 | return; |
| 5528 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5529 | if (sb) mStatusBarController.showTransient(); |
| 5530 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5531 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5532 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5533 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5534 | } |
| 5535 | } |
| 5536 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5537 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5538 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5539 | public void startedGoingToSleep(int why) { |
| 5540 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")"); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 5541 | if (mKeyguardDelegate != null) { |
| 5542 | mKeyguardDelegate.onStartedGoingToSleep(why); |
| 5543 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5544 | } |
| 5545 | |
| 5546 | // Called on the PowerManager's Notifier thread. |
| 5547 | @Override |
| 5548 | public void finishedGoingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5549 | EventLog.writeEvent(70000, 0); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5550 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")"); |
Chris Wren | 9bb290b | 2015-06-29 12:02:13 -0400 | [diff] [blame] | 5551 | MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5552 | |
| 5553 | // We must get this work done here because the power manager will drop |
| 5554 | // 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] | 5555 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5556 | mAwake = false; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5557 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5558 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5559 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5560 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5561 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 5562 | mKeyguardDelegate.onFinishedGoingToSleep(why); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5563 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5564 | } |
| 5565 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5566 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5567 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5568 | public void startedWakingUp() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5569 | EventLog.writeEvent(70000, 1); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5570 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up..."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5571 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5572 | // Since goToSleep performs these functions synchronously, we must |
| 5573 | // do the same here. We cannot post this work to a handler because |
| 5574 | // that might cause it to become reordered with respect to what |
| 5575 | // may happen in a future call to goToSleep. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5576 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5577 | mAwake = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5578 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5579 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5580 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5581 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5582 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5583 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5584 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5585 | mKeyguardDelegate.onStartedWakingUp(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5586 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5587 | } |
| 5588 | |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5589 | // Called on the PowerManager's Notifier thread. |
| 5590 | @Override |
| 5591 | public void finishedWakingUp() { |
| 5592 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up..."); |
| 5593 | } |
| 5594 | |
| 5595 | private void wakeUpFromPowerKey(long eventTime) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5596 | wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER"); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5597 | } |
| 5598 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5599 | private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) { |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 5600 | final boolean theaterModeEnabled = isTheaterModeEnabled(); |
| 5601 | if (!wakeInTheaterMode && theaterModeEnabled) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5602 | return false; |
| 5603 | } |
| 5604 | |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 5605 | if (theaterModeEnabled) { |
| 5606 | Settings.Global.putInt(mContext.getContentResolver(), |
| 5607 | Settings.Global.THEATER_MODE_ON, 0); |
| 5608 | } |
| 5609 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5610 | mPowerManager.wakeUp(wakeTime, reason); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5611 | return true; |
| 5612 | } |
| 5613 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5614 | private void finishKeyguardDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5615 | synchronized (mLock) { |
Jorim Jaggi | f325548 | 2015-07-24 12:32:42 -0700 | [diff] [blame] | 5616 | if (!mScreenOnEarly || mKeyguardDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 5617 | 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] | 5618 | } |
| 5619 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5620 | mKeyguardDrawComplete = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5621 | if (mKeyguardDelegate != null) { |
| 5622 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5623 | } |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5624 | mWindowManagerDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5625 | } |
| 5626 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5627 | // ... eventually calls finishWindowsDrawn which will finalize our screen turn on |
| 5628 | // as well as enabling the orientation change logic/sensor. |
| 5629 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, |
| 5630 | WAITING_FOR_DRAWN_TIMEOUT); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5631 | } |
| 5632 | |
| 5633 | // Called on the DisplayManager's DisplayPowerController thread. |
| 5634 | @Override |
| 5635 | public void screenTurnedOff() { |
| 5636 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); |
| 5637 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 5638 | updateScreenOffSleepToken(true); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5639 | synchronized (mLock) { |
| 5640 | mScreenOnEarly = false; |
| 5641 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 5642 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5643 | mWindowManagerDrawComplete = false; |
| 5644 | mScreenOnListener = null; |
| 5645 | updateOrientationListenerLp(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 5646 | |
| 5647 | if (mKeyguardDelegate != null) { |
| 5648 | mKeyguardDelegate.onScreenTurnedOff(); |
| 5649 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5650 | } |
| 5651 | } |
| 5652 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5653 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5654 | @Override |
| 5655 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5656 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5657 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 5658 | updateScreenOffSleepToken(false); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5659 | synchronized (mLock) { |
| 5660 | mScreenOnEarly = true; |
| 5661 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 5662 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5663 | mWindowManagerDrawComplete = false; |
| 5664 | mScreenOnListener = screenOnListener; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5665 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5666 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | a4b51bc | 2015-08-10 18:20:43 -0700 | [diff] [blame] | 5667 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5668 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5669 | mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback); |
| 5670 | } else { |
| 5671 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 5672 | "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
| 5673 | finishKeyguardDrawn(); |
| 5674 | } |
| 5675 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5676 | } |
| 5677 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 5678 | // Called on the DisplayManager's DisplayPowerController thread. |
| 5679 | @Override |
| 5680 | public void screenTurnedOn() { |
| 5681 | synchronized (mLock) { |
| 5682 | if (mKeyguardDelegate != null) { |
| 5683 | mKeyguardDelegate.onScreenTurnedOn(); |
| 5684 | } |
| 5685 | } |
| 5686 | } |
| 5687 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5688 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5689 | synchronized (mLock) { |
| 5690 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 5691 | 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] | 5692 | } |
| 5693 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5694 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5695 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5696 | |
| 5697 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5698 | } |
| 5699 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5700 | private void finishScreenTurningOn() { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 5701 | synchronized (mLock) { |
| 5702 | // We have just finished drawing screen content. Since the orientation listener |
| 5703 | // gets only installed when all windows are drawn, we try to install it again. |
| 5704 | updateOrientationListenerLp(); |
| 5705 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5706 | final ScreenOnListener listener; |
| 5707 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5708 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5709 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 5710 | "finishScreenTurningOn: mAwake=" + mAwake |
| 5711 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 5712 | + ", mScreenOnFully=" + mScreenOnFully |
| 5713 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 5714 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 5715 | |
| 5716 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 5717 | || (mAwake && !mKeyguardDrawComplete)) { |
| 5718 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5719 | } |
| 5720 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5721 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 5722 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 5723 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5724 | mScreenOnFully = true; |
| 5725 | |
| 5726 | // Remember the first time we draw the keyguard so we know when we're done with |
| 5727 | // the main part of booting and can enable the screen and hide boot messages. |
| 5728 | if (!mKeyguardDrawnOnce && mAwake) { |
| 5729 | mKeyguardDrawnOnce = true; |
| 5730 | enableScreen = true; |
| 5731 | if (mBootMessageNeedsHiding) { |
| 5732 | mBootMessageNeedsHiding = false; |
| 5733 | hideBootMessages(); |
| 5734 | } |
| 5735 | } else { |
| 5736 | enableScreen = false; |
| 5737 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5738 | } |
| 5739 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5740 | if (listener != null) { |
| 5741 | listener.onScreenOn(); |
| 5742 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 5743 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5744 | if (enableScreen) { |
| 5745 | try { |
| 5746 | mWindowManager.enableScreenIfNeeded(); |
| 5747 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5748 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5749 | } |
| 5750 | } |
| 5751 | |
| 5752 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5753 | synchronized (mLock) { |
| 5754 | if (!mKeyguardDrawnOnce) { |
| 5755 | mBootMessageNeedsHiding = true; |
| 5756 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 5757 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5758 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5759 | |
| 5760 | if (mBootMsgDialog != null) { |
| 5761 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 5762 | mBootMsgDialog.dismiss(); |
| 5763 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5764 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5765 | } |
| 5766 | |
| 5767 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5768 | public boolean isScreenOn() { |
| 5769 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5770 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5771 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5772 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5773 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5774 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5775 | if (mKeyguardDelegate != null) { |
| 5776 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5777 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5778 | } |
| 5779 | |
| 5780 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5781 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5782 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5783 | if (mKeyguardDelegate != null) { |
| 5784 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5785 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5786 | } |
| 5787 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5788 | private boolean isKeyguardShowingAndNotOccluded() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5789 | if (mKeyguardDelegate == null) return false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5790 | return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5791 | } |
| 5792 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5793 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5794 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5795 | public boolean isKeyguardLocked() { |
| 5796 | return keyguardOn(); |
| 5797 | } |
| 5798 | |
| 5799 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5800 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5801 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5802 | if (mKeyguardDelegate == null) return false; |
| 5803 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5804 | } |
| 5805 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5806 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5807 | @Override |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 5808 | public boolean isKeyguardShowingOrOccluded() { |
| 5809 | return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing(); |
| 5810 | } |
| 5811 | |
| 5812 | /** {@inheritDoc} */ |
| 5813 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5814 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5815 | if (mKeyguardDelegate == null) return false; |
| 5816 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5817 | } |
| 5818 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5819 | @Override |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5820 | public void dismissKeyguardLw() { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5821 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5822 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5823 | mHandler.post(new Runnable() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5824 | @Override |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5825 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 5826 | // ask the keyguard to prompt the user to authenticate if necessary |
| 5827 | mKeyguardDelegate.dismiss(); |
| 5828 | } |
| 5829 | }); |
| 5830 | } |
| 5831 | } |
| 5832 | |
| 5833 | public void notifyActivityDrawnForKeyguardLw() { |
| 5834 | if (mKeyguardDelegate != null) { |
| 5835 | mHandler.post(new Runnable() { |
| 5836 | @Override |
| 5837 | public void run() { |
| 5838 | mKeyguardDelegate.onActivityDrawn(); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5839 | } |
| 5840 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5841 | } |
| 5842 | } |
| 5843 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5844 | @Override |
| 5845 | public boolean isKeyguardDrawnLw() { |
| 5846 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5847 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5848 | } |
| 5849 | } |
| 5850 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5851 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5852 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5853 | if (mKeyguardDelegate != null) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5854 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5855 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5856 | } |
| 5857 | } |
| 5858 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5859 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5860 | PhoneWindow.sendCloseSystemWindows(mContext, null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5861 | } |
| 5862 | |
| 5863 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5864 | PhoneWindow.sendCloseSystemWindows(mContext, reason); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5865 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 5866 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5867 | @Override |
| 5868 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5869 | if (false) { |
| 5870 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 5871 | + orientation + ", last=" + lastRotation |
| 5872 | + "); user=" + mUserRotation + " " |
| 5873 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 5874 | ? "USER_ROTATION_LOCKED" : "") |
| 5875 | ); |
| 5876 | } |
| 5877 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 5878 | if (mForceDefaultOrientation) { |
| 5879 | return Surface.ROTATION_0; |
| 5880 | } |
| 5881 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5882 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5883 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 5884 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 5885 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5886 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5887 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5888 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 5889 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5890 | // Ignore sensor when lid switch is open and rotation is forced. |
| 5891 | preferredRotation = mLidOpenRotation; |
| 5892 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5893 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5894 | // Ignore sensor when in car dock unless explicitly enabled. |
| 5895 | // This case can override the behavior of NOSENSOR, and can also |
| 5896 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5897 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5898 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 5899 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 5900 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 5901 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5902 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5903 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 5904 | // This case can override the behavior of NOSENSOR, and can also |
| 5905 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5906 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5907 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5908 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 5909 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 5910 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5911 | preferredRotation = mDemoHdmiRotation; |
| 5912 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 5913 | && mUndockedHdmiRotation >= 0) { |
| 5914 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 5915 | // been specified in the configuration (only for legacy devices without |
| 5916 | // full multi-display support). |
| 5917 | // Note that the dock orientation overrides the HDMI orientation. |
| 5918 | preferredRotation = mUndockedHdmiRotation; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 5919 | } else if (mDemoRotationLock) { |
| 5920 | // Ignore sensor when demo rotation lock is enabled. |
| 5921 | // Note that the dock orientation and HDMI rotation lock override this. |
| 5922 | preferredRotation = mDemoRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5923 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 5924 | // Application just wants to remain locked in the last rotation. |
| 5925 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 5926 | } else if (!mSupportAutoRotation) { |
| 5927 | // If we don't support auto-rotation then bail out here and ignore |
| 5928 | // the sensor and any rotation lock settings. |
| 5929 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5930 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5931 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5932 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 5933 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 5934 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 5935 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5936 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 5937 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5938 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 5939 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 5940 | // Otherwise, use sensor only if requested by the application or enabled |
| 5941 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5942 | if (mAllowAllRotations < 0) { |
| 5943 | // Can't read this during init() because the context doesn't |
| 5944 | // have display metrics at that time so we cannot determine |
| 5945 | // tablet vs. phone then. |
| 5946 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 5947 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 5948 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5949 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5950 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5951 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5952 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5953 | preferredRotation = sensorRotation; |
| 5954 | } else { |
| 5955 | preferredRotation = lastRotation; |
| 5956 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5957 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 5958 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 5959 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 5960 | // The idea is that the user rotation expresses a weak preference for the direction |
| 5961 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 5962 | // 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] | 5963 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5964 | } else { |
| 5965 | // No overriding preference. |
| 5966 | // We will do exactly what the application asked us to do. |
| 5967 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5968 | } |
| 5969 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5970 | switch (orientation) { |
| 5971 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5972 | // Return portrait unless overridden. |
| 5973 | if (isAnyPortrait(preferredRotation)) { |
| 5974 | return preferredRotation; |
| 5975 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5976 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5977 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5978 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5979 | // Return landscape unless overridden. |
| 5980 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5981 | return preferredRotation; |
| 5982 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5983 | return mLandscapeRotation; |
| 5984 | |
| 5985 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5986 | // Return reverse portrait unless overridden. |
| 5987 | if (isAnyPortrait(preferredRotation)) { |
| 5988 | return preferredRotation; |
| 5989 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5990 | return mUpsideDownRotation; |
| 5991 | |
| 5992 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5993 | // Return seascape unless overridden. |
| 5994 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5995 | return preferredRotation; |
| 5996 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5997 | return mSeascapeRotation; |
| 5998 | |
| 5999 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6000 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6001 | // Return either landscape rotation. |
| 6002 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6003 | return preferredRotation; |
| 6004 | } |
| 6005 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 6006 | return lastRotation; |
| 6007 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6008 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6009 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6010 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6011 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6012 | // Return either portrait rotation. |
| 6013 | if (isAnyPortrait(preferredRotation)) { |
| 6014 | return preferredRotation; |
| 6015 | } |
| 6016 | if (isAnyPortrait(lastRotation)) { |
| 6017 | return lastRotation; |
| 6018 | } |
| 6019 | return mPortraitRotation; |
| 6020 | |
| 6021 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 6022 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 6023 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6024 | if (preferredRotation >= 0) { |
| 6025 | return preferredRotation; |
| 6026 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6027 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 6028 | } |
| 6029 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 6030 | } |
| 6031 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6032 | @Override |
| 6033 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 6034 | switch (orientation) { |
| 6035 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 6036 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 6037 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 6038 | return isAnyPortrait(rotation); |
| 6039 | |
| 6040 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 6041 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 6042 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 6043 | return isLandscapeOrSeascape(rotation); |
| 6044 | |
| 6045 | default: |
| 6046 | return true; |
| 6047 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 6048 | } |
| 6049 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6050 | @Override |
| 6051 | public void setRotationLw(int rotation) { |
| 6052 | mOrientationListener.setCurrentRotation(rotation); |
| 6053 | } |
| 6054 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6055 | private boolean isLandscapeOrSeascape(int rotation) { |
| 6056 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6057 | } |
| 6058 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6059 | private boolean isAnyPortrait(int rotation) { |
| 6060 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6061 | } |
| 6062 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6063 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6064 | public int getUserRotationMode() { |
| 6065 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 6066 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 6067 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 6068 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6069 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6070 | |
| 6071 | // 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] | 6072 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6073 | public void setUserRotationMode(int mode, int rot) { |
| 6074 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6075 | |
| 6076 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6077 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6078 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6079 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6080 | rot, |
| 6081 | UserHandle.USER_CURRENT); |
| 6082 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6083 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6084 | 0, |
| 6085 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6086 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6087 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6088 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6089 | 1, |
| 6090 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6091 | } |
| 6092 | } |
| 6093 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6094 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6095 | public void setSafeMode(boolean safeMode) { |
| 6096 | mSafeMode = safeMode; |
| 6097 | performHapticFeedbackLw(null, safeMode |
| 6098 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 6099 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6100 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6101 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 6102 | static long[] getLongIntArray(Resources r, int resid) { |
| 6103 | int[] ar = r.getIntArray(resid); |
| 6104 | if (ar == null) { |
| 6105 | return null; |
| 6106 | } |
| 6107 | long[] out = new long[ar.length]; |
| 6108 | for (int i=0; i<ar.length; i++) { |
| 6109 | out[i] = ar[i]; |
| 6110 | } |
| 6111 | return out; |
| 6112 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6113 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6114 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6115 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6116 | public void systemReady() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6117 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext); |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 6118 | mKeyguardDelegate.onSystemReady(); |
| 6119 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 6120 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6121 | updateUiMode(); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6122 | boolean bindKeyguardNow; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6123 | synchronized (mLock) { |
| 6124 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 6125 | mSystemReady = true; |
| 6126 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6127 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 6128 | public void run() { |
| 6129 | updateSettings(); |
| 6130 | } |
| 6131 | }); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6132 | |
| 6133 | bindKeyguardNow = mDeferBindKeyguard; |
| 6134 | if (bindKeyguardNow) { |
| 6135 | // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now. |
| 6136 | mDeferBindKeyguard = false; |
| 6137 | } |
| 6138 | } |
| 6139 | |
| 6140 | if (bindKeyguardNow) { |
| 6141 | mKeyguardDelegate.bindService(mContext); |
| 6142 | mKeyguardDelegate.onBootCompleted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6143 | } |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 6144 | mSystemGestures.systemReady(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6145 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6146 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6147 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6148 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6149 | public void systemBooted() { |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6150 | boolean bindKeyguardNow = false; |
| 6151 | synchronized (mLock) { |
| 6152 | // Time to bind Keyguard; take care to only bind it once, either here if ready or |
| 6153 | // in systemReady if not. |
| 6154 | if (mKeyguardDelegate != null) { |
| 6155 | bindKeyguardNow = true; |
| 6156 | } else { |
| 6157 | // Because mKeyguardDelegate is null, we know that the synchronized block in |
| 6158 | // systemReady didn't run yet and setting this will actually have an effect. |
| 6159 | mDeferBindKeyguard = true; |
| 6160 | } |
| 6161 | } |
| 6162 | if (bindKeyguardNow) { |
Jason Monk | 5eeebf5 | 2014-09-26 12:36:51 -0400 | [diff] [blame] | 6163 | mKeyguardDelegate.bindService(mContext); |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 6164 | mKeyguardDelegate.onBootCompleted(); |
| 6165 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6166 | synchronized (mLock) { |
| 6167 | mSystemBooted = true; |
| 6168 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6169 | startedWakingUp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6170 | screenTurningOn(null); |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 6171 | screenTurnedOn(); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6172 | } |
| 6173 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6174 | ProgressDialog mBootMsgDialog = null; |
| 6175 | |
| 6176 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6177 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6178 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 6179 | mHandler.post(new Runnable() { |
| 6180 | @Override public void run() { |
| 6181 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 6182 | int theme; |
| 6183 | if (mContext.getPackageManager().hasSystemFeature( |
| 6184 | PackageManager.FEATURE_WATCH)) { |
| 6185 | theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert; |
| 6186 | } else if (mContext.getPackageManager().hasSystemFeature( |
| 6187 | PackageManager.FEATURE_TELEVISION)) { |
| 6188 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 6189 | } else { |
| 6190 | theme = 0; |
| 6191 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 6192 | |
| 6193 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 6194 | // This dialog will consume all events coming in to |
| 6195 | // it, to avoid it trying to do things too early in boot. |
| 6196 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 6197 | return true; |
| 6198 | } |
| 6199 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 6200 | return true; |
| 6201 | } |
| 6202 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 6203 | return true; |
| 6204 | } |
| 6205 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 6206 | return true; |
| 6207 | } |
| 6208 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 6209 | return true; |
| 6210 | } |
| 6211 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 6212 | AccessibilityEvent event) { |
| 6213 | return true; |
| 6214 | } |
| 6215 | }; |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 6216 | if (mContext.getPackageManager().isUpgrade()) { |
| 6217 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 6218 | } else { |
| 6219 | mBootMsgDialog.setTitle(R.string.android_start_title); |
| 6220 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6221 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 6222 | mBootMsgDialog.setIndeterminate(true); |
| 6223 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 6224 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6225 | mBootMsgDialog.getWindow().addFlags( |
| 6226 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 6227 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 6228 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 6229 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 6230 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 6231 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6232 | mBootMsgDialog.setCancelable(false); |
| 6233 | mBootMsgDialog.show(); |
| 6234 | } |
| 6235 | mBootMsgDialog.setMessage(msg); |
| 6236 | } |
| 6237 | }); |
| 6238 | } |
| 6239 | |
| 6240 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6241 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6242 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6243 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6244 | } |
| 6245 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6246 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6247 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6248 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6249 | // *************************************** |
| 6250 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 6251 | // *************************************** |
| 6252 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 6253 | // WITH ITS LOCKS HELD. |
| 6254 | // |
| 6255 | // This code must be VERY careful about the locks |
| 6256 | // it acquires. |
| 6257 | // In fact, the current code acquires way too many, |
| 6258 | // and probably has lurking deadlocks. |
| 6259 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6260 | synchronized (mScreenLockTimeout) { |
| 6261 | if (mLockScreenTimerActive) { |
| 6262 | // reset the timer |
| 6263 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 6264 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 6265 | } |
| 6266 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 6267 | } |
| 6268 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6269 | class ScreenLockTimeout implements Runnable { |
| 6270 | Bundle options; |
| 6271 | |
| 6272 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6273 | public void run() { |
| 6274 | synchronized (this) { |
| 6275 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6276 | if (mKeyguardDelegate != null) { |
| 6277 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6278 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6279 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6280 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6281 | } |
| 6282 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6283 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6284 | public void setLockOptions(Bundle options) { |
| 6285 | this.options = options; |
| 6286 | } |
| 6287 | } |
| 6288 | |
| 6289 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 6290 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6291 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6292 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 6293 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 6294 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6295 | if (options != null) { |
| 6296 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 6297 | // until the runnable actually executes. |
| 6298 | mScreenLockTimeout.setLockOptions(options); |
| 6299 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 6300 | mHandler.post(mScreenLockTimeout); |
| 6301 | } |
| 6302 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6303 | private void updateLockScreenTimeout() { |
| 6304 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6305 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6306 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6307 | if (mLockScreenTimerActive != enable) { |
| 6308 | if (enable) { |
| 6309 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 6310 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 6311 | } else { |
| 6312 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 6313 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 6314 | } |
| 6315 | mLockScreenTimerActive = enable; |
| 6316 | } |
| 6317 | } |
| 6318 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6319 | |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6320 | private void updateDreamingSleepToken(boolean acquire) { |
| 6321 | if (acquire) { |
| 6322 | if (mDreamingSleepToken == null) { |
| 6323 | mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream"); |
| 6324 | } |
| 6325 | } else { |
| 6326 | if (mDreamingSleepToken != null) { |
| 6327 | mDreamingSleepToken.release(); |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6328 | mDreamingSleepToken = null; |
| 6329 | } |
| 6330 | } |
| 6331 | } |
| 6332 | |
| 6333 | private void updateScreenOffSleepToken(boolean acquire) { |
| 6334 | if (acquire) { |
| 6335 | if (mScreenOffSleepToken == null) { |
| 6336 | mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff"); |
| 6337 | } |
| 6338 | } else { |
| 6339 | if (mScreenOffSleepToken != null) { |
| 6340 | mScreenOffSleepToken.release(); |
| 6341 | mScreenOffSleepToken = null; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6342 | } |
| 6343 | } |
| 6344 | } |
| 6345 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6346 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6347 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6348 | public void enableScreenAfterBoot() { |
| 6349 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6350 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6351 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6352 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 6353 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6354 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6355 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6356 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 6357 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6358 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6359 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6360 | |
| 6361 | synchronized (mLock) { |
| 6362 | updateWakeGestureListenerLp(); |
| 6363 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6364 | } |
| 6365 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6366 | void updateUiMode() { |
| 6367 | if (mUiModeManager == null) { |
| 6368 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 6369 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 6370 | } |
| 6371 | try { |
| 6372 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 6373 | } catch (RemoteException e) { |
| 6374 | } |
| 6375 | } |
| 6376 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6377 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6378 | try { |
| 6379 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 6380 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 6381 | } catch (RemoteException e) { |
| 6382 | // Ignore |
| 6383 | } |
| 6384 | } |
| 6385 | |
| 6386 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 6387 | try { |
| 6388 | //set orientation on WindowManager |
| 6389 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6390 | } catch (RemoteException e) { |
| 6391 | // Ignore |
| 6392 | } |
| 6393 | } |
| 6394 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6395 | /** |
| 6396 | * Return an Intent to launch the currently active dock app as home. Returns |
| 6397 | * null if the standard home should be launched, which is the case if any of the following is |
| 6398 | * true: |
| 6399 | * <ul> |
| 6400 | * <li>The device is not in either car mode or desk mode |
| 6401 | * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false |
| 6402 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 6403 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 6404 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 6405 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6406 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6407 | */ |
| 6408 | Intent createHomeDockIntent() { |
| 6409 | Intent intent = null; |
| 6410 | |
| 6411 | // What home does is based on the mode, not the dock state. That |
| 6412 | // is, when in car mode you should be taken to car home regardless |
| 6413 | // of whether we are actually in a car dock. |
| 6414 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 6415 | if (ENABLE_CAR_DOCK_HOME_CAPTURE) { |
| 6416 | intent = mCarDockIntent; |
| 6417 | } |
| 6418 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 6419 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 6420 | intent = mDeskDockIntent; |
| 6421 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6422 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 6423 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 6424 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 6425 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 6426 | // Always launch dock home from home when watch is docked, if it exists. |
| 6427 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6428 | } |
| 6429 | |
| 6430 | if (intent == null) { |
| 6431 | return null; |
| 6432 | } |
| 6433 | |
| 6434 | ActivityInfo ai = null; |
| 6435 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 6436 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 6437 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6438 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6439 | if (info != null) { |
| 6440 | ai = info.activityInfo; |
| 6441 | } |
| 6442 | if (ai != null |
| 6443 | && ai.metaData != null |
| 6444 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 6445 | intent = new Intent(intent); |
| 6446 | intent.setClassName(ai.packageName, ai.name); |
| 6447 | return intent; |
| 6448 | } |
| 6449 | |
| 6450 | return null; |
| 6451 | } |
| 6452 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6453 | void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { |
| 6454 | if (awakenFromDreams) { |
| 6455 | awakenDreams(); |
| 6456 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6457 | |
| 6458 | Intent dock = createHomeDockIntent(); |
| 6459 | if (dock != null) { |
| 6460 | try { |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6461 | if (fromHomeKey) { |
| 6462 | dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6463 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6464 | startActivityAsUser(dock, UserHandle.CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6465 | return; |
| 6466 | } catch (ActivityNotFoundException e) { |
| 6467 | } |
| 6468 | } |
| 6469 | |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6470 | Intent intent; |
| 6471 | |
| 6472 | if (fromHomeKey) { |
| 6473 | intent = new Intent(mHomeIntent); |
| 6474 | intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6475 | } else { |
| 6476 | intent = mHomeIntent; |
| 6477 | } |
| 6478 | |
Bryce Lee | 9fc0b6f | 2015-03-19 21:37:45 +0000 | [diff] [blame] | 6479 | startActivityAsUser(intent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6480 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6481 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6482 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6483 | * goes to the home screen |
| 6484 | * @return whether it did anything |
| 6485 | */ |
| 6486 | boolean goHome() { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6487 | if (!isUserSetupComplete()) { |
| 6488 | Slog.i(TAG, "Not going home because user setup is in progress."); |
| 6489 | return false; |
| 6490 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6491 | if (false) { |
| 6492 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 6493 | try { |
| 6494 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6495 | } catch (RemoteException e) { |
| 6496 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 6497 | sendCloseSystemWindows(); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6498 | startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6499 | } else { |
| 6500 | // This code brings home to the front or, if it is already |
| 6501 | // at the front, puts the device to sleep. |
| 6502 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 6503 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 6504 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 6505 | Log.d(TAG, "UTS-TEST-MODE"); |
| 6506 | } else { |
| 6507 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6508 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6509 | Intent dock = createHomeDockIntent(); |
| 6510 | if (dock != null) { |
| 6511 | int result = ActivityManagerNative.getDefault() |
| 6512 | .startActivityAsUser(null, null, dock, |
| 6513 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 6514 | null, null, 0, |
| 6515 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6516 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6517 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 6518 | return false; |
| 6519 | } |
| 6520 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6521 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6522 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6523 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6524 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6525 | null, null, 0, |
| 6526 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6527 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6528 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6529 | return false; |
| 6530 | } |
| 6531 | } catch (RemoteException ex) { |
| 6532 | // bummer, the activity manager, which is in this process, is dead |
| 6533 | } |
| 6534 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6535 | return true; |
| 6536 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6537 | |
| 6538 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6539 | public void setCurrentOrientationLw(int newOrientation) { |
| 6540 | synchronized (mLock) { |
| 6541 | if (newOrientation != mCurrentAppOrientation) { |
| 6542 | mCurrentAppOrientation = newOrientation; |
| 6543 | updateOrientationListenerLp(); |
| 6544 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6545 | } |
| 6546 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6547 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6548 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 6549 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 6550 | return; |
| 6551 | } |
| 6552 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 6553 | Context.AUDIO_SERVICE); |
| 6554 | if (audioManager.isSilentMode()) { |
| 6555 | return; |
| 6556 | } |
| 6557 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 6558 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 6559 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 6560 | ringTone.play(); |
| 6561 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6562 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 6563 | private boolean isTheaterModeEnabled() { |
| 6564 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6565 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 6566 | } |
| 6567 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6568 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 6569 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6570 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 6571 | } |
| 6572 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6573 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6574 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 6575 | if (!mVibrator.hasVibrator()) { |
| 6576 | return false; |
| 6577 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6578 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 6579 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 6580 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6581 | return false; |
| 6582 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6583 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6584 | switch (effectId) { |
| 6585 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6586 | pattern = mLongPressVibePattern; |
| 6587 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6588 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6589 | pattern = mVirtualKeyVibePattern; |
| 6590 | break; |
| 6591 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 6592 | pattern = mKeyboardTapVibePattern; |
| 6593 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 6594 | case HapticFeedbackConstants.CLOCK_TICK: |
| 6595 | pattern = mClockTickVibePattern; |
| 6596 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 6597 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 6598 | pattern = mCalendarDateVibePattern; |
| 6599 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6600 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6601 | pattern = mSafeModeDisabledVibePattern; |
| 6602 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6603 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6604 | pattern = mSafeModeEnabledVibePattern; |
| 6605 | break; |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 6606 | case HapticFeedbackConstants.CONTEXT_CLICK: |
| 6607 | pattern = mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 6608 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6609 | default: |
| 6610 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6611 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6612 | int owningUid; |
| 6613 | String owningPackage; |
| 6614 | if (win != null) { |
| 6615 | owningUid = win.getOwningUid(); |
| 6616 | owningPackage = win.getOwningPackage(); |
| 6617 | } else { |
| 6618 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 6619 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6620 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6621 | if (pattern.length == 1) { |
| 6622 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6623 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6624 | } else { |
| 6625 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6626 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6627 | } |
| 6628 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6629 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6630 | |
| 6631 | @Override |
| 6632 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 6633 | } |
| 6634 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6635 | @Override |
| 6636 | public void keepScreenOnStoppedLw() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6637 | if (isKeyguardShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 6638 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6639 | } |
| 6640 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 6641 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6642 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6643 | // If there is no window focused, there will be nobody to handle the events |
| 6644 | // 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] | 6645 | final WindowState win = mFocusedWindow != null ? mFocusedWindow |
| 6646 | : mTopFullscreenOpaqueWindowState; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6647 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6648 | return 0; |
| 6649 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6650 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6651 | // We are updating at a point where the keyguard has gotten |
| 6652 | // focus, but we were last in a state where the top window is |
| 6653 | // hiding it. This is probably because the keyguard as been |
| 6654 | // shown while the top window was displayed, so we want to ignore |
| 6655 | // it here because this is just a very transient change and it |
| 6656 | // will quickly lose focus once it correctly gets hidden. |
| 6657 | return 0; |
| 6658 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 6659 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 6660 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6661 | & ~mResettingSystemUiFlags |
| 6662 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6663 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6664 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6665 | } |
Thanh Hai Mai | 6c009f5 | 2015-09-01 16:27:32 -0700 | [diff] [blame] | 6666 | |
| 6667 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 6668 | tmpVisibility |= StatusBarManager.DISABLE_RECENT; |
| 6669 | } |
| 6670 | |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6671 | tmpVisibility = updateLightStatusBarLw(tmpVisibility); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6672 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6673 | final int diff = visibility ^ mLastSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6674 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 6675 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6676 | && mFocusedApp == win.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6677 | return 0; |
| 6678 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6679 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6680 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6681 | mFocusedApp = win.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6682 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6683 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6684 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6685 | try { |
| 6686 | IStatusBarService statusbar = getStatusBarService(); |
| 6687 | if (statusbar != null) { |
Adrian Roos | 53f28ec | 2014-10-29 17:26:12 +0100 | [diff] [blame] | 6688 | statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString()); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6689 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6690 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6691 | } catch (RemoteException e) { |
| 6692 | // re-acquire status bar service next time it is needed. |
| 6693 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6694 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6695 | } |
| 6696 | }); |
| 6697 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6698 | } |
| 6699 | |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6700 | private int updateLightStatusBarLw(int vis) { |
| 6701 | WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6702 | ? mStatusBar |
| 6703 | : mTopFullscreenOpaqueOrDimmingWindowState; |
| 6704 | |
| 6705 | if (statusColorWin != null) { |
| 6706 | if (statusColorWin == mTopFullscreenOpaqueWindowState) { |
| 6707 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 6708 | // its light flag. |
| 6709 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6710 | vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) |
| 6711 | & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6712 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 6713 | // Otherwise if it's dimming, clear the light flag. |
| 6714 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6715 | } |
| 6716 | } |
| 6717 | return vis; |
| 6718 | } |
| 6719 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6720 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6721 | final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID); |
| 6722 | final boolean freeformStackVisible = |
| 6723 | mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID); |
| 6724 | final boolean forceShowSystemBars = dockedStackVisible || freeformStackVisible; |
| 6725 | // TODO(multi-window): Update to force opaque independently for status bar and nav bar. |
| 6726 | // This will require refactoring the code to have separate vis flag for each bar so it can |
| 6727 | // be adjusted independently. |
| 6728 | final boolean forceOpaqueSystemBars = forceShowSystemBars; |
| 6729 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6730 | // apply translucent bar vis flags |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6731 | WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6732 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6733 | : mTopFullscreenOpaqueWindowState; |
| 6734 | vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6735 | vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6736 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6737 | // prevent status bar interaction from clearing certain flags |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 6738 | int type = win.getAttrs().type; |
| 6739 | boolean statusBarHasFocus = type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6740 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6741 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 6742 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 6743 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 73fef8d | 2015-02-16 17:32:28 +0100 | [diff] [blame] | 6744 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 6745 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6746 | if (mHideLockScreen) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 6747 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 6748 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6749 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6750 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6751 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6752 | if ((!areTranslucentBarsAllowed() && transWin != mStatusBar) |
| 6753 | || forceOpaqueSystemBars) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 6754 | vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT |
| 6755 | | View.SYSTEM_UI_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6756 | } |
| 6757 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6758 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6759 | boolean immersiveSticky = |
| 6760 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6761 | final boolean hideStatusBarWM = |
| 6762 | mTopFullscreenOpaqueWindowState != null |
| 6763 | && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6764 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6765 | final boolean hideStatusBarSysui = |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6766 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6767 | final boolean hideNavBarSysui = |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6768 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6769 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6770 | final boolean transientStatusBarAllowed = mStatusBar != null |
| 6771 | && (statusBarHasFocus || (!forceShowSystemBars |
| 6772 | && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky)))); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6773 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6774 | final boolean transientNavBarAllowed = mNavigationBar != null |
| 6775 | && !forceShowSystemBars && hideNavBarSysui && immersiveSticky; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6776 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6777 | final long now = SystemClock.uptimeMillis(); |
| 6778 | final boolean pendingPanic = mPendingPanicGestureUptime != 0 |
| 6779 | && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION; |
| 6780 | if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) { |
| 6781 | // The user performed the panic gesture recently, we're about to hide the bars, |
| 6782 | // we're no longer on the Keyguard and the screen is ready. We can now request the bars. |
| 6783 | mPendingPanicGestureUptime = 0; |
| 6784 | mStatusBarController.showTransient(); |
| 6785 | mNavigationBarController.showTransient(); |
| 6786 | } |
| 6787 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6788 | final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6789 | && !transientStatusBarAllowed && hideStatusBarSysui; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6790 | final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6791 | && !transientNavBarAllowed; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6792 | if (denyTransientStatus || denyTransientNav || forceShowSystemBars) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6793 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6794 | clearClearableFlagsLw(); |
tiger_huang | c58d756 | 2014-10-23 20:24:19 +0800 | [diff] [blame] | 6795 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6796 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6797 | |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 6798 | final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 6799 | immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 6800 | final boolean navAllowedHidden = immersive || immersiveSticky; |
| 6801 | |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 6802 | if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType()) |
| 6803 | > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) { |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 6804 | // We can't hide the navbar from this window otherwise the input consumer would not get |
| 6805 | // the input events. |
| 6806 | vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); |
| 6807 | } |
| 6808 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6809 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 6810 | |
| 6811 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6812 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 6813 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 6814 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6815 | final String pkg = win.getOwningPackage(); |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 6816 | mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode, |
| 6817 | isUserSetupComplete()); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6818 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6819 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6820 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 6821 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6822 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6823 | } |
| 6824 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6825 | private void clearClearableFlagsLw() { |
| 6826 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 6827 | if (newVal != mResettingSystemUiFlags) { |
| 6828 | mResettingSystemUiFlags = newVal; |
| 6829 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 6830 | } |
| 6831 | } |
| 6832 | |
| 6833 | private boolean isImmersiveMode(int vis) { |
| 6834 | 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] | 6835 | return mNavigationBar != null |
| 6836 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 6837 | && (vis & flags) != 0 |
| 6838 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6839 | } |
| 6840 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6841 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6842 | * @return whether the navigation or status bar can be made translucent |
| 6843 | * |
| 6844 | * This should return true unless touch exploration is not enabled or |
| 6845 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6846 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6847 | private boolean areTranslucentBarsAllowed() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 6848 | return mTranslucentDecorEnabled; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6849 | } |
| 6850 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6851 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 6852 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6853 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6854 | public boolean hasNavigationBar() { |
| 6855 | return mHasNavigationBar; |
| 6856 | } |
| 6857 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 6858 | @Override |
| 6859 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 6860 | mLastInputMethodWindow = ime; |
| 6861 | mLastInputMethodTargetWindow = target; |
| 6862 | } |
| 6863 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6864 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 6865 | public int getInputMethodWindowVisibleHeightLw() { |
| 6866 | return mDockBottom - mCurBottom; |
| 6867 | } |
| 6868 | |
| 6869 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6870 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6871 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6872 | if (mKeyguardDelegate != null) { |
| 6873 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6874 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 6875 | if (mStatusBarService != null) { |
| 6876 | try { |
| 6877 | mStatusBarService.setCurrentUser(newUserId); |
| 6878 | } catch (RemoteException e) { |
| 6879 | // oh well |
| 6880 | } |
| 6881 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6882 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6883 | } |
| 6884 | |
| 6885 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 6886 | public boolean canMagnifyWindow(int windowType) { |
| 6887 | switch (windowType) { |
| 6888 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 6889 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 6890 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 6891 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 6892 | return false; |
| 6893 | } |
| 6894 | } |
| 6895 | return true; |
| 6896 | } |
| 6897 | |
| 6898 | @Override |
| 6899 | public boolean isTopLevelWindow(int windowType) { |
| 6900 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 6901 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 6902 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 6903 | } |
| 6904 | return true; |
| 6905 | } |
| 6906 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 6907 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 6908 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6909 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6910 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 6911 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 6912 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6913 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 6914 | pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6915 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6916 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 6917 | || mForceClearedSystemUiFlags != 0) { |
| 6918 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 6919 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 6920 | pw.print(" mResettingSystemUiFlags=0x"); |
| 6921 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 6922 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 6923 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6924 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6925 | if (mLastFocusNeedsMenu) { |
| 6926 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 6927 | pw.println(mLastFocusNeedsMenu); |
| 6928 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6929 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 6930 | pw.println(mWakeGestureEnabledSetting); |
| 6931 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 6932 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6933 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 6934 | pw.print(" mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6935 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 6936 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 6937 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 6938 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6939 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6940 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6941 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 6942 | pw.print(mCarDockEnablesAccelerometer); |
| 6943 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 6944 | pw.println(mDeskDockEnablesAccelerometer); |
| 6945 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 6946 | pw.print(mLidKeyboardAccessibility); |
| 6947 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6948 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6949 | pw.print(prefix); |
| 6950 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 6951 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6952 | pw.print(prefix); |
| 6953 | pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); |
| 6954 | pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6955 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6956 | pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); |
| 6957 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 6958 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 6959 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 6960 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 6961 | pw.print(prefix); pw.print("mOrientationSensorEnabled="); |
| 6962 | pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 6963 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 6964 | pw.print(","); pw.print(mOverscanScreenTop); |
| 6965 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 6966 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 6967 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 6968 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 6969 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 6970 | pw.print(" top="); pw.print(mOverscanTop); |
| 6971 | pw.print(" right="); pw.print(mOverscanRight); |
| 6972 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 6973 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 6974 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 6975 | pw.print(mRestrictedOverscanScreenLeft); |
| 6976 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 6977 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 6978 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6979 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 6980 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 6981 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 6982 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 6983 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 6984 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 6985 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 6986 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 6987 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 6988 | pw.print(","); pw.print(mStableFullscreenTop); |
| 6989 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 6990 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6991 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 6992 | pw.print(","); pw.print(mStableTop); |
| 6993 | pw.print(")-("); pw.print(mStableRight); |
| 6994 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 6995 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 6996 | pw.print(","); pw.print(mSystemTop); |
| 6997 | pw.print(")-("); pw.print(mSystemRight); |
| 6998 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6999 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 7000 | pw.print(","); pw.print(mCurTop); |
| 7001 | pw.print(")-("); pw.print(mCurRight); |
| 7002 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 7003 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 7004 | pw.print(","); pw.print(mContentTop); |
| 7005 | pw.print(")-("); pw.print(mContentRight); |
| 7006 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 7007 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 7008 | pw.print(","); pw.print(mVoiceContentTop); |
| 7009 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 7010 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7011 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 7012 | pw.print(","); pw.print(mDockTop); |
| 7013 | pw.print(")-("); pw.print(mDockRight); |
| 7014 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 7015 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 7016 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 7017 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 7018 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 7019 | pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); |
| 7020 | pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7021 | if (mLastInputMethodWindow != null) { |
| 7022 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 7023 | pw.println(mLastInputMethodWindow); |
| 7024 | } |
| 7025 | if (mLastInputMethodTargetWindow != null) { |
| 7026 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 7027 | pw.println(mLastInputMethodTargetWindow); |
| 7028 | } |
| 7029 | if (mStatusBar != null) { |
| 7030 | pw.print(prefix); pw.print("mStatusBar="); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 7031 | pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); |
| 7032 | pw.println(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7033 | } |
| 7034 | if (mNavigationBar != null) { |
| 7035 | pw.print(prefix); pw.print("mNavigationBar="); |
| 7036 | pw.println(mNavigationBar); |
| 7037 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7038 | if (mFocusedWindow != null) { |
| 7039 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 7040 | pw.println(mFocusedWindow); |
| 7041 | } |
| 7042 | if (mFocusedApp != null) { |
| 7043 | pw.print(prefix); pw.print("mFocusedApp="); |
| 7044 | pw.println(mFocusedApp); |
| 7045 | } |
| 7046 | if (mWinDismissingKeyguard != null) { |
| 7047 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 7048 | pw.println(mWinDismissingKeyguard); |
| 7049 | } |
| 7050 | if (mTopFullscreenOpaqueWindowState != null) { |
| 7051 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 7052 | pw.println(mTopFullscreenOpaqueWindowState); |
| 7053 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7054 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 7055 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 7056 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 7057 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 7058 | if (mForcingShowNavBar) { |
| 7059 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 7060 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 7061 | pw.println(mForcingShowNavBarLayer); |
| 7062 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 7063 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7064 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 7065 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 7066 | pw.print(" mForceStatusBarFromKeyguard="); |
| 7067 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7068 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 7069 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7070 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 7071 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 7072 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 7073 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 7074 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 7075 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 7076 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 7077 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 7078 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 7079 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 7080 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 7081 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 7082 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 7083 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 7084 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 7085 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7086 | mStatusBarController.dump(pw, prefix); |
| 7087 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 7088 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 7089 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 7090 | if (mWakeGestureListener != null) { |
| 7091 | mWakeGestureListener.dump(pw, prefix); |
| 7092 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 7093 | if (mOrientationListener != null) { |
| 7094 | mOrientationListener.dump(pw, prefix); |
| 7095 | } |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 7096 | if (mBurnInProtectionHelper != null) { |
| 7097 | mBurnInProtectionHelper.dump(prefix, pw); |
| 7098 | } |
Jorim Jaggi | 84dc08a | 2015-09-11 17:45:22 -0700 | [diff] [blame] | 7099 | if (mKeyguardDelegate != null) { |
| 7100 | mKeyguardDelegate.dump(prefix, pw); |
| 7101 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7102 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7103 | } |