The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2 | * |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package com.android.internal.policy.impl; |
| 17 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 18 | import android.app.ActivityManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 19 | import android.app.ActivityManagerNative; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 20 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 21 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 22 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 23 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 24 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 25 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 26 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 27 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 28 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 29 | import android.content.ContentResolver; |
| 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 32 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 33 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 34 | import android.content.pm.ActivityInfo; |
| 35 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 36 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 37 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 38 | import android.content.res.Configuration; |
| 39 | import android.content.res.Resources; |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 40 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 41 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 42 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 43 | import android.graphics.Rect; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 44 | import android.media.AudioAttributes; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 45 | import android.media.AudioManager; |
| 46 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 47 | import android.media.Ringtone; |
| 48 | import android.media.RingtoneManager; |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 49 | import android.media.session.MediaController; |
| 50 | import android.media.session.MediaSession; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 51 | import android.media.session.MediaSessionLegacyHelper; |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 52 | import android.media.session.MediaSessionManager; |
| 53 | import android.media.session.PlaybackState; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 54 | import android.os.Bundle; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 55 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 56 | import android.os.Handler; |
| 57 | import android.os.IBinder; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 58 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 59 | import android.os.Message; |
| 60 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 61 | import android.os.PowerManager; |
| 62 | import android.os.RemoteException; |
| 63 | import android.os.ServiceManager; |
| 64 | import android.os.SystemClock; |
| 65 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 66 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 67 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 68 | import android.os.Vibrator; |
| 69 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 70 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 71 | import android.service.dreams.DreamService; |
| 72 | import android.service.dreams.IDreamManager; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 73 | import android.speech.RecognizerIntent; |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 74 | import android.telecomm.TelecommManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 75 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 76 | import android.util.EventLog; |
| 77 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 78 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 79 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 80 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 81 | import android.view.Gravity; |
| 82 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 83 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 84 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 85 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 86 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 87 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 88 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 89 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 90 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 91 | import android.view.KeyEvent; |
| 92 | import android.view.MotionEvent; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 93 | import android.view.Surface; |
| 94 | import android.view.View; |
| 95 | import android.view.ViewConfiguration; |
| 96 | import android.view.Window; |
| 97 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 98 | import android.view.WindowManagerGlobal; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 99 | import android.view.WindowManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 100 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 101 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 102 | import android.view.accessibility.AccessibilityManager; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 103 | import android.view.animation.AlphaAnimation; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 104 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 105 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 106 | import android.view.animation.AnimationUtils; |
| 107 | |
| 108 | import com.android.internal.R; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 109 | import com.android.internal.policy.IKeyguardService; |
| 110 | import com.android.internal.policy.IKeyguardServiceConstants; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 111 | import com.android.internal.policy.PolicyManager; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 112 | import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 113 | import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 114 | import com.android.internal.statusbar.IStatusBarService; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 115 | import com.android.internal.widget.PointerLocationView; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 116 | import com.android.server.LocalServices; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 117 | |
| 118 | import java.io.File; |
| 119 | import java.io.FileReader; |
| 120 | import java.io.IOException; |
| 121 | import java.io.PrintWriter; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 122 | import java.util.ArrayList; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 123 | import java.util.HashSet; |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 124 | import java.util.List; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 125 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 126 | import static android.view.WindowManager.LayoutParams.*; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 127 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 128 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
| 129 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 130 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 131 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 132 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 133 | * introduces a new method suffix, Lp, for an internal lock of the |
| 134 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 135 | * 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] | 136 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 137 | */ |
| 138 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 139 | static final String TAG = "WindowManager"; |
| 140 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 141 | static final boolean localLOGV = false; |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 142 | static final boolean DEBUG_LAYOUT = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 143 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 144 | static final boolean DEBUG_STARTING_WINDOW = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 145 | static final boolean DEBUG_WAKEUP = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 146 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 147 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 148 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 149 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 150 | // No longer recommended for desk docks; still useful in car docks. |
| 151 | static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true; |
| 152 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 153 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 154 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 155 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 156 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 157 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3; |
| 158 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 159 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 160 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 161 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 162 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 163 | |
| 164 | // These need to match the documentation/constant in |
| 165 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 166 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 167 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 168 | static final int LONG_PRESS_HOME_ASSIST = 2; |
| 169 | |
| 170 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 171 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 172 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 173 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 174 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 175 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 176 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 177 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 178 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 179 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 180 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 181 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 182 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 183 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 184 | /** |
| 185 | * These are the system UI flags that, when changing, can cause the layout |
| 186 | * of the screen to change. |
| 187 | */ |
| 188 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 189 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 190 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 191 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 192 | | View.NAVIGATION_BAR_TRANSLUCENT |
| 193 | | View.SYSTEM_UI_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 194 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 195 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 196 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 197 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 198 | .build(); |
| 199 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 200 | /** |
| 201 | * Keyguard stuff |
| 202 | */ |
| 203 | private WindowState mKeyguardScrim; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 204 | private boolean mKeyguardHidden; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 205 | private boolean mKeyguardDrawn; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 206 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 207 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 208 | * |
| 209 | * These are special keys that are used to launch particular kinds of applications, |
| 210 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 211 | * usage page. We don't support quite that many yet... |
| 212 | */ |
| 213 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 214 | static { |
| 215 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 216 | sApplicationLaunchKeyCategories.append( |
| 217 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 218 | sApplicationLaunchKeyCategories.append( |
| 219 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 220 | sApplicationLaunchKeyCategories.append( |
| 221 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 222 | sApplicationLaunchKeyCategories.append( |
| 223 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 224 | sApplicationLaunchKeyCategories.append( |
| 225 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 226 | sApplicationLaunchKeyCategories.append( |
| 227 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 228 | } |
| 229 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 230 | /** |
| 231 | * Lock protecting internal state. Must not call out into window |
| 232 | * manager with lock held. (This lock will be acquired in places |
| 233 | * where the window manager is calling in with its own lock held.) |
| 234 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 235 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 236 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 237 | Context mContext; |
| 238 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 239 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 240 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 241 | PowerManager mPowerManager; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 242 | DreamManagerInternal mDreamManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 243 | IStatusBarService mStatusBarService; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 244 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 245 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 246 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 247 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 248 | AccessibilityManager mAccessibilityManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 249 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 250 | // Vibrator pattern for haptic feedback of a long press. |
| 251 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 252 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 253 | // Vibrator pattern for haptic feedback of virtual key press. |
| 254 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 255 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 256 | // Vibrator pattern for a short vibration. |
| 257 | long[] mKeyboardTapVibePattern; |
| 258 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 259 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 260 | long[] mClockTickVibePattern; |
| 261 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 262 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 263 | long[] mCalendarDateVibePattern; |
| 264 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 265 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 266 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 267 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 268 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 269 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 270 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 271 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 272 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 273 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 274 | boolean mSafeMode; |
| 275 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 276 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 277 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 278 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 279 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 280 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 281 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
| 282 | int[] mNavigationBarHeightForRotation = new int[4]; |
| 283 | int[] mNavigationBarWidthForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 284 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 285 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 286 | KeyguardServiceDelegate mKeyguardDelegate; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 287 | // The following are only accessed on the mHandler thread. |
| 288 | boolean mKeyguardDrawComplete; |
| 289 | boolean mWindowManagerDrawComplete; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 290 | ScreenOnListener mScreenOnListener; |
| 291 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 292 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 293 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 294 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 295 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 296 | } |
| 297 | }; |
| 298 | final ShowListener mKeyguardDelegateCallback = new ShowListener() { |
| 299 | @Override |
| 300 | public void onShown(IBinder windowToken) { |
| 301 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown."); |
| 302 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 303 | } |
| 304 | }; |
| 305 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 306 | GlobalActions mGlobalActions; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 307 | volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread |
| 308 | boolean mPendingPowerKeyUpCanceled; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 309 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 310 | WindowState mLastInputMethodWindow = null; |
| 311 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 312 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 313 | boolean mRecentsVisible; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 314 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 315 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 316 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 317 | int mLidState = LID_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 318 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 319 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 320 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 321 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 322 | boolean mHdmiPlugged; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 323 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 324 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 325 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 326 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 327 | int mCarDockRotation; |
| 328 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 329 | int mUndockedHdmiRotation; |
| 330 | int mDemoHdmiRotation; |
| 331 | boolean mDemoHdmiRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 332 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 333 | boolean mWakeGestureEnabledSetting; |
| 334 | MyWakeGestureListener mWakeGestureListener; |
| 335 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 336 | // Default display does not rotate, apps that require non-default orientation will have to |
| 337 | // have the orientation emulated. |
| 338 | private boolean mForceDefaultOrientation = false; |
| 339 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 340 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 341 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 342 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 343 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 344 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 345 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 346 | boolean mCarDockEnablesAccelerometer; |
| 347 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 348 | int mLidKeyboardAccessibility; |
| 349 | int mLidNavigationAccessibility; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 350 | boolean mLidControlsSleep; |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 351 | int mShortPressOnPowerBehavior = -1; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 352 | int mLongPressOnPowerBehavior = -1; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 353 | boolean mScreenOnEarly = false; |
| 354 | boolean mScreenOnFully = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 355 | boolean mOrientationSensorEnabled = false; |
| 356 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 357 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 358 | boolean mTranslucentDecorEnabled = true; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 359 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 360 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 361 | |
| 362 | // The last window we were told about in focusChanged. |
| 363 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 364 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 365 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 366 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 367 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 368 | // The current size of the screen; really; extends into the overscan area of |
| 369 | // the screen and doesn't account for any system elements like the status bar. |
| 370 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 371 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 372 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 373 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 374 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 375 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 376 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 377 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 378 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 379 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 380 | // if the status bar can't be hidden; in that case it effectively carves out |
| 381 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 382 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 383 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 384 | // During layout, the current screen borders accounting for any currently |
| 385 | // visible system UI elements. |
| 386 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 387 | // For applications requesting stable content insets, these are them. |
| 388 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 389 | // For applications requesting stable content insets but have also set the |
| 390 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 391 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 392 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 393 | // During layout, the current screen borders with all outer decoration |
| 394 | // (status bar, input method dock) accounted for. |
| 395 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 396 | // During layout, the frame in which content should be displayed |
| 397 | // to the user, accounting for all screen decoration except for any |
| 398 | // space they deem as available for other content. This is usually |
| 399 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 400 | // content insets. |
| 401 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 402 | // During layout, the frame in which voice content should be displayed |
| 403 | // to the user, accounting for all screen decoration except for any |
| 404 | // space they deem as available for other content. |
| 405 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 406 | // 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] | 407 | // windows are placed. |
| 408 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 409 | // During layout, the layer at which the doc window is placed. |
| 410 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 411 | // During layout, this is the layer of the status bar. |
| 412 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 413 | int mLastSystemUiFlags; |
| 414 | // Bits that we are in the process of clearing, so we want to prevent |
| 415 | // them from being set by applications until everything has been updated |
| 416 | // to have them clear. |
| 417 | int mResettingSystemUiFlags = 0; |
| 418 | // Bits that we are currently always keeping cleared. |
| 419 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 420 | // What we last reported to system UI about whether the compatibility |
| 421 | // menu needs to be displayed. |
| 422 | boolean mLastFocusNeedsMenu = false; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 423 | |
| 424 | FakeWindow mHideNavFakeWindow = null; |
| 425 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 426 | static final Rect mTmpParentFrame = new Rect(); |
| 427 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 428 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 429 | static final Rect mTmpContentFrame = new Rect(); |
| 430 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 431 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 432 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 433 | static final Rect mTmpNavigationFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 434 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 435 | WindowState mTopFullscreenOpaqueWindowState; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 436 | HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 437 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 438 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 439 | boolean mForceStatusBarFromKeyguard; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 440 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 441 | boolean mForcingShowNavBar; |
| 442 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 443 | |
| 444 | // States of keyguard dismiss. |
| 445 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 446 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 447 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 448 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 449 | |
| 450 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 451 | * be done once per window. */ |
| 452 | private WindowState mWinDismissingKeyguard; |
| 453 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 454 | /** The window that is currently showing "over" the keyguard. If there is an app window |
| 455 | * belonging to another app on top of this the keyguard shows. If there is a fullscreen |
| 456 | * app window under this, still dismiss the keyguard but don't show the app underneath. Show |
| 457 | * the wallpaper. */ |
| 458 | private WindowState mWinShowWhenLocked; |
| 459 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 460 | boolean mShowingLockscreen; |
| 461 | boolean mShowingDream; |
| 462 | boolean mDreamingLockscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 463 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 464 | boolean mHomeConsumed; |
| 465 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 466 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 467 | Intent mCarDockIntent; |
| 468 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 469 | boolean mSearchKeyShortcutPending; |
| 470 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 471 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 472 | boolean mPendingMetaAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 473 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 474 | // support for activating the lock screen while the screen is on |
| 475 | boolean mAllowLockscreenWhenOn; |
| 476 | int mLockScreenTimeout; |
| 477 | boolean mLockScreenTimerActive; |
| 478 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 479 | // 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] | 480 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 481 | |
| 482 | // Behavior of POWER button while in-call and screen on. |
| 483 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 484 | int mIncallPowerBehavior; |
| 485 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 486 | Display mDisplay; |
| 487 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 488 | int mLandscapeRotation = 0; // default landscape rotation |
| 489 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 490 | int mPortraitRotation = 0; // default portrait rotation |
| 491 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 492 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 493 | int mOverscanLeft = 0; |
| 494 | int mOverscanTop = 0; |
| 495 | int mOverscanRight = 0; |
| 496 | int mOverscanBottom = 0; |
| 497 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 498 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 499 | private int mLongPressOnHomeBehavior; |
| 500 | |
| 501 | // What we do when the user double-taps on home |
| 502 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 503 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 504 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 505 | // Time to volume and power must be pressed within this interval of each other. |
| 506 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 507 | // Increase the chord delay when taking a screenshot from the keyguard |
| 508 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 509 | private boolean mScreenshotChordEnabled; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 510 | private boolean mVolumeDownKeyTriggered; |
| 511 | private long mVolumeDownKeyTime; |
| 512 | private boolean mVolumeDownKeyConsumedByScreenshotChord; |
| 513 | private boolean mVolumeUpKeyTriggered; |
| 514 | private boolean mPowerKeyTriggered; |
| 515 | private long mPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 516 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 517 | /* The number of steps between min and max brightness */ |
| 518 | private static final int BRIGHTNESS_STEPS = 10; |
| 519 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 520 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 521 | ShortcutManager mShortcutManager; |
| 522 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 523 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 524 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 525 | private int mCurrentUserId; |
| 526 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 527 | // Maps global key codes to the components that will handle them. |
| 528 | private GlobalKeyManager mGlobalKeyManager; |
| 529 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 530 | // Fallback actions by key code. |
| 531 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 532 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 533 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 534 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 535 | = new LogDecelerateInterpolator(100, 0); |
| 536 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 537 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 538 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 539 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 540 | 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] | 541 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 542 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 543 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
| 544 | private static final int MSG_WAKING_UP = 8; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 545 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 546 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 547 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 548 | |
| 549 | private class PolicyHandler extends Handler { |
| 550 | @Override |
| 551 | public void handleMessage(Message msg) { |
| 552 | switch (msg.what) { |
| 553 | case MSG_ENABLE_POINTER_LOCATION: |
| 554 | enablePointerLocation(); |
| 555 | break; |
| 556 | case MSG_DISABLE_POINTER_LOCATION: |
| 557 | disablePointerLocation(); |
| 558 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 559 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 560 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 561 | break; |
| 562 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 563 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 564 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 565 | case MSG_DISPATCH_SHOW_RECENTS: |
| 566 | showRecentApps(false); |
| 567 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 568 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 569 | showGlobalActionsInternal(); |
| 570 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 571 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 572 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
| 573 | mKeyguardDrawComplete = true; |
| 574 | finishScreenTurningOn(); |
| 575 | break; |
| 576 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 577 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
| 578 | mKeyguardDrawComplete = true; |
| 579 | finishScreenTurningOn(); |
| 580 | break; |
| 581 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 582 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
| 583 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 584 | mWindowManagerDrawComplete = true; |
| 585 | finishScreenTurningOn(); |
| 586 | break; |
| 587 | case MSG_WAKING_UP: |
| 588 | handleWakingUp((ScreenOnListener) msg.obj); |
| 589 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 590 | case MSG_HIDE_BOOT_MESSAGE: |
| 591 | handleHideBootMessage(); |
| 592 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | } |
| 596 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 597 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 598 | @Override |
| 599 | public void onUEvent(UEventObserver.UEvent event) { |
| 600 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 601 | } |
| 602 | }; |
| 603 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 604 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 605 | SettingsObserver(Handler handler) { |
| 606 | super(handler); |
| 607 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 608 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 609 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 610 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 611 | ContentResolver resolver = mContext.getContentResolver(); |
| 612 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 613 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 614 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 615 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 616 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 617 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 618 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 619 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 620 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 621 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 622 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 623 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 624 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 625 | Settings.System.USER_ROTATION), false, this, |
| 626 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 627 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 628 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 629 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 630 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 631 | Settings.System.POINTER_LOCATION), false, this, |
| 632 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 633 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 634 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 635 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 636 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 637 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 638 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 639 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 640 | Settings.Global.POLICY_CONTROL), false, this, |
| 641 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 642 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 646 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 647 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 648 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 649 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 650 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 651 | class MyWakeGestureListener extends WakeGestureListener { |
| 652 | MyWakeGestureListener(Context context, Handler handler) { |
| 653 | super(context, handler); |
| 654 | } |
| 655 | |
| 656 | @Override |
| 657 | public void onWakeUp() { |
| 658 | synchronized (mLock) { |
| 659 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 660 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 661 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
| 662 | } |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 667 | class MyOrientationListener extends WindowOrientationListener { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 668 | MyOrientationListener(Context context, Handler handler) { |
| 669 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 670 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 671 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 672 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 673 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 674 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 675 | updateRotation(false); |
| 676 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 677 | } |
| 678 | MyOrientationListener mOrientationListener; |
| 679 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 680 | private final BarController mStatusBarController = new BarController("StatusBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 681 | View.STATUS_BAR_TRANSIENT, |
| 682 | View.STATUS_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 683 | View.STATUS_BAR_TRANSLUCENT, |
| 684 | StatusBarManager.WINDOW_STATUS_BAR, |
| 685 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 686 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 687 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 688 | View.NAVIGATION_BAR_TRANSIENT, |
| 689 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 690 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 691 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
| 692 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 693 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 694 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 695 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 696 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 697 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 698 | IStatusBarService getStatusBarService() { |
| 699 | synchronized (mServiceAquireLock) { |
| 700 | if (mStatusBarService == null) { |
| 701 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 702 | ServiceManager.getService("statusbar")); |
| 703 | } |
| 704 | return mStatusBarService; |
| 705 | } |
| 706 | } |
| 707 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 708 | /* |
| 709 | * We always let the sensor be switched on by default except when |
| 710 | * the user has explicitly disabled sensor based rotation or when the |
| 711 | * screen is switched off. |
| 712 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 713 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 714 | if (mSupportAutoRotation) { |
| 715 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 716 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 717 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 718 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 719 | // If the application has explicitly requested to follow the |
| 720 | // orientation, then we need to turn the sensor on. |
| 721 | return true; |
| 722 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 723 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 724 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 725 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 726 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 727 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 728 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 729 | // orientation management, |
| 730 | return true; |
| 731 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 732 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 733 | // If the setting for using the sensor by default is enabled, then |
| 734 | // we will always leave it on. Note that the user could go to |
| 735 | // a window that forces an orientation that does not use the |
| 736 | // sensor and in theory we could turn it off... however, when next |
| 737 | // turning it on we won't have a good value for the current |
| 738 | // orientation for a little bit, which can cause orientation |
| 739 | // changes to lag, so we'd like to keep it always on. (It will |
| 740 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 741 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 742 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 743 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 744 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 745 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 746 | /* |
| 747 | * Various use cases for invoking this function |
| 748 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 749 | * 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] | 750 | * if not already enabled |
| 751 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 752 | * already enabled |
| 753 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 754 | * screen turning on and current app has nosensor based orientation, do nothing |
| 755 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 756 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 757 | if (!mOrientationListener.canDetectOrientation()) { |
| 758 | // If sensor is turned off or nonexistent for some reason |
| 759 | return; |
| 760 | } |
| 761 | //Could have been invoked due to screen turning on or off or |
| 762 | //change of the currently visible window's orientation |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 763 | if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 764 | ", current orientation="+mCurrentAppOrientation+ |
| 765 | ", SensorEnabled="+mOrientationSensorEnabled); |
| 766 | boolean disable = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 767 | if (mScreenOnEarly) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 768 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 769 | disable = false; |
| 770 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 771 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 772 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 773 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 774 | mOrientationSensorEnabled = true; |
| 775 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 776 | } |
| 777 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 778 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 779 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 780 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 781 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 782 | mOrientationSensorEnabled = false; |
| 783 | } |
| 784 | } |
| 785 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 786 | private void interceptPowerKeyDown(boolean handled) { |
| 787 | mPowerKeyHandled = handled; |
| 788 | if (!handled) { |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 789 | mHandler.postDelayed(mPowerLongPress, |
| 790 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | |
| 794 | private boolean interceptPowerKeyUp(boolean canceled) { |
| 795 | if (!mPowerKeyHandled) { |
| 796 | mHandler.removeCallbacks(mPowerLongPress); |
| 797 | return !canceled; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 798 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 799 | return false; |
| 800 | } |
| 801 | |
| 802 | private void cancelPendingPowerKeyAction() { |
| 803 | if (!mPowerKeyHandled) { |
| 804 | mHandler.removeCallbacks(mPowerLongPress); |
| 805 | } |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 806 | if (mPowerKeyTriggered) { |
| 807 | mPendingPowerKeyUpCanceled = true; |
| 808 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 812 | if (mScreenshotChordEnabled |
| 813 | && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 814 | final long now = SystemClock.uptimeMillis(); |
| 815 | if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 816 | && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 817 | mVolumeDownKeyConsumedByScreenshotChord = true; |
| 818 | cancelPendingPowerKeyAction(); |
| 819 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 820 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 821 | } |
| 822 | } |
| 823 | } |
| 824 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 825 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 826 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 827 | // Double the time it takes to take a screenshot from the keyguard |
| 828 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 829 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 830 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 831 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 834 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 835 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 838 | private void powerShortPress(long eventTime) { |
| 839 | if (mShortPressOnPowerBehavior < 0) { |
| 840 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 841 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 842 | } |
| 843 | |
| 844 | switch (mShortPressOnPowerBehavior) { |
| 845 | case SHORT_PRESS_POWER_NOTHING: |
| 846 | break; |
| 847 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 848 | mPowerManager.goToSleep(eventTime, |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 849 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 850 | break; |
| 851 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 852 | mPowerManager.goToSleep(eventTime, |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 853 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 854 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 855 | break; |
| 856 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 857 | mPowerManager.goToSleep(eventTime, |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 858 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 859 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 860 | launchHomeFromHotKey(); |
| 861 | break; |
| 862 | } |
| 863 | } |
| 864 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 865 | private final Runnable mPowerLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 866 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 867 | public void run() { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 868 | // The context isn't read |
| 869 | if (mLongPressOnPowerBehavior < 0) { |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 870 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 871 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 872 | } |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 873 | int resolvedBehavior = mLongPressOnPowerBehavior; |
| 874 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 875 | resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 876 | } |
| 877 | |
| 878 | switch (resolvedBehavior) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 879 | case LONG_PRESS_POWER_NOTHING: |
| 880 | break; |
| 881 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 882 | mPowerKeyHandled = true; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 883 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 884 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 885 | } |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 886 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 887 | break; |
| 888 | case LONG_PRESS_POWER_SHUT_OFF: |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 889 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 890 | mPowerKeyHandled = true; |
| 891 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 892 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 893 | mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 894 | break; |
| 895 | } |
| 896 | } |
| 897 | }; |
| 898 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 899 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 900 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 901 | public void run() { |
| 902 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 903 | } |
| 904 | }; |
| 905 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 906 | @Override |
| 907 | public void showGlobalActions() { |
| 908 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 909 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 910 | } |
| 911 | |
| 912 | void showGlobalActionsInternal() { |
| 913 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 914 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 915 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 916 | } |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 917 | final boolean keyguardShowing = keyguardIsShowingTq(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 918 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 919 | if (keyguardShowing) { |
| 920 | // since it took two seconds of long press to bring this up, |
| 921 | // 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] | 922 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | |
| 926 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 927 | return Settings.Global.getInt( |
| 928 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 929 | } |
| 930 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 931 | boolean isUserSetupComplete() { |
| 932 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 933 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 934 | } |
| 935 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 936 | private void handleLongPressOnHome() { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 937 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 938 | mHomeConsumed = true; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 939 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 940 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 941 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
| 942 | toggleRecentApps(); |
| 943 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { |
| 944 | launchAssistAction(); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 945 | } |
| 946 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 947 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 948 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 949 | private void handleDoubleTapOnHome() { |
| 950 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 951 | mHomeConsumed = true; |
| 952 | toggleRecentApps(); |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 957 | @Override |
| 958 | public void run() { |
| 959 | if (mHomeDoubleTapPending) { |
| 960 | mHomeDoubleTapPending = false; |
| 961 | launchHomeFromHotKey(); |
| 962 | } |
| 963 | } |
| 964 | }; |
| 965 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 966 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 967 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 968 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 969 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 970 | mContext = context; |
| 971 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 972 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 973 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 974 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 975 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 976 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 977 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 978 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 979 | try { |
| 980 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 981 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 982 | mSettingsObserver = new SettingsObserver(mHandler); |
| 983 | mSettingsObserver.observe(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 984 | mShortcutManager = new ShortcutManager(context, mHandler); |
| 985 | mShortcutManager.observe(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 986 | mUiMode = context.getResources().getInteger( |
| 987 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 988 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 989 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 990 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 991 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 992 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 993 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 994 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 995 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 996 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 997 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 998 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 999 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1000 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1001 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1002 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1003 | "PhoneWindowManager.mBroadcastWakeLock"); |
| 1004 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1005 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1006 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1007 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1008 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1009 | mCarDockRotation = readRotation( |
| 1010 | com.android.internal.R.integer.config_carDockRotation); |
| 1011 | mDeskDockRotation = readRotation( |
| 1012 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1013 | mUndockedHdmiRotation = readRotation( |
| 1014 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1015 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1016 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1017 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1018 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1019 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1020 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1021 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1022 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1023 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1024 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1025 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1026 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1027 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1028 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1029 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1030 | Context.ACCESSIBILITY_SERVICE); |
| 1031 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1032 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1033 | IntentFilter filter = new IntentFilter(); |
| 1034 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1035 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1036 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1037 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1038 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1039 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1040 | if (intent != null) { |
| 1041 | // Retrieve current sticky dock event broadcast. |
| 1042 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1043 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1044 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1045 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1046 | // register for dream-related broadcasts |
| 1047 | filter = new IntentFilter(); |
| 1048 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1049 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1050 | context.registerReceiver(mDreamReceiver, filter); |
| 1051 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1052 | // register for multiuser-relevant broadcasts |
| 1053 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1054 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1055 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1056 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1057 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1058 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1059 | @Override |
| 1060 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1061 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1062 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1063 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1064 | } |
| 1065 | @Override |
| 1066 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1067 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1068 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | @Override |
| 1072 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1073 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1074 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | @Override |
| 1078 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1079 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1080 | } |
| 1081 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1082 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1083 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1084 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1085 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1086 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1087 | com.android.internal.R.array.config_longPressVibePattern); |
| 1088 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1089 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1090 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1091 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1092 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1093 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1094 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1095 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1096 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1097 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1098 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1099 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1100 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1101 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1102 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 1103 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1104 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1105 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1106 | // Controls rotation and the like. |
| 1107 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1108 | |
| 1109 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1110 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 140ffc7 | 2014-05-01 15:18:00 -0700 | [diff] [blame] | 1111 | goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1112 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1115 | /** |
| 1116 | * Read values from config.xml that may be overridden depending on |
| 1117 | * the configuration of the device. |
| 1118 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1119 | */ |
| 1120 | private void readConfigurationDependentBehaviors() { |
| 1121 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 1122 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1123 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 1124 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { |
| 1125 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1126 | } |
| 1127 | |
| 1128 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 1129 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1130 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1131 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1132 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1133 | } |
| 1134 | } |
| 1135 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1136 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1137 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1138 | // This method might be called before the policy has been fully initialized |
| 1139 | // or for other displays we don't care about. |
| 1140 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1141 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1142 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1143 | mDisplay = display; |
| 1144 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1145 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1146 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1147 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1148 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1149 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1150 | mLandscapeRotation = Surface.ROTATION_0; |
| 1151 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1152 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1153 | mPortraitRotation = Surface.ROTATION_90; |
| 1154 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1155 | } else { |
| 1156 | mPortraitRotation = Surface.ROTATION_270; |
| 1157 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1158 | } |
| 1159 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1160 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1161 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1162 | mPortraitRotation = Surface.ROTATION_0; |
| 1163 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1164 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1165 | mLandscapeRotation = Surface.ROTATION_270; |
| 1166 | mSeascapeRotation = Surface.ROTATION_90; |
| 1167 | } else { |
| 1168 | mLandscapeRotation = Surface.ROTATION_90; |
| 1169 | mSeascapeRotation = Surface.ROTATION_270; |
| 1170 | } |
| 1171 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1172 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1173 | mStatusBarHeight = |
| 1174 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1175 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1176 | // Height of the navigation bar when presented horizontally at bottom |
| 1177 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 1178 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1179 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1180 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1181 | mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1182 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1183 | |
| 1184 | // Width of the navigation bar when presented vertically along one side |
| 1185 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 1186 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 1187 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 1188 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1189 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1190 | |
| 1191 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1192 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1193 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1194 | |
Craig Mautner | d4ec3324 | 2013-07-22 10:37:43 -0700 | [diff] [blame] | 1195 | // Allow the navigation bar to move on small devices (phones). |
| 1196 | mNavigationBarCanMove = shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1197 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1198 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1199 | // Allow a system property to override this. Used by the emulator. |
| 1200 | // See also hasNavigationBar(). |
| 1201 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1202 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1203 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1204 | } else if ("0".equals(navBarOverride)) { |
| 1205 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1206 | } |
| 1207 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1208 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1209 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1210 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1211 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1212 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1213 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1214 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1215 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1216 | |
| 1217 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1218 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1219 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1220 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1221 | // For debug purposes the next line turns this feature off with: |
| 1222 | // $ adb shell setprop config.override_forced_orient true |
| 1223 | // $ adb shell wm size reset |
| 1224 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1225 | } |
| 1226 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1227 | /** |
| 1228 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1229 | * navigation bar and touch exploration is not enabled |
| 1230 | */ |
| 1231 | private boolean canHideNavigationBar() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1232 | return mHasNavigationBar |
| 1233 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1234 | } |
| 1235 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1236 | @Override |
| 1237 | public boolean isDefaultOrientationForced() { |
| 1238 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1241 | @Override |
| 1242 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1243 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1244 | mOverscanLeft = left; |
| 1245 | mOverscanTop = top; |
| 1246 | mOverscanRight = right; |
| 1247 | mOverscanBottom = bottom; |
| 1248 | } |
| 1249 | } |
| 1250 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1251 | public void updateSettings() { |
| 1252 | ContentResolver resolver = mContext.getContentResolver(); |
| 1253 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1254 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1255 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1256 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1257 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1258 | UserHandle.USER_CURRENT); |
| 1259 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1260 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1261 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1262 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1263 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1264 | // Configure wake gesture. |
| 1265 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 1266 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 1267 | UserHandle.USER_CURRENT) != 0; |
| 1268 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 1269 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 1270 | updateWakeGestureListenerLp(); |
| 1271 | } |
| 1272 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1273 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1274 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1275 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1276 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1277 | if (mUserRotation != userRotation) { |
| 1278 | mUserRotation = userRotation; |
| 1279 | updateRotation = true; |
| 1280 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1281 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1282 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1283 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1284 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1285 | if (mUserRotationMode != userRotationMode) { |
| 1286 | mUserRotationMode = userRotationMode; |
| 1287 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1288 | updateOrientationListenerLp(); |
| 1289 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1290 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1291 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1292 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1293 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1294 | if (mPointerLocationMode != pointerLocation) { |
| 1295 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1296 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1297 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1298 | } |
| 1299 | } |
| 1300 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1301 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1302 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1303 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1304 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1305 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1306 | if (mHasSoftInput != hasSoftInput) { |
| 1307 | mHasSoftInput = hasSoftInput; |
| 1308 | updateRotation = true; |
| 1309 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1310 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1311 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1312 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1313 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1314 | } |
| 1315 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1316 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1317 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1320 | private void updateWakeGestureListenerLp() { |
| 1321 | if (shouldEnableWakeGestureLp()) { |
| 1322 | mWakeGestureListener.requestWakeUpTrigger(); |
| 1323 | } else { |
| 1324 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | private boolean shouldEnableWakeGestureLp() { |
| 1329 | return mWakeGestureEnabledSetting && !mScreenOnEarly |
| 1330 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 1331 | && mWakeGestureListener.isSupported(); |
| 1332 | } |
| 1333 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1334 | private void enablePointerLocation() { |
| 1335 | if (mPointerLocationView == null) { |
| 1336 | mPointerLocationView = new PointerLocationView(mContext); |
| 1337 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1338 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1339 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1340 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1341 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1342 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1343 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1344 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1345 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1346 | if (ActivityManager.isHighEndGfx()) { |
| 1347 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1348 | lp.privateFlags |= |
| 1349 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1350 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1351 | lp.format = PixelFormat.TRANSLUCENT; |
| 1352 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1353 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1354 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1355 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1356 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1357 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1358 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1359 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1360 | |
| 1361 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1362 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1363 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 1364 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1365 | wm.removeView(mPointerLocationView); |
| 1366 | mPointerLocationView = null; |
| 1367 | } |
| 1368 | } |
| 1369 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1370 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1371 | try { |
| 1372 | int rotation = mContext.getResources().getInteger(resID); |
| 1373 | switch (rotation) { |
| 1374 | case 0: |
| 1375 | return Surface.ROTATION_0; |
| 1376 | case 90: |
| 1377 | return Surface.ROTATION_90; |
| 1378 | case 180: |
| 1379 | return Surface.ROTATION_180; |
| 1380 | case 270: |
| 1381 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1382 | } |
| 1383 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1384 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1385 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1386 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1390 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1391 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1392 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1393 | |
| 1394 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1395 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1396 | if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW |
| 1397 | || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1398 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1399 | } |
| 1400 | String permission = null; |
| 1401 | switch (type) { |
| 1402 | case TYPE_TOAST: |
| 1403 | // XXX right now the app process has complete control over |
| 1404 | // this... should introduce a token to let the system |
| 1405 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1406 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1407 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1408 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1409 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1410 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1411 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1412 | case TYPE_VOICE_INTERACTION: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1413 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1414 | break; |
| 1415 | case TYPE_PHONE: |
| 1416 | case TYPE_PRIORITY_PHONE: |
| 1417 | case TYPE_SYSTEM_ALERT: |
| 1418 | case TYPE_SYSTEM_ERROR: |
| 1419 | case TYPE_SYSTEM_OVERLAY: |
| 1420 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1421 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1422 | break; |
| 1423 | default: |
| 1424 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1425 | } |
| 1426 | if (permission != null) { |
| 1427 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1428 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1429 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1430 | } |
| 1431 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1432 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1433 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1434 | |
| 1435 | @Override |
| 1436 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1437 | |
| 1438 | // If this switch statement is modified, modify the comment in the declarations of |
| 1439 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1440 | switch (attrs.type) { |
| 1441 | default: |
| 1442 | // These are the windows that by default are shown only to the user that created |
| 1443 | // them. If this needs to be overridden, set |
| 1444 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1445 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1446 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1447 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1448 | return true; |
| 1449 | } |
| 1450 | break; |
| 1451 | |
| 1452 | // These are the windows that by default are shown to all users. However, to |
| 1453 | // protect against spoofing, check permissions below. |
| 1454 | case TYPE_APPLICATION_STARTING: |
| 1455 | case TYPE_BOOT_PROGRESS: |
| 1456 | case TYPE_DISPLAY_OVERLAY: |
| 1457 | case TYPE_HIDDEN_NAV_CONSUMER: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1458 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1459 | case TYPE_KEYGUARD_DIALOG: |
| 1460 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1461 | case TYPE_NAVIGATION_BAR: |
| 1462 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1463 | case TYPE_PHONE: |
| 1464 | case TYPE_POINTER: |
| 1465 | case TYPE_PRIORITY_PHONE: |
| 1466 | case TYPE_RECENTS_OVERLAY: |
| 1467 | case TYPE_SEARCH_BAR: |
| 1468 | case TYPE_STATUS_BAR: |
| 1469 | case TYPE_STATUS_BAR_PANEL: |
| 1470 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1471 | case TYPE_SYSTEM_DIALOG: |
| 1472 | case TYPE_UNIVERSE_BACKGROUND: |
| 1473 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1474 | case TYPE_PRIVATE_PRESENTATION: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1475 | break; |
| 1476 | } |
| 1477 | |
| 1478 | // Check if third party app has set window to system window type. |
| 1479 | return mContext.checkCallingOrSelfPermission( |
| 1480 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 1481 | != PackageManager.PERMISSION_GRANTED; |
| 1482 | } |
| 1483 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1484 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1485 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 1486 | switch (attrs.type) { |
| 1487 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1488 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1489 | // These types of windows can't receive input events. |
| 1490 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1491 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1492 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1493 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1494 | case TYPE_STATUS_BAR: |
| 1495 | |
| 1496 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 1497 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 1498 | // the keyguard as occluded wouldn't set these flags again. |
| 1499 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 1500 | if (mKeyguardHidden) { |
| 1501 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 1502 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1503 | } |
| 1504 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1505 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 1506 | |
| 1507 | if (attrs.type != TYPE_STATUS_BAR) { |
| 1508 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 1509 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1510 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1511 | |
| 1512 | if (ActivityManager.isHighEndGfx() |
| 1513 | && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
| 1514 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1515 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1516 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1517 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1518 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1519 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1520 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 1521 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1522 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1523 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1524 | private boolean isHidden(int accessibilityMode) { |
| 1525 | switch (accessibilityMode) { |
| 1526 | case 1: |
| 1527 | return mLidState == LID_CLOSED; |
| 1528 | case 2: |
| 1529 | return mLidState == LID_OPEN; |
| 1530 | default: |
| 1531 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1532 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1533 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1534 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1535 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1536 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1537 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 1538 | int navigationPresence) { |
| 1539 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 1540 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1541 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1542 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1543 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1544 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1545 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 1546 | || (keyboardPresence == PRESENCE_INTERNAL |
| 1547 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1548 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1549 | if (!mHasSoftInput) { |
| 1550 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1551 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1552 | } |
| 1553 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1554 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 1555 | || (navigationPresence == PRESENCE_INTERNAL |
| 1556 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1557 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1558 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1559 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1560 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1561 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1562 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1563 | public int windowTypeToLayerLw(int type) { |
| 1564 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1565 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1566 | } |
| 1567 | switch (type) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1568 | case TYPE_UNIVERSE_BACKGROUND: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1569 | return 1; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1570 | case TYPE_PRIVATE_PRESENTATION: |
| 1571 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1572 | case TYPE_WALLPAPER: |
| 1573 | // wallpaper is at the bottom, though the window manager may move it. |
| 1574 | return 2; |
| 1575 | case TYPE_PHONE: |
| 1576 | return 3; |
| 1577 | case TYPE_SEARCH_BAR: |
| 1578 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1579 | case TYPE_VOICE_INTERACTION: |
| 1580 | // voice interaction layer is almost immediately above apps. |
| 1581 | return 5; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1582 | case TYPE_RECENTS_OVERLAY: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1583 | case TYPE_SYSTEM_DIALOG: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1584 | return 6; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1585 | case TYPE_TOAST: |
| 1586 | // toasts and the plugged-in battery thing |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1587 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1588 | case TYPE_PRIORITY_PHONE: |
| 1589 | // SIM errors and unlock. Not sure if this really should be in a high layer. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1590 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1591 | case TYPE_DREAM: |
| 1592 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1593 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1594 | case TYPE_SYSTEM_ALERT: |
| 1595 | // like the ANR / app crashed dialogs |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1596 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1597 | case TYPE_INPUT_METHOD: |
| 1598 | // on-screen keyboards and other such input method user interfaces go here. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1599 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1600 | case TYPE_INPUT_METHOD_DIALOG: |
| 1601 | // on-screen keyboards and other such input method user interfaces go here. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1602 | return 12; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1603 | case TYPE_KEYGUARD_SCRIM: |
| 1604 | // the safety window that shows behind keyguard while keyguard is starting |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1605 | return 13; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1606 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1607 | return 14; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1608 | case TYPE_STATUS_BAR: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1609 | return 15; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1610 | case TYPE_STATUS_BAR_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1611 | return 16; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1612 | case TYPE_KEYGUARD_DIALOG: |
| 1613 | return 17; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1614 | case TYPE_VOLUME_OVERLAY: |
| 1615 | // the on-screen volume indicator and controller shown when the user |
| 1616 | // changes the device volume |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1617 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1618 | case TYPE_SYSTEM_OVERLAY: |
| 1619 | // the on-screen volume indicator and controller shown when the user |
| 1620 | // changes the device volume |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1621 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1622 | case TYPE_NAVIGATION_BAR: |
| 1623 | // the navigation bar, if available, shows atop most things |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1624 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1625 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1626 | // some panels (e.g. search) need to show on top of the navigation bar |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1627 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1628 | case TYPE_SYSTEM_ERROR: |
| 1629 | // system-level error dialogs |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1630 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1631 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1632 | // used to highlight the magnified portion of a display |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1633 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1634 | case TYPE_DISPLAY_OVERLAY: |
| 1635 | // used to simulate secondary display devices |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1636 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1637 | case TYPE_DRAG: |
| 1638 | // the drag layer: input for drag-and-drop is associated with this window, |
| 1639 | // which sits above all other focusable windows |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1640 | return 25; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1641 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1642 | return 26; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1643 | case TYPE_BOOT_PROGRESS: |
| 1644 | return 27; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1645 | case TYPE_POINTER: |
| 1646 | // the (mouse) pointer layer |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1647 | return 28; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1648 | case TYPE_HIDDEN_NAV_CONSUMER: |
| 1649 | return 29; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1650 | } |
| 1651 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1652 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1656 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1657 | public int subWindowTypeToLayerLw(int type) { |
| 1658 | switch (type) { |
| 1659 | case TYPE_APPLICATION_PANEL: |
| 1660 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 1661 | return APPLICATION_PANEL_SUBLAYER; |
| 1662 | case TYPE_APPLICATION_MEDIA: |
| 1663 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 1664 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 1665 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1666 | case TYPE_APPLICATION_SUB_PANEL: |
| 1667 | return APPLICATION_SUB_PANEL_SUBLAYER; |
| 1668 | } |
| 1669 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 1670 | return 0; |
| 1671 | } |
| 1672 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1673 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1674 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1675 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1678 | @Override |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1679 | public int getAboveUniverseLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1680 | return windowTypeToLayerLw(TYPE_SYSTEM_ERROR); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1683 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1684 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1685 | if (mHasNavigationBar) { |
| 1686 | // For a basic navigation bar, when we are in landscape mode we place |
| 1687 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1688 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 1689 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1690 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1691 | } |
| 1692 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1693 | } |
| 1694 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1695 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1696 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1697 | if (mHasNavigationBar) { |
| 1698 | // For a basic navigation bar, when we are in portrait mode we place |
| 1699 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1700 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 1701 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1702 | } |
| 1703 | } |
| 1704 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1707 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1708 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 1709 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1710 | } |
| 1711 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1712 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1713 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1714 | // There is a separate status bar at the top of the display. We don't count that as part |
| 1715 | // 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] | 1716 | // we do want to exclude it since applications can't generally use that part |
| 1717 | // of the screen. |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1718 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1719 | } |
| 1720 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1721 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 1722 | public boolean isForceHiding(WindowManager.LayoutParams attrs) { |
| 1723 | return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
Adrian Roos | 69e510d | 2014-07-13 14:57:59 +0200 | [diff] [blame] | 1724 | (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden()) || |
| 1725 | (attrs.type == TYPE_KEYGUARD_SCRIM); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1726 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1727 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1728 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 1729 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 1730 | return attrs.type == TYPE_STATUS_BAR; |
| 1731 | } |
| 1732 | |
| 1733 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1734 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1735 | switch (attrs.type) { |
| 1736 | case TYPE_STATUS_BAR: |
| 1737 | case TYPE_NAVIGATION_BAR: |
| 1738 | case TYPE_WALLPAPER: |
| 1739 | case TYPE_DREAM: |
| 1740 | case TYPE_UNIVERSE_BACKGROUND: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1741 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1742 | return false; |
| 1743 | default: |
| 1744 | return true; |
| 1745 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1746 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1747 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1748 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1749 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1750 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 1751 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1752 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1753 | if (!SHOW_STARTING_ANIMATIONS) { |
| 1754 | return null; |
| 1755 | } |
| 1756 | if (packageName == null) { |
| 1757 | return null; |
| 1758 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1759 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1760 | WindowManager wm = null; |
| 1761 | View view = null; |
| 1762 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1763 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1764 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1765 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 1766 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 1767 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1768 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1769 | try { |
| 1770 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1771 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1772 | } catch (PackageManager.NameNotFoundException e) { |
| 1773 | // Ignore |
| 1774 | } |
| 1775 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1776 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1777 | Window win = PolicyManager.makeNewWindow(context); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1778 | final TypedArray ta = win.getWindowStyle(); |
| 1779 | if (ta.getBoolean( |
| 1780 | com.android.internal.R.styleable.Window_windowDisablePreview, false) |
| 1781 | || ta.getBoolean( |
| 1782 | com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1783 | return null; |
| 1784 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1785 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1786 | Resources r = context.getResources(); |
| 1787 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1788 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1789 | win.setType( |
| 1790 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
| 1791 | // Force the window flags: this is a fake window, so it is not really |
| 1792 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 1793 | // flag because we do know that the next window will take input |
| 1794 | // focus, so we want to get the IME window up on top of us right away. |
| 1795 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1796 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1797 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1798 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1799 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1800 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1801 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1802 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1803 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1804 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1805 | win.setDefaultIcon(icon); |
| 1806 | win.setDefaultLogo(logo); |
| 1807 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1808 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1809 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1810 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1811 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 1812 | params.token = appToken; |
| 1813 | params.packageName = packageName; |
| 1814 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 1815 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 1816 | params.privateFlags |= |
| 1817 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1818 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1819 | |
| 1820 | if (!compatInfo.supportsScreen()) { |
| 1821 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 1822 | } |
| 1823 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1824 | params.setTitle("Starting " + packageName); |
| 1825 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1826 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 1827 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1828 | |
| 1829 | if (win.isFloating()) { |
| 1830 | // Whoops, there is no way to display an animation/preview |
| 1831 | // of such a thing! After all that work... let's skip it. |
| 1832 | // (Note that we must do this here because it is in |
| 1833 | // getDecorView() where the theme is evaluated... maybe |
| 1834 | // we should peek the floating attribute from the theme |
| 1835 | // earlier.) |
| 1836 | return null; |
| 1837 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1838 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1839 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1840 | TAG, "Adding starting window for " + packageName |
| 1841 | + " / " + appToken + ": " |
| 1842 | + (view.getParent() != null ? view : null)); |
| 1843 | |
| 1844 | wm.addView(view, params); |
| 1845 | |
| 1846 | // Only return the view if it was successfully added to the |
| 1847 | // window manager... which we can tell by it having a parent. |
| 1848 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1849 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1850 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 1851 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 1852 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1853 | } catch (RuntimeException e) { |
| 1854 | // don't crash if something else bad happens, for example a |
| 1855 | // failure loading resources because we are loading from an app |
| 1856 | // on external storage that has been unmounted. |
| 1857 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1858 | } finally { |
| 1859 | if (view != null && view.getParent() == null) { |
| 1860 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 1861 | wm.removeViewImmediate(view); |
| 1862 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | return null; |
| 1866 | } |
| 1867 | |
| 1868 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1869 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1870 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1871 | if (DEBUG_STARTING_WINDOW) { |
| 1872 | RuntimeException e = new RuntimeException("here"); |
| 1873 | e.fillInStackTrace(); |
| 1874 | Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e); |
| 1875 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1876 | |
| 1877 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1878 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1879 | wm.removeView(window); |
| 1880 | } |
| 1881 | } |
| 1882 | |
| 1883 | /** |
| 1884 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1885 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1886 | * Currently enforces that three window types are singletons: |
| 1887 | * <ul> |
| 1888 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1889 | * <li>KEYGUARD_TYPE</li> |
| 1890 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1891 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1892 | * @param win The window to be added |
| 1893 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1894 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1895 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 1896 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1897 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1898 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1899 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 1900 | switch (attrs.type) { |
| 1901 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1902 | mContext.enforceCallingOrSelfPermission( |
| 1903 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1904 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1905 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1906 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1907 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1908 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1909 | } |
| 1910 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1911 | mStatusBarController.setWindow(win); |
John Spurlock | 8fdfe62 | 2014-05-21 17:10:10 -0400 | [diff] [blame] | 1912 | mKeyguardDelegate.hideScrim(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1913 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1914 | case TYPE_NAVIGATION_BAR: |
| 1915 | mContext.enforceCallingOrSelfPermission( |
| 1916 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1917 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1918 | if (mNavigationBar != null) { |
| 1919 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1920 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1921 | } |
| 1922 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1923 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1924 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1925 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1926 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 1927 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1928 | mContext.enforceCallingOrSelfPermission( |
| 1929 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1930 | "PhoneWindowManager"); |
| 1931 | break; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1932 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1933 | mContext.enforceCallingOrSelfPermission( |
| 1934 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1935 | "PhoneWindowManager"); |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1936 | break; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1937 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1938 | mContext.enforceCallingOrSelfPermission( |
| 1939 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1940 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1941 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1942 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1943 | if (mKeyguardScrim != null) { |
| 1944 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 1945 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1946 | mKeyguardScrim = win; |
| 1947 | break; |
| 1948 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1949 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1950 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1954 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1955 | public void removeWindowLw(WindowState win) { |
| 1956 | if (mStatusBar == win) { |
| 1957 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1958 | mStatusBarController.setWindow(null); |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 1959 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1960 | } else if (mKeyguardScrim == win) { |
| 1961 | Log.v(TAG, "Removing keyguard scrim"); |
| 1962 | mKeyguardScrim = null; |
| 1963 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1964 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1965 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1970 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1971 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1972 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1973 | public int selectAnimationLw(WindowState win, int transit) { |
| 1974 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 1975 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1976 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1977 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1978 | if (transit == TRANSIT_EXIT |
| 1979 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1980 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1981 | } else if (transit == TRANSIT_ENTER |
| 1982 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1983 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1984 | } |
| 1985 | } else if (win == mNavigationBar) { |
| 1986 | // This can be on either the bottom or the right. |
| 1987 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1988 | if (transit == TRANSIT_EXIT |
| 1989 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1990 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1991 | } else if (transit == TRANSIT_ENTER |
| 1992 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1993 | return R.anim.dock_bottom_enter; |
| 1994 | } |
| 1995 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1996 | if (transit == TRANSIT_EXIT |
| 1997 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1998 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1999 | } else if (transit == TRANSIT_ENTER |
| 2000 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2001 | return R.anim.dock_right_enter; |
| 2002 | } |
| 2003 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2007 | if (win.hasAppShownWindows()) { |
| 2008 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 2009 | return com.android.internal.R.anim.app_starting_exit; |
| 2010 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 2011 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2012 | && transit == TRANSIT_ENTER) { |
| 2013 | // Special case: we are animating in a dream, while the keyguard |
| 2014 | // is shown. We don't want an animation on the dream, because |
| 2015 | // we need it shown immediately with the keyguard animating away |
| 2016 | // to reveal it. |
| 2017 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | return 0; |
| 2021 | } |
| 2022 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 2023 | @Override |
| 2024 | public void selectRotationAnimationLw(int anim[]) { |
| 2025 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 2026 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 2027 | + (mTopFullscreenOpaqueWindowState == null ? |
| 2028 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 2029 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 2030 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 2031 | case ROTATION_ANIMATION_CROSSFADE: |
| 2032 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 2033 | anim[1] = R.anim.rotation_animation_enter; |
| 2034 | break; |
| 2035 | case ROTATION_ANIMATION_JUMPCUT: |
| 2036 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 2037 | anim[1] = R.anim.rotation_animation_enter; |
| 2038 | break; |
| 2039 | case ROTATION_ANIMATION_ROTATE: |
| 2040 | default: |
| 2041 | anim[0] = anim[1] = 0; |
| 2042 | break; |
| 2043 | } |
| 2044 | } else { |
| 2045 | anim[0] = anim[1] = 0; |
| 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | @Override |
| 2050 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 2051 | boolean forceDefault) { |
| 2052 | switch (exitAnimId) { |
| 2053 | case R.anim.rotation_animation_xfade_exit: |
| 2054 | case R.anim.rotation_animation_jump_exit: |
| 2055 | // These are the only cases that matter. |
| 2056 | if (forceDefault) { |
| 2057 | return false; |
| 2058 | } |
| 2059 | int anim[] = new int[2]; |
| 2060 | selectRotationAnimationLw(anim); |
| 2061 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 2062 | default: |
| 2063 | return true; |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2068 | public Animation createForceHideEnterAnimation(boolean onWallpaper, |
| 2069 | boolean goingToNotificationShade) { |
| 2070 | if (goingToNotificationShade) { |
| 2071 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
| 2072 | } else if (onWallpaper) { |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2073 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 2074 | R.anim.lock_screen_behind_enter_wallpaper); |
| 2075 | AnimationSet set = (AnimationSet) a; |
| 2076 | |
| 2077 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2078 | set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator); |
| 2079 | set.getAnimations().get(1).setInterpolator(mLogDecelerateInterpolator); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2080 | return set; |
| 2081 | } else { |
| 2082 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 2083 | R.anim.lock_screen_behind_enter); |
| 2084 | AnimationSet set = (AnimationSet) a; |
| 2085 | |
| 2086 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2087 | set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator); |
| 2088 | return set; |
| 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | |
| 2093 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2094 | public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) { |
| 2095 | if (goingToNotificationShade) { |
| 2096 | return null; |
| 2097 | } else { |
| 2098 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 2099 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2100 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 2101 | |
| 2102 | private static void awakenDreams() { |
| 2103 | IDreamManager dreamManager = getDreamManager(); |
| 2104 | if (dreamManager != null) { |
| 2105 | try { |
| 2106 | dreamManager.awaken(); |
| 2107 | } catch (RemoteException e) { |
| 2108 | // fine, stay asleep then |
| 2109 | } |
| 2110 | } |
| 2111 | } |
| 2112 | |
| 2113 | static IDreamManager getDreamManager() { |
| 2114 | return IDreamManager.Stub.asInterface( |
| 2115 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 2116 | } |
| 2117 | |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 2118 | TelecommManager getTelecommService() { |
| 2119 | return (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2120 | } |
| 2121 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2122 | static IAudioService getAudioService() { |
| 2123 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 2124 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 2125 | if (audioService == null) { |
| 2126 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 2127 | } |
| 2128 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | boolean keyguardOn() { |
| 2132 | return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode(); |
| 2133 | } |
| 2134 | |
| 2135 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 2136 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 2137 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 2138 | }; |
| 2139 | |
| 2140 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2141 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2142 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2143 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2144 | final int keyCode = event.getKeyCode(); |
| 2145 | final int repeatCount = event.getRepeatCount(); |
| 2146 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2147 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2148 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 2149 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2150 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2151 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2152 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2153 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 2154 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2155 | } |
| 2156 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2157 | // If we think we might have a volume down & power key chord on the way |
| 2158 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 2159 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2160 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2161 | if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) { |
| 2162 | final long now = SystemClock.uptimeMillis(); |
| 2163 | final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
| 2164 | if (now < timeoutTime) { |
| 2165 | return timeoutTime - now; |
| 2166 | } |
| 2167 | } |
| 2168 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 2169 | && mVolumeDownKeyConsumedByScreenshotChord) { |
| 2170 | if (!down) { |
| 2171 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 2172 | } |
| 2173 | return -1; |
| 2174 | } |
| 2175 | } |
| 2176 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2177 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 2178 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 2179 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2180 | mPendingMetaAction = false; |
| 2181 | } |
| 2182 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2183 | // First we always handle the home key here, so applications |
| 2184 | // can never break it, although if keyguard is on, we do let |
| 2185 | // it handle it, because that gives us the correct 5 second |
| 2186 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2187 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2188 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2189 | // If we have released the home key, and didn't do anything else |
| 2190 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2191 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2192 | cancelPreloadRecentApps(); |
| 2193 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2194 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2195 | if (mHomeConsumed) { |
| 2196 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2197 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2198 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2199 | |
| 2200 | if (canceled) { |
| 2201 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 2202 | return -1; |
| 2203 | } |
| 2204 | |
| 2205 | // If an incoming call is ringing, HOME is totally disabled. |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 2206 | // (The user is already on the InCallUI at this point, |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2207 | // and his ONLY options are to answer or reject the call.) |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 2208 | TelecommManager telecommManager = getTelecommService(); |
| 2209 | if (telecommManager != null && telecommManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 2210 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2211 | return -1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | // Delay handling home if a double-tap is possible. |
| 2215 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2216 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2217 | mHomeDoubleTapPending = true; |
| 2218 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2219 | ViewConfiguration.getDoubleTapTimeout()); |
| 2220 | return -1; |
| 2221 | } |
| 2222 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2223 | // If there's a dream running then use home to escape the dream |
| 2224 | // but don't actually go home. |
| 2225 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 2226 | mDreamManagerInternal.stopDream(false /*immediate*/); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2227 | return -1; |
| 2228 | } |
| 2229 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2230 | // Go home! |
| 2231 | launchHomeFromHotKey(); |
| 2232 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2233 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2234 | |
| 2235 | // If a system window has focus, then it doesn't make sense |
| 2236 | // right now to interact with applications. |
| 2237 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2238 | if (attrs != null) { |
| 2239 | final int type = attrs.type; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2240 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 2241 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG |
| 2242 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2243 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2244 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2245 | } |
| 2246 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2247 | for (int i=0; i<typeCount; i++) { |
| 2248 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2249 | // 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] | 2250 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2251 | } |
| 2252 | } |
| 2253 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2254 | |
| 2255 | // Remember that home is pressed and handle special actions. |
| 2256 | if (repeatCount == 0) { |
| 2257 | mHomePressed = true; |
| 2258 | if (mHomeDoubleTapPending) { |
| 2259 | mHomeDoubleTapPending = false; |
| 2260 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2261 | handleDoubleTapOnHome(); |
| 2262 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2263 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2264 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2265 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2266 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2267 | if (!keyguardOn) { |
| 2268 | handleLongPressOnHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2269 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2270 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2271 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2272 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2273 | // Hijack modified menu keys for debugging features |
| 2274 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2275 | |
| 2276 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2277 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2278 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2279 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2280 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2281 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2282 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2283 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2284 | Intent service = new Intent(); |
| 2285 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2286 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2287 | boolean shown = Settings.Global.getInt( |
| 2288 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2289 | if (!shown) { |
| 2290 | mContext.startService(service); |
| 2291 | } else { |
| 2292 | mContext.stopService(service); |
| 2293 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2294 | Settings.Global.putInt( |
| 2295 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2296 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2297 | } |
| 2298 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2299 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2300 | if (down) { |
| 2301 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2302 | mSearchKeyShortcutPending = true; |
| 2303 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2304 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2305 | } else { |
| 2306 | mSearchKeyShortcutPending = false; |
| 2307 | if (mConsumeSearchKeyUp) { |
| 2308 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2309 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2310 | } |
| 2311 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2312 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2313 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2314 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2315 | if (down && repeatCount == 0) { |
| 2316 | preloadRecentApps(); |
| 2317 | } else if (!down) { |
| 2318 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2319 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2320 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2321 | return -1; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2322 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2323 | if (down) { |
| 2324 | if (repeatCount == 0) { |
| 2325 | mAssistKeyLongPressed = false; |
| 2326 | } else if (repeatCount == 1) { |
| 2327 | mAssistKeyLongPressed = true; |
| 2328 | if (!keyguardOn) { |
| 2329 | launchAssistLongPressAction(); |
| 2330 | } |
| 2331 | } |
| 2332 | } else { |
| 2333 | if (mAssistKeyLongPressed) { |
| 2334 | mAssistKeyLongPressed = false; |
| 2335 | } else { |
| 2336 | if (!keyguardOn) { |
| 2337 | launchAssistAction(); |
| 2338 | } |
| 2339 | } |
| 2340 | } |
| 2341 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2342 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 2343 | if (!down) { |
| 2344 | Intent voiceIntent; |
| 2345 | if (!keyguardOn && mPowerManager.isInteractive()) { |
| 2346 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 2347 | } else { |
| 2348 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 2349 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardOn); |
| 2350 | } |
| 2351 | mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
| 2352 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2353 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2354 | if (down && repeatCount == 0) { |
| 2355 | mHandler.post(mScreenshotRunnable); |
| 2356 | } |
| 2357 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2358 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2359 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2360 | if (down) { |
| 2361 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2362 | |
| 2363 | // Disable autobrightness if it's on |
| 2364 | int auto = Settings.System.getIntForUser( |
| 2365 | mContext.getContentResolver(), |
| 2366 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2367 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2368 | UserHandle.USER_CURRENT_OR_SELF); |
| 2369 | if (auto != 0) { |
| 2370 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2371 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2372 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2373 | UserHandle.USER_CURRENT_OR_SELF); |
| 2374 | } |
| 2375 | |
| 2376 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 2377 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 2378 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 2379 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 2380 | Settings.System.SCREEN_BRIGHTNESS, |
| 2381 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 2382 | UserHandle.USER_CURRENT_OR_SELF); |
| 2383 | brightness += step; |
| 2384 | // Make sure we don't go beyond the limits. |
| 2385 | brightness = Math.min(max, brightness); |
| 2386 | brightness = Math.max(min, brightness); |
| 2387 | |
| 2388 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2389 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 2390 | UserHandle.USER_CURRENT_OR_SELF); |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 2391 | mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
| 2392 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2393 | } |
| 2394 | return -1; |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2395 | } else if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2396 | if (down) { |
| 2397 | mPendingMetaAction = true; |
| 2398 | } else if (mPendingMetaAction) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2399 | launchAssistAction(); |
| 2400 | } |
| 2401 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2402 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2403 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2404 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2405 | // Any printing key that is chorded with Search should be consumed |
| 2406 | // even if no shortcut was invoked. This prevents text from being |
| 2407 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2408 | // 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] | 2409 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2410 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2411 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2412 | mConsumeSearchKeyUp = true; |
| 2413 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2414 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2415 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2416 | if (shortcutIntent != null) { |
| 2417 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2418 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2419 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2420 | } catch (ActivityNotFoundException ex) { |
| 2421 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2422 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2423 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2424 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2425 | } else { |
| 2426 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2427 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2428 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2429 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2430 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2434 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2435 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2436 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2437 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2438 | if (kcm.isPrintingKey(keyCode)) { |
| 2439 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2440 | metaState & ~(KeyEvent.META_META_ON |
| 2441 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2442 | if (shortcutIntent != null) { |
| 2443 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2444 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2445 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2446 | } catch (ActivityNotFoundException ex) { |
| 2447 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2448 | + "the activity to which it is registered was not found: " |
| 2449 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2450 | } |
| 2451 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2452 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2453 | } |
| 2454 | } |
| 2455 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2456 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2457 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2458 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 2459 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 2460 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2461 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2462 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2463 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2464 | } catch (ActivityNotFoundException ex) { |
| 2465 | Slog.w(TAG, "Dropping application launch key because " |
| 2466 | + "the activity to which it is registered was not found: " |
| 2467 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 2468 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2469 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2470 | } |
| 2471 | } |
| 2472 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2473 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2474 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2475 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2476 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2477 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2478 | mRecentAppsHeldModifiers = shiftlessModifiers; |
| 2479 | showRecentApps(true); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2480 | return -1; |
| 2481 | } |
| 2482 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2483 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 2484 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 2485 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2486 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2487 | } |
| 2488 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 2489 | // Handle keyboard language switching. |
| 2490 | if (down && repeatCount == 0 |
| 2491 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2492 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 2493 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 2494 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 2495 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 2496 | return -1; |
| 2497 | } |
| 2498 | if (mLanguageSwitchKeyPressed && !down |
| 2499 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2500 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 2501 | mLanguageSwitchKeyPressed = false; |
| 2502 | return -1; |
| 2503 | } |
| 2504 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2505 | if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
| 2506 | return -1; |
| 2507 | } |
| 2508 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2509 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2510 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2511 | return -1; |
| 2512 | } |
| 2513 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2514 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2515 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2516 | } |
| 2517 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2518 | /** {@inheritDoc} */ |
| 2519 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2520 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2521 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2522 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2523 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 2524 | + ", flags=" + event.getFlags() |
| 2525 | + ", keyCode=" + event.getKeyCode() |
| 2526 | + ", scanCode=" + event.getScanCode() |
| 2527 | + ", metaState=" + event.getMetaState() |
| 2528 | + ", repeatCount=" + event.getRepeatCount() |
| 2529 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2530 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2531 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2532 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2533 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 2534 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2535 | final int keyCode = event.getKeyCode(); |
| 2536 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2537 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 2538 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2539 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2540 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2541 | final FallbackAction fallbackAction; |
| 2542 | if (initialDown) { |
| 2543 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 2544 | } else { |
| 2545 | fallbackAction = mFallbackActions.get(keyCode); |
| 2546 | } |
| 2547 | |
| 2548 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2549 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2550 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 2551 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2552 | } |
| 2553 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2554 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 2555 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2556 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2557 | event.getAction(), fallbackAction.keyCode, |
| 2558 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2559 | event.getDeviceId(), event.getScanCode(), |
| 2560 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2561 | |
| 2562 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 2563 | fallbackEvent.recycle(); |
| 2564 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2565 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2566 | |
| 2567 | if (initialDown) { |
| 2568 | mFallbackActions.put(keyCode, fallbackAction); |
| 2569 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2570 | mFallbackActions.remove(keyCode); |
| 2571 | fallbackAction.recycle(); |
| 2572 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2573 | } |
| 2574 | } |
| 2575 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2576 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2577 | if (fallbackEvent == null) { |
| 2578 | Slog.d(TAG, "No fallback."); |
| 2579 | } else { |
| 2580 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 2581 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2582 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2583 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2584 | } |
| 2585 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2586 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2587 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2588 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 2589 | long delayMillis = interceptKeyBeforeDispatching( |
| 2590 | win, fallbackEvent, policyFlags); |
| 2591 | if (delayMillis == 0) { |
| 2592 | return true; |
| 2593 | } |
| 2594 | } |
| 2595 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2596 | } |
| 2597 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2598 | private void launchAssistLongPressAction() { |
| 2599 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2600 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2601 | |
| 2602 | // launch the search activity |
| 2603 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 2604 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2605 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2606 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2607 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2608 | SearchManager searchManager = getSearchManager(); |
| 2609 | if (searchManager != null) { |
| 2610 | searchManager.stopSearch(); |
| 2611 | } |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2612 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2613 | } catch (ActivityNotFoundException e) { |
| 2614 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 2615 | } |
| 2616 | } |
| 2617 | |
| 2618 | private void launchAssistAction() { |
| 2619 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 2620 | Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2621 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2622 | if (intent != null) { |
| 2623 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2624 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 2625 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2626 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2627 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2628 | } catch (ActivityNotFoundException e) { |
| 2629 | Slog.w(TAG, "No activity to handle assist action.", e); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2630 | } |
| 2631 | } |
| 2632 | } |
| 2633 | |
| 2634 | private SearchManager getSearchManager() { |
| 2635 | if (mSearchManager == null) { |
| 2636 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 2637 | } |
| 2638 | return mSearchManager; |
| 2639 | } |
| 2640 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2641 | private void preloadRecentApps() { |
| 2642 | mPreloadedRecentApps = true; |
| 2643 | try { |
| 2644 | IStatusBarService statusbar = getStatusBarService(); |
| 2645 | if (statusbar != null) { |
| 2646 | statusbar.preloadRecentApps(); |
| 2647 | } |
| 2648 | } catch (RemoteException e) { |
| 2649 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 2650 | // re-acquire status bar service next time it is needed. |
| 2651 | mStatusBarService = null; |
| 2652 | } |
| 2653 | } |
| 2654 | |
| 2655 | private void cancelPreloadRecentApps() { |
| 2656 | if (mPreloadedRecentApps) { |
| 2657 | mPreloadedRecentApps = false; |
| 2658 | try { |
| 2659 | IStatusBarService statusbar = getStatusBarService(); |
| 2660 | if (statusbar != null) { |
| 2661 | statusbar.cancelPreloadRecentApps(); |
| 2662 | } |
| 2663 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2664 | Slog.e(TAG, "RemoteException when cancelling recent apps preload", e); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2665 | // re-acquire status bar service next time it is needed. |
| 2666 | mStatusBarService = null; |
| 2667 | } |
| 2668 | } |
| 2669 | } |
| 2670 | |
| 2671 | private void toggleRecentApps() { |
| 2672 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2673 | try { |
| 2674 | IStatusBarService statusbar = getStatusBarService(); |
| 2675 | if (statusbar != null) { |
| 2676 | statusbar.toggleRecentApps(); |
| 2677 | } |
| 2678 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2679 | Slog.e(TAG, "RemoteException when toggling recent apps", e); |
| 2680 | // re-acquire status bar service next time it is needed. |
| 2681 | mStatusBarService = null; |
| 2682 | } |
| 2683 | } |
| 2684 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2685 | @Override |
| 2686 | public void showRecentApps() { |
| 2687 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
| 2688 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS); |
| 2689 | } |
| 2690 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2691 | private void showRecentApps(boolean triggeredFromAltTab) { |
| 2692 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 2693 | try { |
| 2694 | IStatusBarService statusbar = getStatusBarService(); |
| 2695 | if (statusbar != null) { |
| 2696 | statusbar.showRecentApps(triggeredFromAltTab); |
| 2697 | } |
| 2698 | } catch (RemoteException e) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2699 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 2700 | // re-acquire status bar service next time it is needed. |
| 2701 | mStatusBarService = null; |
| 2702 | } |
| 2703 | } |
| 2704 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2705 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2706 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 2707 | try { |
| 2708 | IStatusBarService statusbar = getStatusBarService(); |
| 2709 | if (statusbar != null) { |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2710 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2711 | } |
| 2712 | } catch (RemoteException e) { |
| 2713 | Slog.e(TAG, "RemoteException when closing recent apps", e); |
| 2714 | // re-acquire status bar service next time it is needed. |
| 2715 | mStatusBarService = null; |
| 2716 | } |
| 2717 | } |
| 2718 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2719 | /** |
| 2720 | * A home key -> launch home action was detected. Take the appropriate action |
| 2721 | * given the situation with the keyguard. |
| 2722 | */ |
| 2723 | void launchHomeFromHotKey() { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 2724 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2725 | // don't launch home if keyguard showing |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2726 | } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2727 | // when in keyguard restricted mode, must first verify unlock |
| 2728 | // before launching home |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2729 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2730 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2731 | public void onKeyguardExitResult(boolean success) { |
| 2732 | if (success) { |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2733 | try { |
| 2734 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2735 | } catch (RemoteException e) { |
| 2736 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 2737 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2738 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2739 | } |
| 2740 | } |
| 2741 | }); |
| 2742 | } else { |
| 2743 | // no keyguard stuff to worry about, just launch home! |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2744 | try { |
| 2745 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2746 | } catch (RemoteException e) { |
| 2747 | } |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 2748 | if (mRecentsVisible) { |
| 2749 | // Hide Recents and notify it to launch Home |
| 2750 | awakenDreams(); |
| 2751 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2752 | hideRecentApps(false, true); |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 2753 | } else { |
| 2754 | // Otherwise, just launch Home |
| 2755 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 2756 | startDockOrHome(); |
| 2757 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2758 | } |
| 2759 | } |
| 2760 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2761 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 2762 | @Override |
| 2763 | public void run() { |
| 2764 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2765 | // Clear flags. |
| 2766 | mForceClearedSystemUiFlags &= |
| 2767 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 2768 | } |
| 2769 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2770 | } |
| 2771 | }; |
| 2772 | |
| 2773 | /** |
| 2774 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 2775 | * to determine when the nav bar should be shown and prevent applications from |
| 2776 | * receiving those touches. |
| 2777 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2778 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 2779 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 2780 | super(inputChannel, looper); |
| 2781 | } |
| 2782 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2783 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2784 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2785 | boolean handled = false; |
| 2786 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 2787 | if (event instanceof MotionEvent |
| 2788 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 2789 | final MotionEvent motionEvent = (MotionEvent)event; |
| 2790 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2791 | // When the user taps down, we re-show the nav bar. |
| 2792 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2793 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2794 | // Any user activity always causes us to show the |
| 2795 | // navigation controls, if they had been hidden. |
| 2796 | // We also clear the low profile and only content |
| 2797 | // flags so that tapping on the screen will atomically |
| 2798 | // restore all currently hidden screen decorations. |
| 2799 | int newVal = mResettingSystemUiFlags | |
| 2800 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 2801 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 2802 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2803 | if (mResettingSystemUiFlags != newVal) { |
| 2804 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2805 | changed = true; |
| 2806 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2807 | // We don't allow the system's nav bar to be hidden |
| 2808 | // again for 1 second, to prevent applications from |
| 2809 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2810 | newVal = mForceClearedSystemUiFlags | |
| 2811 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2812 | if (mForceClearedSystemUiFlags != newVal) { |
| 2813 | mForceClearedSystemUiFlags = newVal; |
| 2814 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2815 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2816 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2817 | } |
| 2818 | if (changed) { |
| 2819 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 2820 | } |
| 2821 | } |
| 2822 | } |
| 2823 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2824 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2825 | } |
| 2826 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2827 | } |
| 2828 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 2829 | new InputEventReceiver.Factory() { |
| 2830 | @Override |
| 2831 | public InputEventReceiver createInputEventReceiver( |
| 2832 | InputChannel inputChannel, Looper looper) { |
| 2833 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 2834 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2835 | }; |
| 2836 | |
| 2837 | @Override |
| 2838 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 2839 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 2840 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 2841 | mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2842 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2843 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 2844 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2845 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2846 | // Clear any bits in the new visibility that are currently being |
| 2847 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2848 | return visibility & ~mResettingSystemUiFlags |
| 2849 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2850 | } |
| 2851 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2852 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2853 | public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 2854 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 2855 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 2856 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2857 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2858 | 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] | 2859 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2860 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2861 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2862 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2863 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 2864 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 2865 | } else { |
| 2866 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 2867 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 2868 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2869 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 2870 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 2871 | contentInset.set(mStableFullscreenLeft, mStableFullscreenTop, |
| 2872 | availRight - mStableFullscreenRight, |
| 2873 | availBottom - mStableFullscreenBottom); |
| 2874 | } else { |
| 2875 | contentInset.set(mStableLeft, mStableTop, |
| 2876 | availRight - mStableRight, availBottom - mStableBottom); |
| 2877 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2878 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2879 | contentInset.setEmpty(); |
| 2880 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2881 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
| 2882 | contentInset.set(mCurLeft, mCurTop, |
| 2883 | availRight - mCurRight, availBottom - mCurBottom); |
| 2884 | } else { |
| 2885 | contentInset.set(mCurLeft, mCurTop, |
| 2886 | availRight - mCurRight, availBottom - mCurBottom); |
| 2887 | } |
| 2888 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2889 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2890 | contentInset.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2891 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2892 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2893 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2894 | @Override |
| 2895 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 2896 | int displayRotation) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2897 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 2898 | if (isDefaultDisplay) { |
| 2899 | switch (displayRotation) { |
| 2900 | case Surface.ROTATION_90: |
| 2901 | overscanLeft = mOverscanTop; |
| 2902 | overscanTop = mOverscanRight; |
| 2903 | overscanRight = mOverscanBottom; |
| 2904 | overscanBottom = mOverscanLeft; |
| 2905 | break; |
| 2906 | case Surface.ROTATION_180: |
| 2907 | overscanLeft = mOverscanRight; |
| 2908 | overscanTop = mOverscanBottom; |
| 2909 | overscanRight = mOverscanLeft; |
| 2910 | overscanBottom = mOverscanTop; |
| 2911 | break; |
| 2912 | case Surface.ROTATION_270: |
| 2913 | overscanLeft = mOverscanBottom; |
| 2914 | overscanTop = mOverscanLeft; |
| 2915 | overscanRight = mOverscanTop; |
| 2916 | overscanBottom = mOverscanRight; |
| 2917 | break; |
| 2918 | default: |
| 2919 | overscanLeft = mOverscanLeft; |
| 2920 | overscanTop = mOverscanTop; |
| 2921 | overscanRight = mOverscanRight; |
| 2922 | overscanBottom = mOverscanBottom; |
| 2923 | break; |
| 2924 | } |
| 2925 | } else { |
| 2926 | overscanLeft = 0; |
| 2927 | overscanTop = 0; |
| 2928 | overscanRight = 0; |
| 2929 | overscanBottom = 0; |
| 2930 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2931 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 2932 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 2933 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 2934 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2935 | mSystemLeft = 0; |
| 2936 | mSystemTop = 0; |
| 2937 | mSystemRight = displayWidth; |
| 2938 | mSystemBottom = displayHeight; |
| 2939 | mUnrestrictedScreenLeft = overscanLeft; |
| 2940 | mUnrestrictedScreenTop = overscanTop; |
| 2941 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 2942 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 2943 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 2944 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2945 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 2946 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2947 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2948 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2949 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2950 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2951 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2952 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2953 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2954 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2955 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2956 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2957 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2958 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 2959 | final Rect pf = mTmpParentFrame; |
| 2960 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2961 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2962 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2963 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2964 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 2965 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 2966 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 2967 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2968 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2969 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2970 | if (isDefaultDisplay) { |
| 2971 | // For purposes of putting out fake window up to steal focus, we will |
| 2972 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2973 | final int sysui = mLastSystemUiFlags; |
| 2974 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2975 | boolean navTranslucent = (sysui |
| 2976 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2977 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 2978 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 2979 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 2980 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 2981 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen; |
| 2982 | if (!isKeyguardShowing) { |
| 2983 | navTranslucent &= areTranslucentBarsAllowed(); |
| 2984 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2985 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2986 | // When the navigation bar isn't visible, we put up a fake |
| 2987 | // input window to catch all touch events. This way we can |
| 2988 | // detect when the user presses anywhere to bring back the nav |
| 2989 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2990 | if (navVisible || navAllowedHidden) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2991 | if (mHideNavFakeWindow != null) { |
| 2992 | mHideNavFakeWindow.dismiss(); |
| 2993 | mHideNavFakeWindow = null; |
| 2994 | } |
| 2995 | } else if (mHideNavFakeWindow == null) { |
| 2996 | mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow( |
| 2997 | mHandler.getLooper(), mHideNavInputEventReceiverFactory, |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2998 | "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2999 | 0, false, false, true); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3000 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3001 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3002 | // For purposes of positioning and showing the nav bar, if we have |
| 3003 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 3004 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3005 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3006 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3007 | boolean updateSysUiVisibility = false; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3008 | if (mNavigationBar != null) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3009 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3010 | // Force the navigation bar to its appropriate place and |
| 3011 | // size. We need to do this directly, instead of relying on |
| 3012 | // it to bubble up from the nav bar, because this needs to |
| 3013 | // change atomically with screen rotations. |
| 3014 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 3015 | if (mNavigationBarOnBottom) { |
| 3016 | // It's a system nav bar or a portrait screen; nav bar goes on bottom. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3017 | int top = displayHeight - overscanBottom |
| 3018 | - mNavigationBarHeightForRotation[displayRotation]; |
| 3019 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3020 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3021 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3022 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3023 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3024 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3025 | mDockBottom = mTmpNavigationFrame.top; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3026 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 3027 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3028 | } else { |
| 3029 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3030 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3031 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3032 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3033 | && !mNavigationBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3034 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3035 | // If the opaque nav bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3036 | // and not in the process of animating on or off, then |
| 3037 | // we can tell the app that it is covered by it. |
| 3038 | mSystemBottom = mTmpNavigationFrame.top; |
| 3039 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3040 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3041 | // Landscape screen; nav bar goes to the right. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3042 | int left = displayWidth - overscanRight |
| 3043 | - mNavigationBarWidthForRotation[displayRotation]; |
| 3044 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3045 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3046 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3047 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3048 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3049 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3050 | mDockRight = mTmpNavigationFrame.left; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3051 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 3052 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3053 | } else { |
| 3054 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3055 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3056 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3057 | if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw() |
| 3058 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3059 | // If the nav bar is currently requested to be visible, |
| 3060 | // and not in the process of animating on or off, then |
| 3061 | // we can tell the app that it is covered by it. |
| 3062 | mSystemRight = mTmpNavigationFrame.left; |
| 3063 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3064 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3065 | // Make sure the content and current rectangles are updated to |
| 3066 | // account for the restrictions from the navigation bar. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3067 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3068 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3069 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3070 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3071 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 3072 | // And compute the final frame. |
| 3073 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3074 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
| 3075 | mTmpNavigationFrame); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3076 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3077 | if (mNavigationBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3078 | updateSysUiVisibility = true; |
| 3079 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3080 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3081 | 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] | 3082 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
| 3083 | |
| 3084 | // decide where the status bar goes ahead of time |
| 3085 | if (mStatusBar != null) { |
| 3086 | // apply any navigation bar insets |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3087 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3088 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3089 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3090 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 3091 | + mUnrestrictedScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3092 | vf.left = mStableLeft; |
| 3093 | vf.top = mStableTop; |
| 3094 | vf.right = mStableRight; |
| 3095 | vf.bottom = mStableBottom; |
| 3096 | |
| 3097 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 3098 | |
| 3099 | // Let the status bar determine its size. |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3100 | mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3101 | |
| 3102 | // For layout, the status bar is always at the top with our fixed height. |
| 3103 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3104 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3105 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3106 | boolean statusBarTranslucent = (sysui |
| 3107 | & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3108 | if (!isKeyguardShowing) { |
| 3109 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 3110 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3111 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3112 | // If the status bar is hidden, we don't want to cause |
| 3113 | // windows behind it to scroll. |
John Spurlock | eda1f69 | 2013-09-16 11:38:44 -0400 | [diff] [blame] | 3114 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3115 | // Status bar may go away, so the screen area it occupies |
| 3116 | // is available to apps but just covering them when the |
| 3117 | // status bar is visible. |
| 3118 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3119 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3120 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3121 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3122 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3123 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3124 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3125 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3126 | String.format( |
| 3127 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 3128 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 3129 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 3130 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 3131 | } |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3132 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3133 | && !statusBarTransient && !statusBarTranslucent |
| 3134 | && !mStatusBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3135 | // If the opaque status bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3136 | // and not in the process of animating on or off, then |
| 3137 | // we can tell the app that it is covered by it. |
| 3138 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3139 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3140 | if (mStatusBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3141 | updateSysUiVisibility = true; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3142 | } |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3143 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3144 | if (updateSysUiVisibility) { |
| 3145 | updateSystemUiVisibilityLw(); |
| 3146 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3147 | } |
| 3148 | } |
| 3149 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3150 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3151 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3152 | public int getSystemDecorLayerLw() { |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3153 | if (mStatusBar != null) return mStatusBar.getSurfaceLayer(); |
| 3154 | if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer(); |
| 3155 | return 0; |
| 3156 | } |
| 3157 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3158 | @Override |
| 3159 | public void getContentRectLw(Rect r) { |
| 3160 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 3161 | } |
| 3162 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3163 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 3164 | 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] | 3165 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 3166 | // Here's a special case: if this attached window is a panel that is |
| 3167 | // above the dock window, and the window it is attached to is below |
| 3168 | // the dock window, then the frames we computed for the window it is |
| 3169 | // attached to can not be used because the dock is effectively part |
| 3170 | // of the underlying window and the attached window is floating on top |
| 3171 | // of the whole thing. So, we ignore the attached window and explicitly |
| 3172 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3173 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3174 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 3175 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 3176 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3177 | } else { |
| 3178 | // The effective display frame of the attached window depends on |
| 3179 | // whether it is taking care of insetting its content. If not, |
| 3180 | // we need to use the parent's content frame so that the entire |
| 3181 | // window is positioned within that content. Otherwise we can use |
| 3182 | // the display frame and let the attached window take care of |
| 3183 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3184 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3185 | cf.set(attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3186 | } else { |
| 3187 | // If the window is resizing, then we want to base the content |
| 3188 | // frame on our attached content frame to resize... however, |
| 3189 | // things can be tricky if the attached window is NOT in resize |
| 3190 | // mode, in which case its content frame will be larger. |
| 3191 | // Ungh. So to deal with that, make sure the content frame |
| 3192 | // we end up using is not covering the IM dock. |
| 3193 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3194 | if (attached.isVoiceInteraction()) { |
| 3195 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 3196 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 3197 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 3198 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 3199 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3200 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 3201 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 3202 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 3203 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 3204 | } |
| 3205 | } |
| 3206 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3207 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3208 | vf.set(attached.getVisibleFrameLw()); |
| 3209 | } |
| 3210 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 3211 | // window should be positioned relative to its parent or the entire |
| 3212 | // screen. |
| 3213 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 3214 | ? attached.getFrameLw() : df); |
| 3215 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3216 | |
| 3217 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 3218 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3219 | // If app is requesting a stable layout, don't let the |
| 3220 | // content insets go below the stable values. |
| 3221 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 3222 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 3223 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 3224 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 3225 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 3226 | } else { |
| 3227 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 3228 | if (r.top < mStableTop) r.top = mStableTop; |
| 3229 | if (r.right > mStableRight) r.right = mStableRight; |
| 3230 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 3231 | } |
| 3232 | } |
| 3233 | } |
| 3234 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3235 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3236 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3237 | public void layoutWindowLw(WindowState win, WindowState attached) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3238 | // we've already done the status bar |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3239 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
| 3240 | if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) || |
| 3241 | win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3242 | return; |
| 3243 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3244 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 3245 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3246 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 3247 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3248 | 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] | 3249 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 3250 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3251 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3252 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3253 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3254 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3255 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3256 | final Rect pf = mTmpParentFrame; |
| 3257 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3258 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3259 | final Rect cf = mTmpContentFrame; |
| 3260 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3261 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3262 | final Rect sf = mTmpStableFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3263 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3264 | |
| 3265 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3266 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3267 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 3268 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 3269 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3270 | if (isDefaultDisplay) { |
| 3271 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 3272 | } else { |
| 3273 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 3274 | } |
| 3275 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3276 | if (!isDefaultDisplay) { |
| 3277 | if (attached != null) { |
| 3278 | // If this window is attached to another, our display |
| 3279 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3280 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3281 | } else { |
| 3282 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3283 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3284 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3285 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3286 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3287 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3288 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3289 | } |
| 3290 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3291 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3292 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 3293 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3294 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 3295 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3296 | // ...with content insets above the nav bar |
| 3297 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3298 | // IM dock windows always go to the bottom of the screen. |
| 3299 | attrs.gravity = Gravity.BOTTOM; |
| 3300 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 3301 | } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 3302 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3303 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3304 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3305 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 3306 | cf.left = vf.left = mStableLeft; |
| 3307 | cf.top = vf.top = mStableTop; |
| 3308 | cf.right = vf.right = mStableRight; |
| 3309 | vf.bottom = mStableBottom; |
| 3310 | cf.bottom = mContentBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3311 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3312 | |
| 3313 | // Default policy decor for the default display |
| 3314 | dcf.left = mSystemLeft; |
| 3315 | dcf.top = mSystemTop; |
| 3316 | dcf.right = mSystemRight; |
| 3317 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3318 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 3319 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 3320 | final boolean isAppWindow = |
| 3321 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 3322 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 3323 | final boolean topAtRest = |
| 3324 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 3325 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3326 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 3327 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3328 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 3329 | && (fl & WindowManager.LayoutParams. |
| 3330 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3331 | // Ensure policy decor includes status bar |
| 3332 | dcf.top = mStableTop; |
| 3333 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3334 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3335 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 3336 | && (fl & WindowManager.LayoutParams. |
| 3337 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3338 | // Ensure policy decor includes navigation bar |
| 3339 | dcf.bottom = mStableBottom; |
| 3340 | dcf.right = mStableRight; |
| 3341 | } |
| 3342 | } |
| 3343 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3344 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 3345 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3346 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3347 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3348 | // This is the case for a normal activity window: we want it |
| 3349 | // to cover all of the screen space, and it can take care of |
| 3350 | // moving its contents to account for screen decorations that |
| 3351 | // intrude into that space. |
| 3352 | if (attached != null) { |
| 3353 | // If this window is attached to another, our display |
| 3354 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3355 | 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] | 3356 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3357 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3358 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3359 | // Status bar panels are the only windows who can go on top of |
| 3360 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3361 | // permission, so they have the same privileges as the status |
| 3362 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3363 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3364 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3365 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3366 | pf.left = df.left = of.left = hasNavBar |
| 3367 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3368 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3369 | pf.right = df.right = of.right = hasNavBar |
| 3370 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 3371 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3372 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 3373 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 3374 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3375 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3376 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3377 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 3378 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3379 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3380 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3381 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3382 | // Asking to layout into the overscan region, so give it that pure |
| 3383 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3384 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 3385 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 3386 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3387 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 3388 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3389 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3390 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3391 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3392 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3393 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3394 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3395 | // only do this for application windows to ensure no window that |
| 3396 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3397 | pf.left = df.left = mOverscanScreenLeft; |
| 3398 | pf.top = df.top = mOverscanScreenTop; |
| 3399 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3400 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3401 | // We need to tell the app about where the frame inside the overscan |
| 3402 | // is, so it can inset its content by that amount -- it didn't ask |
| 3403 | // to actually extend itself into the overscan region. |
| 3404 | of.left = mUnrestrictedScreenLeft; |
| 3405 | of.top = mUnrestrictedScreenTop; |
| 3406 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3407 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3408 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3409 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 3410 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 3411 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 3412 | + mRestrictedOverscanScreenWidth; |
| 3413 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 3414 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3415 | // We need to tell the app about where the frame inside the overscan |
| 3416 | // is, so it can inset its content by that amount -- it didn't ask |
| 3417 | // to actually extend itself into the overscan region. |
| 3418 | of.left = mUnrestrictedScreenLeft; |
| 3419 | of.top = mUnrestrictedScreenTop; |
| 3420 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3421 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3422 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3423 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3424 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3425 | if (win.isVoiceInteraction()) { |
| 3426 | cf.left = mVoiceContentLeft; |
| 3427 | cf.top = mVoiceContentTop; |
| 3428 | cf.right = mVoiceContentRight; |
| 3429 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3430 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3431 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 3432 | cf.left = mDockLeft; |
| 3433 | cf.top = mDockTop; |
| 3434 | cf.right = mDockRight; |
| 3435 | cf.bottom = mDockBottom; |
| 3436 | } else { |
| 3437 | cf.left = mContentLeft; |
| 3438 | cf.top = mContentTop; |
| 3439 | cf.right = mContentRight; |
| 3440 | cf.bottom = mContentBottom; |
| 3441 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3442 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3443 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3444 | // Full screen windows are always given a layout that is as if the |
| 3445 | // status bar and other transient decors are gone. This is to avoid |
| 3446 | // bad states when moving from a window that is not hding the |
| 3447 | // status bar to one that is. |
| 3448 | cf.left = mRestrictedScreenLeft; |
| 3449 | cf.top = mRestrictedScreenTop; |
| 3450 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3451 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3452 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3453 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3454 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3455 | vf.left = mCurLeft; |
| 3456 | vf.top = mCurTop; |
| 3457 | vf.right = mCurRight; |
| 3458 | vf.bottom = mCurBottom; |
| 3459 | } else { |
| 3460 | vf.set(cf); |
| 3461 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3462 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3463 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 3464 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 3465 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3466 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3467 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3468 | // A window that has requested to fill the entire screen just |
| 3469 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3470 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3471 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3472 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 3473 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3474 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3475 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3476 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3477 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3478 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3479 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3480 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3481 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3482 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 3483 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3484 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 3485 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3486 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3487 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3488 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3489 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 3490 | + mUnrestrictedScreenWidth; |
| 3491 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 3492 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3493 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3494 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 3495 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3496 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 3497 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 3498 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 3499 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3500 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3501 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3502 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3503 | + mOverscanScreenWidth; |
| 3504 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3505 | + mOverscanScreenHeight; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 3506 | } else if (attrs.type == TYPE_BOOT_PROGRESS |
| 3507 | || attrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3508 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3509 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3510 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3511 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3512 | + mOverscanScreenWidth; |
| 3513 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3514 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3515 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 3516 | // The wallpaper also has Real Ultimate Power. |
| 3517 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3518 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3519 | pf.right = df.right = of.right = cf.right |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3520 | = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3521 | pf.bottom = df.bottom = of.bottom = cf.bottom |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3522 | = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3523 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3524 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3525 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3526 | // Asking to layout into the overscan region, so give it that pure |
| 3527 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3528 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3529 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3530 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3531 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3532 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3533 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3534 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3535 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 3536 | && (attrs.type == TYPE_STATUS_BAR |
| 3537 | || attrs.type == TYPE_TOAST |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3538 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3539 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3540 | // Asking for layout as if the nav bar is hidden, lets the |
| 3541 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3542 | // 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] | 3543 | // can be above the nav bar can do this. |
| 3544 | // XXX This assumes that an app asking for this will also |
| 3545 | // ask for layout in only content. We can't currently figure out |
| 3546 | // 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] | 3547 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3548 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3549 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 3550 | + mUnrestrictedScreenWidth; |
| 3551 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3552 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3553 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3554 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3555 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3556 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3557 | + mRestrictedScreenWidth; |
| 3558 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3559 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3560 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3561 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3562 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3563 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3564 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3565 | vf.left = mCurLeft; |
| 3566 | vf.top = mCurTop; |
| 3567 | vf.right = mCurRight; |
| 3568 | vf.bottom = mCurBottom; |
| 3569 | } else { |
| 3570 | vf.set(cf); |
| 3571 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3572 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3573 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3574 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3575 | // A child window should be placed inside of the same visible |
| 3576 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3577 | 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] | 3578 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3579 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3580 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3581 | // Otherwise, a normal window must be placed inside the content |
| 3582 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3583 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 3584 | // Status bar panels are the only windows who can go on top of |
| 3585 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3586 | // permission, so they have the same privileges as the status |
| 3587 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3588 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3589 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3590 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3591 | + mRestrictedScreenWidth; |
| 3592 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3593 | + mRestrictedScreenHeight; |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 3594 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT |
| 3595 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 3596 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3597 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 3598 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 3599 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 3600 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3601 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3602 | pf.left = mContentLeft; |
| 3603 | pf.top = mContentTop; |
| 3604 | pf.right = mContentRight; |
| 3605 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 3606 | if (win.isVoiceInteraction()) { |
| 3607 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 3608 | df.top = of.top = cf.top = mVoiceContentTop; |
| 3609 | df.right = of.right = cf.right = mVoiceContentRight; |
| 3610 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 3611 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3612 | df.left = of.left = cf.left = mDockLeft; |
| 3613 | df.top = of.top = cf.top = mDockTop; |
| 3614 | df.right = of.right = cf.right = mDockRight; |
| 3615 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3616 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3617 | df.left = of.left = cf.left = mContentLeft; |
| 3618 | df.top = of.top = cf.top = mContentTop; |
| 3619 | df.right = of.right = cf.right = mContentRight; |
| 3620 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3621 | } |
| 3622 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3623 | vf.left = mCurLeft; |
| 3624 | vf.top = mCurTop; |
| 3625 | vf.right = mCurRight; |
| 3626 | vf.bottom = mCurBottom; |
| 3627 | } else { |
| 3628 | vf.set(cf); |
| 3629 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3630 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3631 | } |
| 3632 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3633 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 3634 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 3635 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3636 | df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 3637 | df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom |
| 3638 | = vf.right = vf.bottom = 10000; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3639 | } |
| 3640 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3641 | 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] | 3642 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3643 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3644 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3645 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3646 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3647 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3648 | + " dcf=" + dcf.toShortString() |
| 3649 | + " sf=" + sf.toShortString()); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3650 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3651 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3652 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3653 | // Dock windows carve out the bottom of the screen, so normal windows |
| 3654 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 3655 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 3656 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3657 | setLastInputMethodWindowLw(null, null); |
| 3658 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3659 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3660 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw() |
| 3661 | && !win.getGivenInsetsPendingLw()) { |
| 3662 | offsetVoiceInputWindowLw(win); |
| 3663 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3664 | } |
| 3665 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3666 | private void offsetInputMethodWindowLw(WindowState win) { |
| 3667 | int top = win.getContentFrameLw().top; |
| 3668 | top += win.getGivenContentInsetsLw().top; |
| 3669 | if (mContentBottom > top) { |
| 3670 | mContentBottom = top; |
| 3671 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3672 | if (mVoiceContentBottom > top) { |
| 3673 | mVoiceContentBottom = top; |
| 3674 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3675 | top = win.getVisibleFrameLw().top; |
| 3676 | top += win.getGivenVisibleInsetsLw().top; |
| 3677 | if (mCurBottom > top) { |
| 3678 | mCurBottom = top; |
| 3679 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3680 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3681 | + mDockBottom + " mContentBottom=" |
| 3682 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 3683 | } |
| 3684 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3685 | private void offsetVoiceInputWindowLw(WindowState win) { |
| 3686 | final int gravity = win.getAttrs().gravity; |
| 3687 | switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER) |
| 3688 | << Gravity.AXIS_X_SHIFT)) { |
| 3689 | case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: { |
| 3690 | int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right; |
| 3691 | if (mVoiceContentLeft < right) { |
| 3692 | mVoiceContentLeft = right; |
| 3693 | } |
| 3694 | } break; |
| 3695 | case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: { |
| 3696 | int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left; |
| 3697 | if (mVoiceContentRight < left) { |
| 3698 | mVoiceContentRight = left; |
| 3699 | } |
| 3700 | } break; |
| 3701 | } |
| 3702 | switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER) |
| 3703 | << Gravity.AXIS_Y_SHIFT)) { |
| 3704 | case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: { |
| 3705 | int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom; |
| 3706 | if (mVoiceContentTop < bottom) { |
| 3707 | mVoiceContentTop = bottom; |
| 3708 | } |
| 3709 | } break; |
| 3710 | case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: { |
| 3711 | int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top; |
| 3712 | if (mVoiceContentBottom < top) { |
| 3713 | mVoiceContentBottom = top; |
| 3714 | } |
| 3715 | } break; |
| 3716 | } |
| 3717 | } |
| 3718 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3719 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 3720 | @Override |
| 3721 | public void finishLayoutLw() { |
| 3722 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3723 | } |
| 3724 | |
| 3725 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3726 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3727 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3728 | mTopFullscreenOpaqueWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 3729 | mAppsToBeHidden.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3730 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3731 | mForceStatusBarFromKeyguard = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3732 | mForcingShowNavBar = false; |
| 3733 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3734 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3735 | mHideLockScreen = false; |
| 3736 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3737 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3738 | mShowingLockscreen = false; |
| 3739 | mShowingDream = false; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3740 | mWinShowWhenLocked = null; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3744 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3745 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3746 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 3747 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3748 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 3749 | if (mTopFullscreenOpaqueWindowState == null |
| 3750 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 3751 | mForcingShowNavBar = true; |
| 3752 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3753 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 3754 | if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 3755 | mForceStatusBarFromKeyguard = true; |
| 3756 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3757 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 3758 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3759 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3760 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3761 | mForceStatusBarFromKeyguard = true; |
| 3762 | } else { |
| 3763 | mForceStatusBar = true; |
| 3764 | } |
| 3765 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3766 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3767 | mShowingLockscreen = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3768 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3769 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3770 | && attrs.type <= LAST_APPLICATION_WINDOW; |
| 3771 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3772 | // If the lockscreen was showing when the dream started then wait |
| 3773 | // for the dream to draw before hiding the lockscreen. |
| 3774 | if (!mDreamingLockscreen |
| 3775 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 3776 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3777 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3778 | } |
| 3779 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3780 | |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 3781 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
Craig Mautner | 74ee938 | 2014-04-01 15:20:16 -0700 | [diff] [blame] | 3782 | final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3783 | final boolean secureKeyguard = isKeyguardSecure(); |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3784 | if (appWindow) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3785 | if (showWhenLocked || (dismissKeyguard && !secureKeyguard)) { |
| 3786 | // Remove any previous windows with the same appToken. |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 3787 | mAppsToBeHidden.remove(win.getAppToken()); |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3788 | if (mAppsToBeHidden.isEmpty() && showWhenLocked && |
| 3789 | isKeyguardSecureIncludingHidden()) { |
| 3790 | mWinShowWhenLocked = win; |
| 3791 | mHideLockScreen = true; |
| 3792 | mForceStatusBarFromKeyguard = false; |
| 3793 | } |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 3794 | } else { |
| 3795 | mAppsToBeHidden.add(win.getAppToken()); |
| 3796 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3797 | if (attrs.x == 0 && attrs.y == 0 |
| 3798 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 3799 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
| 3800 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 3801 | mTopFullscreenOpaqueWindowState = win; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 3802 | if (mAppsToBeHidden.isEmpty()) { |
Craig Mautner | da09ae3 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3803 | if (showWhenLocked) { |
| 3804 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 3805 | "Setting mHideLockScreen to true by win " + win); |
| 3806 | mHideLockScreen = true; |
| 3807 | mForceStatusBarFromKeyguard = false; |
| 3808 | } |
Craig Mautner | 4bdab6b | 2014-04-01 12:05:11 -0700 | [diff] [blame] | 3809 | if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
Craig Mautner | da09ae3 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3810 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 3811 | "Setting mDismissKeyguard true by win " + win); |
| 3812 | mDismissKeyguard = mWinDismissingKeyguard == win ? |
| 3813 | DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
| 3814 | mWinDismissingKeyguard = win; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3815 | mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard; |
Craig Mautner | da09ae3 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3816 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3817 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 3818 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3819 | mAllowLockscreenWhenOn = true; |
| 3820 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3821 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3822 | |
| 3823 | if (mWinShowWhenLocked != null && |
| 3824 | mWinShowWhenLocked.getAppToken() != win.getAppToken()) { |
| 3825 | win.hideLw(false); |
| 3826 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3827 | } |
| 3828 | } |
| 3829 | } |
| 3830 | |
| 3831 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3832 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3833 | public int finishPostLayoutPolicyLw() { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3834 | if (mWinShowWhenLocked != null && |
| 3835 | mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) { |
| 3836 | // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the |
| 3837 | // fullscreen window. |
| 3838 | // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not. |
| 3839 | mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 3840 | mTopFullscreenOpaqueWindowState.hideLw(false); |
| 3841 | mTopFullscreenOpaqueWindowState = mWinShowWhenLocked; |
| 3842 | } |
| 3843 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3844 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3845 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3846 | |
| 3847 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 3848 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 3849 | : null; |
| 3850 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3851 | // If we are not currently showing a dream then remember the current |
| 3852 | // lockscreen state. We will use this to determine whether the dream |
| 3853 | // started while the lockscreen was showing and remember this state |
| 3854 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3855 | if (!mShowingDream) { |
| 3856 | mDreamingLockscreen = mShowingLockscreen; |
| 3857 | } |
| 3858 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3859 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3860 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3861 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 3862 | + " top=" + mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3863 | if (mForceStatusBar || mForceStatusBarFromKeyguard) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3864 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3865 | if (mStatusBarController.setBarShowingLw(true)) { |
| 3866 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3867 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 3868 | // Maintain fullscreen layout until incoming animation is complete. |
| 3869 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 3870 | // Transient status bar on the lockscreen is not allowed |
| 3871 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 3872 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 3873 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 3874 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3875 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3876 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3877 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3878 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3879 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3880 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3881 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3882 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3883 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3884 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3885 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
| 3886 | // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window |
| 3887 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 3888 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3889 | if (mStatusBarController.isTransientShowing()) { |
| 3890 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3891 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3892 | } |
| 3893 | } else if (topIsFullscreen) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3894 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3895 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3896 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3897 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 3898 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 3899 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3900 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3901 | 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] | 3902 | if (mStatusBarController.setBarShowingLw(true)) { |
| 3903 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3904 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3905 | } |
| 3906 | } |
| 3907 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3908 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 3909 | if (mTopIsFullscreen != topIsFullscreen) { |
| 3910 | if (!topIsFullscreen) { |
| 3911 | // Force another layout when status bar becomes fully shown. |
| 3912 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3913 | } |
| 3914 | mTopIsFullscreen = topIsFullscreen; |
| 3915 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3916 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3917 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 3918 | // displayed when the screen is locked. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3919 | if (mKeyguardDelegate != null && mStatusBar != null) { |
| 3920 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 3921 | + mHideLockScreen); |
| 3922 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) { |
| 3923 | mKeyguardHidden = true; |
| 3924 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3925 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3926 | | FINISH_LAYOUT_REDO_CONFIG |
| 3927 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3928 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3929 | if (mKeyguardDelegate.isShowing()) { |
| 3930 | mHandler.post(new Runnable() { |
| 3931 | @Override |
| 3932 | public void run() { |
| 3933 | mKeyguardDelegate.keyguardDone(false, false); |
| 3934 | } |
| 3935 | }); |
| 3936 | } |
| 3937 | } else if (mHideLockScreen) { |
| 3938 | mKeyguardHidden = true; |
| 3939 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) { |
| 3940 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3941 | | FINISH_LAYOUT_REDO_CONFIG |
| 3942 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3943 | } |
| 3944 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
| 3945 | // This is the case of keyguard isSecure() and not mHideLockScreen. |
| 3946 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 3947 | // Only launch the next keyguard unlock window once per window. |
| 3948 | mKeyguardHidden = false; |
| 3949 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) { |
| 3950 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3951 | | FINISH_LAYOUT_REDO_CONFIG |
| 3952 | | FINISH_LAYOUT_REDO_WALLPAPER; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3953 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3954 | mHandler.post(new Runnable() { |
| 3955 | @Override |
| 3956 | public void run() { |
| 3957 | mKeyguardDelegate.dismiss(); |
| 3958 | } |
| 3959 | }); |
| 3960 | } |
| 3961 | } else { |
| 3962 | mWinDismissingKeyguard = null; |
| 3963 | mKeyguardHidden = false; |
| 3964 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) { |
| 3965 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3966 | | FINISH_LAYOUT_REDO_CONFIG |
| 3967 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3968 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3969 | } |
| 3970 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3971 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3972 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3973 | // If the navigation bar has been hidden or shown, we need to do another |
| 3974 | // layout pass to update that window. |
| 3975 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3976 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3977 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 3978 | // update since mAllowLockscreenWhenOn might have changed |
| 3979 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3980 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3981 | } |
| 3982 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3983 | /** |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3984 | * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3985 | * immediately need to put the wallpaper directly behind the Keyguard when a window with flag |
| 3986 | * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we |
| 3987 | * would wait for Keyguard to change the flags, that would be running asynchronously and thus be |
| 3988 | * too late so the user might see the window behind. |
| 3989 | * |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3990 | * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3991 | * @return Whether the flags have changed and we have to redo the layout. |
| 3992 | */ |
| 3993 | private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3994 | if (setHiddenResult |
| 3995 | == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3996 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 3997 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 3998 | return true; |
| 3999 | } else if (setHiddenResult |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4000 | == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4001 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 4002 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 4003 | return true; |
| 4004 | } else { |
| 4005 | return false; |
| 4006 | } |
| 4007 | } |
| 4008 | |
| 4009 | private boolean isStatusBarKeyguard() { |
| 4010 | return mStatusBar != null |
| 4011 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 4012 | } |
| 4013 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4014 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4015 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4016 | if (isStatusBarKeyguard() || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 4017 | // 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] | 4018 | return false; |
| 4019 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4020 | return true; |
| 4021 | } |
| 4022 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4023 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4024 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4025 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4026 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4027 | // If the navigation bar has been hidden or shown, we need to do another |
| 4028 | // layout pass to update that window. |
| 4029 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 4030 | } |
| 4031 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4032 | } |
| 4033 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 4034 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4035 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4036 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 4037 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4038 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 4039 | if (newLidState == mLidState) { |
| 4040 | return; |
| 4041 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4042 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4043 | mLidState = newLidState; |
| 4044 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4045 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4046 | |
| 4047 | if (lidOpen) { |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 4048 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4049 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4050 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4051 | } |
| 4052 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4053 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4054 | void setHdmiPlugged(boolean plugged) { |
| 4055 | if (mHdmiPlugged != plugged) { |
| 4056 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4057 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4058 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4059 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4060 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 4061 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4062 | } |
| 4063 | } |
| 4064 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4065 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4066 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4067 | // watch for HDMI plug messages if the hdmi switch exists |
| 4068 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 4069 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 4070 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4071 | final String filename = "/sys/class/switch/hdmi/state"; |
| 4072 | FileReader reader = null; |
| 4073 | try { |
| 4074 | reader = new FileReader(filename); |
| 4075 | char[] buf = new char[15]; |
| 4076 | int n = reader.read(buf); |
| 4077 | if (n > 1) { |
| 4078 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 4079 | } |
| 4080 | } catch (IOException ex) { |
| 4081 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4082 | } catch (NumberFormatException ex) { |
| 4083 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4084 | } finally { |
| 4085 | if (reader != null) { |
| 4086 | try { |
| 4087 | reader.close(); |
| 4088 | } catch (IOException ex) { |
| 4089 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4090 | } |
| 4091 | } |
| 4092 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4093 | // This dance forces the code in setHdmiPlugged to run. |
| 4094 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 4095 | mHdmiPlugged = !plugged; |
| 4096 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4097 | } |
| 4098 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 4099 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4100 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4101 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4102 | final Runnable mScreenshotTimeout = new Runnable() { |
| 4103 | @Override public void run() { |
| 4104 | synchronized (mScreenshotLock) { |
| 4105 | if (mScreenshotConnection != null) { |
| 4106 | mContext.unbindService(mScreenshotConnection); |
| 4107 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4108 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4109 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4110 | } |
| 4111 | }; |
| 4112 | |
| 4113 | // Assume this is called from the Handler thread. |
| 4114 | private void takeScreenshot() { |
| 4115 | synchronized (mScreenshotLock) { |
| 4116 | if (mScreenshotConnection != null) { |
| 4117 | return; |
| 4118 | } |
| 4119 | ComponentName cn = new ComponentName("com.android.systemui", |
| 4120 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 4121 | Intent intent = new Intent(); |
| 4122 | intent.setComponent(cn); |
| 4123 | ServiceConnection conn = new ServiceConnection() { |
| 4124 | @Override |
| 4125 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 4126 | synchronized (mScreenshotLock) { |
| 4127 | if (mScreenshotConnection != this) { |
| 4128 | return; |
| 4129 | } |
| 4130 | Messenger messenger = new Messenger(service); |
| 4131 | Message msg = Message.obtain(null, 1); |
| 4132 | final ServiceConnection myConn = this; |
| 4133 | Handler h = new Handler(mHandler.getLooper()) { |
| 4134 | @Override |
| 4135 | public void handleMessage(Message msg) { |
| 4136 | synchronized (mScreenshotLock) { |
| 4137 | if (mScreenshotConnection == myConn) { |
| 4138 | mContext.unbindService(mScreenshotConnection); |
| 4139 | mScreenshotConnection = null; |
| 4140 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 4141 | } |
| 4142 | } |
| 4143 | } |
| 4144 | }; |
| 4145 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 4146 | msg.arg1 = msg.arg2 = 0; |
| 4147 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 4148 | msg.arg1 = 1; |
| 4149 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 4150 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4151 | try { |
| 4152 | messenger.send(msg); |
| 4153 | } catch (RemoteException e) { |
| 4154 | } |
| 4155 | } |
| 4156 | } |
| 4157 | @Override |
| 4158 | public void onServiceDisconnected(ComponentName name) {} |
| 4159 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 4160 | if (mContext.bindServiceAsUser( |
| 4161 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4162 | mScreenshotConnection = conn; |
| 4163 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 4164 | } |
| 4165 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4166 | } |
| 4167 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4168 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4169 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4170 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4171 | if (!mSystemBooted) { |
| 4172 | // If we have not yet booted, don't let key events do anything. |
| 4173 | return 0; |
| 4174 | } |
| 4175 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4176 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 4177 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 4178 | final boolean canceled = event.isCanceled(); |
| 4179 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 4180 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4181 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4182 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 4183 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 4184 | // the same as if it were open and in front. |
| 4185 | // This will prevent any keys other than the power button from waking the screen |
| 4186 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4187 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4188 | (interactive ? |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4189 | mKeyguardDelegate.isShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4190 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4191 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4192 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4193 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4194 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4195 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4196 | } |
| 4197 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4198 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4199 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 4200 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 4201 | || event.isWakeKey(); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4202 | if (interactive || (isInjected && !isWakeKey)) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4203 | // When the screen is on or if the key is injected pass the key to the application. |
| 4204 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4205 | isWakeKey = false; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4206 | } else { |
| 4207 | // When the screen is off and the key is not injected, determine whether |
| 4208 | // to wake the device but don't pass the key to the application. |
| 4209 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4210 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 4211 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4212 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4213 | } |
| 4214 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4215 | // If the key would be handled globally, just return the result, don't worry about special |
| 4216 | // key processing. |
| 4217 | if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4218 | if (isWakeKey) { |
| 4219 | mPowerManager.wakeUp(event.getEventTime()); |
| 4220 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4221 | return result; |
| 4222 | } |
| 4223 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4224 | boolean useHapticFeedback = down |
| 4225 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 4226 | && event.getRepeatCount() == 0; |
| 4227 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4228 | // Handle special keys. |
| 4229 | switch (keyCode) { |
| 4230 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 4231 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4232 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4233 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 4234 | if (down) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4235 | if (interactive && !mVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4236 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 4237 | mVolumeDownKeyTriggered = true; |
| 4238 | mVolumeDownKeyTime = event.getDownTime(); |
| 4239 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 4240 | cancelPendingPowerKeyAction(); |
| 4241 | interceptScreenshotChord(); |
| 4242 | } |
| 4243 | } else { |
| 4244 | mVolumeDownKeyTriggered = false; |
| 4245 | cancelPendingScreenshotChordAction(); |
| 4246 | } |
| 4247 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 4248 | if (down) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4249 | if (interactive && !mVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4250 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 4251 | mVolumeUpKeyTriggered = true; |
| 4252 | cancelPendingPowerKeyAction(); |
| 4253 | cancelPendingScreenshotChordAction(); |
| 4254 | } |
| 4255 | } else { |
| 4256 | mVolumeUpKeyTriggered = false; |
| 4257 | cancelPendingScreenshotChordAction(); |
| 4258 | } |
| 4259 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4260 | if (down) { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4261 | TelecommManager telecommManager = getTelecommService(); |
| 4262 | if (telecommManager != null) { |
| 4263 | if (telecommManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4264 | // If an incoming call is ringing, either VOLUME key means |
| 4265 | // "silence ringer". We handle these keys here, rather than |
| 4266 | // in the InCallScreen, to make sure we'll respond to them |
| 4267 | // even if the InCallScreen hasn't come to the foreground yet. |
| 4268 | // Look for the DOWN event here, to agree with the "fallback" |
| 4269 | // behavior in the InCallScreen. |
| 4270 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4271 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4272 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4273 | // Silence the ringer. (It's safe to call this |
| 4274 | // even if the ringer has already been silenced.) |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4275 | telecommManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4276 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4277 | // And *don't* pass this key thru to the current activity |
| 4278 | // (which is probably the InCallScreen.) |
| 4279 | result &= ~ACTION_PASS_TO_USER; |
| 4280 | break; |
| 4281 | } |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 4282 | if (telecommManager.isInCall() |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4283 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 4284 | // 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] | 4285 | // the application, just pass it to the session service. |
| 4286 | |
| 4287 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 4288 | .sendVolumeKeyEvent(event, false); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4289 | break; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4290 | } |
| 4291 | } |
| 4292 | |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 4293 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 4294 | // If we aren't passing to the user and no one else |
| 4295 | // handled it send it to the session manager to figure |
| 4296 | // out. |
| 4297 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 4298 | .sendVolumeKeyEvent(event, true); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4299 | break; |
| 4300 | } |
| 4301 | } |
| 4302 | break; |
| 4303 | } |
| 4304 | |
| 4305 | case KeyEvent.KEYCODE_ENDCALL: { |
| 4306 | result &= ~ACTION_PASS_TO_USER; |
| 4307 | if (down) { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4308 | TelecommManager telecommManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4309 | boolean hungUp = false; |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4310 | if (telecommManager != null) { |
| 4311 | hungUp = telecommManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4312 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4313 | interceptPowerKeyDown(!interactive || hungUp); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4314 | } else { |
| 4315 | if (interceptPowerKeyUp(canceled)) { |
| 4316 | if ((mEndcallBehavior |
| 4317 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 4318 | if (goHome()) { |
| 4319 | break; |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 4320 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4321 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4322 | if ((mEndcallBehavior |
| 4323 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 4324 | mPowerManager.goToSleep(event.getEventTime(), |
| 4325 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4326 | isWakeKey = false; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4327 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4328 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4329 | } |
| 4330 | break; |
| 4331 | } |
| 4332 | |
| 4333 | case KeyEvent.KEYCODE_POWER: { |
| 4334 | result &= ~ACTION_PASS_TO_USER; |
| 4335 | if (down) { |
Jeff Brown | 26c6a50 | 2014-04-11 02:15:54 -0700 | [diff] [blame] | 4336 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 4337 | event.getDownTime(), isImmersiveMode(mLastSystemUiFlags)); |
| 4338 | if (panic) { |
| 4339 | mHandler.post(mRequestTransientNav); |
| 4340 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4341 | if (interactive && !mPowerKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4342 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 4343 | mPowerKeyTriggered = true; |
| 4344 | mPowerKeyTime = event.getDownTime(); |
| 4345 | interceptScreenshotChord(); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4346 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4347 | |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4348 | TelecommManager telecommManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4349 | boolean hungUp = false; |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4350 | if (telecommManager != null) { |
| 4351 | if (telecommManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4352 | // Pressing Power while there's a ringing incoming |
| 4353 | // call should silence the ringer. |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4354 | telecommManager.silenceRinger(); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4355 | } else if ((mIncallPowerBehavior |
| 4356 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 4357 | && telecommManager.isInCall() && interactive) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4358 | // Otherwise, if "Power button ends call" is enabled, |
| 4359 | // the Power button will hang up any current active call. |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4360 | hungUp = telecommManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4361 | } |
| 4362 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4363 | interceptPowerKeyDown(!interactive || hungUp |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4364 | || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4365 | } else { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4366 | mPowerKeyTriggered = false; |
| 4367 | cancelPendingScreenshotChordAction(); |
| 4368 | if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 4369 | powerShortPress(event.getEventTime()); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4370 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4371 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4372 | mPendingPowerKeyUpCanceled = false; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4373 | } |
| 4374 | break; |
| 4375 | } |
| 4376 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4377 | case KeyEvent.KEYCODE_SLEEP: { |
| 4378 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4379 | if (!mPowerManager.isInteractive()) { |
| 4380 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 4381 | } |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 4382 | mPowerManager.goToSleep(event.getEventTime(), |
| 4383 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4384 | isWakeKey = false; |
| 4385 | break; |
| 4386 | } |
| 4387 | |
| 4388 | case KeyEvent.KEYCODE_WAKEUP: { |
| 4389 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4390 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4391 | break; |
| 4392 | } |
| 4393 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4394 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4395 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4396 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4397 | if (down) { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4398 | TelecommManager telecommManager = getTelecommService(); |
| 4399 | if (telecommManager != null) { |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 4400 | if (telecommManager.isInCall()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4401 | // Suppress PLAY/PAUSE toggle when phone is ringing or in-call |
| 4402 | // to avoid music playback. |
| 4403 | break; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4404 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4405 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4406 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4407 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4408 | case KeyEvent.KEYCODE_MUTE: |
| 4409 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4410 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4411 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4412 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4413 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4414 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 4415 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4416 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 4417 | // Only do this if we would otherwise not pass it to the user. In that |
| 4418 | // case, the PhoneWindow class will do the same thing, except it will |
| 4419 | // 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] | 4420 | // Note that we need to make a copy of the key event here because the |
| 4421 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4422 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4423 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 4424 | new KeyEvent(event)); |
| 4425 | msg.setAsynchronous(true); |
| 4426 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4427 | } |
| 4428 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4429 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4430 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4431 | case KeyEvent.KEYCODE_CALL: { |
| 4432 | if (down) { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4433 | TelecommManager telecommManager = getTelecommService(); |
| 4434 | if (telecommManager != null) { |
| 4435 | if (telecommManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4436 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4437 | + " CALL key-down while ringing: Answer the call!"); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4438 | telecommManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4439 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4440 | // And *don't* pass this key thru to the current activity |
| 4441 | // (which is presumably the InCallScreen.) |
| 4442 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4443 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4444 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4445 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4446 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4447 | } |
| 4448 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4449 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4450 | if (useHapticFeedback) { |
| 4451 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 4452 | } |
| 4453 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4454 | if (isWakeKey) { |
| 4455 | mPowerManager.wakeUp(event.getEventTime()); |
| 4456 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4457 | return result; |
| 4458 | } |
| 4459 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4460 | /** |
| 4461 | * When the screen is off we ignore some keys that might otherwise typically |
| 4462 | * be considered wake keys. We filter them out here. |
| 4463 | * |
| 4464 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 4465 | * is always considered a wake key. |
| 4466 | */ |
| 4467 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 4468 | switch (keyCode) { |
| 4469 | // ignore volume keys unless docked |
| 4470 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4471 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 4472 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 4473 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 4474 | |
| 4475 | // ignore media and camera keys |
| 4476 | case KeyEvent.KEYCODE_MUTE: |
| 4477 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4478 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4479 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4480 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4481 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4482 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4483 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4484 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4485 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 4486 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4487 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4488 | case KeyEvent.KEYCODE_CAMERA: |
| 4489 | return false; |
| 4490 | } |
| 4491 | return true; |
| 4492 | } |
| 4493 | |
| 4494 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4495 | /** {@inheritDoc} */ |
| 4496 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4497 | public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) { |
| 4498 | // We already know this is a wake motion so just wake up. |
| 4499 | // Note that we would observe policyFlags containing |
| 4500 | // FLAG_WAKE and FLAG_INTERACTIVE here. |
| 4501 | mPowerManager.wakeUp(whenNanos / 1000000); |
| 4502 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4503 | } |
| 4504 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4505 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 4506 | if (DEBUG_INPUT) { |
| 4507 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4508 | } |
| 4509 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4510 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 4511 | if (DEBUG_INPUT) { |
| 4512 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 4513 | } |
| 4514 | |
| 4515 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 4516 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4517 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 4518 | } |
| 4519 | |
| 4520 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 4521 | |
| 4522 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 4523 | && event.getRepeatCount() == 0) { |
| 4524 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 4525 | |
| 4526 | Message msg = mHandler.obtainMessage( |
| 4527 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 4528 | msg.setAsynchronous(true); |
| 4529 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 4530 | } else { |
| 4531 | mBroadcastWakeLock.release(); |
| 4532 | } |
| 4533 | } |
| 4534 | |
| 4535 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 4536 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4537 | |
| 4538 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 4539 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 4540 | if (DEBUG_INPUT) { |
| 4541 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 4542 | } |
| 4543 | |
| 4544 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 4545 | mBroadcastWakeLock.release(); |
| 4546 | } |
| 4547 | |
| 4548 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 4549 | if (ActivityManagerNative.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 4550 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4551 | } |
| 4552 | } |
| 4553 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4554 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4555 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4556 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 4557 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 4558 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 4559 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4560 | } else { |
| 4561 | try { |
| 4562 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 4563 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 4564 | mUiMode = uiModeService.getCurrentModeType(); |
| 4565 | } catch (RemoteException e) { |
| 4566 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 4567 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4568 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4569 | synchronized (mLock) { |
| 4570 | updateOrientationListenerLp(); |
| 4571 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4572 | } |
| 4573 | }; |
| 4574 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4575 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 4576 | @Override |
| 4577 | public void onReceive(Context context, Intent intent) { |
| 4578 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4579 | if (mKeyguardDelegate != null) { |
| 4580 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4581 | } |
| 4582 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4583 | if (mKeyguardDelegate != null) { |
| 4584 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4585 | } |
| 4586 | } |
| 4587 | } |
| 4588 | }; |
| 4589 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4590 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 4591 | @Override |
| 4592 | public void onReceive(Context context, Intent intent) { |
| 4593 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 4594 | // tickle the settings observer: this first ensures that we're |
| 4595 | // observing the relevant settings for the newly-active user, |
| 4596 | // and then updates our own bookkeeping based on the now- |
| 4597 | // current user. |
| 4598 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4599 | |
| 4600 | // force a re-application of focused window sysui visibility. |
| 4601 | // the window may never have been shown for this user |
| 4602 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4603 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4604 | mLastSystemUiFlags = 0; |
| 4605 | updateSystemUiVisibilityLw(); |
| 4606 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4607 | } |
| 4608 | } |
| 4609 | }; |
| 4610 | |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 4611 | private final Runnable mRequestTransientNav = new Runnable() { |
| 4612 | @Override |
| 4613 | public void run() { |
| 4614 | requestTransientBars(mNavigationBar); |
| 4615 | } |
| 4616 | }; |
| 4617 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4618 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4619 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 4620 | if (!isUserSetupComplete()) { |
| 4621 | // Swipe-up for navigation bar is disabled during setup |
| 4622 | return; |
| 4623 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4624 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 4625 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4626 | if (sb || nb) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4627 | WindowState barTarget = sb ? mStatusBar : mNavigationBar; |
| 4628 | if (sb ^ nb && barTarget != swipeTarget) { |
| 4629 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4630 | return; |
| 4631 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4632 | if (sb) mStatusBarController.showTransient(); |
| 4633 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 4634 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4635 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4636 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4640 | @Override |
Jeff Brown | 140ffc7 | 2014-05-01 15:18:00 -0700 | [diff] [blame] | 4641 | public void goingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4642 | EventLog.writeEvent(70000, 0); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4643 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4644 | mScreenOnEarly = false; |
| 4645 | mScreenOnFully = false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4646 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4647 | if (mKeyguardDelegate != null) { |
| 4648 | mKeyguardDelegate.onScreenTurnedOff(why); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4649 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4650 | synchronized (mLock) { |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 4651 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4652 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4653 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4654 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4655 | } |
| 4656 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4657 | @Override |
Jeff Brown | 140ffc7 | 2014-05-01 15:18:00 -0700 | [diff] [blame] | 4658 | public void wakingUp(final ScreenOnListener screenOnListener) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4659 | EventLog.writeEvent(70000, 1); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4660 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...", |
| 4661 | new RuntimeException("here").fillInStackTrace()); |
| 4662 | mHandler.obtainMessage(MSG_WAKING_UP, screenOnListener).sendToTarget(); |
| 4663 | } |
| 4664 | |
| 4665 | // Called on the mHandler thread. |
| 4666 | private void handleWakingUp(final ScreenOnListener screenOnListener) { |
| 4667 | if (screenOnListener != null) { |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 4668 | mScreenOnListener = screenOnListener; |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 4669 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4670 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4671 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4672 | mScreenOnEarly = true; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 4673 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4674 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4675 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4676 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4677 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4678 | mKeyguardDrawComplete = false; |
| 4679 | mWindowManagerDrawComplete = false; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4680 | if (mKeyguardDelegate != null) { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4681 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 4682 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
| 4683 | mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4684 | } else { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4685 | if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
| 4686 | mKeyguardDrawComplete = true; |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4687 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4688 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, 500); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4689 | } |
| 4690 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4691 | // Called on the mHandler thread. |
| 4692 | private void finishScreenTurningOn() { |
| 4693 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 4694 | "finishScreenTurningOn: mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 4695 | + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 4696 | if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) { |
| 4697 | return; |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4698 | } |
| 4699 | |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 4700 | ScreenOnListener screenOnListener; |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4701 | synchronized (mLock) { |
| 4702 | mScreenOnFully = true; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 4703 | screenOnListener = mScreenOnListener; |
| 4704 | mScreenOnListener = null; |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4705 | } |
| 4706 | |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 4707 | try { |
| 4708 | mWindowManager.setEventDispatching(true); |
| 4709 | } catch (RemoteException unhandled) { |
| 4710 | } |
| 4711 | |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 4712 | if (screenOnListener != null) { |
| 4713 | screenOnListener.onScreenOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4714 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4715 | |
| 4716 | setKeyguardDrawn(); |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 4717 | |
| 4718 | if (mBootMessageNeedsHiding) { |
| 4719 | handleHideBootMessage(); |
| 4720 | mBootMessageNeedsHiding = false; |
| 4721 | } |
| 4722 | } |
| 4723 | |
| 4724 | private void handleHideBootMessage() { |
| 4725 | if (mBootMsgDialog == null) { |
| 4726 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: boot message not up"); |
| 4727 | return; |
| 4728 | } |
| 4729 | if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) { |
| 4730 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: deferring until keyguard ready"); |
| 4731 | mBootMessageNeedsHiding = true; |
| 4732 | return; |
| 4733 | } |
| 4734 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 4735 | mBootMsgDialog.dismiss(); |
| 4736 | mBootMsgDialog = null; |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4737 | } |
| 4738 | |
| 4739 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4740 | public boolean isScreenOnEarly() { |
| 4741 | return mScreenOnEarly; |
| 4742 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4743 | |
| 4744 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4745 | public boolean isScreenOnFully() { |
| 4746 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4747 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4748 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4749 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4750 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4751 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4752 | if (mKeyguardDelegate != null) { |
| 4753 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4754 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4758 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4759 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4760 | if (mKeyguardDelegate != null) { |
| 4761 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4762 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4763 | } |
| 4764 | |
Mike Lockwood | f791330 | 2009-11-28 22:27:10 -0500 | [diff] [blame] | 4765 | private boolean keyguardIsShowingTq() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4766 | if (mKeyguardDelegate == null) return false; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4767 | return mKeyguardDelegate.isShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4768 | } |
| 4769 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4770 | |
| 4771 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4772 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4773 | public boolean isKeyguardLocked() { |
| 4774 | return keyguardOn(); |
| 4775 | } |
| 4776 | |
| 4777 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4778 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4779 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4780 | if (mKeyguardDelegate == null) return false; |
| 4781 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4782 | } |
| 4783 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4784 | // Returns true if keyguard is currently locked whether or not it is currently hidden. |
| 4785 | private boolean isKeyguardSecureIncludingHidden() { |
| 4786 | return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing(); |
| 4787 | } |
| 4788 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4789 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4790 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4791 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4792 | if (mKeyguardDelegate == null) return false; |
| 4793 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4794 | } |
| 4795 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4796 | @Override |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4797 | public void dismissKeyguardLw() { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4798 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4799 | mHandler.post(new Runnable() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4800 | @Override |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4801 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 4802 | // ask the keyguard to prompt the user to authenticate if necessary |
| 4803 | mKeyguardDelegate.dismiss(); |
| 4804 | } |
| 4805 | }); |
| 4806 | } |
| 4807 | } |
| 4808 | |
| 4809 | public void notifyActivityDrawnForKeyguardLw() { |
| 4810 | if (mKeyguardDelegate != null) { |
| 4811 | mHandler.post(new Runnable() { |
| 4812 | @Override |
| 4813 | public void run() { |
| 4814 | mKeyguardDelegate.onActivityDrawn(); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4815 | } |
| 4816 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4817 | } |
| 4818 | } |
| 4819 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 4820 | private void setKeyguardDrawn() { |
| 4821 | synchronized (mLock) { |
| 4822 | mKeyguardDrawn = true; |
| 4823 | } |
| 4824 | try { |
| 4825 | mWindowManager.enableScreenIfNeeded(); |
| 4826 | } catch (RemoteException unhandled) { |
| 4827 | } |
| 4828 | } |
| 4829 | |
| 4830 | @Override |
| 4831 | public boolean isKeyguardDrawnLw() { |
| 4832 | synchronized (mLock) { |
| 4833 | return mKeyguardDrawn; |
| 4834 | } |
| 4835 | } |
| 4836 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 4837 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 4838 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 4839 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 4840 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 4841 | } |
| 4842 | } |
| 4843 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4844 | void sendCloseSystemWindows() { |
| 4845 | sendCloseSystemWindows(mContext, null); |
| 4846 | } |
| 4847 | |
| 4848 | void sendCloseSystemWindows(String reason) { |
| 4849 | sendCloseSystemWindows(mContext, reason); |
| 4850 | } |
| 4851 | |
| 4852 | static void sendCloseSystemWindows(Context context, String reason) { |
| 4853 | if (ActivityManagerNative.isSystemReady()) { |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 4854 | try { |
| 4855 | ActivityManagerNative.getDefault().closeSystemDialogs(reason); |
| 4856 | } catch (RemoteException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4857 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4858 | } |
| 4859 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 4860 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4861 | @Override |
| 4862 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4863 | if (false) { |
| 4864 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 4865 | + orientation + ", last=" + lastRotation |
| 4866 | + "); user=" + mUserRotation + " " |
| 4867 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 4868 | ? "USER_ROTATION_LOCKED" : "") |
| 4869 | ); |
| 4870 | } |
| 4871 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 4872 | if (mForceDefaultOrientation) { |
| 4873 | return Surface.ROTATION_0; |
| 4874 | } |
| 4875 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4876 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4877 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 4878 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 4879 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4880 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4881 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4882 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 4883 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4884 | // Ignore sensor when lid switch is open and rotation is forced. |
| 4885 | preferredRotation = mLidOpenRotation; |
| 4886 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4887 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4888 | // Ignore sensor when in car dock unless explicitly enabled. |
| 4889 | // This case can override the behavior of NOSENSOR, and can also |
| 4890 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4891 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4892 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 4893 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 4894 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 4895 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4896 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4897 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 4898 | // This case can override the behavior of NOSENSOR, and can also |
| 4899 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4900 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4901 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 4902 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 4903 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 4904 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 4905 | preferredRotation = mDemoHdmiRotation; |
| 4906 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 4907 | && mUndockedHdmiRotation >= 0) { |
| 4908 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 4909 | // been specified in the configuration (only for legacy devices without |
| 4910 | // full multi-display support). |
| 4911 | // Note that the dock orientation overrides the HDMI orientation. |
| 4912 | preferredRotation = mUndockedHdmiRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4913 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 4914 | // Application just wants to remain locked in the last rotation. |
| 4915 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 4916 | } else if (!mSupportAutoRotation) { |
| 4917 | // If we don't support auto-rotation then bail out here and ignore |
| 4918 | // the sensor and any rotation lock settings. |
| 4919 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4920 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4921 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4922 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 4923 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 4924 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 4925 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4926 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 4927 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4928 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 4929 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 4930 | // Otherwise, use sensor only if requested by the application or enabled |
| 4931 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4932 | if (mAllowAllRotations < 0) { |
| 4933 | // Can't read this during init() because the context doesn't |
| 4934 | // have display metrics at that time so we cannot determine |
| 4935 | // tablet vs. phone then. |
| 4936 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 4937 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 4938 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4939 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4940 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4941 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4942 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4943 | preferredRotation = sensorRotation; |
| 4944 | } else { |
| 4945 | preferredRotation = lastRotation; |
| 4946 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4947 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 4948 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 4949 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 4950 | // The idea is that the user rotation expresses a weak preference for the direction |
| 4951 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 4952 | // 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] | 4953 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4954 | } else { |
| 4955 | // No overriding preference. |
| 4956 | // We will do exactly what the application asked us to do. |
| 4957 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4958 | } |
| 4959 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4960 | switch (orientation) { |
| 4961 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4962 | // Return portrait unless overridden. |
| 4963 | if (isAnyPortrait(preferredRotation)) { |
| 4964 | return preferredRotation; |
| 4965 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4966 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4967 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4968 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4969 | // Return landscape unless overridden. |
| 4970 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4971 | return preferredRotation; |
| 4972 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4973 | return mLandscapeRotation; |
| 4974 | |
| 4975 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4976 | // Return reverse portrait unless overridden. |
| 4977 | if (isAnyPortrait(preferredRotation)) { |
| 4978 | return preferredRotation; |
| 4979 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4980 | return mUpsideDownRotation; |
| 4981 | |
| 4982 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4983 | // Return seascape unless overridden. |
| 4984 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4985 | return preferredRotation; |
| 4986 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4987 | return mSeascapeRotation; |
| 4988 | |
| 4989 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4990 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4991 | // Return either landscape rotation. |
| 4992 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4993 | return preferredRotation; |
| 4994 | } |
| 4995 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 4996 | return lastRotation; |
| 4997 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4998 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4999 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5000 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5001 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5002 | // Return either portrait rotation. |
| 5003 | if (isAnyPortrait(preferredRotation)) { |
| 5004 | return preferredRotation; |
| 5005 | } |
| 5006 | if (isAnyPortrait(lastRotation)) { |
| 5007 | return lastRotation; |
| 5008 | } |
| 5009 | return mPortraitRotation; |
| 5010 | |
| 5011 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5012 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 5013 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5014 | if (preferredRotation >= 0) { |
| 5015 | return preferredRotation; |
| 5016 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5017 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 5018 | } |
| 5019 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5020 | } |
| 5021 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5022 | @Override |
| 5023 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 5024 | switch (orientation) { |
| 5025 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 5026 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 5027 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 5028 | return isAnyPortrait(rotation); |
| 5029 | |
| 5030 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 5031 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 5032 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 5033 | return isLandscapeOrSeascape(rotation); |
| 5034 | |
| 5035 | default: |
| 5036 | return true; |
| 5037 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5038 | } |
| 5039 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5040 | @Override |
| 5041 | public void setRotationLw(int rotation) { |
| 5042 | mOrientationListener.setCurrentRotation(rotation); |
| 5043 | } |
| 5044 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5045 | private boolean isLandscapeOrSeascape(int rotation) { |
| 5046 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5047 | } |
| 5048 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5049 | private boolean isAnyPortrait(int rotation) { |
| 5050 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5051 | } |
| 5052 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5053 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5054 | public int getUserRotationMode() { |
| 5055 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 5056 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 5057 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 5058 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5059 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5060 | |
| 5061 | // 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] | 5062 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5063 | public void setUserRotationMode(int mode, int rot) { |
| 5064 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5065 | |
| 5066 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5067 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5068 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5069 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5070 | rot, |
| 5071 | UserHandle.USER_CURRENT); |
| 5072 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5073 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5074 | 0, |
| 5075 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5076 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5077 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5078 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5079 | 1, |
| 5080 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5081 | } |
| 5082 | } |
| 5083 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5084 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5085 | public void setSafeMode(boolean safeMode) { |
| 5086 | mSafeMode = safeMode; |
| 5087 | performHapticFeedbackLw(null, safeMode |
| 5088 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 5089 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5090 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5091 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 5092 | static long[] getLongIntArray(Resources r, int resid) { |
| 5093 | int[] ar = r.getIntArray(resid); |
| 5094 | if (ar == null) { |
| 5095 | return null; |
| 5096 | } |
| 5097 | long[] out = new long[ar.length]; |
| 5098 | for (int i=0; i<ar.length; i++) { |
| 5099 | out[i] = ar[i]; |
| 5100 | } |
| 5101 | return out; |
| 5102 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5103 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5104 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5105 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5106 | public void systemReady() { |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 5107 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null); |
| 5108 | mKeyguardDelegate.onSystemReady(); |
| 5109 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5110 | updateUiMode(); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5111 | synchronized (mLock) { |
| 5112 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5113 | mSystemReady = true; |
| 5114 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5115 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5116 | public void run() { |
| 5117 | updateSettings(); |
| 5118 | } |
| 5119 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5120 | } |
| 5121 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5122 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5123 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5124 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5125 | public void systemBooted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5126 | if (mKeyguardDelegate != null) { |
| 5127 | mKeyguardDelegate.onBootCompleted(); |
| 5128 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5129 | synchronized (mLock) { |
| 5130 | mSystemBooted = true; |
| 5131 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5132 | wakingUp(null); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5133 | } |
| 5134 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5135 | ProgressDialog mBootMsgDialog = null; |
| 5136 | |
| 5137 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5138 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5139 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 5140 | mHandler.post(new Runnable() { |
| 5141 | @Override public void run() { |
| 5142 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 5143 | int theme; |
| 5144 | if (mContext.getPackageManager().hasSystemFeature( |
| 5145 | PackageManager.FEATURE_WATCH)) { |
| 5146 | theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert; |
| 5147 | } else if (mContext.getPackageManager().hasSystemFeature( |
| 5148 | PackageManager.FEATURE_TELEVISION)) { |
| 5149 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 5150 | } else { |
| 5151 | theme = 0; |
| 5152 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 5153 | |
| 5154 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 5155 | // This dialog will consume all events coming in to |
| 5156 | // it, to avoid it trying to do things too early in boot. |
| 5157 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 5158 | return true; |
| 5159 | } |
| 5160 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 5161 | return true; |
| 5162 | } |
| 5163 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 5164 | return true; |
| 5165 | } |
| 5166 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 5167 | return true; |
| 5168 | } |
| 5169 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 5170 | return true; |
| 5171 | } |
| 5172 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 5173 | AccessibilityEvent event) { |
| 5174 | return true; |
| 5175 | } |
| 5176 | }; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5177 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 5178 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 5179 | mBootMsgDialog.setIndeterminate(true); |
| 5180 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5181 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5182 | mBootMsgDialog.getWindow().addFlags( |
| 5183 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 5184 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 5185 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 5186 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 5187 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 5188 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5189 | mBootMsgDialog.setCancelable(false); |
| 5190 | mBootMsgDialog.show(); |
| 5191 | } |
| 5192 | mBootMsgDialog.setMessage(msg); |
| 5193 | } |
| 5194 | }); |
| 5195 | } |
| 5196 | |
| 5197 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5198 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5199 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5200 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5201 | } |
| 5202 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5203 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5204 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5205 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5206 | // *************************************** |
| 5207 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 5208 | // *************************************** |
| 5209 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 5210 | // WITH ITS LOCKS HELD. |
| 5211 | // |
| 5212 | // This code must be VERY careful about the locks |
| 5213 | // it acquires. |
| 5214 | // In fact, the current code acquires way too many, |
| 5215 | // and probably has lurking deadlocks. |
| 5216 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5217 | synchronized (mScreenLockTimeout) { |
| 5218 | if (mLockScreenTimerActive) { |
| 5219 | // reset the timer |
| 5220 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5221 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5222 | } |
| 5223 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 5224 | } |
| 5225 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5226 | class ScreenLockTimeout implements Runnable { |
| 5227 | Bundle options; |
| 5228 | |
| 5229 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5230 | public void run() { |
| 5231 | synchronized (this) { |
| 5232 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5233 | if (mKeyguardDelegate != null) { |
| 5234 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5235 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5236 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5237 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5238 | } |
| 5239 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5240 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5241 | public void setLockOptions(Bundle options) { |
| 5242 | this.options = options; |
| 5243 | } |
| 5244 | } |
| 5245 | |
| 5246 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 5247 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5248 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5249 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5250 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 5251 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5252 | if (options != null) { |
| 5253 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 5254 | // until the runnable actually executes. |
| 5255 | mScreenLockTimeout.setLockOptions(options); |
| 5256 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5257 | mHandler.post(mScreenLockTimeout); |
| 5258 | } |
| 5259 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5260 | private void updateLockScreenTimeout() { |
| 5261 | synchronized (mScreenLockTimeout) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5262 | boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5263 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5264 | if (mLockScreenTimerActive != enable) { |
| 5265 | if (enable) { |
| 5266 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 5267 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5268 | } else { |
| 5269 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 5270 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5271 | } |
| 5272 | mLockScreenTimerActive = enable; |
| 5273 | } |
| 5274 | } |
| 5275 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5276 | |
| 5277 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5278 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5279 | public void enableScreenAfterBoot() { |
| 5280 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5281 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5282 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5283 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 5284 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5285 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5286 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5287 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 5288 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5289 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5290 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5291 | |
| 5292 | synchronized (mLock) { |
| 5293 | updateWakeGestureListenerLp(); |
| 5294 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5295 | } |
| 5296 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5297 | void updateUiMode() { |
| 5298 | if (mUiModeManager == null) { |
| 5299 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 5300 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5301 | } |
| 5302 | try { |
| 5303 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 5304 | } catch (RemoteException e) { |
| 5305 | } |
| 5306 | } |
| 5307 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5308 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5309 | try { |
| 5310 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5311 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 5312 | } catch (RemoteException e) { |
| 5313 | // Ignore |
| 5314 | } |
| 5315 | } |
| 5316 | |
| 5317 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 5318 | try { |
| 5319 | //set orientation on WindowManager |
| 5320 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5321 | } catch (RemoteException e) { |
| 5322 | // Ignore |
| 5323 | } |
| 5324 | } |
| 5325 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5326 | /** |
| 5327 | * Return an Intent to launch the currently active dock app as home. Returns |
| 5328 | * null if the standard home should be launched, which is the case if any of the following is |
| 5329 | * true: |
| 5330 | * <ul> |
| 5331 | * <li>The device is not in either car mode or desk mode |
| 5332 | * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false |
| 5333 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 5334 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 5335 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 5336 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5337 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5338 | */ |
| 5339 | Intent createHomeDockIntent() { |
| 5340 | Intent intent = null; |
| 5341 | |
| 5342 | // What home does is based on the mode, not the dock state. That |
| 5343 | // is, when in car mode you should be taken to car home regardless |
| 5344 | // of whether we are actually in a car dock. |
| 5345 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 5346 | if (ENABLE_CAR_DOCK_HOME_CAPTURE) { |
| 5347 | intent = mCarDockIntent; |
| 5348 | } |
| 5349 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 5350 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 5351 | intent = mDeskDockIntent; |
| 5352 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5353 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 5354 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 5355 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 5356 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 5357 | // Always launch dock home from home when watch is docked, if it exists. |
| 5358 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | if (intent == null) { |
| 5362 | return null; |
| 5363 | } |
| 5364 | |
| 5365 | ActivityInfo ai = null; |
| 5366 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 5367 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 5368 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 5369 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5370 | if (info != null) { |
| 5371 | ai = info.activityInfo; |
| 5372 | } |
| 5373 | if (ai != null |
| 5374 | && ai.metaData != null |
| 5375 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 5376 | intent = new Intent(intent); |
| 5377 | intent.setClassName(ai.packageName, ai.name); |
| 5378 | return intent; |
| 5379 | } |
| 5380 | |
| 5381 | return null; |
| 5382 | } |
| 5383 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5384 | void startDockOrHome() { |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 5385 | awakenDreams(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5386 | |
| 5387 | Intent dock = createHomeDockIntent(); |
| 5388 | if (dock != null) { |
| 5389 | try { |
| 5390 | mContext.startActivityAsUser(dock, UserHandle.CURRENT); |
| 5391 | return; |
| 5392 | } catch (ActivityNotFoundException e) { |
| 5393 | } |
| 5394 | } |
| 5395 | |
Dianne Hackborn | d888399 | 2012-09-07 15:58:52 -0700 | [diff] [blame] | 5396 | mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5397 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5398 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5399 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5400 | * goes to the home screen |
| 5401 | * @return whether it did anything |
| 5402 | */ |
| 5403 | boolean goHome() { |
| 5404 | if (false) { |
| 5405 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 5406 | try { |
| 5407 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 5408 | } catch (RemoteException e) { |
| 5409 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 5410 | sendCloseSystemWindows(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5411 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5412 | } else { |
| 5413 | // This code brings home to the front or, if it is already |
| 5414 | // at the front, puts the device to sleep. |
| 5415 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 5416 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 5417 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 5418 | Log.d(TAG, "UTS-TEST-MODE"); |
| 5419 | } else { |
| 5420 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 5421 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5422 | Intent dock = createHomeDockIntent(); |
| 5423 | if (dock != null) { |
| 5424 | int result = ActivityManagerNative.getDefault() |
| 5425 | .startActivityAsUser(null, null, dock, |
| 5426 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 5427 | null, null, 0, |
| 5428 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame^] | 5429 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5430 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 5431 | return false; |
| 5432 | } |
| 5433 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5434 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5435 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5436 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5437 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5438 | null, null, 0, |
| 5439 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame^] | 5440 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5441 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5442 | return false; |
| 5443 | } |
| 5444 | } catch (RemoteException ex) { |
| 5445 | // bummer, the activity manager, which is in this process, is dead |
| 5446 | } |
| 5447 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5448 | return true; |
| 5449 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5450 | |
| 5451 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5452 | public void setCurrentOrientationLw(int newOrientation) { |
| 5453 | synchronized (mLock) { |
| 5454 | if (newOrientation != mCurrentAppOrientation) { |
| 5455 | mCurrentAppOrientation = newOrientation; |
| 5456 | updateOrientationListenerLp(); |
| 5457 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5458 | } |
| 5459 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5460 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 5461 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 5462 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 5463 | return; |
| 5464 | } |
| 5465 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 5466 | Context.AUDIO_SERVICE); |
| 5467 | if (audioManager.isSilentMode()) { |
| 5468 | return; |
| 5469 | } |
| 5470 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 5471 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 5472 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 5473 | ringTone.play(); |
| 5474 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5475 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 5476 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 5477 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 5478 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 5479 | } |
| 5480 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5481 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5482 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 5483 | if (!mVibrator.hasVibrator()) { |
| 5484 | return false; |
| 5485 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5486 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 5487 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 5488 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5489 | return false; |
| 5490 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5491 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5492 | switch (effectId) { |
| 5493 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5494 | pattern = mLongPressVibePattern; |
| 5495 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5496 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5497 | pattern = mVirtualKeyVibePattern; |
| 5498 | break; |
| 5499 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 5500 | pattern = mKeyboardTapVibePattern; |
| 5501 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 5502 | case HapticFeedbackConstants.CLOCK_TICK: |
| 5503 | pattern = mClockTickVibePattern; |
| 5504 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 5505 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 5506 | pattern = mCalendarDateVibePattern; |
| 5507 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5508 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5509 | pattern = mSafeModeDisabledVibePattern; |
| 5510 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5511 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5512 | pattern = mSafeModeEnabledVibePattern; |
| 5513 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5514 | default: |
| 5515 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5516 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5517 | int owningUid; |
| 5518 | String owningPackage; |
| 5519 | if (win != null) { |
| 5520 | owningUid = win.getOwningUid(); |
| 5521 | owningPackage = win.getOwningPackage(); |
| 5522 | } else { |
| 5523 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 5524 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5525 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5526 | if (pattern.length == 1) { |
| 5527 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 5528 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5529 | } else { |
| 5530 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 5531 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5532 | } |
| 5533 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5534 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5535 | |
| 5536 | @Override |
| 5537 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 5538 | } |
| 5539 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5540 | @Override |
| 5541 | public void keepScreenOnStoppedLw() { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5542 | if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 5543 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5544 | } |
| 5545 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 5546 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5547 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5548 | // If there is no window focused, there will be nobody to handle the events |
| 5549 | // anyway, so just hang on in whatever state we're in until things settle down. |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5550 | WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState; |
| 5551 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5552 | return 0; |
| 5553 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5554 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5555 | // We are updating at a point where the keyguard has gotten |
| 5556 | // focus, but we were last in a state where the top window is |
| 5557 | // hiding it. This is probably because the keyguard as been |
| 5558 | // shown while the top window was displayed, so we want to ignore |
| 5559 | // it here because this is just a very transient change and it |
| 5560 | // will quickly lose focus once it correctly gets hidden. |
| 5561 | return 0; |
| 5562 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5563 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 5564 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5565 | & ~mResettingSystemUiFlags |
| 5566 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5567 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5568 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5569 | } |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5570 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5571 | final int diff = visibility ^ mLastSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5572 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 5573 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5574 | && mFocusedApp == win.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5575 | return 0; |
| 5576 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5577 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 5578 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5579 | mFocusedApp = win.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5580 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5581 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5582 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5583 | try { |
| 5584 | IStatusBarService statusbar = getStatusBarService(); |
| 5585 | if (statusbar != null) { |
| 5586 | statusbar.setSystemUiVisibility(visibility, 0xffffffff); |
| 5587 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5588 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5589 | } catch (RemoteException e) { |
| 5590 | // re-acquire status bar service next time it is needed. |
| 5591 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5592 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5593 | } |
| 5594 | }); |
| 5595 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5596 | } |
| 5597 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5598 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5599 | // apply translucent bar vis flags |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5600 | WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen |
| 5601 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5602 | : mTopFullscreenOpaqueWindowState; |
| 5603 | vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 5604 | vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 5605 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5606 | // prevent status bar interaction from clearing certain flags |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5607 | boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 5608 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5609 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 5610 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 5611 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5612 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 5613 | if (mHideLockScreen) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5614 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 5615 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5616 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5617 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5618 | |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 5619 | if (!areTranslucentBarsAllowed() && transWin != mStatusBar) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 5620 | vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT |
| 5621 | | View.SYSTEM_UI_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5622 | } |
| 5623 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5624 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5625 | boolean immersiveSticky = |
| 5626 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5627 | boolean hideStatusBarWM = |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5628 | mTopFullscreenOpaqueWindowState != null && |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5629 | (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5630 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 5631 | boolean hideStatusBarSysui = |
| 5632 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5633 | boolean hideNavBarSysui = |
| 5634 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5635 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5636 | boolean transientStatusBarAllowed = |
| 5637 | mStatusBar != null && ( |
| 5638 | hideStatusBarWM |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5639 | || (hideStatusBarSysui && immersiveSticky) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5640 | || statusBarHasFocus); |
| 5641 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5642 | boolean transientNavBarAllowed = |
| 5643 | mNavigationBar != null && |
| 5644 | hideNavBarSysui && immersiveSticky; |
| 5645 | |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 5646 | boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5647 | && !transientStatusBarAllowed && hideStatusBarSysui; |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 5648 | boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5649 | && !transientNavBarAllowed; |
| 5650 | if (denyTransientStatus || denyTransientNav) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5651 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5652 | clearClearableFlagsLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5653 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5654 | |
| 5655 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 5656 | |
| 5657 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5658 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 5659 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 5660 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5661 | final String pkg = win.getOwningPackage(); |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 5662 | mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode, |
| 5663 | isUserSetupComplete()); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5664 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5665 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5666 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 5667 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5668 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5669 | } |
| 5670 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5671 | private void clearClearableFlagsLw() { |
| 5672 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 5673 | if (newVal != mResettingSystemUiFlags) { |
| 5674 | mResettingSystemUiFlags = newVal; |
| 5675 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 5676 | } |
| 5677 | } |
| 5678 | |
| 5679 | private boolean isImmersiveMode(int vis) { |
| 5680 | 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] | 5681 | return mNavigationBar != null |
| 5682 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 5683 | && (vis & flags) != 0 |
| 5684 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5685 | } |
| 5686 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5687 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 5688 | * @return whether the navigation or status bar can be made translucent |
| 5689 | * |
| 5690 | * This should return true unless touch exploration is not enabled or |
| 5691 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5692 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 5693 | private boolean areTranslucentBarsAllowed() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 5694 | return mTranslucentDecorEnabled |
| 5695 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5696 | } |
| 5697 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 5698 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 5699 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5700 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 5701 | public boolean hasNavigationBar() { |
| 5702 | return mHasNavigationBar; |
| 5703 | } |
| 5704 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5705 | @Override |
| 5706 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 5707 | mLastInputMethodWindow = ime; |
| 5708 | mLastInputMethodTargetWindow = target; |
| 5709 | } |
| 5710 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5711 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 5712 | public int getInputMethodWindowVisibleHeightLw() { |
| 5713 | return mDockBottom - mCurBottom; |
| 5714 | } |
| 5715 | |
| 5716 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5717 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 5718 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5719 | if (mKeyguardDelegate != null) { |
| 5720 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5721 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 5722 | if (mStatusBarService != null) { |
| 5723 | try { |
| 5724 | mStatusBarService.setCurrentUser(newUserId); |
| 5725 | } catch (RemoteException e) { |
| 5726 | // oh well |
| 5727 | } |
| 5728 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5729 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5730 | } |
| 5731 | |
| 5732 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 5733 | public boolean canMagnifyWindow(int windowType) { |
| 5734 | switch (windowType) { |
| 5735 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 5736 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 5737 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 5738 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 5739 | return false; |
| 5740 | } |
| 5741 | } |
| 5742 | return true; |
| 5743 | } |
| 5744 | |
| 5745 | @Override |
| 5746 | public boolean isTopLevelWindow(int windowType) { |
| 5747 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 5748 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 5749 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 5750 | } |
| 5751 | return true; |
| 5752 | } |
| 5753 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 5754 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 5755 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5756 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5757 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 5758 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 5759 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5760 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
| 5761 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5762 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 5763 | || mForceClearedSystemUiFlags != 0) { |
| 5764 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 5765 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 5766 | pw.print(" mResettingSystemUiFlags=0x"); |
| 5767 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 5768 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 5769 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5770 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 5771 | if (mLastFocusNeedsMenu) { |
| 5772 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 5773 | pw.println(mLastFocusNeedsMenu); |
| 5774 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5775 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 5776 | pw.println(mWakeGestureEnabledSetting); |
| 5777 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 5778 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5779 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 5780 | pw.print(" mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5781 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 5782 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 5783 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 5784 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5785 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5786 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5787 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 5788 | pw.print(mCarDockEnablesAccelerometer); |
| 5789 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 5790 | pw.println(mDeskDockEnablesAccelerometer); |
| 5791 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 5792 | pw.print(mLidKeyboardAccessibility); |
| 5793 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5794 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5795 | pw.print(prefix); |
| 5796 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 5797 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
| 5798 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 5799 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 5800 | pw.print(" mScreenOnFully="); pw.print(mScreenOnFully); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5801 | pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 5802 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 5803 | pw.print(","); pw.print(mOverscanScreenTop); |
| 5804 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 5805 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 5806 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 5807 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 5808 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 5809 | pw.print(" top="); pw.print(mOverscanTop); |
| 5810 | pw.print(" right="); pw.print(mOverscanRight); |
| 5811 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 5812 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 5813 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 5814 | pw.print(mRestrictedOverscanScreenLeft); |
| 5815 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 5816 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 5817 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5818 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 5819 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 5820 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 5821 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 5822 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 5823 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 5824 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 5825 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 5826 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 5827 | pw.print(","); pw.print(mStableFullscreenTop); |
| 5828 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 5829 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5830 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 5831 | pw.print(","); pw.print(mStableTop); |
| 5832 | pw.print(")-("); pw.print(mStableRight); |
| 5833 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 5834 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 5835 | pw.print(","); pw.print(mSystemTop); |
| 5836 | pw.print(")-("); pw.print(mSystemRight); |
| 5837 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5838 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 5839 | pw.print(","); pw.print(mCurTop); |
| 5840 | pw.print(")-("); pw.print(mCurRight); |
| 5841 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 5842 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 5843 | pw.print(","); pw.print(mContentTop); |
| 5844 | pw.print(")-("); pw.print(mContentRight); |
| 5845 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5846 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 5847 | pw.print(","); pw.print(mVoiceContentTop); |
| 5848 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 5849 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5850 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 5851 | pw.print(","); pw.print(mDockTop); |
| 5852 | pw.print(")-("); pw.print(mDockRight); |
| 5853 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 5854 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 5855 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5856 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 5857 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
| 5858 | pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5859 | if (mLastInputMethodWindow != null) { |
| 5860 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 5861 | pw.println(mLastInputMethodWindow); |
| 5862 | } |
| 5863 | if (mLastInputMethodTargetWindow != null) { |
| 5864 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 5865 | pw.println(mLastInputMethodTargetWindow); |
| 5866 | } |
| 5867 | if (mStatusBar != null) { |
| 5868 | pw.print(prefix); pw.print("mStatusBar="); |
| 5869 | pw.println(mStatusBar); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5870 | pw.print(prefix); pw.print("isStatusBarKeyguard="); |
| 5871 | pw.print(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5872 | } |
| 5873 | if (mNavigationBar != null) { |
| 5874 | pw.print(prefix); pw.print("mNavigationBar="); |
| 5875 | pw.println(mNavigationBar); |
| 5876 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5877 | if (mFocusedWindow != null) { |
| 5878 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 5879 | pw.println(mFocusedWindow); |
| 5880 | } |
| 5881 | if (mFocusedApp != null) { |
| 5882 | pw.print(prefix); pw.print("mFocusedApp="); |
| 5883 | pw.println(mFocusedApp); |
| 5884 | } |
| 5885 | if (mWinDismissingKeyguard != null) { |
| 5886 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 5887 | pw.println(mWinDismissingKeyguard); |
| 5888 | } |
| 5889 | if (mTopFullscreenOpaqueWindowState != null) { |
| 5890 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 5891 | pw.println(mTopFullscreenOpaqueWindowState); |
| 5892 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5893 | if (mForcingShowNavBar) { |
| 5894 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 5895 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 5896 | pw.println(mForcingShowNavBarLayer); |
| 5897 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5898 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5899 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5900 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 5901 | pw.print(" mForceStatusBarFromKeyguard="); |
| 5902 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5903 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5904 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5905 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 5906 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 5907 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 5908 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 5909 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 5910 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 5911 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 5912 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 5913 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 5914 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 5915 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5916 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 5917 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 5918 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 5919 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 5920 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5921 | mStatusBarController.dump(pw, prefix); |
| 5922 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5923 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 5924 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5925 | if (mWakeGestureListener != null) { |
| 5926 | mWakeGestureListener.dump(pw, prefix); |
| 5927 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 5928 | if (mOrientationListener != null) { |
| 5929 | mOrientationListener.dump(pw, prefix); |
| 5930 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5931 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5932 | } |